guoshipeng
2023-08-14 828fedaae4ff767e0b9696a2a0702ab4d3721c66
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
import { Component, Prop, Vue } from 'vue-property-decorator';
 
/**
 * 动态表单组件注册类
 * 提供注册和获取方法
 */
class WidgetRegistry {
 
    private widgets: Map<string, any> = new Map<string, any>();
 
    private defaultWidget: any;
 
    /**
     * 设置默认组件,以便找不到type对应的逐渐时候显示
     * @param widget
     */
    public setDefault(widget: any) {
        this.defaultWidget = widget;
    }
 
    /**
     * 注册动态表单组件
     * @param type
     * @param widget
     */
    public register(type: string, widget: any) {
        this.widgets.set(type, widget);
    }
 
    /**
     * 判断指定的组件名称是否存在
     * @param type
     */
    public has(type: string) {
        return this.widgets.has(type);
    }
 
    /**
     * 根据指定类型获取动态组件
     * @param type
     */
    public getType(type: string): any {
        if (this.has(type)) {
            return this.widgets.get(type);
        }
        return this.defaultWidget;
    }
 
}
 
const widgetRegistry = new WidgetRegistry();
export default widgetRegistry;