Files
sora_front/src/router/index.ts
X1627315083 39e3418029 put name
2024-08-30 16:51:08 +08:00

145 lines
3.9 KiB
TypeScript

import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { defineAsyncComponent } from 'vue'
const _import = (path : string) => defineAsyncComponent(() => import(`../views/${path}.vue`));
const _import_custom = (path : string) => defineAsyncComponent(() => import(`../views/${path}`));
import {getCookie} from '@/tool/cookie'
const routes: Array<RouteRecordRaw> = [
{
path: "/",
// redirect重定向
redirect: "/login"
},
{
path: '/login',
name: 'login',
component: _import('LoginPage')
},
{
path: '/noPermission',
name: 'noPermission',
component: _import('NoPermissionPage')
},
{
path: '/home',
name: 'home',
component: _import('HomeView'),
children:[
{
path:'worktable',
name:'worktable',
component: _import_custom('childView/worktable.vue'),
},
{
path:'storemanage',
name:'storeManage',
component: _import_custom('childView/storeManage.vue'),
},
{
path:'labelmanage',
name:'labelManage',
component: _import_custom('childView/labelManage.vue'),
},
{
path:'productmanage',
name:'productManage',
component: _import_custom('childView/productManage.vue'),
},
{
path:'productDetail',
name:'productDetail',
component: _import_custom('childView/productDetail.vue'),
},
{
path:'usermanage',
name:'userManage',
component: _import_custom('childView/systemSetting/userManage.vue'),
},
{
path:'rolemanage',
name:'roleManage',
component: _import_custom('childView/systemSetting/roleManage.vue'),
},
{
path:'exportExcil',
name:'exportExcil',
component: _import_custom('childView/exportExcil.vue'),
},
{
path:'growingThroughLifeTask',
name:'growingThroughLifeTask',
component: _import_custom('childView/growingThroughLife/growingThroughLifeTask.vue'),
},
{
path:'growingThroughLifeList',
name:'growingThroughLifeList',
component: _import_custom('childView/growingThroughLife/growingThroughLifeList.vue'),
},
// {
// path:'excil1',
// name:'excil1',
// component: _import_custom('childView/exportExcil/userManage.vue'),
// },
// {
// path:'excil2',
// name:'excil2',
// component: _import_custom('childView/exportExcil/roleManage.vue'),
// },
]
},
]
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes
})
router.beforeEach((to, from, next) =>{
let routeRoleMap:any = sessionStorage.getItem('menuList')
routeRoleMap = JSON.parse(routeRoleMap) || []
let routeList = ['/login','/home/productDetail','/noPermission']
if(!getCookie('token')){
next()
}
if(routeList.indexOf(to.path) > -1){
next()
}else{
let status = false
let allStatus = false
for(let item of routeRoleMap){
allStatus = item.isShow
if(to.path === item.route && item.isShow){
status = true
break
}
if(item.children && item.children.length){
for(let child of item.children){
allStatus = item.isShow
if(to.path === child.route && child.isShow){
status = true
break
}
}
}
if(status) {
break
}
}
if(!allStatus){
next('/login')
}
if(status){
next()
}else{
next('/noPermission')
}
}
})
export default router