Files
aida_front/src/router/index.ts

233 lines
5.3 KiB
TypeScript
Raw Normal View History

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-06-17 09:39:01 +08:00
import store from "@/store"
2024-02-19 10:33:54 +08:00
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-21 10:49:21 +08:00
const _import_component = (path : string) => defineAsyncComponent(() => import(`../component/${path}`));
const _import_custom = (path : string) => defineAsyncComponent(() => import(`../views/${path}`));
2023-01-06 16:00:15 +08:00
const routes: Array<RouteRecordRaw> = [
2024-01-05 14:12:03 +08:00
{
path: "/",
// redirect重定向
2024-06-01 10:02:21 +08:00
// redirect: "/login"
2024-07-09 09:29:58 +08:00
redirect: "/upgrade"
// name: "HomeRecommend",
// component: _import('HomeRecommend'),
2024-01-05 14:12:03 +08:00
},
{
path: '/login',
name: 'login',
component: _import('LoginPage')
},
2024-06-27 22:23:28 +08:00
// {
// path: '/register',
// name: 'register',
// component: _import('RegisterPage')
// },
2024-01-05 14:12:03 +08:00
{
path: '/upgrade',
name: 'upgrade',
component: _import('Upgrade'),
},
2024-03-21 10:49:21 +08:00
// {
// path: '/home',
// name: 'home',
// component: _import('HomeView')
// },
2024-01-05 14:12:03 +08:00
{
path: '/home',
name: 'home',
2024-03-21 10:49:21 +08:00
component: _import('HomeMain'),
2024-04-15 16:09:33 +08:00
meta:{keepAlive:true},
2024-03-21 10:49:21 +08:00
children:[
{
path: "",
2024-06-01 10:02:21 +08:00
name:'""',
2024-03-21 10:49:21 +08:00
redirect: "home/homePage"
},
{
path:'homePage',
name:'homePage',
component: _import_custom('HomeView/HomeView.vue'),
2024-04-15 16:09:33 +08:00
meta:{keepAlive:true},
},{
2024-03-21 10:49:21 +08:00
path:'library',
name:'library',
component: _import_custom('HomeView/library.vue'),
},{
path:'history',
name:'history',
component: _import_custom('HomeView/history.vue'),
2024-05-09 13:34:15 +08:00
},{
path:'works',
name:'works',
component: _import_custom('HomeView/Works.vue'),
2024-03-21 10:49:21 +08:00
},
]
2024-01-05 14:12:03 +08:00
},
{
path: '/demo',
name: 'demo',
component: _import('Demo')
},
2024-03-21 10:49:21 +08:00
// {
// path: '/history',
// name: 'history',
// component: _import('history')
// },
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',
2024-03-21 10:49:21 +08:00
component: _import_component('Administrator/allUser.vue'),
2024-03-08 16:51:24 +08:00
},
{
path:'testClickData',
name:'testClickData',
2024-03-21 10:49:21 +08:00
component: _import_component('Administrator/TestClickData.vue'),
2024-03-08 16:51:24 +08:00
},
{
path:'trialApproval',
name:'trialApproval',
2024-03-21 10:49:21 +08:00
component: _import_component('Administrator/trialApproval.vue'),
2024-03-08 16:51:24 +08:00
},
]
2024-03-05 10:33:29 +08:00
},
2024-02-19 15:30:49 +08:00
{
path: '/paySucceed',
name: 'paySucceed',
component: _import('paySucceed')
},
2024-03-21 10:49:21 +08:00
// {
// path: '/library',
// name: 'library',
// component: _import('library')
// },
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-06-18 10:45:15 +08:00
{
path: '/feedbackSurvey',
name: 'feedbackSurvey',
component: _import('feedbackSurvey'),
},
2024-06-20 10:36:45 +08:00
{
path: '/feedbackSurveyCN',
name: 'feedbackSurveyCN',
component: _import('feedbackSurveyCN'),
},
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-06-17 09:39:01 +08:00
// 刷新保存数据-
let state:any = store.state
window.addEventListener("beforeunload", (e) => {
sessionStorage.setItem(
"vuex_setSystemUser",
JSON.stringify(state.UserHabit.systemUser.value)
);
});
var vuex_setSystemUser:any = sessionStorage.getItem("vuex_setSystemUser");
if (vuex_setSystemUser == 0 || vuex_setSystemUser == 1) {
store.commit("setSystemUser", JSON.parse(vuex_setSystemUser));
sessionStorage.removeItem("vuex_setSystemUser");
}
2024-01-15 17:05:55 +08:00
router.beforeEach((to, from, next) => {
2024-03-28 13:44:05 +08:00
2024-02-19 10:33:54 +08:00
// 系统维护
let upgradeList = ['/feedbackSurvey','/feedbackSurveyCN']//指定页面系统维护也可以访问
2024-07-09 09:29:58 +08:00
const toName = to.name === 'upgrade';
if(upgradeList.indexOf(to.path) > -1){
2024-07-09 09:29:58 +08:00
next();
}else{
if (toName) {
next();
} else {
next({ name: 'upgrade' });
}
2024-07-09 09:29:58 +08:00
}
return
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)
let routeList = ['/testClickData','/trialApproval']//指定页面需要指定id才能进入
let userIdList = [88,6,46,31,73,83,87]
let isSystemUserRouteList = ['/login','/']//指定页面
2024-06-17 09:39:01 +08:00
let systemUser = state.UserHabit.systemUser
2024-02-19 10:33:54 +08:00
const routeExists = router.getRoutes().some(({ name }) =>{
if(name){
2024-03-15 09:21:17 +08:00
return name === to.name
2024-02-19 10:33:54 +08:00
}else{
return false
}
});
2024-06-17 09:39:01 +08:00
if(systemUser.value == 0){
if(isSystemUserRouteList.indexOf(to.path) > -1){
next();
}else{
next('/');
}
return
}
2024-03-04 10:04:00 +08:00
if (routeExists) {
if (isMurmur && murmurStr && token) {
const toName = to.name === 'login';
if (toName) {
2024-04-19 13:09:14 +08:00
next({ name: '/homePage' });
2024-03-04 10:04:00 +08:00
} else {
2024-02-19 10:33:54 +08:00
next();
2024-03-04 10:04:00 +08:00
}
} else {
if (routeList.indexOf(to.path) > -1 ) {
2024-03-05 10:33:29 +08:00
if(userIdList.indexOf(userInfo.userId) > -1){
next();
}else{
2024-03-15 09:21:17 +08:00
next({ name: '/404' });
}
}else{
2024-03-04 10:04:00 +08:00
next();
}
// 如果页面存在,正常跳转
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