user1
2024-06-19 53c71572f88a86514a41f0a8f489fccfcaeed6e2
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
import Vue from "vue";
import App from "./App.vue";
import less from "less";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import store from "./store";
 
Vue.config.productionTip = false;
 
// 自定义配置
import config from "@/assets/js/config";
Vue.prototype.config = config;
// Vue.prototype.thisBookConfig = await config.getBookConfig();
 
// 请求处理
import MG from "@/assets/js/middleGround/WebMiddleGroundApi";
Vue.prototype.MG = MG;
 
//工具类
import toolClass from "./assets/js/toolClass";
Vue.prototype.tool = toolClass;
 
// 时间处理
import moment from "moment";
Vue.prototype.moment = moment;
 
Vue.use(less);
Vue.use(ElementUI);
 
let instance = null;
 
function render(props = {}) {
  const { container, onGlobalStateChange, setGlobalState } = props;
  Vue.prototype.onGlobalStateChange = onGlobalStateChange;
  Vue.prototype.setGlobalState = setGlobalState;
  Vue.prototype.container = container;
  instance = new Vue({
    // router,
    store,
    render: (h) => h(App)
  }).$mount(container ? container.querySelector("#app") : "#app");
}
 
// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}
 
// qiankun
export async function bootstrap() {}
export async function mount(props) {
  console.log(props, "子层propspropspropsprops");
  props.onGlobalStateChange((state, prev) => {
    // state: 变更后的状态; prev 变更前的状态
    console.log("子层变化:", state, prev);
    // 状态变化同步vuex,用于各页面调用
    store.commit("setQiankun", state);
  });
 
  // props.setGlobalState({
  //   state: 3, // 应用挂载完成,同时用于触发一次stateChange将state挂载在vuex当中
  // });
 
  render(props);
}
export async function unmount() {
  instance.$destroy();
  instance.$el.innerHTML = "";
  instance = null;
}
 
// 增加 update 钩子以便主应用手动更新微应用
// export async function update(props) {
//   render(props);
// }