CONTROL-BASE.vue.ftl 11.5 KB
Newer Older
tony001's avatar
tony001 committed
1 2 3 4
<#ibizinclude>
../../@MACRO/LANG_FUN.ftl
</#ibizinclude>
<template>
5 6 7
<#if ctrl.render??>
    ${ctrl.render.code}
<#else>
8
  <gantt-elastic :class="ganttClass<#if ctrl.getPSSysCss?? && ctrl.getPSSysCss()??><#assign singleCss = ctrl.getPSSysCss()> ${singleCss.getCssName()}</#if>" :tasks="tasks" :options="getOptions(this.locale)" :dynamic-style="dynamicStyle" @taskList-item-dblclick="taskClick" @task-item-expand="taskItemExpand">
tony001's avatar
tony001 committed
9
  </gantt-elastic>
10
</#if>
tony001's avatar
tony001 committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
</template>
<#assign import_block>
import GanttElastic from "ibiz-gantt-elastic/src/GanttElastic.vue";
</#assign>

<#assign component_block>
GanttElastic,
</#assign>

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

    /**
     * 显示处理提示
     *
     * @type {boolean}
KK's avatar
KK committed
28
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
29 30 31 32 33 34 35
     */
    @Prop({ default: true }) public showBusyIndicator?: boolean;

    /**
     * 部件行为--load
     *
     * @type {string}
KK's avatar
KK committed
36
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
37 38 39 40 41 42 43 44
     */
    @Prop() public loadAction!: string;

    /**
     * 部件样式名
     *
     * @public
     * @type {any[]}
KK's avatar
KK committed
45
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
46 47 48 49 50 51 52 53
     */
    public ganttClass: string = "gantt";

     /**
     * 语言
     *
     * @public
     * @type {string}
KK's avatar
KK committed
54
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
55 56 57 58 59 60 61 62
     */  
    public locale: string = 'zh-CN';

     /**
     * 语言资源
     *
     * @public
     * @type {any[]}
KK's avatar
KK committed
63
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
     */   
    public localeZH: any =  {
        weekdays: ['星期一','星期二','星期三','星期四','星期五','星期六','星期日'],
        months: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        Now: "现在",
        "X-Scale": "时间颗粒度",
        "Display task list": "显示列表",
        "Before/After": "数据范围"
    }

    /**
     * 配置参数
     *
     * @public
     * @type {any[]}
KK's avatar
KK committed
79
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
80 81 82
     */
    public options: any = {
        isflex: true,
83
        maxRows: 1000,
tony001's avatar
tony001 committed
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
        dataType: 'treegrid',
        title: {
            label: ""
        },
        header: {
            yScole: false,
            taskListWidth: false,
        },
        calendar: {
            hour: {
                display: false
            }
        },
        chart: {
            progress: {
                bar: false
            },
            expander: {
                display: true
            },
        },
        taskList: {
            expander: {
                straight: false
            },
            labelField: 'text',
            columns: [
                <#if ctrl.getPSDETreeColumns()??>
                <#list ctrl.getPSDETreeColumns() as column>
                {
                    label: '${column.getCaption()}',
tony001's avatar
tony001 committed
115 116
                    value: '<#if column.getName() == "begin">start<#else>${column.getName()}</#if>',
                    render: (task: any) => {
117 118 119 120 121 122
                        <#if column.render??> 
                        ${column.render.code}
                        <#else>
                        return this.getColumnValue(task, '<#if column.getName() == "begin">start<#else>${column.getName()}</#if>')
                        </#if>
                    },
123
                    <#if column.getName() == "text">
tony001's avatar
tony001 committed
124 125
                    expander: true,
                    </#if>
126 127 128 129 130 131 132 133 134 135
                    width: <#if column.getWidth() gt 0>${column.getWidth()}<#else>100</#if>,
                    <#if column.isHideDefault()>
                    hidden: true,
                    </#if>
                    <#if column.getHeaderPSSysCss()??>
                    headerCls: '${column.getHeaderPSSysCss().getCssName()}',
                    </#if>
                    <#if column.getCellPSSysCss()??>
                    cellCls: '${column.getCellPSSysCss().getCssName()}',
                    </#if>
tony001's avatar
tony001 committed
136 137 138 139 140 141 142 143 144 145 146 147
                },
                </#list>
                </#if>
            ]
        }
    };

    /**
     * 样式
     *
     * @public
     * @type {any[]}
KK's avatar
KK committed
148
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
149
     */
