Commit 4fc185fd authored by 邓晓峰's avatar 邓晓峰

fix: 修复开启网关后获取全局配置

parent 68952f56
Pipeline #47012 passed with stages
in 8 minutes 49 seconds
......@@ -37,7 +37,7 @@ const MICRO_STATUS = {
};
export const initMicroApps = () => {
/* eslint-disable */
const config = window.globalConfig || {};
//createStoreage.get('globalConfig');
......@@ -190,12 +190,12 @@ export const initMicroApps = () => {
addGlobalUncaughtErrorHandler(event => {
console.log(event);
});
};
export const defaultApp = () => {
// eslint-disable-next-line no-undef
const config = window.globalConfig;
......@@ -211,14 +211,14 @@ export const defaultApp = () => {
// createStoreage.set('init_web4', true)
// }
// let homepage = config.homepage.replace('civweb4/', '');
let url = !config.home ? (config.homepage === '' ? `/civbase/civweb4`: `/civbase/civweb4/${config.homepage.replace(/^\//, '').replace(/^civweb4\//, '')}`) : `/civbase/${config.homepage.replace(/^\//, '')}`;
let url = !config.home ? ((config.homepage === '' || _.isNull(config.homepage)) ? `/civbase/civweb4`: `/civbase/civweb4/${config.homepage.replace(/^\//, '').replace(/^civweb4\//, '')}`) : `/civbase/${config.homepage.replace(/^\//, '')}`;
/**
* issue 处理监听路由规则
*/
// if(url === '/civbase/civweb4/') {
// url = url.replace(/civweb4\//, 'civweb4');
// }
setDefaultMountApp(url);
// if(config.homepage.indexOf('civweb4') > -1) createStoreage.set('init_web4', true);
}
......@@ -238,7 +238,7 @@ window.app = {
modules: {},
require: function (request, method) {
if (request !== '.' && this.modules[request]) {
return _.isFunction(this.modules[request]) ? this.modules[request]() : _.isFunction(this.modules[request][method]) && this.modules[request][method]();
}
......@@ -277,7 +277,7 @@ window.app = {
return _.isFunction(this.modules[request]) && this.modules[request]();
},
define: function (name, context, index) {
let keys = context.keys();
for (let key of keys) {
let parts = name.indexOf('@') > -1 ? [name, ...(key.slice(1).split('/'))] : (name + key.slice(1)).split('/');
......@@ -293,7 +293,7 @@ window.app = {
dir[parts[parts.length - 1]] = context.bind(context, key);
}
if (index && index !== null) {
this.modules[name] = this.modules[name][index];
}
},
......
......@@ -5,14 +5,14 @@ import { decode, encode } from 'js-base64';
import Cookies from 'js-cookie';
import sha1 from 'sha1';
import { SlideVerify } from '@wisdom-utils/components';
import { appService } from '@/api';
import { getUserInfo, getWebSiteConfig } from '@/api/service/base'
import { getUserInfo, getWebSiteConfig } from '@/api/service/base';
import {
SERVICE_APP_LOGIN_MODE,
SERVICE_INTERFACE_SUCCESS_CODE,
WX_REDIRECT_URI,
} from '@/constants';
import { SlideVerify } from '@wisdom-utils/components';
// eslint-disable-next-line no-undef
const Logger = logger('login');
......@@ -41,19 +41,23 @@ class Login {
let { ddCode } = this.globalConfig;
let { loginName } = this.globalConfig;
let { password } = this.globalConfig;
loginName = params.getParams('loginName') ? params.getParams('loginName'): loginName;
loginName = params.getParams('loginName')
? params.getParams('loginName')
: loginName;
const redirect = params.getParams('redirect');
const generateType = params.getParams('generateType');
if(redirect) {
if (redirect) {
this.globalConfig.homepage = redirect;
// this.globalConfig.layout = 'blank';
}
if(generateType) {
if (generateType) {
this.globalConfig.generateType = generateType;
}
self.updateConfig && self.updateConfig(self.globalConfig);
password = params.getParams('password') ? params.getParams('password'): password;
password = params.getParams('password')
? params.getParams('password')
: password;
const loginMode = Cookies.get('loginMode') || null;
if (loginMode && loginMode === 'iotWechat') ddCode = null;
// self.qrcodeLogin(self.globalConfig.qrcodeData.code);
......@@ -65,7 +69,6 @@ class Login {
} else if (ddCode && loginMode === 'qywx') {
self.qywxLoginIn(ddCode);
} else if (!!loginName && !!password) {
self.otherLoginIn(loginName, password);
} else if (
self.globalConfig.qrcodeData &&
......@@ -90,44 +93,42 @@ class Login {
// eslint-disable-next-line no-undef
getUserInfo({
token: this.globalConfig.token,
subOID: 'subOID',
site: this.getLocalSiteBytoken(token),
'request.preventCache': Date.now(),
ignoreSite: true,
})
.then(response => {
if (response && !response.errMsg) {
self.globalConfig.userInfo = {};
if (
response.Groups &&
response.Groups instanceof Array &&
response.Groups.length
) {
self.globalConfig.userInfo.Groups = response.Groups;
}
self.globalConfig.userInfo = Object.assign(
{},
response,
self.globalConfig.userInfo,
);
self.updateConfig && self.updateConfig(self.globalConfig);
self.getUserInfoAndConfig();
} else {
self.logout && self.logout();
if (
self.globalConfig.style === 'ios' &&
self.globalConfig.loginTemplate === 'IOSCloud.html'
) {
window.location.href = `${window.location.origin}`;
return false;
}
window.location.reload();
token: this.globalConfig.token,
subOID: 'subOID',
site: this.getLocalSiteBytoken(token),
'request.preventCache': Date.now(),
ignoreSite: true,
}).then(response => {
if (response && !response.errMsg) {
self.globalConfig.userInfo = {};
if (
response.Groups &&
response.Groups instanceof Array &&
response.Groups.length
) {
self.globalConfig.userInfo.Groups = response.Groups;
}
});
self.globalConfig.userInfo = Object.assign(
{},
response,
self.globalConfig.userInfo,
);
self.updateConfig && self.updateConfig(self.globalConfig);
self.getUserInfoAndConfig();
} else {
self.logout && self.logout();
if (
self.globalConfig.style === 'ios' &&
self.globalConfig.loginTemplate === 'IOSCloud.html'
) {
window.location.href = `${window.location.origin}`;
return false;
}
window.location.reload();
}
});
}
writeLogs() {
if (this.globalConfig.userInfo.UserImge === '') {
// _config.userInfo.UserImge = __webpack_public_path__ + "assets/images/icon/熊猫新2.png";
......@@ -153,7 +154,7 @@ class Login {
.catch(error => {});
}
if(window.location.host === 'panda-water.com') {
if (window.location.host === 'panda-water.com') {
appService
.loginLogs({
origin: window.location.origin,
......@@ -169,7 +170,6 @@ class Login {
})
.catch(error => {});
}
}
getIndustry(flag, token, getIndustry) {
......@@ -206,42 +206,51 @@ class Login {
getWebConfig(token, getIndustry) {
const self = this;
// eslint-disable-next-line no-undef
getWebSiteConfig({
client: self.globalConfig.client,
token,
'request.preventCache': Date.now(),
})
client: self.globalConfig.client,
token,
'request.preventCache': Date.now(),
})
.then(response => {
const result = response && response.code === SERVICE_INTERFACE_SUCCESS_CODE ? Array.isArray(response.data)? response.data: [] : response;
debugger
const result =
response && response.code === SERVICE_INTERFACE_SUCCESS_CODE
? Array.isArray(response.data)
? response.data
: []
: response;
if (result && result.length > 0) {
const config = result.shift();
const homeType = config.productType || 'civweb4';
// 产品类型和首页路径同时有才行
const homepage = homeType && (params.getParams('redirect') || config.homepage) ? homeType + '/' + (params.getParams('redirect') || config.homepage) : '';
const homepage =
homeType && (params.getParams('redirect') || config.homepage)
? `${homeType}/${params.getParams('redirect') || config.homepage}`
: '';
self.globalConfig = Object.assign(self.globalConfig, config, {
theme: self.globalConfig.theme,
menu: self.globalConfig.menu,
style: self.globalConfig.style,
homepage: homepage
homepage: homepage || '',
// mapsettings: config.mapsettings
});
if(self.globalConfig.hasOwnProperty('webConfig')) {
self.globalConfig = {
// eslint-disable-next-line no-prototype-builtins
if (self.globalConfig.hasOwnProperty('webConfig')) {
self.globalConfig = Object.assign(self.globalConfig ,{
// ...self.globalConfig,
...self.globalConfig.webConfig.basicConfig,
...self.globalConfig.webConfig.optionalConfig
}
...self.globalConfig.webConfig.optionalConfig,
});
}
self.updateConfig && self.updateConfig(self.globalConfig);
self.getProjectItems().then((res) => {
self.getProjectItems().then(res => {
window.subSysCfg = {};
self.globalConfig = Object.assign(self.globalConfig, {
mapsettings: res
})
mapsettings: res,
});
result.forEach(item => {
window.subSysCfg[item.client] = item;
});
......@@ -255,21 +264,24 @@ class Login {
// this.events.removeAllListeners('loginSuccess')
// this.events.removeAllListeners('toggleIndustry')
// window.share.event = this.events;
if (self.globalConfig.userInfo && self.globalConfig.userInfo.site &&self.globalConfig.userInfo.site.length > 0) {
if (
self.globalConfig.userInfo &&
self.globalConfig.userInfo.site &&
self.globalConfig.userInfo.site.length > 0
) {
// eslint-disable-next-line no-undef,no-underscore-dangle
getWebSiteConfig(
{
client: self.globalConfig.client,
token,
ignoreSite: true,
'request.preventCache': Date.now(),
},
// eslint-disable-next-line no-shadow
)
getWebSiteConfig(
{
client: self.globalConfig.client,
token,
ignoreSite: true,
'request.preventCache': Date.now(),
},
// eslint-disable-next-line no-shadow
)
// eslint-disable-next-line no-shadow
.then(response => {
const resultData =
response && response.code === SERVICE_INTERFACE_SUCCESS_CODE
? Array.isArray(response.data)
......@@ -280,7 +292,9 @@ class Login {
const mainConf = resultData.shift();
const mainType = mainConf.productType || 'civweb4';
if (mainConf.homepage)
self.globalConfig.homepage = `${mainType}/${mainConf.homepage}`;
self.globalConfig.homepage = `${mainType}/${
mainConf.homepage
}`;
if (mainConf.bannerLogo)
self.globalConfig.bannerLogo = mainConf.bannerLogo;
if (mainConf.logo) self.globalConfig.logo = mainConf.logo;
......@@ -301,7 +315,6 @@ class Login {
});
} else {
// loginSuccess
self.updateConfig && self.updateConfig(self.globalConfig);
// console.log("===loginSuccess===")
......@@ -335,19 +348,19 @@ class Login {
let widgetIndex = -1;
this.globalConfig.uiwidgets &&
this.globalConfig.uiwidgets.map((item, index) => {
// eslint-disable-next-line radix
if (parseInt(item.bottom) > MAX_BOTTOM) {
// eslint-disable-next-line radix
MAX_BOTTOM = parseInt(item.bottom);
}
if (!isScale && item.url.toLowerCase().indexOf('widgets/zoom') > -1)
isScale = true;
if (
widgetIndex === -1 &&
item.url.indexOf('ToggleProject/ToggleProject') > -1
)
widgetIndex = index;
});
if (parseInt(item.bottom) > MAX_BOTTOM) {
// eslint-disable-next-line radix
MAX_BOTTOM = parseInt(item.bottom);
}
if (!isScale && item.url.toLowerCase().indexOf('widgets/zoom') > -1)
isScale = true;
if (
widgetIndex === -1 &&
item.url.indexOf('ToggleProject/ToggleProject') > -1
)
widgetIndex = index;
});
const { layers = [] } = this.globalConfig.mapsettings || {};
if (layers.length === 0) {
......@@ -372,24 +385,24 @@ class Login {
url: 'product/webgisPanda/ToggleProject/ToggleProject',
});
}
debugger
debugger;
if (layer.areaName) {
this.globalConfig.mapsettings.areasettings.areaName = layer.areaName;
}
if (layer.backgroundColor) {
this.globalConfig.mapsettings.areasettings.backgroundColor =
layer.backgroundColor;
layer.backgroundColor;
}
if (layer.boundColor) {
this.globalConfig.mapsettings.areasettings.boundColor = layer.boundColor;
}
if (layer.boundWidth) {
this.globalConfig.mapsettings.areasettings.boundWidth = layer.boundWidth;
}
// eslint-disable-next-line radix
if (Number.isInteger(parseInt(layer.backgroundOpacity))) {
this.globalConfig.mapsettings.areasettings.backgroundOpacity =
......@@ -400,7 +413,7 @@ class Login {
if (layer.basemaps && layer.basemaps.length > 0) {
this.globalConfig.mapsettings.basemaps = layer.basemaps;
}
// this.updateConfig && this.updateConfig(Object.assign({}, this.globalConfig, {
// mapsettings: this.globalConfig.mapsettings
// }));
......@@ -430,7 +443,6 @@ class Login {
}
goLogin() {
if (
this.globalConfig.style === 'ios' &&
this.globalConfig.loginTemplate === 'IOSCloud.html'
......@@ -617,14 +629,14 @@ class Login {
expiration: this.globalConfig.expiration, // token过期时间(单位:秒)
client: 'referer',
username: usr,
password: params.getParams('generateType') ? pwd : sha1(pwd).toUpperCase(),
password: params.getParams('generateType')
? pwd
: sha1(pwd).toUpperCase(),
referer: this.globalConfig.client,
skipMenuTest: 1,
generateType: params.getParams('generateType') || ''
generateType: params.getParams('generateType') || '',
})
.then(response => {
// self.globalConfig.layout = 'blank';
if (response && response.token) {
const tk = response.token;
......@@ -632,28 +644,24 @@ class Login {
// eslint-disable-next-line no-undef,no-debugger
getUserInfo(
{
token: tk,
subOID: 'subOID',
site: this.getLocalSiteBytoken(tk),
ignoreSite: true,
},
// eslint-disable-next-line no-shadow
)
{
token: tk,
subOID: 'subOID',
site: this.getLocalSiteBytoken(tk),
ignoreSite: true,
},
// eslint-disable-next-line no-shadow
)
// eslint-disable-next-line no-shadow
.then(response => {
try {
if (response && !response.errMsg) {
self.globalConfig.userInfo = Object.assign(
{},
response,
);
if(response.hasOwnProperty('data')) {
self.globalConfig.userInfo = Object.assign({}, response);
if (response.hasOwnProperty('data')) {
self.globalConfig.userInfo = {
// ... self.globalConfig.userInfo,
...response.data
}
...response.data,
};
}
const date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
......@@ -666,8 +674,8 @@ class Login {
Cookies.set('token', tk, {
expires: date,
path: '/',
})
});
// self.globalConfig.Industry = industry;
self.isSignIn = true;
self.updateConfig && self.updateConfig(self.globalConfig);
......@@ -714,7 +722,7 @@ class Login {
/* eslint-disable */
let _industrySite = null;
if (industry) {
const userInfo =
self.globalConfig.userInfo &&
self.globalConfig.userInfo.Groups &&
......@@ -871,7 +879,7 @@ class Login {
type: mode,
generateType: params.getParams('generateType') || ''
}).then(res => {
if(res.code === 0) {
const data = res.data;
self.updateConfig && self.updateConfig(Object.assign({}, self.globalConfig, {
......@@ -911,7 +919,7 @@ class Login {
self.transformLoginHander(response, isRememberPWD)
})
.catch(error => {
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', error.message);
......
......@@ -64,7 +64,7 @@ const generRotes = (widgets, parent, level = 0) => {
const path = `/civweb/${guid('web_console')}`;
const subKey = guid('panda');
const alias = DEFAULT_APPLICATION;
const convertURL = transformURL(item.icon.replace(/\s*/g, ''));
const convertURL = item.icon ? transformURL(item.icon.replace(/\s*/g, '')): '';
const icon = (item && item.icon && item.icon !== null &&
isAbsoluteURL(convertURL) ? convertURL: /(\\|\/)/.test(convertURL) ?
window.globalConfig.transformDevAssetsBaseURL(transformURL(item.icon.replace(/\s*/g, ''))): item.icon
......@@ -164,7 +164,7 @@ export const transformWidgets = (widgets) => {
return widgets.map(item => {
const widgets = item.widgets;
const homepage = window.globalConfig.homepage;
const homePageConvertArray = homepage.split("/");
const homePageConvertArray = homepage ? homepage.split("/"): [];
const findIndex = widgets && widgets.findIndex(item => item.label === '系统菜单组');
if(findIndex === -1 && homePageConvertArray[0] !== 'civweb4') {
const index = widgets.findIndex(item => item.label === '首页');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment