You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.9 KiB
106 lines
2.9 KiB
import {
|
|
createRouter,
|
|
createWebHistory,
|
|
createWebHashHistory,
|
|
} from "vue-router";
|
|
|
|
let routes = [
|
|
{
|
|
path: "/",
|
|
// redirect: "/home",
|
|
redirect: "/enforceHome",
|
|
// redirect: "/login",
|
|
name: "App",
|
|
},
|
|
{
|
|
path: "/:pathMatch(.*)*",
|
|
name: "404",
|
|
component: () => import("@/views/404"),
|
|
},
|
|
];
|
|
|
|
routes = $globalRouterModules(routes); // 加载模块路由
|
|
|
|
// vite base 保持 './',一份包可挂不同目录;这里只决定 Router 前缀
|
|
const getRouterBase = () => {
|
|
const pathname = window.location.pathname;
|
|
if (pathname === "/enforce" || pathname.startsWith("/enforce/")) {
|
|
return "/enforce/";
|
|
}
|
|
if (pathname === "/enterprise" || pathname.startsWith("/enterprise/")) {
|
|
return "/enterprise/";
|
|
}
|
|
return "/";
|
|
};
|
|
|
|
// 业务约定不可改:企业端 Hash(第三方),执法端 History(第三方)
|
|
// 与上面 redirect 切换保持一致:/enforceHome=执法端,/home=企业端
|
|
const createAppHistory = () => {
|
|
const base = getRouterBase();
|
|
const pathname = window.location.pathname;
|
|
// 按 nginx 挂载路径区分
|
|
if (pathname === "/enterprise" || pathname.startsWith("/enterprise/")) {
|
|
return createWebHashHistory(base); // 企业端
|
|
}
|
|
if (pathname === "/enforce" || pathname.startsWith("/enforce/")) {
|
|
return createWebHistory(base); // 执法端
|
|
}
|
|
// 根路径部署:与当前 redirect 一致(现在是执法端)
|
|
// 打企业端包时改 redirect 为 /home,并把下面改成 createWebHashHistory(base)
|
|
return createWebHistory(base);
|
|
};
|
|
|
|
const $globalRouter = createRouter({
|
|
// 企业端
|
|
// history: createWebHashHistory(),
|
|
// 执法端
|
|
// history: createWebHistory(),
|
|
|
|
history: createAppHistory(),
|
|
routes,
|
|
});
|
|
|
|
$globalExpandRouter($globalRouter, routes); // 添加路由扩展
|
|
|
|
$globalRouter.beforeEach((to, from, next) => {
|
|
// let pattern3 = new RegExp("^[0-9]*$");
|
|
// if (null != to.query) {
|
|
// for (let key in to.query) {
|
|
// if (pattern3.test(to.query[key])) {
|
|
// if (to.query[key].toString().lengeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeth > 9) {
|
|
// console.log(to.query[key])
|
|
// to.query[key] = 0;
|
|
// console.log(to.query[key])
|
|
// }
|
|
// } else {
|
|
// if (to.query[key].toString().length > 33) {
|
|
// to.query[key] = "";
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// if (null != to.params) {
|
|
// for (let key in to.params) {
|
|
// if (pattern3.test(to.params[key])) {
|
|
// if (to.params[key].toString().length > 9) {
|
|
// to.params[key] = 0;
|
|
// }
|
|
// } else {
|
|
// if (to.params[key].toString().length > 33) {
|
|
// to.params[key] = "";
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// if (to.path.includes('src')) {
|
|
// // 可以重定向或者做其他处理
|
|
// next('/'); // 或者 next(from.path) 返回之前的路径
|
|
// } else {
|
|
// next(); // 允许路由继续
|
|
// }
|
|
next(); // 允许路由继续
|
|
});
|
|
|
|
export { $globalRouter };
|
|
|