Files
aida_front/src/router/index.ts

406 lines
10 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-09-13 14:36:38 +08:00
import { Https } from "@/tool/https";
2024-02-19 10:33:54 +08:00
import { getCookie, setCookie } from "@/tool/cookie";
const _import = (path: string) => () => import(`../views/${path}.vue`);
const _import_component = (path : string) => () => import(`../component/${path}`);
const _import_custom = (path : string) => () => import(`../views/${path}`);
// defineAsyncComponent(import(`../views/${path}.vue`))
2023-01-06 16:00:15 +08:00
const routes: Array<RouteRecordRaw> = [
2024-01-05 14:12:03 +08:00
{
path: "/",
// redirect重定向
2024-10-20 09:31:32 +08:00
// redirect: "/Square"
redirect: "/upgrade"
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'),
children:[
{
path: "",
name:'HomeChil',
redirect: "/home/homePage"
2024-03-21 10:49:21 +08:00
},
{
path:'homePage',
name:'homePage',
component: _import_custom('HomeView/HomeView.vue'),
2024-04-15 16:09:33 +08:00
},{
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'),
},{
path:'events',
name:'events',
component: _import_custom('HomeView/Events.vue'),
},{
path:'eventsDetail',
name:'eventsDetail',
component: _import_component('Events/eventsDetail.vue'),
2024-08-05 16:16:08 +08:00
},{
path:'account',
name:'account',
component: _import_component('Account/account.vue'),
children:[
{
path: "",
name:'accountChil',
redirect: "/home/account/accountHome"
},
{
path:'accountHome',
name:'accountHome',
component: _import_component('Account/accountHome.vue'),
},
{
path:'accountEdit',
name:'accountEdit',
component: _import_component('Account/accountEdit.vue'),
},
{
path:'accountMessage',
name:'accountMessage',
component: _import_component('Account/accountMessage.vue'),
},
{
path:'accountFollowFans',
name:'accountFollowFans',
component: _import_component('Account/accountFollowFans.vue'),
}
]
2024-08-13 09:36:13 +08:00
},{
path:'otherUsers',
name:'otherUsers',
component: _import_component('Account/otherUsers.vue'),
}
]
},
{
path: '/Square',
name: "HomeRecommend",
component: _import('HomeRecommend'),
children:[
{
path: "",
name:'SquareChil',
redirect: "/Square/works"
2024-03-21 10:49:21 +08:00
},
{
path:'works',
name:'SquareWorks',
component: _import_custom('HomeView/Works.vue'),
},{
path:'events',
name:'SquareEvents',
component: _import_custom('HomeView/Events.vue'),
},{
path:'eventsDetail',
name:'SquareEventsDetail',
component: _import_component('Events/eventsDetail.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: "",
name:'adminChil',
redirect: "/administrator/allUser"
},
2024-03-08 16:51:24 +08:00
{
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'),
},{
path:'questionnaire',
name:'questionnaire',
component: _import_component('Administrator/questionnaire.vue'),
2024-08-05 16:15:43 +08:00
},{
path:'recentActiveChart',
name:'recentActiveChart',
component: _import_component('Administrator/recentActiveChart.vue'),
},{
path:'recentActiveUser',
name:'recentActiveUser',
component: _import_component('Administrator/recentActiveUser.vue'),
},{
path:'recentActiveUserChart',
name:'recentActiveUserChart',
component: _import_component('Administrator/recentActiveUserChart.vue'),
},{
path:'recentNewUser',
name:'recentNewUser',
component: _import_component('Administrator/recentNewUser.vue'),
},{
path:'recentNewUserChart',
name:'recentNewUserChart',
component: _import_component('Administrator/recentNewUserChart.vue'),
},{
path:'trialUserCountry',
name:'trialUserCountry',
component: _import_component('Administrator/trialUserCountry.vue'),
},{
path:'trialUserConversionRateChart',
name:'trialUserConversionRateChart',
component: _import_component('Administrator/trialUserConversionRateChart.vue'),
},{
path:'trialAllUser',
name:'trialAllUser',
component: _import_component('Administrator/trialAllUser.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-09-26 15:43:27 +08:00
{
path: '/emailVerify',
name: 'emailVerify',
component: _import('emailVerify'),
},
2024-02-19 10:33:54 +08:00
{
path: '/404',
name: '404',
component: _import('404')
},
2024-09-26 15:43:27 +08:00
{
path: "/:catchAll(.*)",
redirect: "/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) => {
2024-08-23 10:19:02 +08:00
localStorage.setItem(
2024-06-17 09:39:01 +08:00
"vuex_setSystemUser",
JSON.stringify(state.UserHabit.systemUser.value)
);
2024-08-23 10:19:02 +08:00
localStorage.setItem(
"vuex_setUserInfo",
JSON.stringify(state.UserHabit.userInfo)
);
2024-06-17 09:39:01 +08:00
});
2024-08-23 10:19:02 +08:00
var vuex_setSystemUser:any = localStorage.getItem("vuex_setSystemUser");
var vuex_setUserInfo:any = localStorage.getItem("vuex_setUserInfo");
2024-06-17 09:39:01 +08:00
if (vuex_setSystemUser == 0 || vuex_setSystemUser == 1) {
store.commit("setSystemUser", JSON.parse(vuex_setSystemUser));
2024-08-23 10:19:02 +08:00
localStorage.removeItem("vuex_setSystemUser");
}
if (vuex_setUserInfo) {
store.commit("setUserInfo", JSON.parse(vuex_setUserInfo));
localStorage.removeItem("vuex_setSystemUser");
2024-06-17 09:39:01 +08:00
}
2024-09-13 14:36:38 +08:00
let setMurmur = (id:any)=> {
let murmurStr: any = localStorage.getItem('murmurStr')
// let isSxis = false
let data = {
browserIdentifiers: murmurStr,
id:id
}
if(data.id){
Https.axiosPost(Https.httpUrls.noLoginRequired, data)
.then((rv) => {
let isTest = rv.systemUser == 3 ? true : false
let isBeginner = rv.isBeginner == 1 ? true : false
setCookie("isMurmur", true);
setCookie("token", rv.token);
setCookie("isTest", isTest);
setCookie("isBeginner", isBeginner);
setCookie("isBeginnerNum", 0);//从第一步开始,机器人开始的话就是从第二部开始
setCookie("userInfo", JSON.stringify(rv));
sessionStorage.setItem('isTimeOne', JSON.stringify(false));//是否需要公告 提示 弹窗
let randomNum: any = Math.floor(Math.random() * 9000000000000000) + 1000000000000000;
sessionStorage.setItem('sessionId', randomNum);
router.push("/home");
})
.catch((res) => {
// router.push('/Square')
});
}
}
router.beforeEach((to:any, from, next) => {
2024-09-26 15:43:27 +08:00
let upgradeList = ['/feedbackSurvey','/feedbackSurveyCN','emailVerify']//指定页面系统维护也可以访问
2024-03-28 13:44:05 +08:00
2024-10-21 10:59:24 +08:00
// // 系统维护
// const toName = to.name === 'upgrade';
// if(upgradeList.indexOf(to.path) > -1){
// next();
// }else{
// if (toName) {
// next();
// } else {
// next({ name: 'upgrade' });
// }
// }
// return
2024-02-19 10:33:54 +08:00
// 检查路由是否存在
2024-01-26 09:51:36 +08:00
// 机房用户
2024-09-13 14:36:38 +08:00
let herfData = window.location.search.substring(1)
if(herfData.split('=')[0] == 'noLogin' && to.name != 'homePage'){
setMurmur(herfData.split('=')[1])
2024-09-25 15:16:02 +08:00
// console.log(`-------------------成功${herfData.split('=')[1]}-------------------`)
2024-09-13 14:36:38 +08:00
return
}
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,4]
let isSystemUserRouteList = ['/login','/Square']//游客用户只能进入这两个页面
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-09-13 14:36:38 +08:00
return (name === to.name || to.path == '/')
2024-02-19 10:33:54 +08:00
}else{
return false
}
});
if(upgradeList.indexOf(to.path) > -1){//指定页面任何用户都可以进入
next();
return
}
if(systemUser.value == 0){//游客用户只能进入这两个页面
let sSystemUser = false
for (let index = 0; index < isSystemUserRouteList.length; index++) {
if(to.path.indexOf(isSystemUserRouteList[index]) > -1){
sSystemUser = true
break
}
}
if(sSystemUser){
2024-06-17 09:39:01 +08:00
next();
}else{
next('/Square');
2024-06-17 09:39:01 +08:00
}
return
}
2024-09-26 15:43:27 +08:00
if (isMurmur && murmurStr && token) {
const toName = to.name === 'login';
if (toName) {
return next({ name: '/home' });//机房用户
}
} else {
if (routeList.indexOf(to.path) > -1 ) {//指定也买你必须指定用户可以进入
if(userIdList.indexOf(userInfo.userId) > -1){
}else{
2024-09-26 15:43:27 +08:00
return next({ name: '/404' });
2024-03-04 10:04:00 +08:00
}
}
2024-09-26 15:43:27 +08:00
// 如果页面存在,正常跳转
2024-03-04 10:04:00 +08:00
}
2024-09-26 15:43:27 +08:00
next();
// if (routeExists) {//检测档期那页面是否存在
// } else {
// // 如果页面不存在可以跳转到404页面或者其他页面
// next('/404');
// }
2024-02-19 10:33:54 +08:00
2024-01-15 17:05:55 +08:00
});
2024-09-13 14:36:38 +08:00
2023-01-06 16:00:15 +08:00
export default router