Files
mosr-web/src/router/index.js

201 lines
6.8 KiB
JavaScript

import {createRouter, createWebHistory} from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import Layout from '@/layout/index.vue'
import {getToken} from '../utils/auth'
import {usePermisstionStroe} from '@/stores/permisstion.js'
import {useAuthStore} from '@/stores/userstore.js'
NProgress.configure({showSpinner: false})
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/login',
name: 'login',
component: () => import('@/views/login/index.vue'),
meta: {
hidden: true,
title: '登录'
}
},
{
path: '/cas/login',
name: 'casLogin',
component: () => import('@/views/cas-login/index.vue'),
},
{
path: '/projectdetail/mobile',
name: 'projectDetailMobile',
component: () => import('@/views/project-management/mobledetail/index.vue')
},
{
path: '/fund/mobile',
name: 'specialFundDetailMobile',
component: () => import('@/views/project-management/mobledetail/SpecialFundDetailMobile.vue')
},
{
path: '/share/mobile',
name: 'shareDetailMobile',
component: () => import('@/views/project-management/mobledetail/ShareDetailMobile.vue')
},
{
path: '/projectDemand/requirement/moblie',
name: 'projectDemandRequirementMoblie',
component: () => import('@/views/project-demand/requirement/moblieDetail/index.vue')
},
{
path: '/expenseManagement/share/moblie',
name: 'expenseManagementMoblie',
component: () => import('@/views/expense-management/share/moblieDetail/index.vue')
},
{
path: '/phase/detail/moblie',
name: 'phaseDetailMoblie',
component: () => import('@/views/project-management/phaseDetailMoblie/index.vue')
},
{
path: '/',
name: 'layout',
component: Layout,
redirect: '/home',
meta: {
hidden: false
},
children: [
{
path: '/home',
name: 'home',
component: () => import('@/views/home/index.vue'),
meta: {
title: '首页',
breadcrumb: true
}
},
{
path: '/auth',
name: 'auth',
component: () => import('@/views/auth/index.vue'),
meta: {
title: '个人中心',
breadcrumb: true
}
},
{
path: '/workflow/process/edit/:deploymentId',
name: 'processEdit',
component: () => import('@/views/workflow/process/ProcessEdit.vue'),
meta: {
title: '编辑流程',
breadcrumb: true
}
},
{
path: '/workflow/process',
name: 'process',
component: () => import('@/views/workflow/process/index.vue'),
meta: {
title: '流程管理',
breadcrumb: true
}
},
{
path: '/workflow/process/add',
name: 'processAdd',
component: () => import('@/views/workflow/process/ProcessEdit.vue'),
meta: {
title: '新增流程',
breadcrumb: true
}
},
{
path: '/role-auth/user/:roleId(\\d+)/:roleName',
name: 'distribute',
component: () => import('@/views/system/role/DistributeUser.vue'),
meta: {
title: '角色分配用户',
breadcrumb: true
}
},
{
path: '/post-auth/user/:postId(\\d+)/:postName',
name: 'assignUser',
component: () => import('@/views/system/post/DistributeUser.vue'),
meta: {
title: '岗位分配用户',
breadcrumb: true
}
},
{
path: '/menu-auth/role/:menuId(\\d+)/:menuName',
name: 'assignRole',
component: () => import('@/views/system/menu/DistributeRole.vue'),
meta: {
title: '菜单分配角色',
breadcrumb: true
}
},
{
path: '/system/notice/inform/index/:queryId',
name: 'notify',
component: () => import('@/views/system/notice/inform/index.vue'),
meta: {
title: '通知公告',
breadcrumb: false
}
},
]
},
{
path: '/forbidden',
name: 'forbidden',
component: () => import('@/views/forbidden/index.vue'),
}
]
})
router.beforeEach(async (to, form, next) => {
const permisstionStore = usePermisstionStroe()
const authStore = useAuthStore()
NProgress.start()
if (!getToken()) {
if (to.path === '/login' || to.path === '/cas/login' || to.path === '/forbidden') {
next()
NProgress.done()
} else {
let path = window.location.pathname;
let query = window.location.search
sessionStorage.setItem('toView', JSON.stringify({
path: path,
query: query
}))
window.location.href = `${window.location.origin}/api/auth/cas/login`
// next({path: '/api/auth/cas/login'})
}
} else {
if (to.path === '/login' || to.path === '/cas/login') {
next('/')
NProgress.done()
} else {
permisstionStore.setIsLoadRoutes(true)
if (permisstionStore.isLoadRoutes && !permisstionStore.isSussessReq) {
await permisstionStore.setAsyncRouters()
await authStore.setUserInfo()
next({...to, replace: true})
} else {
next()
}
}
}
})
router.afterEach(() => {
NProgress.done()
})
export default router