app-store.js
952 Bytes
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
import { initGlobalState, MicroAppStateActions } from "qiankun";
import store from "@/store";
import { useMessage } from '@/utils/globalUI/elementMsg';
const { createMessage } = useMessage();
const error = createMessage.error;
const initialState = {
token: localStorage.getItem('token') || '',
showLoading: false,
errorMsg: ''
};
// 初始化 state
const actions = initGlobalState(initialState);
actions.onGlobalStateChange((state, prev) => {
// 同步token、全局Loading和报错提示
// console.log("主应用: 变更前");
// console.log(prev);
// console.log("主应用: 变更后");
// console.log(state);
const { token, showLoading, errorMsg } = state;
if(errorMsg) {
error(errorMsg);
}
if(token === 'removeToken') {
store.dispatch('app/setToken', '');
setTimeout(() => {
window.location.reload();
},300)
}
// store.dispatch('app/showLoading', showLoading);
});
export default actions;