fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { Store, StoreOptions } from "vuex"
import { InjectionKey, ComputedRef } from "vue"
 
/**
 * store 状态管理
 * @copyright 火星科技 mars3d.cn
 * @author 火星吴彦祖 2022-5-19
 */
declare module "@mars/widgets/common/store/widget" {
  // 为 store state 声明类型
  export interface DefaultOption {
    autoDisable?: boolean
    disableOther?: boolean | string[]
    group?: string // group相同的widget一定是互斥的
    meta?: any // 额外参数 不会在每次关闭后清除
  }
 
  export interface Widget {
    name: string // 唯一标识
    key?: string // 作为组件 diff 环节的key,用于控制组件重载
    component?: any // widget关联的异步组件
    autoDisable?: boolean // 是否能够被自动关闭
    disableOther?: boolean | string[] // 是否自动关闭其他widget,或通过数组指定需要被关闭的widget
    group?: string // group相同的widget一定是互斥的
    visible?: boolean // 显示隐藏
    data?: any // 额外传参 会在每次关闭后清除
    meta?: any // 额外参数 不会在每次关闭后清除
  }
 
  export interface WidgetState {
    widgets?: Widget[] // widget具体配置
    openAtStart?: string[] // 默认加载的widget
    defaultOption?: DefaultOption // 支持配置默认参数
  }
 
  export const key: InjectionKey<Store<WidgetState>>
 
  export const getInjectKey: () => string
 
  export const injectState: (options: StoreOptions<WidgetState>) => Store<WidgetState>
 
  export const useWidgetStore: any
 
  export const useWidget: () => {
    currentWidget: any
    // 获取指定的widget
    getWidget: (name: string) => any
    // 出发对应widget的onUpdate
    updateWidget: (name: string, ...args: any[]) => any
    // 获取widget的当前激活状态
    isActivate: (name: string) => boolean
    // 激活指定 widget模块
    activate: (widget: string | Widget | (string | Widget)[], reload?: boolean) => void
    // 释放指定的widget
    disable: (name: string | string[]) => void
    // 关闭释放所有widget ,hasAll传true值强制释放所有widget(默认autoDisable为false的widet不会释放)
    disableAll: (hasAll?: boolean) => void
  }
}