2023-09-12 10:11:27 +08:00
|
|
|
|
import { createRouter, createWebHistory, RouteRecordRaw, createWebHashHistory } from 'vue-router'
|
2023-01-06 16:00:15 +08:00
|
|
|
|
import { defineAsyncComponent } from 'vue'
|
2024-02-19 10:33:54 +08:00
|
|
|
|
import { getBrowserInfo, murmur } from '@/tool/util'
|
|
|
|
|
|
import { getCookie, setCookie } from "@/tool/cookie";
|
2024-01-05 14:12:03 +08:00
|
|
|
|
const _import = (path: string) => defineAsyncComponent(() => import(`../views/${path}.vue`));
|
2024-03-08 16:51:24 +08:00
|
|
|
|
const _import_custom = (path : string) => defineAsyncComponent(() => import(`../component/${path}`));
|
2023-01-06 16:00:15 +08:00
|
|
|
|
|
|
|
|
|
|
const routes: Array<RouteRecordRaw> = [
|
2024-01-05 14:12:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
path: "/",
|
|
|
|
|
|
// redirect重定向
|
|
|
|
|
|
redirect: "/login"
|
2024-03-04 16:35:32 +08:00
|
|
|
|
// redirect: "/upgrade"
|
2024-01-05 14:12:03 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
path: '/login',
|
|
|
|
|
|
name: 'login',
|
|
|
|
|
|
component: _import('LoginPage')
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
path: '/upgrade',
|
|
|
|
|
|
name: 'upgrade',
|
|
|
|
|
|
component: _import('Upgrade'),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
path: '/home',
|
|
|
|
|
|
name: 'home',
|
|
|
|
|
|
component: _import('HomeView')
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
path: '/demo',
|
|
|
|
|
|
name: 'demo',
|
|
|
|
|
|
component: _import('Demo')
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
path: '/history',
|
|
|
|
|
|
name: 'history',
|
|
|
|
|
|
component: _import('HistoryPage')
|
|
|
|
|
|
},
|
2024-03-08 16:51:24 +08:00
|
|
|
|
// {
|
|
|
|
|
|
// path: '/testClickData',
|
|
|
|
|
|
// name: 'testClickData',
|
|
|
|
|
|
// component: _import('TestClickData')
|
|
|
|
|
|
// },
|
2024-03-05 10:33:29 +08:00
|
|
|
|
{
|
2024-03-08 16:51:24 +08:00
|
|
|
|
path: '/administrator',
|
|
|
|
|
|
name: 'administrator',
|
|
|
|
|
|
component: _import('Administrator'),
|
|
|
|
|
|
children:[
|
|
|
|
|
|
{
|
|
|
|
|
|
path:'allUser',
|
|
|
|
|
|
name:'allUser',
|
|
|
|
|
|
component: _import_custom('Administrator/allUser.vue'),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
path:'testClickData',
|
|
|
|
|
|
name:'testClickData',
|
|
|
|
|
|
component: _import_custom('Administrator/TestClickData.vue'),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
path:'trialApproval',
|
|
|
|
|
|
name:'trialApproval',
|
|
|
|
|
|
component: _import_custom('Administrator/trialApproval.vue'),
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
2024-03-05 10:33:29 +08:00
|
|
|
|
},
|
2024-02-19 10:33:54 +08:00
|
|
|
|
// {//老版本history
|
2024-02-19 09:48:03 +08:00
|
|
|
|
// path: '/oldHistory',
|
|
|
|
|
|
// name: 'oldHistory',
|
|
|
|
|
|
// component: _import('OldHistoryPage')
|
|
|
|
|
|
// },
|
2024-02-19 15:30:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
path: '/paySucceed',
|
|
|
|
|
|
name: 'paySucceed',
|
|
|
|
|
|
component: _import('paySucceed')
|
|
|
|
|
|
},
|
2024-01-05 14:12:03 +08:00
|
|
|
|
{
|
|
|
|
|
|
path: '/library',
|
|
|
|
|
|
name: 'library',
|
|
|
|
|
|
component: _import('LibraryPage')
|
|
|
|
|
|
},
|
2024-03-08 16:51:24 +08:00
|
|
|
|
// {
|
|
|
|
|
|
// path: '/trialApproval',
|
|
|
|
|
|
// name: 'trialApproval',
|
|
|
|
|
|
// component: _import('trialApproval')
|
|
|
|
|
|
// },
|
2024-01-15 13:20:53 +08:00
|
|
|
|
{
|
|
|
|
|
|
path: '/setIdentification',
|
|
|
|
|
|
name: 'setIdentification',
|
|
|
|
|
|
component: _import('setIdentification')
|
|
|
|
|
|
},
|
2024-02-19 10:33:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
path: '/404',
|
|
|
|
|
|
name: '404',
|
|
|
|
|
|
component: _import('404')
|
|
|
|
|
|
},
|
2023-01-06 16:00:15 +08:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
2024-01-05 14:12:03 +08:00
|
|
|
|
history: createWebHistory(process.env.BASE_URL),
|
|
|
|
|
|
// history: createWebHashHistory(),
|
|
|
|
|
|
routes
|
2023-01-06 16:00:15 +08:00
|
|
|
|
})
|
2024-01-15 17:05:55 +08:00
|
|
|
|
router.beforeEach((to, from, next) => {
|
2024-02-19 10:33:54 +08:00
|
|
|
|
// 系统维护
|
2024-01-26 09:51:36 +08:00
|
|
|
|
// const toName = to.name === 'upgrade';
|
|
|
|
|
|
// if (toName) {
|
2024-01-25 17:15:20 +08:00
|
|
|
|
// next();
|
2024-01-26 09:51:36 +08:00
|
|
|
|
// } else {
|
|
|
|
|
|
// next({ name: 'upgrade' });
|
2024-01-25 17:15:20 +08:00
|
|
|
|
// }
|
2024-02-19 10:33:54 +08:00
|
|
|
|
// 检查路由是否存在
|
2024-01-26 09:51:36 +08:00
|
|
|
|
// 机房用户
|
2024-03-05 10:33:29 +08:00
|
|
|
|
let userInfo = JSON.parse(getCookie("userInfo") as any);
|
2024-02-19 10:33:54 +08:00
|
|
|
|
let murmurStr: any = localStorage.getItem('murmurStr')
|
|
|
|
|
|
let getIsMurmur: any = getCookie("isMurmur")
|
2024-01-26 09:51:36 +08:00
|
|
|
|
let token = getCookie("token");
|
|
|
|
|
|
let isMurmur = JSON.parse(getIsMurmur)
|
2024-03-08 11:19:33 +08:00
|
|
|
|
let routeList = ['/testClickData','/trialApproval']//指定页面需要指定id才能进入
|
|
|
|
|
|
let userIdList = [83,88,6]
|
2024-02-19 10:33:54 +08:00
|
|
|
|
const routeExists = router.getRoutes().some(({ name }) =>{
|
|
|
|
|
|
if(name){
|
2024-03-08 16:51:24 +08:00
|
|
|
|
console.log(name , to.name);
|
|
|
|
|
|
return name === to.name
|
2024-02-19 10:33:54 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2024-03-08 16:51:24 +08:00
|
|
|
|
|
2024-03-04 10:04:00 +08:00
|
|
|
|
if (routeExists) {
|
|
|
|
|
|
if (isMurmur && murmurStr && token) {
|
|
|
|
|
|
const toName = to.name === 'login';
|
|
|
|
|
|
if (toName) {
|
|
|
|
|
|
next({ name: 'home' });
|
|
|
|
|
|
} else {
|
2024-02-19 10:33:54 +08:00
|
|
|
|
next();
|
2024-03-04 10:04:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2024-03-08 11:19:33 +08:00
|
|
|
|
if (routeList.indexOf(to.path) > -1 ) {
|
2024-03-05 10:33:29 +08:00
|
|
|
|
|
2024-03-08 11:19:33 +08:00
|
|
|
|
if(userIdList.indexOf(userInfo.userId) > -1){
|
|
|
|
|
|
next();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
next({ name: 'home' });
|
|
|
|
|
|
}
|
|
|
|
|
|
}else{
|
2024-03-04 10:04:00 +08:00
|
|
|
|
next();
|
|
|
|
|
|
}
|
2024-03-08 11:19:33 +08:00
|
|
|
|
// 如果页面存在,正常跳转
|
2024-03-04 10:04:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果页面不存在,可以跳转到404页面或者其他页面
|
|
|
|
|
|
next('/404');
|
|
|
|
|
|
}
|
2024-02-19 10:33:54 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-01-15 17:05:55 +08:00
|
|
|
|
});
|
2023-01-06 16:00:15 +08:00
|
|
|
|
export default router
|