Commit 83c714e2 authored by 崔佳豪's avatar 崔佳豪

fix: 获取网关与获取全局配置互相覆盖引起的异常问题

parent cd7ae4fb
Pipeline #46965 skipped with stages
...@@ -10,7 +10,7 @@ import Login from './pages/user/login/login'; ...@@ -10,7 +10,7 @@ import Login from './pages/user/login/login';
const namespace = `__PANDA_STORE__${location.hostname}`; const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace); window.createStoreage = new Storeage(namespace);
export const initGlobalConfig = () => { export const initGlobalConfig = () => {
// eslint-disable-next-line no-debugger // eslint-disable-next-line no-debugger
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.remove(`__PANDA_STORE__${location.hostname}`); createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
...@@ -45,92 +45,96 @@ export const initGlobalConfig = () => { ...@@ -45,92 +45,96 @@ export const initGlobalConfig = () => {
updateTheme('#ff9600'); updateTheme('#ff9600');
} }
} else { } else {
// eslint-disable-next-line react-hooks/rules-of-hooks
let client = params.getParams('client') || Cookies.get('city')
client = client && client !== 'undefined' ? client : 'city';
appService.getWateWayConfig().then(res => { appService.getWateWayConfig().then(res => {
const hasGateWay = const hasGateWay =
res && res.data && isString(res.data) ? JSON.parse(res.data) : res.data; !res || !res.data ? false : isString(res.data) ? JSON.parse(res.data) : typeof res.data === 'boolean' ? res.data : false;
if (res.code === 0 && res.data === 'true') { // if (res.code === 0 && res.data === 'true') {
store.dispatch( // store.dispatch(
actionCreators.getConfig( // actionCreators.getConfig(
Object.assign({}, window.globalConfig, { // Object.assign({}, window.globalConfig, {
hasGateWay, // hasGateWay,
apiGatewayDomain: `${window.location.origin}/PandaCore`, // apiGatewayDomain: `${window.location.origin}/PandaCore`,
}), // }),
), // ),
); // );
// }
return {
hasGateWay,
apiGatewayDomain: `${window.location.origin}/PandaCore`,
} }
}); }).then((gateWayConfig) => {
// eslint-disable-next-line react-hooks/rules-of-hooks appService
let client = params.getParams('client') || Cookies.get('city') .queryConfig({
client = client && client !== 'undefined' ? client : 'city'; client: client || 'city',
appService ignoreSite: true,
.queryConfig({ })
client: client || 'city', .then(res => {
ignoreSite: true, if (res) {
}) const data = res;
.then(res => { if (!data.client) {
if (res) { data.client = client;
}
store.dispatch(actionCreators.getConfig(Object.assign({}))); // Cookies.set('city', data.client);
const data = res; store.dispatch(
if (!data.client) { actionCreators.getConfig(
data.client = client; Object.assign({}, data, {
} token: '',
// Cookies.set('city', data.client); access_token: '',
store.dispatch( userInfo: null
actionCreators.getConfig( }, gateWayConfig),
Object.assign({}, data, { ),
token: '', );
access_token: '',
userInfo: null
}),
),
);
//Cookies.set('city', params.getParams('client'))
if (data.loginTemplate === '新春 - 智联.html') {
updateTheme('#ff9600');
}
// eslint-disable-next-line no-new
if (getToken()) {
//Cookies.set('city', params.getParams('client'))
if (data.loginTemplate === '新春 - 智联.html') {
updateTheme('#ff9600');
}
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Login( if (getToken()) {
{
global: Object.assign({}, data, { // eslint-disable-next-line no-new
token: getToken(), new Login(
}), {
// eslint-disable-next-line no-shadow global: Object.assign({}, data, {
updateConfig: data =>store.dispatch(actionCreators.getConfig(data)), token: getToken(),
isInit: false, }),
logout: () => store.dispatch(actionCreators.logout()), // eslint-disable-next-line no-shadow
}, updateConfig: data =>store.dispatch(actionCreators.getConfig(data)),
() => { isInit: false,
(async () => { logout: () => store.dispatch(actionCreators.logout()),
(await (getToken() && },
window.globalConfig && () => {
window.globalConfig.token)) && initMicroApps(loader, store); (async () => {
})(); (await (getToken() &&
}, window.globalConfig &&
true, window.globalConfig.token)) && initMicroApps(loader, store);
); })();
},
true,
);
}
// eslint-disable-next-line no-shadow
} }
return res;
// eslint-disable-next-line no-shadow })
} // eslint-disable-next-line no-shadow
return res; .then(res => {
}) // eslint-disable-next-line no-use-before-define
// eslint-disable-next-line no-shadow // initSensorType();
.then(res => { // eslint-disable-next-line no-use-before-define
// eslint-disable-next-line no-use-before-define // initIsMock();
// initSensorType(); render({ appContent: '', loading: true });
// eslint-disable-next-line no-use-before-define })
// initIsMock(); .catch(error => {
render({ appContent: '', loading: true }); console.log(error);
}) store.dispatch(actionCreators.getConfigError(error));
.catch(error => { });
console.log(error); });
store.dispatch(actionCreators.getConfigError(error));
});
} }
}; };
\ No newline at end of file
...@@ -27,10 +27,7 @@ class SecurityLayout extends React.Component { ...@@ -27,10 +27,7 @@ class SecurityLayout extends React.Component {
// const queryString = stringify({ // const queryString = stringify({
// redirect: window.location.href, // redirect: window.location.href,
// }); // });
if ( if (!Cookies.get('token')) {
_.isNull(global.token) ||
(global.hasGateWay && _.isNull(global.access_token))
) {
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0); this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
let client = global.client || Cookies.get('city'); let client = global.client || Cookies.get('city');
client = client =
......
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