Browse Source

chore: 微服务架构调整

master
wangxiang 2 years ago
parent
commit
b2266ed6d3
  1. 16
      src/enums/microAppEnum.ts
  2. 6
      src/qiankun/index.ts
  3. 20
      src/qiankun/state.ts
  4. 11
      src/store/modules/microApp.ts
  5. 6
      src/views/workflow/extension/form/helper/WorkflowFormDesign.vue

16
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',
}

6
src/qiankun/index.ts

@ -5,10 +5,12 @@
* @create: 2023/7/20 * @create: 2023/7/20
*/ */
import { registerMicroApps, start, runAfterFirstMounted, addGlobalUncaughtErrorHandler } from 'qiankun'; import { registerMicroApps, start, runAfterFirstMounted, addGlobalUncaughtErrorHandler, MicroAppStateActions } from 'qiankun';
import { apps } from './apps'; import { apps } from './apps';
import { getSubDefineProps, initGlState } from './state'; import { getSubDefineProps, initGlState } from './state';
export let microState: MicroAppStateActions;
/** 匹配激活微服务路由规则 */ /** 匹配激活微服务路由规则 */
function listenerRouteActiveRule(routerPath) { function listenerRouteActiveRule(routerPath) {
return (location) => location.pathname.endsWith(routerPath); return (location) => location.pathname.endsWith(routerPath);
@ -50,7 +52,7 @@ function registerApps() {
// 全局的未捕获异常处理器 // 全局的未捕获异常处理器
addGlobalUncaughtErrorHandler((event) => console.log(event)); addGlobalUncaughtErrorHandler((event) => console.log(event));
// 初始化全局通信 // 初始化全局通信
initGlState(); microState = initGlState({ foo: 'bar' });
// 启动qiankun // 启动qiankun
start({ start({
sandbox: { experimentalStyleIsolation: true } sandbox: { experimentalStyleIsolation: true }

20
src/qiankun/state.ts

@ -5,11 +5,12 @@
* @create: 2023/7/20 * @create: 2023/7/20
*/ */
import { initGlobalState } from 'qiankun'; import { initGlobalState, MicroAppStateActions } from 'qiankun';
import { store } from '/@/store'; import { store } from '/@/store';
import { router } from '/@/router'; import { router } from '/@/router';
import { getAccessToken } from '/@/utils/auth'; import { getAccessToken } from '/@/utils/auth';
import { useMicroAppStore } from '/@/store/modules/microApp'; import { useMicroAppStore } from '/@/store/modules/microApp';
import { GlStateEnum } from '/@/enums/microAppEnum';
/** 子应用的数据 */ /** 子应用的数据 */
export function getSubDefineProps() { export function getSubDefineProps() {
@ -27,15 +28,14 @@ export function getSubDefineProps() {
* *
* @param state 穿 * @param state 穿
*/ */
export function initGlState(info = {}) { export function initGlState(state = {}): MicroAppStateActions {
const microAppStore = useMicroAppStore(); const microAppStore = useMicroAppStore();
const actions = initGlobalState(info); const actions = initGlobalState(state);
actions.setGlobalState(info);
actions.onGlobalStateChange((newState, prev) => { actions.onGlobalStateChange((newState, prev) => {
const { formDesignEmit } = newState; const { [GlStateEnum.FORM_DESIGN_EMIT_KEY]: formDesignEmit, [GlStateEnum.WORKFLOW_DESIGN_EMIT_KEY]: workflowDesignEmit } = newState;
microAppStore.setFormDesignApp({ formDesignEmit && microAppStore.setFormDesignApp(formDesignEmit);
formDesignEmit workflowDesignEmit && microAppStore.setWorkflowDesignApp(workflowDesignEmit);
}); console.log(1)
console.log('Emit收参数', newState, prev); }, true);
}); return actions;
} }

11
src/store/modules/microApp.ts

@ -8,28 +8,35 @@ import { defineStore } from 'pinia';
import { store } from '/@/store'; import { store } from '/@/store';
interface MicroAppState { interface MicroAppState {
// 表单设计APP
formDesignApp: Recordable; formDesignApp: Recordable;
workflowDesignApp: Recordable;
} }
export const useMicroAppStore = defineStore({ export const useMicroAppStore = defineStore({
id: 'micro-app', id: 'micro-app',
state: (): MicroAppState => ({ state: (): MicroAppState => ({
formDesignApp: {}, formDesignApp: {},
workflowDesignApp: {}
}), }),
getters: { getters: {
getFormDesignApp(): Recordable { getFormDesignApp(): Recordable {
return this.formDesignApp; return this.formDesignApp;
}, },
getWorkflowDesignApp(): Recordable {
return this.workflowDesignApp;
}
}, },
actions: { actions: {
setFormDesignApp(data: Recordable): void { setFormDesignApp(data: Recordable): void {
this.formDesignApp = data; this.formDesignApp = data;
},
setWorkflowDesignApp(data: Recordable): void {
this.workflowDesignApp = data;
} }
} }
}); });
// 需要在设置之外使用 // 需要在设置之外使用
export function useAppStoreWithOut() { export function useMicroAppStoreWithOut() {
return useMicroAppStore(store); return useMicroAppStore(store);
} }

6
src/views/workflow/extension/form/helper/WorkflowFormDesign.vue

@ -13,7 +13,8 @@
import { reactive } from 'vue'; import { reactive } from 'vue';
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal';
import { loadMicroApp } from 'qiankun'; import { loadMicroApp } from 'qiankun';
import { microState } from '/@/qiankun';
import { initGlState } from '/@/qiankun/state';
interface TableState { interface TableState {
tag: string; tag: string;
} }
@ -42,6 +43,9 @@
function test(){ function test(){
console.log(10101); console.log(10101);
microState.setGlobalState({
foo: 'barbar'
});
} }
/** 处理弹出框提交 */ /** 处理弹出框提交 */

Loading…
Cancel
Save