CONTROL-BASE.vue.ftl 6.8 KB
Newer Older
1 2
<template>
    <div class = "drtab">
3
        <tabs :animated='false' class='app-dr-tab' name='${ctrl.getCodeName()?lower_case}' @on-click="tabPanelClick">
4
  <#list ctrl.getRootItem().getAllItems() as dritem>
5
                <tab-pane <#if dritem_index == 0>v-if="isShowSlot"</#if> :index='${dritem_index?c}' name='${dritem.getId()?lower_case}' tab='${ctrl.getCodeName()?lower_case}' class='' :disabled='items[${dritem_index?c}].disabled'
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
                label='${dritem.text}'>
    <#if dritem.getId()?lower_case == 'form'>
                <div class='main-data'>
                    <slot></slot>
                </div>
    <#else>
                <component
                  v-if="Object.is(this.selection.id, '${dritem.getId()?lower_case}') && this.selection.view && !Object.is(this.selection.view.viewname, '')"
                  :is="selection.view.viewname"
                  class="viewcontainer2"
                  :viewdata="JSON.stringify(selection.data)"
                  :viewparam="JSON.stringify(selection.param)"
                  :viewDefaultUsage="false"
                  :key="this.$util.createUUID()">
                </component>
    </#if>
            </tab-pane>
  </#list>
            </tabs>
    </div>
    
</template>
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>
    /**
     * 是否显示插槽
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
37
    @Prop({default:true}) public isShowSlot?: boolean;
38 39 40 41 42 43 44

    /**
     *  应用实体参数名称
     *
     * @type string
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
45
    @Prop() public parentName!: string;
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
    
    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public getDatas(): any[] {
        return this.items;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public getData(): any {
        return this.selection;
    }

    /**
     * 数据选中项
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
73
    public selection: any = {};
74 75 76 77

    /**
     * 父数据
     *
78
     * @public
79 80 81
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
82
    public parentData: any = {};
83 84 85 86 87 88 89

    /**
     * 关系栏数据项
     *
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
90
    public items: any[] = [
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        <#list ctrl.getRootItem().getAllItems() as dritem>
        {
            index: ${dritem_index?c}, 
            id: '${dritem.getId()?lower_case}',
            name: '${dritem.getId()?lower_case}', 
            text: '${dritem.text}', 
            disabled: false, 
        },
        </#list>
    ];

    /**
     * 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
107
    public created(): void {
108 109 110 111 112 113 114 115
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}Base
     */    
116
    public afterCreated(){
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('state', action)) {
                    const state = !this.context.${ctrl.getPSAppDataEntity().getCodeName()?lower_case} ? true : false;
                    this.setItemDisabled(state);
                }
            });
        }
        this.$nextTick(() => {
            this.$emit('selectionchange', [this.items[0]]);
        });
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
138
    public destroyed() {
139 140 141 142 143 144 145 146
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
147
    public afterDestroy() {
148 149 150 151 152 153 154 155 156 157 158
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

    /**
     * 获取关系项
     *
159
     * @public
160 161 162 163
     * @param {*} [arg={}]
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
164
    public getDRTabItem(arg: any = {}): any {
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
        let expmode = arg.nodetype.toUpperCase();
        if (!expmode) {
            expmode = '';
        }
        <#list ctrl.getPSAppViewRefs() as item>
        <#if (item.getName()?index_of("DRITEM:")==0)>
        <#assign refview = item.getRefPSAppView()>
        if (Object.is(expmode, '${item.getName()?substring(7)}')) {
            return {  
                viewname: '${srffilepath2(refview.codeName)}', 
                parentdatajo: <#if item.getParentDataJO()??>${item.getParentDataJO()}<#else>{},</#if>
			};
        }
        </#if>
        </#list>
        return undefined;
    }

    /**
     * 设置关系项状态
     *
     * @param {boolean} state
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
189
    public setItemDisabled(state: boolean): void {
190 191 192 193 194 195 196 197 198 199 200 201
        this.items.forEach((item: any) => {
            if (Object.is(item.name, 'form')) {
                item.disabled = false;
            } else {
                item.disabled = state;
            }
        });
    }

    /**
     * 获取数据项
     *
202
     * @public
203 204 205 206
     * @param {string} id
     * @returns {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
207
    public getItem(id: string): any {
208 209 210 211 212 213 214 215 216 217 218 219 220
        const arr: any[] = this.items.filter((_item: any) => Object.is(_item.id, id));
        if (arr) {
            return arr[0];
        }
        return null;
    }

    /**
     * 选中节点
     *
     * @param {*} $event
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
221
    public tabPanelClick($event: any): void {
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
        const item = this.getItem($event);
        if (Object.is(item.id, this.selection.id)) {
            return;
        }
        this.$emit('selectionchange', [item]);

        const refview = this.getDRTabItem({ nodetype: item.id });
        this.selection = {};
        const _context: any = { ...JSON.parse(JSON.stringify(this.context)) };
        Object.assign(_context,{srfparentdename:this.parentName,srfparentkey:_context[this.parentName.toLowerCase()]});
        const _params: any = { ...JSON.parse(JSON.stringify(this.viewparams)) };
        if (refview && refview.parentdatajo) {
            Object.assign(_context, refview.parentdatajo);
            Object.assign(this.selection, { view: { viewname: refview.viewname }, data: _context, param: _params });
        }
        Object.assign(this.selection, item);
    }

<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

<#ibizinclude>
../@MACRO/CONTROL/CONTROL-BASE.style.ftl
</#ibizinclude>