150
    public dynamicStyle: any = {};
tony001's avatar
tony001 committed
151 152 153 154 155 156

    /**
     * 日程事件集合
     *
     * @public
     * @type {any[]}
KK's avatar
KK committed
157
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
158 159 160
     */
    public tasks: any[] = [];

161 162 163 164 165 166 167 168 169
    /**
     * 应用状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public appStateEvent: Subscription | undefined;

tony001's avatar
tony001 committed
170 171 172 173
    /**
     * 监听语言变化
     *
     * @public
KK's avatar
KK committed
174
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
175 176 177 178 179 180
     */
    @Watch('$i18n.locale')
    public onLocaleChange(newval: any, val: any) {
        this.locale = newval;
    }

181 182 183 184
    /**
     * 获取列属性值
     *
     * @public
KK's avatar
KK committed
185
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
186 187 188 189 190 191 192 193 194 195
     */
    public getColumnValue(task: any, field: string) {
        <#if ctrl.getPSDETreeNodes()??>
        <#list ctrl.getPSDETreeNodes() as node>
        if(Object.is(task.id.split(';')[0], '${srfjavastring(node.getNodeType())}')) {
            <#if node.getPSDETreeNodeDataItems()??>
            <#list node.getPSDETreeNodeDataItems() as dataItem>
            <#if dataItem.getFrontPSCodeList()??>
            <#assign codelist = dataItem.getFrontPSCodeList()/>
            if (Object.is(field, '${dataItem.name}')) {
tony001's avatar
tony001 committed
196
                let codelist: any[] = this.$store.getters.getCodeList('${codelist.getCodeName()}');
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
                if(codelist) {
                    return this.getCodeListItem(codelist, task[field]);
                }
            }
            </#if>
            </#list>
            </#if>
            return task[field];
        }
        </#list>
        </#if>
    }

    /**
     * 获取代码项
     *
     * @public
KK's avatar
KK committed
214
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
215 216 217 218 219 220 221 222 223 224
     */
    public getCodeListItem(codelist: any, val: any) {
        for(let i = 0; i < codelist.items.length; i++) {
            if(Object.is(codelist.items[i].value, val)) {
                return codelist.items[i].text;
            }
        }
        return codelist.emptytext;
    }

