You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
/** |
|
* @program: kicc-ui |
|
* @description: 微应用数据通信 |
|
* @author: wangxiang4 |
|
* @create: 2023/7/20 |
|
*/ |
|
|
|
import { initGlobalState, MicroAppStateActions } from 'qiankun'; |
|
import { store } from '/@/store'; |
|
import { router } from '/@/router'; |
|
import { getAccessToken } from '/@/utils/auth'; |
|
import { useMicroAppStore } from '/@/store/modules/microApp'; |
|
import { GlStateEnum } from '/@/enums/microAppEnum'; |
|
import { isEmpty } from '/@/utils/is'; |
|
import { useMessage } from '/@/hooks/web/useMessage'; |
|
|
|
/** 子应用的数据 */ |
|
export function getSubDefineProps() { |
|
return { |
|
microData: { |
|
publicPath: '/', |
|
token: getAccessToken(), |
|
store, |
|
router, |
|
useMessage: useMessage.call(this) |
|
} |
|
}; |
|
} |
|
|
|
/** |
|
* 初始化全局通信状态 |
|
* @param state 主应穿透子应用的定义数据(必须声明) |
|
* 不声明会导致修改state检查不到当前声明的对象属性发生改变,无法触发监听事件 |
|
* https://qiankun.umijs.org/api#initglobalstatestate |
|
*/ |
|
export function initGlState(state?: Recordable): MicroAppStateActions { |
|
const microAppStore = useMicroAppStore(); |
|
const actions = initGlobalState(state); |
|
actions.onGlobalStateChange((newState, prev) => { |
|
const { [GlStateEnum.FORM_DESIGN_EMIT_KEY]: formDesignEmit, [GlStateEnum.WORKFLOW_DESIGN_EMIT_KEY]: workflowDesignEmit } = newState; |
|
!isEmpty(formDesignEmit) && microAppStore.setFormDesignApp(formDesignEmit); |
|
!isEmpty(workflowDesignEmit) && microAppStore.setWorkflowDesignApp(workflowDesignEmit); |
|
}); |
|
return actions; |
|
}
|
|
|