daimp-front/main/src/micro/actions.js

30 lines
611 B
JavaScript
Raw Normal View History

import { initGlobalState } from 'qiankun';
import { reactive } from 'vue';
const initialState = reactive({
2025-02-13 07:06:39 +00:00
token: null,
user: {
name: 'admin',
},
menus: [],
auths: [],
});
const actions = initGlobalState(initialState);
actions.onGlobalStateChange((newState, prev) => {
console.log('main change', newState, prev);
for (const key in newState) {
initialState[key] = newState[key];
}
});
// 有key表示取globalState下的某个子级对象
// 无key表示取全部
actions.getGlobalState = (key) => {
return key ? initialState[key] : initialState;
};
export default actions;