From b2266ed6d3f430c82887730b32f0d15c4b0b3029 Mon Sep 17 00:00:00 2001 From: wangxiang <1827945911@qq.com> Date: Tue, 25 Jul 2023 15:27:04 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=BE=AE=E6=9C=8D=E5=8A=A1=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/enums/microAppEnum.ts | 16 +++++++++++++++ src/qiankun/index.ts | 6 ++++-- src/qiankun/state.ts | 20 +++++++++---------- src/store/modules/microApp.ts | 11 ++++++++-- .../form/helper/WorkflowFormDesign.vue | 6 +++++- 5 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 src/enums/microAppEnum.ts diff --git a/src/enums/microAppEnum.ts b/src/enums/microAppEnum.ts new file mode 100644 index 0000000..d39279a --- /dev/null +++ b/src/enums/microAppEnum.ts @@ -0,0 +1,16 @@ +/** + * @program: dolphin-admin + * @description: 微应用枚举 + * @author: wangxiang4 + * @since: 2023/7/24 + */ + +export enum GlStateEnum { + // 表单设计器 + FORM_DESIGN_PROPS_KEY = 'MICRO_APP_FORM_DESIGN_PROPS_KEY', + FORM_DESIGN_EMIT_KEY = 'MICRO_APP_FORM_DESIGN_EMIT_KEY', + // 工作流设计器 + WORKFLOW_DESIGN_PROPS_KEY = 'MICRO_APP_WORKFLOW_DESIGN_PROPS_KEY', + WORKFLOW_DESIGN_EMIT_KEY = 'MICRO_APP_WORKFLOW_DESIGN_EMIT_KEY', +} + diff --git a/src/qiankun/index.ts b/src/qiankun/index.ts index 8410fb7..dc0045e 100644 --- a/src/qiankun/index.ts +++ b/src/qiankun/index.ts @@ -5,10 +5,12 @@ * @create: 2023/7/20 */ -import { registerMicroApps, start, runAfterFirstMounted, addGlobalUncaughtErrorHandler } from 'qiankun'; +import { registerMicroApps, start, runAfterFirstMounted, addGlobalUncaughtErrorHandler, MicroAppStateActions } from 'qiankun'; import { apps } from './apps'; import { getSubDefineProps, initGlState } from './state'; +export let microState: MicroAppStateActions; + /** 匹配激活微服务路由规则 */ function listenerRouteActiveRule(routerPath) { return (location) => location.pathname.endsWith(routerPath); @@ -50,7 +52,7 @@ function registerApps() { // 全局的未捕获异常处理器 addGlobalUncaughtErrorHandler((event) => console.log(event)); // 初始化全局通信 - initGlState(); + microState = initGlState({ foo: 'bar' }); // 启动qiankun start({ sandbox: { experimentalStyleIsolation: true } diff --git a/src/qiankun/state.ts b/src/qiankun/state.ts index 96fd400..c4a0311 100644 --- a/src/qiankun/state.ts +++ b/src/qiankun/state.ts @@ -5,11 +5,12 @@ * @create: 2023/7/20 */ -import { initGlobalState } from 'qiankun'; +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'; /** 子应用的数据 */ export function getSubDefineProps() { @@ -27,15 +28,14 @@ export function getSubDefineProps() { * 初始化全局通信状态 * @param state 主应用穿的公共数据 */ -export function initGlState(info = {}) { +export function initGlState(state = {}): MicroAppStateActions { const microAppStore = useMicroAppStore(); - const actions = initGlobalState(info); - actions.setGlobalState(info); + const actions = initGlobalState(state); actions.onGlobalStateChange((newState, prev) => { - const { formDesignEmit } = newState; - microAppStore.setFormDesignApp({ - formDesignEmit - }); - console.log('Emit收参数', newState, prev); - }); + const { [GlStateEnum.FORM_DESIGN_EMIT_KEY]: formDesignEmit, [GlStateEnum.WORKFLOW_DESIGN_EMIT_KEY]: workflowDesignEmit } = newState; + formDesignEmit && microAppStore.setFormDesignApp(formDesignEmit); + workflowDesignEmit && microAppStore.setWorkflowDesignApp(workflowDesignEmit); + console.log(1) + }, true); + return actions; } diff --git a/src/store/modules/microApp.ts b/src/store/modules/microApp.ts index 401daa6..78b0043 100644 --- a/src/store/modules/microApp.ts +++ b/src/store/modules/microApp.ts @@ -8,28 +8,35 @@ import { defineStore } from 'pinia'; import { store } from '/@/store'; interface MicroAppState { - // 表单设计APP formDesignApp: Recordable; + workflowDesignApp: Recordable; } export const useMicroAppStore = defineStore({ id: 'micro-app', state: (): MicroAppState => ({ formDesignApp: {}, + workflowDesignApp: {} }), getters: { getFormDesignApp(): Recordable { return this.formDesignApp; }, + getWorkflowDesignApp(): Recordable { + return this.workflowDesignApp; + } }, actions: { setFormDesignApp(data: Recordable): void { this.formDesignApp = data; + }, + setWorkflowDesignApp(data: Recordable): void { + this.workflowDesignApp = data; } } }); // 需要在设置之外使用 -export function useAppStoreWithOut() { +export function useMicroAppStoreWithOut() { return useMicroAppStore(store); } diff --git a/src/views/workflow/extension/form/helper/WorkflowFormDesign.vue b/src/views/workflow/extension/form/helper/WorkflowFormDesign.vue index 4477135..5cfaeb2 100644 --- a/src/views/workflow/extension/form/helper/WorkflowFormDesign.vue +++ b/src/views/workflow/extension/form/helper/WorkflowFormDesign.vue @@ -13,7 +13,8 @@ import { reactive } from 'vue'; import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; import { loadMicroApp } from 'qiankun'; - + import { microState } from '/@/qiankun'; + import { initGlState } from '/@/qiankun/state'; interface TableState { tag: string; } @@ -42,6 +43,9 @@ function test(){ console.log(10101); + microState.setGlobalState({ + foo: 'barbar' + }); } /** 处理弹出框提交 */