From 0e1dcbb5fd09f0313e533fa0c759626cc0552fd4 Mon Sep 17 00:00:00 2001 From: fan Date: Thu, 13 Apr 2023 16:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=96=B0=E9=A1=B5=E9=9D=A2baseUrl?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E9=94=99=E8=AF=AF=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 4 ++- src/permission.js | 66 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/App.vue b/src/App.vue index 9bfa07c06..82e28f4bf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -93,6 +93,9 @@ export default { if (this.project !== this.$store.state.projectConfig.markKey) { this.initFrontProjectConfig(); } + }, + '$store.state.projectConfig.markKey': function(val) { + if (val) { this.loadingComponent = true; } } }, mounted() { @@ -121,7 +124,6 @@ export default { methods: { initFrontProjectConfig() { getFrontProjectConfigByLogin(this.project).then(resp => { - this.loadingComponent = true; const urlData = handlerUrl(); const { baseApiUrl, baseSite, ossUrl, loginProLogo, browserTitle} = resp.data.viewSetting; this.$store.dispatch('setBaseUrl', baseApiUrl || urlData.BASE_API); diff --git a/src/permission.js b/src/permission.js index 8ea0856d1..af8fef76d 100644 --- a/src/permission.js +++ b/src/permission.js @@ -4,14 +4,16 @@ import router from './router/index'; import NProgress from 'nprogress'; import 'nprogress/nprogress.css'; import { setToken, getToken, getSessionStorage, setSessionStorage } from '@/utils/auth'; +import { getFrontProjectConfigByLogin} from '@/api/projectConfig'; import localStore from 'storejs'; +import { handlerUrl } from '@/utils/baseUrl'; const whiteList = ['/login', '/design/login', '/loginNew', '/gzzbxy/relay', '/authorization', '/AUSline', '/AUStool', '/demo', '/thirdLogin']; // 不重定向白名单 // 登录路径判断获取 function getRouteInfo(to) { let loginPath = ''; - const markKey = store.state.projectConfig.markKey; + const markKey = store.state.projectConfig.markKey || getSessionStorage('project'); loginPath = markKey == 'login' ? '/login' : '/login?project=' + markKey; if (to.query.projectDevice && to.query.type && loginPath.includes('?')) { loginPath = `${loginPath}&projectDevice=${to.query.projectDevice}&type=${to.query.type}`; @@ -21,30 +23,52 @@ function getRouteInfo(to) { return loginPath; } -function handleRoute(to, next, loginPath) { - if (store.getters.roles.length == 0) { - store.dispatch('GetInfo', getToken()).then(res => { - // 根据roles权限生成可访问的路由表 - // const roles = res.roles; - store.dispatch('GenerateRoutes', res).then(() => { - router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表 - if (to.redirectedFrom) { - next({ path: to.redirectedFrom, replace: true }); - } else { - next({ ...to, replace: true }); - } - }); - - }).catch(() => { - store.dispatch('FedLogOut').then(() => { - Vue.prototype.$messageBox('验证失败,请重新登录!'); - next({ path: loginPath }); - }); +function getInfoAndGenerateRoutes(to, next, loginPath) { + store.dispatch('GetInfo', getToken()).then(res => { + // 根据roles权限生成可访问的路由表 + // const roles = res.roles; + store.dispatch('GenerateRoutes', res).then(() => { + router.addRoutes(store.getters.addRouters); // 动态添加可访问路由表 + if (to.redirectedFrom) { + next({ path: to.redirectedFrom, replace: true }); + } else { + next({ ...to, replace: true }); + } }); + + }).catch(() => { + store.dispatch('FedLogOut').then(() => { + Vue.prototype.$messageBox('验证失败,请重新登录!'); + next({ path: loginPath }); + }); + }); +} + +function handleRoute(to, next, loginPath) { + const project = getSessionStorage('project'); + if (store.getters.roles.length == 0) { + if (!store.state.projectConfig.markKey) { + getFrontProjectConfigByLogin(project).then(resp => { + const urlData = handlerUrl(); + const { baseApiUrl, baseSite, ossUrl, loginProLogo, browserTitle} = resp.data.viewSetting; + store.dispatch('setBaseUrl', baseApiUrl || urlData.BASE_API); + store.dispatch('setBaseSite', baseSite || urlData.BASE_SITE); + store.dispatch('setOssUrl', ossUrl || urlData.OSS_URL); + store.dispatch('projectConfig/setMarkKey', resp.data.markKey); + store.dispatch('projectConfig/setProjectCode', resp.data.project); + store.dispatch('projectConfig/setViewSetting', resp.data.viewSetting); + document.title = browserTitle; + if (loginProLogo) { + document.querySelector("link[rel*='icon']").href = (ossUrl || urlData.OSS_URL) + '/logo/' + loginProLogo; + } + getInfoAndGenerateRoutes(to, next, loginPath); + }).catch(e => this.$message.error('获取配置数据失败!')); + } else { + getInfoAndGenerateRoutes(to, next, loginPath); + } } else { // 除没有动态改变权限的需求可直接next() 删下方权限判断 if (to.path === '/404' && to.redirectedFrom === '/') { - const project = getSessionStorage('project'); next(localStore.get('trainingPlatformRoute' + store.getters.id + project) || '/trainingPlatform'); } else { next();