MDViewBase.tsx 4.2 KB
Newer Older
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
import { Prop } from 'vue-property-decorator';
import { ViewBase } from './ViewBase';
import CodeListService from '@/service/app/codelist-service';

/**
 * 多数据视图基类
 *
 * @export
 * @class MDViewBase
 * @extends {ViewBase}
 */
export class MDViewBase extends ViewBase {

    /**
     * 代码表服务对象
     *
     * @type {CodeListService}
     * @memberof MDViewBase
     */
    public codeListService: CodeListService = new CodeListService({ $store: this.$store });

    /**
     * 是否嵌入关系界面
     *
     * @readonly
     * @type {boolean}
     * @memberof MDViewBase
     */
    @Prop({ default: false })
    protected isformDruipart?: boolean;

    /**
     * 是否展开搜索表单
     *
     * @readonly
     * @type {boolean}
     * @memberof MDViewBase
     */
    protected isExpandSearchForm: boolean = false;

    /**
     * 快速搜索栏数据对象
     *
     * @type {*}
     * @memberof MDViewBase
     */
    public quickFormData: any = {};

    /**
     * 快速分组数据对象
     *
     * @type {*}
     * @memberof MDViewBase
     */
    public quickGroupData: any = {};

    /**
     * 快速分组是否有抛值
     *
     * @type {boolean}
     * @memberof MDViewBase
     */
    public isEmitQuickGroupValue: boolean = false;

    /**
     * 快速分组模型
     *
     * @type {any[]}
     * @memberof MDViewBase
     */
    public quickGroupModel: any[] = [];

    /**
     * 快速搜索栏值变化
     *
     * @param {*} $event
     * @memberof MDViewBase
     */
    public quickFormValueChange = ($event: any) => {
        this.quickFormData = $event;
        this.onSearch();
    }

    /**
     * 视图挂载完毕
     *
     * @protected
     * @memberof MDViewBase
     */
    protected viewMounted(): void {
        this.loadQuickGroupModel();
    }

    /**
     * 加载快速分组模型
     *
     * @protected
     * @memberof MDViewBase
     */
    protected loadQuickGroupModel(): void { }

    /**
     * 快速搜索
     *
     * @protected
     * @memberof MDViewBase
     */
    protected onSearch(): void { }

    /**
     * 视图创建完毕
     *
     * @protected
     * @memberof MDViewBase
     */
    protected viewCreated(): void {
        if (this.formDruipart) {
            this.formDruipart.subscribe((res: any) => {
                if (Object.is(res.action, 'save')) {
                    this.viewState.next({ tag: 'grid', action: 'save', data: this.viewparams });
                }
                if (Object.is(res.action, 'load')) {
                    this.engine.load(res.data, true);
                }
            });
        }
    }

    /**
     * 快速分组值变化
     *
     * @protected
     * @param {*} $event
     * @memberof MDViewBase
     */
    protected quickGroupValueChange = ($event: any) => {
        if ($event) {
            this.quickGroupData.clearAll();
            if ($event.data) {
                Object.assign(this.quickGroupData, $event.data);
            }
            this.onSearch();
        }
        this.isEmitQuickGroupValue = true;
    }

    /**
     * 处理快速分组模型动态数据部分(%xxx%)
     *
     * @protected
     * @param {any[]} inputArray
     * @returns {any[]}
     * @memberof MDViewBase
     */
    protected handleDynamicData(inputArray: any[]): any[] {
        if (inputArray.length > 0) {
            inputArray.forEach((item: any) => {
                if (item.data && Object.keys(item.data).length > 0) {
                    Object.keys(item.data).forEach((name: any) => {
                        let value: any = item.data[name];
                        if (value && typeof (value) == 'string' && value.startsWith('%') && value.endsWith('%')) {
                            const key = (value.substring(1, value.length - 1)).toLowerCase();
                            if (this.context[key]) {
                                value = this.context[key];
                            } else if (this.viewparams[key]) {
                                value = this.viewparams[key];
                            }
                        }
                        item.data[name] = value;
                    })
                }
            })
        }
        return inputArray;
    }

}