optview-base.tsx 3.1 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
import { MainViewBase } from "./mainview-base";
import { OptionViewEngine, ModelTool, throttle, OptViewInterface } from 'ibiz-core';
import { IPSAppDEEditView, IPSDEForm } from "@ibiz/dynamic-model-api";

/**
 * 选项操作视图基类
 *
 * @export
 * @class OptViewBase
 * @extends {MainViewBase}
 * @implements {OptViewInterface}
 */
export class OptViewBase extends MainViewBase implements OptViewInterface {

    /**
     * 视图实例
     * 
     * @memberof OptViewBase
     */
    public declare viewInstance: IPSAppDEEditView;

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

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

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


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

    /**
     *  渲染视图底部按钮
     */
    public renderFooter() {
        return <template slot="footer">
            <div dis-hover bordered={false}  class="view-footer__buttons">
                    <app-button
                        type="primary"
                        caption={this.viewButtonModel.view_okbtn.text}
                        on-onClick={(e: any) => throttle(this.onClickOk, e, this)}>
                    </app-button>                
                    &nbsp;&nbsp;
                    <app-button
                        caption={this.viewButtonModel.view_cancelbtn.text}
                        on-onClick={(e: any) => throttle(this.onClickCancel, e, this)}>
                    </app-button>
            </div>
        </template>
    }

    /**
     * 确定
     *
     * @memberof OptViewBase
     */
    public onClickOk(e: MouseEvent): void {
        if (this.engine) {
            this.engine.ok();
        }
    }

    /**
     * 取消
     *
     * @memberof OptViewBase
     */
    public onClickCancel(e: MouseEvent): void {
        if (this.engine) {
            this.engine.cancel();
        }
    }

}