mob-edit-view3-base.tsx 6.3 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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
import { MobEditView3Interface, ModelTool } from 'ibiz-core';
import { MobEditViewBase } from './mob-edit-view-base';
import { IPSAppDEMobEditView, IPSDEDRTab, IPSDEDRTabPage } from '@ibiz/dynamic-model-api';

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

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

    /**
     * 数据关系分页部件实例
     *
     * @public
     * @type {IBizFormModel}
     * @memberof MobEditView3Base
     */
    public drtabInstance !: IPSDEDRTab;

    /**
     * 关系项
     *
     * @type {*}
     * @memberof EditView3Base
     */
    public drItem: any;

    /**
     * 关系项缓存
     *
     * @type {*}
     * @memberof MobEditView3Base
     */
    public drItemCache: any[] = [];

    /**
     * 选中数据
     *
     * @type {*}
     * @memberof MobEditView3Base
     */
    public selection: any = {};

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

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

    /**
     * 计算tab样式
     *
     * @memberof MobEditView3Base
     */
    calcTabStyle(tag: string) {
        const items: any = this.drtabInstance.getPSDEDRTabPages();
        const count = 100 / (items.length + 1);
        return tag == 'form' ? { width: (count) + '%' } : { width: (100 - count) + '%' };
    }

    /**
     * 数据关系栏变更
     *
     * @param {*} tab
     * @param {MouseEvent} event
     * @memberof MobEditView3Base
     */
    public drTabChange(tab: any, event: MouseEvent) {
        if (this.engine) {
            this.engine.drTabSelectionChange(tab);
        }
    }
    /**
     * 渲染表单
     *
     * @return {*} 
     * @memberof AppEditView3Base
     */
    public renderForm() {
        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 });
    }

    /**
     * 渲染数据关系分页部件
     *
     * @return {*} 
     * @memberof AppEditView3Base
     */
    public renderDrTab() {
        if (!this.drtabInstance) {
            return null;
        }
        let { targetCtrlName, targetCtrlParam, targetCtrlEvent } = this.computeTargetCtrlData(this.drtabInstance);
        Object.assign(targetCtrlParam.staticProps, {
            needFirstSelected: false
        });
        return this.$createElement(targetCtrlName, {
            props: targetCtrlParam,
            ref: this.drtabInstance?.name,
            style: this.calcTabStyle(this.drtabInstance?.name),
            on: targetCtrlEvent
        });
    }

    /**
     * 传染主内容区
     *
     * @return {*} 
     * @memberof AppDefaultMobEditView
     */
    public renderMainContent() {
        return (
                <div class="app-vc-tab">
                    <div class="app-vc-tab__header">
                        <div class="app-vc-tab__header__drtab">
                            <div
                                class={["drtab__item", (this.drItem && this.drItem.name === 'form') || !this.drItem ? 'drtab__item--select' : '']}
                                style={this.calcTabStyle('form')}
                                on-click={(event: any) => this.drTabChange({ name: 'form' }, event)}>
                                {this.drtabInstance ? this.$tl((this.drtabInstance.getEditItemCapPSLanguageRes()?.lanResTag, this.drtabInstance.editItemCaption)) : ''}
                            </div>
                            {this.renderDrTab()}
                        </div>
                    </div>
                    <div class="app-vc-tab__content">
                        <div class="app-vc-tab__content__form" style={this.drItem && this.drItem.name !== 'form' ? 'display: none;' : ''}>{this.renderForm()}</div>
                        {...this.renderDrView()}
                    </div>
                </div>
        )
    }

    /**
     * 渲染关系视图
     *
     * @return {*}  {*}
     * @memberof AppEditView3Base
     */
    public renderDrView(): any {
        if (!this.drItem) {
            return [];
        }
        return this.drtabInstance.getPSDEDRTabPages()?.map((item: IPSDEDRTabPage) => {
            const viewContext = this.drItem?.srfnavdata?.context || this.context;
            const viewParam = this.drItem?.srfnavdata?.viewparams || this.viewparams;
            Object.assign(viewContext, { viewpath: item.getPSAppView()?.modelPath });
            const cache = this.drItemCache.indexOf(item.name);
            return cache>-1 ? (
                this.$createElement('app-view-shell', {
                    props: {
                        staticProps: {
                            viewDefaultUsage: 'INCLUDEDVIEW',
                            appDeCodeName: this.appDeCodeName,
                        },
                        dynamicProps: {
                            _context: JSON.stringify(viewContext),
                            _viewparams: JSON.stringify(viewParam),
                        }
                    },
                    class: "view-container2",
                    style: { display: this.drItem?.name == item.name ? 'block' : 'none' },
                    on: {
                    }
                })
            ) : null
        })
    }

}