
import { createRouter, createWebHistory } from 'vue-router'
import {hzybRoutes} from './hzyb/index'// 弘则研报小程序路由
import {cygxRoutes} from './cygx/index'// 查研观向小程序路由
import {hzslRoutes} from './hzsl/index'// 弘则思路小程序路由
import { htgjRoutes } from "./htgj/index"; // 海通国际 APP 路由
import { ssbgRoutes } from './ssbg';//随手办公
import store from "@/store";

const routes=[
    ...hzybRoutes,
    ...cygxRoutes,
    ...hzslRoutes,
    ...htgjRoutes,
    ...ssbgRoutes,
    //404
    {
        path: "/:pathMatch(.*)",
        name:"404",
        component: () => import("@/views/Error.vue"),
    },
]

const router = createRouter({
  history: createWebHistory(import.meta.env.VITE_APP_BASE_URL),
  routes,
});

router.beforeEach((to, from, next) => {
  if (to.fullPath.includes("htgj")) {
    let data = {
      CompanyCode: to.query.CompanyCode, //编码
      CompanyName: to.query.CompanyName, // 名称
      Email: to.query.Email, //邮箱
      Sign: to.query.Sign, //签名
    };
    if (!store.state.userData.CompanyCode || !store.state.userData.CompanyName || !store.state.userData.Email || !store.state.userData.Sign) {
      store.commit("getUserData", data);
    }
  }
  next();
});

export default router;
