刷新页面baseUrl调用错误调整

This commit is contained in:
fan 2023-04-13 16:04:14 +08:00
parent f5ffa562ce
commit 0e1dcbb5fd
2 changed files with 48 additions and 22 deletions

View File

@ -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);

View File

@ -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();