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

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

View File

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

View File

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