tony001's avatar
tony001 committed
225 226 227 228
    /**
     * 获取部件参数
     *
     * @returns {any}
KK's avatar
KK committed
229
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
230 231 232 233 234 235 236 237 238 239 240 241
     */
    public getOptions() {
        if(Object.is(this.locale, 'zh-CN')) {
            return { locale: this.localeZH, ...this.options };
        }
        return this.options;
    }

    /**
     * 搜索获取日程事件
     *
     * @param {*} $event 日期信息
KK's avatar
KK committed
242
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
     */
    public load(task: any = {}) {
        const params: any = {
            srfnodeid: task && task.id ? task.id : "#",
            srfnodefilter: ''
        };
        let tempViewParams:any = JSON.parse(JSON.stringify(this.viewparams));
        let curNode:any = {}; 
        Util.deepObjectMerge(curNode, task);
        let tempContext:any = this.computecurNodeContext(curNode);
        if(curNode && curNode.srfparentdename) {
            Object.assign(tempContext,{ srfparentdename: curNode.srfparentdename });
            Object.assign(tempViewParams,{ srfparentdename: curNode.srfparentdename });
        }
        if(curNode && curNode.srfparentkey) {
            Object.assign(tempContext,{ srfparentkey: curNode.srfparentkey });
            Object.assign(tempViewParams,{ srfparentkey: curNode.srfparentkey });
        }
        Object.assign(params,{viewparams:tempViewParams});
        this.service.getNodes(tempContext,params).then((response: any) => {
            if (!response || response.status !== 200) {
264
                this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.info });
tony001's avatar
tony001 committed
265 266 267 268 269 270 271 272 273 274 275 276 277
                return;
            }
            this.tasks = [...this.tasks, ...response.data];
            response.data.forEach((item: any) => {
                if(!item.collapsed) {
                    this.load(item);
                }
            })
            this.$emit("load", this.tasks);
        }).catch((response: any) => {
            if (response && response.status === 401) {
                return;
            }
278
            this.$Notice.error({ title: (this.$t('app.commonWords.wrong') as string), desc: response.info });
tony001's avatar
tony001 committed
279 280 281 282 283 284 285
        });
    }

    /**
     * 计算当前节点的上下文
     *
     * @param {*} curNode 当前节点
KK's avatar
KK committed
286
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
     */
    public computecurNodeContext(curNode:any){
        let tempContext:any = {};
        if(curNode && curNode.data && curNode.data.srfappctx){
            tempContext = JSON.parse(JSON.stringify(curNode.data.srfappctx));
        }else{
            tempContext = JSON.parse(JSON.stringify(this.context));
        }
        return tempContext;
    }

    /**
     * 节点展开
     *
     * @param {*} task 当前节点
KK's avatar
KK committed
302
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
303 304 305
     */
    public taskItemExpand(task: any) {
        if(!task.collapsed) {
306 307 308
            let index: number = this.tasks.findIndex((item: any) => Object.is(task.id, item.parentId));
            if(index < 0) {
                this.load(task);
tony001's avatar
tony001 committed
309 310 311 312 313 314 315
            }
        }
    }

    /**
     * 刷新
     *
KK's avatar
KK committed
316
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
317 318 319 320 321 322 323 324 325 326 327
     */
    public refresh() {
        this.load();
    }



    /**
     * 选中的数据
     *
     * @returns {any[]}
KK's avatar
KK committed
328
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
329 330 331 332 333 334 335
     */
    public selections: any[] = [];

    /**
     * 获取多项数据
     *
     * @returns {any[]}
KK's avatar
KK committed
336
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
337 338 339 340 341 342 343 344 345
     */
    public getDatas(): any[] {
        return this.selections;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
KK's avatar
KK committed
346
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
347 348 349 350 351 352 353 354 355
     */
    public getData(): any {
        return null;
    }
             
    /**
     * vue 生命周期
     *
     * @returns
KK's avatar
KK committed
356
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
357 358 359 360
     */
    public created() {
        this.locale = this.$i18n.locale;
        this.load();
361 362 363 364 365 366 367 368 369 370
        if(AppCenterService && AppCenterService.getMessageCenter()){
            this.appStateEvent = AppCenterService.getMessageCenter().subscribe(({ name, action, data }) =>{
                if(!Object.is(name,"${ctrl.getPSAppDataEntity().getCodeName()}")){
                    return;
                }
                if(Object.is(action,'appRefresh')){
                    this.refresh();
                }
            })
        }
tony001's avatar
tony001 committed
371 372 373 374 375 376
    }

    /**
     * 点击事件
     *
     * @returns
KK's avatar
KK committed
377
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
tony001's avatar
tony001 committed
378 379
     */
    public taskClick({event, data}: {event: any, data: any}) {
380
        const _this: any = this;
tony001's avatar
tony001 committed
381
        let key: string = data.id.split(';')[0];
382 383
        if(_this[key + '_opendata'] instanceof Function) {
            _this[key + '_opendata']([data]);
tony001's avatar
tony001 committed
384 385 386
        }
    }

387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public destroyed() {
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}Base
     */
    public afterDestroy() {
        if(this.appStateEvent){
            this.appStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    } 

tony001's avatar
tony001 committed
410 411 412 413 414 415 416
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

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