Blame view

ant-design-vue-jeecg/src/qiankun/index.js 1.67 KB
肖超群 authored
1
2
3
/**
 * qiankun配置
 */
肖超群 authored
4
5
6
7
8
9
10
import {
  registerMicroApps,
  setDefaultMountApp,
  start,
  runAfterFirstMounted,
  addGlobalUncaughtErrorHandler
} from 'qiankun';
肖超群 authored
11
12
import {apps} from './apps';
import {getProps, initGlState} from './state';
肖超群 authored
13
肖超群 authored
14
15
16
17
/**
 * 重构apps
 */
function filterApps() {
肖超群 authored
18
19
20
21
22
23
24
  apps.forEach((item) => {
    //主应用需要传递给微应用的数据。
    item.props = getProps();
    //微应用触发的路由规则
    item.activeRule = genActiveRule('/' + item.activeRule);
  });
  return apps;
肖超群 authored
25
26
27
28
29
30
31
}

/**
 * 路由监听
 * @param {*} routerPrefix 前缀
 */
function genActiveRule(routerPrefix) {
肖超群 authored
32
  return location => location.pathname.startsWith(routerPrefix);
肖超群 authored
33
34
35
36
37
38
}

/**
 * 微应用注册
 */
function registerApps() {
肖超群 authored
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
  const _apps = filterApps();
  registerMicroApps(_apps,
    {
      beforeLoad: [
        loadApp => {
          console.log('before load', loadApp);
        }
      ],
      beforeMount: [
        mountApp => {
          console.log('before mount', mountApp);
        }
      ],
      afterMount: [
        mountApp => {
          console.log('before mount', mountApp);
        }
      ],
      afterUnmount: [
        unloadApp => {
          console.log('after unload', unloadApp);
        }
      ]
    });
  // 设置默认子应用,与 genActiveRule中的参数保持一致
  // setDefaultMountApp();
  // 第一个微应用 mount 后需要调用的方法,比如开启一些监控或者埋点脚本。
  runAfterFirstMounted(() => console.log('开启监控'));
  // 添加全局的未捕获异常处理器。
  addGlobalUncaughtErrorHandler(event => console.log(event));
  // 定义全局状态
  initGlState();
  //启动qiankun
  start({});
肖超群 authored
73
74
75
}

export default registerApps;