Files
aida_front/src/router/index.ts

110 lines
2.2 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-01-15 17:05:55 +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`));
2023-01-06 16:00:15 +08:00
const routes: Array<RouteRecordRaw> = [
2024-01-05 14:12:03 +08:00
{
path: "/",
// redirect重定向
redirect: "/login"
// redirect: "/Upgrade"
},
{
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')
},
{
path: '/library',
name: 'library',
component: _import('LibraryPage')
},
{
path: '/trialApproval',
name: 'trialApproval',
component: _import('trialApproval')
},
2024-01-15 13:20:53 +08:00
{
path: '/setIdentification',
name: 'setIdentification',
component: _import('setIdentification')
},
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) => {
// // 获取路由配置对象
// const route = router.resolve({ path: '/' }).route
// // 修改重定向
// route.redirect = '/new-path'
// router.addRoute(route)
// next();
// let token = getCookie("token");
// console.log(to,from);
// if(from.path == '/' && !token){
// console.log(111);
// murmur().then((rv)=>{
// console.log(rv);
// if(rv){
// console.log(123123);
// next({ name: 'history' });
// }
// })
// }else{
// console.log(333);
// next()
// }
//系统维护
// const toName = to.name === 'upgrade';
// if (toName) {
// next();
// } else {
// next({ name: 'upgrade' });
// }
//机房用户
let murmurStr:any = localStorage.getItem('murmurStr')
let getIsMurmur:any = getCookie("isMurmur")
let isMurmur = JSON.parse(getIsMurmur)
if(isMurmur&& murmurStr){
const toName = to.name === 'login';
if (toName) {
next({ name: 'home' });
} else {
next();
}
}else{
next();
}
});
2023-01-06 16:00:15 +08:00
export default router