1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import Cookies from 'js-cookie';
import { params, Storeage } from '@wisdom-utils/utils/lib/helpers';
import { appService } from './api';
import { initMicroApps } from './micro';
import { actionCreators } from './containers/App/store';
import { getToken } from './utils/utils';
import loader, { render } from './render';
import store from './stores';
import Login from './pages/user/login/login';
// eslint-disable-next-line no-restricted-globals
const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace);
export const initGlobalConfig = () => {
/* eslint-disable */
createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
window.globalConfig = {};
window.__INITIAL_STATE__ = {};
let config = window.globalConfig || {};
// createStoreage.get('globalConfig') || {};
store.dispatch(actionCreators.updateComplexConfig({}));
if (!getToken() || config.token == null) {
// eslint-disable-next-line no-undef
createStoreage.remove(namespace);
config = {};
}
if (!params.getParams('client', window.location.search) && config) {
// eslint-disable-next-line no-undef
createStoreage.remove(namespace);
}
// eslint-disable-next-line no-undef
if (!createStoreage.get('globalConfig')) {
window.createStoreage = new Storeage(namespace);
}
if (!getToken()) {
localStorage.removeItem('loginSite');
}
/* eslint-disable */
// if (window.globalConfig.token !== null && Object.keys(window.globalConfig).length > 0) {
// store.dispatch(actionCreators.getConfig(window.globalConfig));
// // render({ appContent: '', loading: true });
// initMicroApps(loader, store);
// if (config.isNewYear) {
// updateTheme('#ff9600');
// }
// } else {
// // eslint-disable-next-line react-hooks/rules-of-hooks
// }
let client = params.getParams('client') || Cookies.get('client');
client = client && client !== 'undefined' ? client : 'city';
const queryConfig = (gateWayConfig = {}) => {
appService
.queryConfig({
client: client || 'city',
ignoreSite: true,
})
.then(res => {
if (res) {
const { data } = res;
if (!data.client) {
data.client = client;
}
// Cookies.set('client', data.client);
store.dispatch(
actionCreators.getConfig(
Object.assign(
{},
data,
{
token: '',
access_token: '',
userInfo: null,
},
gateWayConfig,
),
),
);
// Cookies.set('client', params.getParams('client'))
// if (data.loginTemplate === '新春 - 智联.html') {
// updateTheme('#ff9600');
// }
const products = (data.products || []).map(item => {
if (item.PackageName === 'civweb4') {
return 'web4_console'
}
return `${item.PackageName}-main`;
});
if(products && products.length > 0) {
Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({ store: store });
});
initMicroApps();
}
// eslint-disable-next-line no-new
if (getToken()) {
// eslint-disable-next-line no-new
new Login(
{
global: Object.assign({}, data,
{
token: getToken(),
},
gateWayConfig,
),
// eslint-disable-next-line no-shadow
updateConfig: data => store.dispatch(actionCreators.getConfig(data)),
isInit: false,
logout: () => store.dispatch(actionCreators.logout()),
},
() => {
(async () => {
(await (getToken() &&
window.globalConfig &&
window.globalConfig.token)) &&
initMicroApps(loader, store);
})();
},
true,
);
}
}
return res;
})
.then(res => {
render({ appContent: '', loading: true });
})
.catch(error => {
store.dispatch(actionCreators.getConfigError(error));
});
}
appService
.getWateWayConfig({
ignoreSite: true,
})
.then(res => {
/* eslint-disable */
const hasGateWay = !res || !res.data ? false : _.isString(res.data) ? JSON.parse(res.data) : typeof res.data === 'boolean' ? res.data : false;
return {
hasGateWay,
apiGatewayDomain: `${window.location.origin}${hasGateWay ? '/PandaCore/GateWay' : ''}`,
};
})
.then(gateWayConfig => {
queryConfig(gateWayConfig);
})
.catch(err => {
queryConfig();
});
};