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
154
155
156
157
158
159
160
161
162
163
164
165
166
import {
addGlobalUncaughtErrorHandler,
initGlobalState,
registerMicroApps,
runAfterFirstMounted,
setDefaultMountApp,
start,
} from 'qiankun';
import micorConfig from '../config/micor';
import pkg from '../package.json';
import { FILTER_FOLER_REG } from './utils/constants';
const MICRO_STATUS = {
NOT_LOADED: "NOT_LOADED",
LOADING_SOURCE_CODE: "LOADING_SOURCE_CODE",
NOT_BOOTSTRAPPED: "NOT_BOOTSTRAPPED",
BOOTSTRAPPING: 'BOOTSTRAPPING',
NOT_MOUNTED: 'NOT_MOUNTED',
MOUNTING: 'MOUNTING',
MOUNTED: 'MOUNTED',
UPDATING: 'UPDATING',
UNMOUNTING: 'UNMOUNTING',
UNLOADING: 'UNLOADING',
SKIP_BECAUSE_BROKEN: 'SKIP_BECAUSE_BROKEN',
LOAD_ERROR: 'LOAD_ERROR'
}
export const initMicroApps = loader => {
const entrys =
process.env.NODE_ENV !== 'production' ? micorConfig.dev : micorConfig.prod;
registerMicroApps(
entrys.map(item => {
item.loader = loader;
item.props = {
emitter: window.share.event,
baseRoot: item.name,
globalConfig: createStoreage.get('globalConfig'),
XMLHttpRequest: window.XMLHttpRequest,
};
return item;
}),
{
beforeLoad: [
app => {
console.log(
'[LifeCycle] before load %c%s',
'color: green;',
app.name,
);
},
],
beforeMount: [
app => {
// hookRequest()
// ReactDOM.unmountComponentAtNode(
// document.getElementById('subapp-container'),
// );
// console.log(
// '[LifeCycle] before mount %c%s',
// 'color: green;',
// JSON.stringify(app),
// );
// window.share.event.removeAllListeners();
console.log(
'[LifeCycle] before mount %c%s',
'color: green;',
app.name,
);
},
],
afterMount: [
app => {
console.log(
'[LifeCycle] after mount %c%s',
'color: green;',
app.name,
);
},
],
beforeUnmount: [
app => {
window.share.event.removeAllListeners('changeRoute');
console.log(
'[LifeCycle] after unmount %c%s',
'color: green;',
app.name,
);
},
],
afterUnmount: [
app => {
},
],
},
);
const { setGlobalState } = initGlobalState({
globalConfig: createStoreage.get('globalConfig')
});
setGlobalState({
globalConfig: createStoreage.get('globalConfig')
})
start({
sandbox: {
experimentalStyleIsolation: true,
loose: true,
},
singular: true,
scopedCSS: true,
getPublicPath: window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__,
excludeAssetFilter: url => {
return (
url.indexOf('framework/amap/AMap.UI') !== -1 ||
url.indexOf('framework/amap/init.js') !== -1 ||
url.indexOf('framework/three.js') !== -1 ||
url.indexOf('threedimensional/frameworkthree') !== -1 ||
url.indexOf('iframe/Civ3DLLab/js') !== -1 ||
url.indexOf('framework/jquery/gridify-min.js') !== -1 ||
url.indexOf('framework/jquery/gridify.qrcode.js') !== -1 ||
url.indexOf('echarts') !== -1 ||
url.indexOf('lbs.amap.com') !== -1 ||
url.indexOf('restapi.amap.com') !== -1 ||
url.indexOf('webapi.amap.com') !== -1 ||
url.indexOf('webapi.amap.com/count') !== -1 ||
url.indexOf('api.map.baidu.com') !== -1 ||
url.indexOf('map.baidu.com') !== -1 ||
url.indexOf('pv.sohu.com') !== -1 ||
url.indexOf('mt0.google.cn') !== -1 ||
url.indexOf('mt1.google.cn') !== -1 ||
url.indexOf('mt2.google.cn') !== -1 ||
url.indexOf('mt3.google.cn') !== -1 ||
url.indexOf('hm.baidu.com') !== -1 ||
url.indexOf('https://maponline0.bdimg.com') !== -1 ||
url.indexOf('https://maponline1.bdimg.com') !== -1 ||
url.indexOf('https://maponline2.bdimg.com') !== -1 ||
url.indexOf('https://maponline3.bdimg.com') !== -1 ||
url.indexOf('https://api.map.baidu.com/getscript') !== -1
);
},
});
runAfterFirstMounted(() => {
console.log('[MainApp] first app mounted');
});
defaultApp();
addGlobalUncaughtErrorHandler(event => {
console.log(event);
const error = event.error;
const reson = 'Failed to fetch';
if(error && error.message.indexOf(MICRO_STATUS.LOADING_SOURCE_CODE) && error.message.indexOf(reson)) {
// window.history.pushState({message: '应用服务请求异常,请检查应用配置'}, null, '/civbase/500')
}
});
};
export const defaultApp = () => {
const config = createStoreage.get('globalConfig');
if (config && config.token) {
// const startWith = config.homepage ? config.homepage.split('/') : [];
const basePath = (config.homepage !== "" && FILTER_FOLER_REG.test(config.homepage)) ? 'civweb4': 'civweb4';
setDefaultMountApp( `/${pkg.name.toLocaleLowerCase()}/${basePath}/?client=${config.client}`,
);
}
};