diff --git a/sf-ui/src/permission.js b/sf-ui/src/permission.js index 4af59ff..73fd6bf 100644 --- a/sf-ui/src/permission.js +++ b/sf-ui/src/permission.js @@ -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() }) diff --git a/sf-ui/src/store/modules/user.js b/sf-ui/src/store/modules/user.js index 7b8ffd8..a53c413 100644 --- a/sf-ui/src/store/modules/user.js +++ b/sf-ui/src/store/modules/user.js @@ -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(); + } } } }