CONTROL-BASE.vue.ftl 9.8 KB
Newer Older
1 2 3
<template>
    ${P.getPartCode(item,'PANEL').code}
</template>
tony001's avatar
tony001 committed
4
<#assign import_block>
tony001's avatar
tony001 committed
5
import { PanelDetailModel,PanelRawitemModel,PanelTabPanelModel,PanelTabPageModel,PanelFieldModel,PanelContainerModel,PanelControlModel,PanelUserControlModel,PanelButtonModel } from '@/model/panel-detail';
tony001's avatar
tony001 committed
6
import ${srfclassname('${ctrl.codeName}')}Model from './${srffilepath2(ctrl.codeName)}-${ctrl.getControlType()?lower_case}-model';
7
import CodeListService from "@/codelist/codelist-service";
tony001's avatar
tony001 committed
8
</#assign>
9 10 11 12 13 14 15 16
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>

    /**
     * 接口实现
     *
     * @returns {any[]}
KK's avatar
KK committed
17
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
18 19
     */
    getDatas(): any[] {
tony001's avatar
tony001 committed
20
        if (!this.panelData) {
21 22
            return [];
        }
tony001's avatar
tony001 committed
23
        return [this.panelData];
24
    }
tony001's avatar
tony001 committed
25 26 27 28 29

    /**
     * 接口实现
     *
     * @returns {*}
KK's avatar
KK committed
30
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
31
     */
32
    getData() {
33
        return this.panelData;
34 35
    }

tony001's avatar
tony001 committed
36 37 38 39
    /**
     * 父级部件引用
     *
     * @type {*}
KK's avatar
KK committed
40
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
41 42 43
     */
    @Prop() public parentRef?: any;

44 45 46 47
    /**
     * 面板数据对象
     *
     * @type {*}
KK's avatar
KK committed
48
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
49
     */
tony001's avatar
tony001 committed
50 51 52
    @Prop() public inputData?: any;

    /**
53
     * UI数据对象
tony001's avatar
tony001 committed
54
     *
55
     * @type {*}
KK's avatar
KK committed
56
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
57
     */
58
    public data:any = {};
tony001's avatar
tony001 committed
59

60
    /**
61
     * 面板数据对象
62 63
     *
     * @type {*}
KK's avatar
KK committed
64
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
65
     */
66
    public panelData:any = null;
67

tony001's avatar
tony001 committed
68 69 70 71
    /**
     * 数据模型对象
     *
     * @type {${srfclassname('${ctrl.codeName}')}Model}
KK's avatar
KK committed
72
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
73 74 75 76
     */
    public dataModel:${srfclassname('${ctrl.codeName}')}Model = new ${srfclassname('${ctrl.codeName}')}Model();

    /**
77
     * 代码表服务对象
tony001's avatar
tony001 committed
78
     *
79
     * @type {CodeListService}
KK's avatar
KK committed
80
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
81
     */
82
    public codeListService:CodeListService = new CodeListService({ $store:this.$store });
tony001's avatar
tony001 committed
83

84
    <#if appde??>
tony001's avatar
tony001 committed
85
    /**
86 87 88 89 90 91 92 93 94 95
     * 界面UI服务对象
     *
     * @type {${srfclassname('${appde.getCodeName()}')}UIService}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */  
    public appUIService:${srfclassname('${appde.getCodeName()}')}UIService = new ${srfclassname('${appde.getCodeName()}')}UIService(this.$store);
    </#if>

    /**
     * 详情模型集合
tony001's avatar
tony001 committed
96 97
     *
     * @type {*}
tony001's avatar
tony001 committed
98
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
99
     */
100 101 102 103 104
    public detailsModel: any = {
        <#list ctrl.getAllPSPanelItems() as panelItem>
        ${panelItem.name}: ${P.getPartCode(panelItem, 'ITEM_MODEL').code},
        </#list>
    };
tony001's avatar
tony001 committed
105

tony001's avatar
tony001 committed
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    /**
     * 值规则对象
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public rules:any={
    <#if ctrl.getAllPSPanelItems()??>
    <#list ctrl.getAllPSPanelItems() as panelItem>
    <#if panelItem.getItemType() == "FIELD">
        ${panelItem.getName()}:[
            { required: <#if panelItem.isAllowEmpty()>false<#else>true</#if>, type: 'string', message: '${panelItem.getCaption()} 值不能为空'},
            { required: <#if panelItem.isAllowEmpty()>false<#else>true</#if>, type: 'string', message: '${panelItem.getCaption()} 值不能为空'}
        ],
    </#if>
    </#list>
    </#if>
    };

tony001's avatar
tony001 committed
125 126 127
    /**
     * 监听数据对象
     *
KK's avatar
KK committed
128
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
129
     */
130
    @Watch('inputData',{immediate:true,deep: true})
131
    public onInputDataChange(newVal: any, oldVal: any){
tony001's avatar
tony001 committed
132
        if(newVal){
133
            this.computedUIData(newVal);
134
            this.panelData = Util.deepCopy(newVal);
135
            this.computeButtonState(newVal);
tony001's avatar
tony001 committed
136 137 138 139 140
            this.panelLogic({ name: '', newVal: null, oldVal: null });
            this.$forceUpdate();
        }
    }

tony001's avatar
tony001 committed
141 142 143 144
    /**
     * 计算UI展示数据
     * 
     * @param codelistArray 代码表模型数组
KK's avatar
KK committed
145
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
146
     */
