获取项目配置接口频繁调用调整

This commit is contained in:
fan 2023-03-02 14:21:59 +08:00
parent 8c5f4b3cdf
commit 8a89c93603

View File

@ -9,6 +9,7 @@ import { handlerUrl } from '@/utils/baseUrl';
import { getFrontProjectConfigByLogin} from '@/api/projectConfig';
const whiteList = ['/login', '/design/login', '/loginNew', '/gzzbxy/relay', '/authorization', '/AUSline', '/AUStool', '/demo', '/thirdLogin']; // 不重定向白名单
let frontConfigMark = '';
// 登录路径判断获取
function getRouteInfo(to, markKey) {
@ -81,8 +82,8 @@ router.beforeEach( async (to, from, next) => {
// 登陆成功页面
project = getSessionStorage('project') || 'login';
}
const response = await getFrontProjectConfigByLogin(project);
if (response.data) {
if (frontConfigMark !== project) {
const response = await getFrontProjectConfigByLogin(project);
const {browserTitle, loginProLogo, baseApiUrl, baseSite, caseShow, helpShow, ossUrl, homeTitle, homeProLogoWidth} = response.data.viewSetting;
if (!store.state.user.baseUrl && project) {
const urlData = handlerUrl();
@ -91,6 +92,7 @@ router.beforeEach( async (to, from, next) => {
store.dispatch('setOssUrl', ossUrl || urlData.OSS_URL);
subscribe();
}
frontConfigMark = response.data.markKey;
document.title = browserTitle;
const url = loginProLogo ? store.state.user.ossUrl + '/logo/' + loginProLogo : '';
document.querySelector("link[rel*='icon']").href = url;
@ -100,32 +102,32 @@ router.beforeEach( async (to, from, next) => {
store.dispatch('setLoginProLogo', url);
store.dispatch('setHomeTitle', homeTitle);
NProgress.start();
const loginPath = getRouteInfo(to, response.data.markKey);
const token = to.query.token;
if (/demoTraining/.test(to.path) && token) {
const header = { group: to.query.group, 'X-Token': token };
setToken(token);
store.commit('SET_TOKEN', token);
store.commit('SUBSCRIBE', { header, type: '' });
}
const loginPath = getRouteInfo(to, frontConfigMark);
const token = to.query.token;
if (/demoTraining/.test(to.path) && token) {
const header = { group: to.query.group, 'X-Token': token };
setToken(token);
store.commit('SET_TOKEN', token);
store.commit('SUBSCRIBE', { header, type: '' });
next();
} else if (getToken()) {
if (to.path === loginPath) {
// 登录页面不拦截
next();
} else if (getToken()) {
if (to.path === loginPath) {
// 登录页面不拦截
next();
} else {
// 进入系统重新计算路由
handleRoute(to, next, loginPath);
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next();
} else if (to.path.substr(0, 13) == whiteList[2]) {
next();
} else {
// 否则全部重定向到登录页
next(loginPath);
}
// 进入系统重新计算路由
handleRoute(to, next, loginPath);
}
} else {
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next();
} else if (to.path.substr(0, 13) == whiteList[2]) {
next();
} else {
// 否则全部重定向到登录页
next(loginPath);
}
}
});