Commit d6e61d6f authored by 杨思琦's avatar 杨思琦

fix: 部分服务进行网关过滤

parent e62762fc
Pipeline #74829 passed with stages
......@@ -115,9 +115,9 @@
"@wisdom-map/arcgismap": "1.4.0-164",
"@wisdom-map/basemap": "1.1.0-24",
"@wisdom-map/util": "^1.0.28-0",
"@wisdom-utils/components": "0.1.303",
"@wisdom-utils/components": "0.1.304",
"@wisdom-utils/runtime": "0.0.46",
"@wisdom-utils/utils": "0.1.343",
"@wisdom-utils/utils": "0.1.344",
"animate.css": "^4.1.1",
"antd": "4.21.2",
"compression": "1.7.4",
......
......@@ -399,10 +399,11 @@ class Site {
config.widgets = [];
config.allWidgets = [];
config.userInfo = window?.globalConfig?.transformUserInfo?.(res.data) ?? res.data;
window.globalConfig = config;
// 重置网关配置
// eslint-disable-next-line prettier/prettier, no-undef
const hasGateWay = !gatewayRes || !gatewayRes.data ? false : _.isString(gatewayRes.data) ? JSON.parse(gatewayRes.data) : (typeof gatewayRes.data === 'boolean' ? gatewayRes.data : false);
config.hasGateWay = hasGateWay;
config.apiGatewayDomain = `${window.location.origin}${hasGateWay ? '/PandaCore/GateWay' : ''}`;
if (hasGateWay) {
appService
.authorizationToken({
......@@ -411,14 +412,17 @@ class Site {
})
.then(tokenRes => {
const accessToken = tokenRes.data?.access_token ?? null;
config.access_token = accessToken;
localStorage.setItem('access_token', accessToken);
this.writeCookie(token, site, onChangeVisible, actionRef, accessToken);
})
.catch(err => {
this.setLoading(false);
config.access_token = null;
this.writeCookie(token, site, onChangeVisible, actionRef, null);
});
} else {
config.access_token = null;
localStorage.setItem('access_token', null);
this.writeCookie(token, site, onChangeVisible, actionRef, null);
}
......
......@@ -286,16 +286,58 @@ class Login {
this.history.push('/industry');
return false;
}
this.getWebConfig(token, getIndustry);
this.initGateWay(token, getIndustry);
}
getWebConfig(token, getIndustry) {
initGateWay(token, getIndustry) {
const self = this;
// eslint-disable-next-line no-undef
// 获取网站配置的同时,预先获取到mqtt配置,注册进子应用
const gateWayParam = {
_site: this?.globalConfig?.userInfo?.site ?? '',
};
appService
.getWateWayConfig(gateWayParam)
.then(res => {
// eslint-disable-next-line prettier/prettier, no-undef
const hasGateWay =!res || !res.data? false: _.isString(res.data)? JSON.parse(res.data): typeof res.data === 'boolean'? res.data: false;
self.globalConfig.hasGateWay = hasGateWay;
self.globalConfig.apiGatewayDomain = `${window.location.origin}${hasGateWay ? '/PandaCore/GateWay' : ''}`;
if (hasGateWay) {
appService
.authorizationToken({
loginName: self.globalConfig.userInfo?.loginName || '',
type: 'WorkNo',
})
.then(tokenRes => {
if (tokenRes.code === 0) {
self.globalConfig.access_token = tokenRes.data?.access_token ?? '';
localStorage.setItem('access_token', self.globalConfig.access_token);
}
self.updateConfig(self.globalConfig);
})
.then(() => {
// eslint-disable-next-line no-use-before-define
this.getWebConfig(token, getIndustry);
})
.catch(err => {
self.updateConfig(self.globalConfig);
});
} else {
self.globalConfig.access_token = null;
localStorage.setItem('access_token', self.globalConfig.access_token);
self.updateConfig(self.globalConfig);
this.getWebConfig(token, getIndustry);
}
})
.catch(err => {
// eslint-disable-next-line no-use-before-define
this.getWebConfig(token, getIndustry);
});
}
getWebConfig(token, getIndustry) {
const self = this;
// eslint-disable-next-line no-undef
// 获取网站配置的同时,预先获取到mqtt配置,注册进子应用
Promise.allSettled([
noticeService.getMqttSiteCode({ 'request.preventCache': Date.now() }),
getWebSiteConfig({
......@@ -303,7 +345,6 @@ class Login {
token,
'request.preventCache': Date.now(),
}),
appService.getWateWayConfig(gateWayParam),
])
.then(results => {
const promise = results[0];
......@@ -368,14 +409,8 @@ class Login {
? response.data
: []
: response;
const gatewayRes = results[2]?.value ?? {};
// 重置网关配置
// eslint-disable-next-line prettier/prettier, no-undef
const hasGateWay = !gatewayRes || !gatewayRes.data ? false : _.isString(gatewayRes.data) ? JSON.parse(gatewayRes.data) : (typeof gatewayRes.data === 'boolean' ? gatewayRes.data : false);
if (result && result.length > 0) {
const config = result.shift();
config.hasGateWay = hasGateWay;
config.apiGatewayDomain = `${window.location.origin}${hasGateWay ? '/PandaCore/GateWay' : ''}`;
const homeType = config.productType || 'civweb4';
// 产品类型和首页路径同时有才行
// eslint-disable-next-line prettier/prettier
......@@ -393,27 +428,6 @@ class Login {
products: self.globalConfig.products,
// mapsettings: config.mapsettings
});
if (hasGateWay) {
appService
.authorizationToken({
loginName: self.globalConfig.userInfo?.loginName || '',
type: 'WorkNo',
})
.then(tokenRes => {
if (tokenRes.code === 0) {
self.globalConfig.access_token = tokenRes.data?.access_token ?? '';
localStorage.setItem('access_token', self.globalConfig.access_token);
}
self.updateConfig(self.globalConfig);
})
.catch(err => {
self.updateConfig(self.globalConfig);
});
} else {
self.globalConfig.access_token = null;
localStorage.setItem('access_token', self.globalConfig.access_token);
self.updateConfig(self.globalConfig);
}
self.getProjectItems().then(res => {
window.subSysCfg = {};
self.globalConfig = Object.assign(self.globalConfig, {
......@@ -422,7 +436,6 @@ class Login {
result.forEach(item => {
window.subSysCfg[item.client] = item;
});
if (self.globalConfig.isShared) {
self.globalConfig.mode = 'single';
self.globalConfig.style = 'sandbox';
......@@ -438,7 +451,6 @@ class Login {
self.globalConfig.userInfo.site.length > 0
) {
// eslint-disable-next-line no-undef,no-underscore-dangle
getWebSiteConfig(
{
client: self.globalConfig.client,
......@@ -469,7 +481,6 @@ class Login {
if (mainConf && mainConf.hasOwnProperty('topMenu')) self.globalConfig.topMenu = mainConf.topMenu;
if (mainConf && mainConf.navTheme && self.globalConfig.CloudStyle !== '否')
self.globalConfig.navTheme = mainConf.navTheme; // 云平台统一navTheme
// 云平台切换站点 应用站点自己主题配置
if (config.CloudStyle === '否') {
self.globalConfig.variableTheme = {
......@@ -488,7 +499,6 @@ class Login {
// self.globalConfig.productType = mainConf.productType;
self.updateConfig && self.updateConfig(self.globalConfig);
}
if (self.globalConfig.widgets.length === 0) {
message.error({
duration: 3,
......@@ -1151,45 +1161,44 @@ class Login {
}
}
}
loginJiang(usr, pwd, userPhone, isRememberPWD, mode = SERVICE_APP_LOGIN_MODE.password) {
loginJiang(usr, pwd, userPhone, isRememberPWD, mode = SERVICE_APP_LOGIN_MODE.password) {
this.globalConfig = getGlobalConfig();
const self = this;
appService
.getJiangXiManage({
username: usr,
password: btoa(pwd),
IsGateWay: window.globalConfig.hasGateWay,
'request.preventCache': Date.now(),
})
.then(response => {
if(response.code === 0) {
if(window.globalConfig?.hasGateWay) {
const data = response.data;
self.updateConfig &&
self.updateConfig(
Object.assign({}, self.globalConfig, {
access_token: data.access_token,
token: data.user_token,
}),
);
self.transformLoginHander(response.data, isRememberPWD, pwd);
} else {
self.transformLoginHander({token: response.data.user_token}, isRememberPWD, pwd);
}
appService
.getJiangXiManage({
username: usr,
password: btoa(pwd),
IsGateWay: window.globalConfig.hasGateWay,
'request.preventCache': Date.now(),
})
.then(response => {
if (response.code === 0) {
if (window.globalConfig?.hasGateWay) {
const data = response.data;
self.updateConfig &&
self.updateConfig(
Object.assign({}, self.globalConfig, {
access_token: data.access_token,
token: data.user_token,
}),
);
self.transformLoginHander(response.data, isRememberPWD, pwd);
} else {
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', response.msg);
message.error(response.msg);
self.transformLoginHander({ token: response.data.user_token }, isRememberPWD, pwd);
}
})
.catch(error => {
} else {
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', error.message);
message.error('登录服务异常');
});
self.events.emit('loginError', response.msg);
message.error(response.msg);
}
})
.catch(error => {
self.hasTry = true;
self.handleLoginError();
self.events.emit('loginError', error.message);
message.error('登录服务异常');
});
}
phoneLoginFormHandler(userPhone, captcha) {
this.login('', '', userPhone, '', SERVICE_APP_LOGIN_MODE.phone);
......
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