147
    public computedUIData(newVal:any){
tony001's avatar
tony001 committed
148 149
        if((this.dataModel.getDataItems instanceof Function) && this.dataModel.getDataItems().length >0){
            this.dataModel.getDataItems().forEach((item:any) =>{
150
                this.data[item.name] = newVal[item.prop];
tony001's avatar
tony001 committed
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
    /**
     * 计算面板按钮权限状态
     *
     * @param {*} [data] 传入数据
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public computeButtonState(data:any){
        // 若为项布局面板,存在parentRef
        if(this.parentRef){
            let targetData:any = this.parentRef.transformData(data);
            if(this.detailsModel && Object.keys(this.detailsModel).length >0){
                Object.keys(this.detailsModel).forEach((name:any) =>{
                    if(this.detailsModel[name] && this.detailsModel[name].uiaction && this.detailsModel[name].uiaction.dataaccaction && Object.is(this.detailsModel[name].itemType,"BUTTON")){
                        this.detailsModel[name].isPower = true;
                        let tempUIAction:any = JSON.parse(JSON.stringify(this.detailsModel[name].uiaction));
                        let result: any[] = ViewTool.calcActionItemAuthState(targetData,[tempUIAction],this.appUIService?this.appUIService:null);
                        this.detailsModel[name].visible = tempUIAction.visabled;
                        this.detailsModel[name].disabled = tempUIAction.disabled;
                        this.detailsModel[name].isPower = result[0] === 1 ? true : false;
                    }
                })
            }
        }
    }

tony001's avatar
tony001 committed
180 181 182 183 184 185
    /**
     * 界面行为
     *
     * @param {*} row
     * @param {*} tag
     * @param {*} $event
KK's avatar
KK committed
186
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
187
     */
188
    public uiAction(row: any, tag: any, $event: any) {
tony001's avatar
tony001 committed
189 190 191 192 193 194 195 196 197
        <#if ctrl.getPSAppViewLogics()??>
        <#list ctrl.getPSAppViewLogics() as logic>
        <#if logic.getPSAppViewUIAction().getPSUIAction()??>
        <#assign action = logic.getPSAppViewUIAction().getPSUIAction()>
        if(Object.is('${action.getUIActionTag()}', tag)) {
            this.${logic.getName()}(row, tag, $event);
        }
        </#if>
        </#list>
198 199
        </#if>
    }
tony001's avatar
tony001 committed
200 201 202 203 204

    /**
     * 打开编辑数据视图
     *
     * @type {any}
KK's avatar
KK committed
205
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
206 207 208 209 210 211 212 213 214 215 216
     */
    public opendata(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any){
        if (this.parentRef.opendata && this.parentRef.opendata instanceof Function) {
            this.parentRef.opendata(args,fullargs,params, $event, xData);
        }
    }

    /**
     * 打开新建数据视图
     *
     * @type {any}
KK's avatar
KK committed
217
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
218 219 220 221 222 223 224 225 226 227 228 229
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
        if (this.parentRef.newdata && this.parentRef.newdata instanceof Function) {
            this.parentRef.newdata(args,fullargs,params, $event, xData);
        }
    }
    
    /**
     * 删除
     *
     * @param {any[]} datas
     * @returns {Promise<any>}
KK's avatar
KK committed
230
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
231 232 233 234 235 236 237 238 239 240 241
     */
    public async remove(datas: any[]): Promise<any> {
        if (this.parentRef.remove && this.parentRef.remove instanceof Function) {
            return this.parentRef.remove(datas);
        }
    }

    /**
     * 刷新
     *
     * @param {*} [opt={}]
242
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
243 244 245 246 247 248
     */
    public refresh(opt: any = {}) {
        if (this.parentRef.refresh && this.parentRef.refresh instanceof Function) {
            this.parentRef.refresh(opt);
        }
    }
249

tony001's avatar
tony001 committed
250
    /**
251
     * 设置变更面板编辑项的值
tony001's avatar
tony001 committed
252 253 254 255
     *  
     * @param data 面板数据
     * @param {{ name: string, value: any }} $event
     * @returns {void}
KK's avatar
KK committed
256
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
257 258 259 260 261 262 263 264 265 266 267 268 269
     */
    public onPanelItemValueChange(data: any,$event: { name: string, value: any }): void {
        if (!$event) {
            return;
        }
        if (!$event.name || Object.is($event.name, '') || !data.hasOwnProperty($event.name)) {
            return;
        }
        data[$event.name] = $event.value;
        this.panelEditItemChange(data, $event.name, $event.value);
    }

    /**
270
     * 面板编辑项值变化后续操作
tony001's avatar
tony001 committed
271 272 273 274 275 276
     *
     * @public
     * @param data 面板数据
     * @param property 编辑项名
     * @param value 编辑项值
     * @returns {void}
KK's avatar
KK committed
277
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
278 279
     */
    public panelEditItemChange(data: any, property: string, value: any){
280 281 282 283 284 285 286 287 288
        // 面板数据变化事件
        if((this.dataModel.getDataItems instanceof Function) && this.dataModel.getDataItems().length >0){
            let modelitem =this.dataModel.getDataItems().find((item:any) =>{
                return item.name === property;
            }) 
            if(modelitem){
                this.$emit('panelDataChange',{[modelitem.prop]: value});
            }
        }
tony001's avatar
tony001 committed
289 290 291

    }

tony001's avatar
tony001 committed
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
    /**
     * 分页切换事件
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public handleTabPanelClick(name:string,$event:any){
        this.detailsModel[name].clickPage($event.name);
    }

    /**
     * 面板逻辑
     *
     * @public
     * @param {{ name: string, newVal: any, oldVal: any }} { name, newVal, oldVal }
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public panelLogic({ name, newVal, oldVal }: { name: string, newVal: any, oldVal: any }): void {
        <#if P.getPartCode(item,'PANEL_LOGIC').code?length gt 0>
        ${P.getPartCode(item,'PANEL_LOGIC').code}
        </#if>
    }

314 315 316 317 318 319 320 321
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

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