From aa13c22813c2a2c00bdcc15bcc55431345c596e2 Mon Sep 17 00:00:00 2001 From: yin fuxian Date: Fri, 12 Apr 2024 15:09:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E5=85=A5=E9=9C=80=E8=A6=81=E5=85=B3?= =?UTF-8?q?=E8=81=94=E9=A1=B9=E7=9B=AE=E7=9A=84=E9=A1=B5=E9=9D=A2=E6=8B=A6?= =?UTF-8?q?=E6=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf-ui/src/permission.js | 17 +++++++++++++++-- sf-ui/src/store/modules/user.js | 9 +++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) 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(); + } } } }