进入需要关联项目的页面拦截

This commit is contained in:
yin fuxian 2024-04-12 15:09:52 +08:00
parent 2efac23978
commit aa13c22813
2 changed files with 22 additions and 4 deletions

View File

@ -5,10 +5,12 @@ import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth'
import { isRelogin } from '@/utils/request'
import { getApplicationId } from './utils/application'
NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/register']
const needApplicationList = ['/build/installationList', '/build/whiteListManagement', '/build/publish']
router.beforeEach((to, from, next) => {
NProgress.start()
@ -25,7 +27,9 @@ router.beforeEach((to, from, next) => {
store.dispatch('GetInfo').then(() => {
isRelogin.show = false
if (to.path === '/index') {
next()
next();
} else if (checkApplication(to.path)) {
next({ path: '/' })
} else {
store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
@ -40,7 +44,12 @@ router.beforeEach((to, from, next) => {
})
})
} else {
next()
if (checkApplication(to.path)) {
next({ path: '/' })
NProgress.done()
} else {
next()
}
}
}
} else {
@ -55,6 +64,10 @@ router.beforeEach((to, from, next) => {
}
})
function checkApplication(path) {
return needApplicationList.includes(path) && !getApplicationId();
}
router.afterEach(() => {
NProgress.done()
})

View File

@ -31,7 +31,7 @@ const user = {
},
SET_APPLICATION: (state, applicationInfo) => {
const { id } = applicationInfo;
state.applicationId = id;
state.applicationId = id || '';
state.applicationInfo = applicationInfo;
},
},
@ -106,7 +106,12 @@ const user = {
// 设置选中的项目应用信息
SetApplication({ commit }, applicationInfo) {
commit('SET_APPLICATION', applicationInfo)
setApplicationId(applicationInfo?.id);
const { id } = applicationInfo || {};
if (id) {
setApplicationId(applicationInfo.id);
} else {
removeApplicationId();
}
}
}
}