mob-edit-view-base.tsx 3.6 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
import { IPSAppDEMobEditView, IPSDEForm } from "@ibiz/dynamic-model-api";
import { MobEditViewInterface, ModelTool } from "ibiz-core";
import { MainViewBase } from "./main-view-base";

/**
 * 编辑视图基类
 *
 * @export
 * @class MobEditViewBase
 * @extends {MainViewBase}
 */
export class MobEditViewBase extends MainViewBase implements MobEditViewInterface {

    /**
     * 视图实例
     * 
     * @memberof MobEditViewBase
     */
    public declare viewInstance: IPSAppDEMobEditView;

    /**
     * 编辑表单实例
     *
     * @public
     * @type {IPSDEForm}
     * @memberof MobEditViewBase
     */
    public editFormInstance !: IPSDEForm;

    /**
     * 表单数据是否变化
     *
     * @type {boolean}
     * @memberof MobEditViewBase
     */
    public dataChange: boolean = false;

    /**
     * 引擎初始化
     *
     * @public
     * @memberof MobEditViewBase
     */
    public engineInit(opts: any = {}): void {
        if (this.Environment?.isPreviewMode) {
            return;
        }
        this.engine.init({
            view: this,
            form: (this.$refs[this.editFormInstance.name] as any).ctrl,
            p2k: '0',
            isLoadDefault: this.viewInstance.loadDefault,
            keyPSDEField: this.appDeCodeName.toLowerCase(),
            majorPSDEField: this.appDeMajorFieldName.toLowerCase(),
        });
    }

    /**
     * 初始化编辑视图实例
     * 
     * @memberof MobEditViewBase
     */
    public async viewModelInit() {
        await super.viewModelInit();
        this.editFormInstance = ModelTool.findPSControlByName('form', this.viewInstance.getPSControls()) as IPSDEForm;
    }

    /**
     * 检查表单是否修改
     *
     * @return {*}  {Promise<boolean>}
     * @memberof MobEditViewBase
     */
    public async checkChange(): Promise<boolean> {
        if (!this.dataChange) {
            return true;
        }
        const title: any = this.$t('app.tabpage.sureclosetip.title');
        const content: any = this.$t('app.tabpage.sureclosetip.content');
        const result = await this.$Notice.confirm.call(this, title, content);
        if (result) {
            this.dataChange = false;
            return true;
        } else {
            return false;
        }
    }

    /**
     * 关闭视图
     * 
     * @param {any[]} [args]
     * @memberof MobEditViewBase
     */
    public async closeView(args?: any[]) {
        let result = await this.checkChange();
        if (result) {
            super.closeView(args);
        }
    }

    /**
     * 渲染视图主体内容区
     * 
     * @memberof MobEditViewBase
     */
    public renderMainContent() {
        if (!this.editFormInstance) {
            return null;
        }
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.editFormInstance);
        return this.$createElement(targetCtrlName, {props: targetCtrlParam, ref: this.editFormInstance.name, on: targetCtrlEvent });
    }

    /**
     * 绘制头部标题栏
     * 
     * @memberof MobEditViewBase
     */
    public renderViewHeaderCaptionBar() {
        if (!this.showCaptionBar) {
            return null;
        }
        const srfCaption = this.model.srfCaption;
        const dataInfo: string = this.model.dataInfo ? (`-${this.model.dataInfo}`) : '';
        const showInfoBar: boolean = (this.viewInstance as IPSAppDEMobEditView).showDataInfoBar;
        const psImage = this.viewInstance.getPSSysImage();
        return <ion-title slot="captionbar" class="view-title"><app-ps-sys-image imageModel={psImage}></app-ps-sys-image>{dataInfo && showInfoBar ? srfCaption + dataInfo : srfCaption}</ion-title>
    }
}