CONTROL-BASE.vue.ftl 19.5 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
<template>
<#if quick_menus??>
  ${quick_menus}
<#else>
<div class="app-app-menu">
    <el-menu
      class="app-menu"
      :default-openeds="defaultOpeneds"
      :mode="mode"
      :menu-trigger="trigger"
      :collapse="isCollapse"
      @select="select"
      :default-active="defaultActive">
        <template v-for="item0 in menus">
            <template v-if="item0.items && Array.isArray(item0.items) && item0.items.length > 0">
                <el-submenu v-show="!item0.hidden" :index="item0.name" :popper-class="popperClass" :key="item0.id">
                    <template slot='title'>
                        <template v-if="item0.icon && item0.icon != ''">
                            <img :src="item0.icon" class='app-menu-icon' />
                        </template>
                        <template v-else-if="item0.iconcls && item0.iconcls != ''">
                            <i :class="[item0.iconcls, 'app-menu-icon']"></i>
                        </template>
                        <template v-else>
                            <i class='fa fa-cogs app-menu-icon'></i>
                        </template>
                        <span class='text' :title="$t('app.menus.${ctrl.codeName?lower_case}.' + item0.name)">{{$t('app.menus.${ctrl.codeName?lower_case}.' + item0.name)}}</span>
                    </template>
                    <template v-for="item1 in item0.items">
                        <template v-if="item1.items && Array.isArray(item1.items) && item1.items.length > 0">
                            <el-submenu v-show="!item1.hidden" :index="item1.name" :popper-class="popperClass" :key="item1.id">
                                <template slot='title'>
                                    <template v-if="item1.icon && item1.icon != ''">
                                        <img :src="item1.icon" class='app-menu-icon' />
                                    </template>
                                    <template v-else-if="item1.iconcls && item1.iconcls != ''">
                                        <i :class="[item1.iconcls, 'app-menu-icon']"></i>
                                    </template>
                                    <span class='text' :title="$t('app.menus.${ctrl.codeName?lower_case}.' + item1.name)">{{$t('app.menus.${ctrl.codeName?lower_case}.' + item1.name)}}</span>
                                </template>
                                <template v-for="item2 in item1.items">
                                    <template v-if="item2.type =='MENUITEM'">
                                        <el-menu-item v-show="!item2.hidden" :index="item2.name" :key="item2.id">
                                            <template v-if="item2.icon && item2.icon != ''">
                                                <img :src="item2.icon" class='app-menu-icon' />
                                            </template>
                                            <template v-else-if="item2.iconcls && item2.iconcls != ''">
                                                <i :class="[item2.iconcls, 'app-menu-icon']"></i>
                                            </template>
                                            <template slot="title">
                                                <span class="text" :title="$t('app.menus.${ctrl.codeName?lower_case}.' + item2.name)">{{$t('app.menus.${ctrl.codeName?lower_case}.' + item2.name)}}</span>
                                                <template v-if="counterdata && counterdata[item2.counterid] && counterdata[item2.counterid] > 0">
                                                    <span class="pull-right">
                                                        <badge :count="counterdata[item2.counterid]" :overflow-count="9999"></badge>
                                                    </span>
                                                </template>
                                            </template>
                                        </el-menu-item>
                                    </template>
                                    <template v-if="item2.type =='SEPERATOR'">
                                            <divider :key="item2.id" />
                                    </template>
                                </template>
                            </el-submenu>
                        </template>
                        <template v-else>
                            <template v-if="item1.type =='MENUITEM'">
                                <el-menu-item v-show="!item1.hidden" :index="item1.name" :key="item1.id">
                                    <template v-if="item1.icon && item1.icon != ''">
                                        <img :src="item1.icon" class='app-menu-icon' />
                                    </template>
                                    <template v-else-if="item1.iconcls && item1.iconcls != ''">
                                        <i :class="[item1.iconcls, 'app-menu-icon']"></i>
                                    </template>
                                    <template slot="title">
                                        <span class="text" :title="$t('app.menus.${ctrl.codeName?lower_case}.' + item1.name)">{{$t('app.menus.${ctrl.codeName?lower_case}.' + item1.name)}} </span>
                                        <template v-if="counterdata && counterdata[item1.counterid] && counterdata[item1.counterid] > 0">
                                            <span class="pull-right">
                                                <badge :count="counterdata[item1.counterid]" :overflow-count="9999"></badge>
                                            </span>
                                        </template>
                                    </template>
                                </el-menu-item>
                            </template>
                            <template v-if="item1.type =='SEPERATOR'">
                                    <divider :key="item1.id" />
                            </template>
                        </template>
                    </template>
                </el-submenu>
            </template>
            <template v-else>
                <template v-if="item0.type =='MENUITEM'">
                    <el-menu-item v-show="!item0.hidden" :index="item0.name" :key="item0.id">
                        <template v-if="item0.icon && item0.icon != ''">
                            <img :src="item0.icon" class='app-menu-icon' />
                        </template>
                        <template v-else-if="item0.iconcls && item0.iconcls != ''">
                            <i :class="[item0.iconcls, 'app-menu-icon']"></i>
                        </template>
                        <template v-else>
                            <i class='fa fa-cogs app-menu-icon'></i>
                        </template>
                        <template slot="title">
                            <span class="text" :title="$t('app.menus.${ctrl.codeName?lower_case}.' + item0.name)">{{$t('app.menus.${ctrl.codeName?lower_case}.' + item0.name)}}</span>
                            <template v-if="counterdata && counterdata[item0.counterid] && counterdata[item0.counterid] > 0">
                                <span class="pull-right">
                                    <badge :count="counterdata[item0.counterid]" :overflow-count="9999"></badge>
                                </span>
                            </template>
                        </template>
                    </el-menu-item>
                </template>
                <template v-if="item0.type =='SEPERATOR'">
                        <divider :key="item0.id" />
                </template>
            </template>
        </template>
    </el-menu>
</div>
</#if>
</template>

<#assign import_block>
import ${srfclassname('${ctrl.codeName}')}Model from './${srffilepath2(ctrl.codeName)}-${ctrl.getControlType()?lower_case}-model';
</#assign>
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_HEADER-BASE.vue.ftl
</#ibizinclude>

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public getDatas(): any[] {
        return [];
    }

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

    /**
     * 菜单模型
     *
154
     * @public
155 156 157
     * @type {${srfclassname('${ctrl.codeName}')}Model}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
158
    public menuMode: ${srfclassname('${ctrl.codeName}')}Model = new ${srfclassname('${ctrl.codeName}')}Model();
159 160 161 162 163 164 165

    /**
     * 显示处理提示
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
166
    @Prop({ default: true }) public showBusyIndicator?: boolean;
167 168 169 170

    /**
     * 菜单数据
     *
171
     * @public
172 173 174 175
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Provide()
176
    public menus: any[] = [];
177 178 179 180 181 182 183

    /**
     * 菜单收缩改变
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
184
    @Model() public collapsechange?: boolean;
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245

    /**
     * 监听菜单收缩
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Watch('collapsechange')
    onCollapsechangeChange(newVal: any, oldVal: any) {
        if (newVal !== this.isCollapse) {
            this.isCollapse = !this.isCollapse;
        }
    }

    /**
     * 当前模式,菜单在顶部还是在底部
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() mode: any;

    /**
     * 当前菜单是否在默认视图上
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop({ default: false }) isDefaultPage?: boolean;

    /**
     * 默认打开视图
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() defPSAppView: any;

    /**
     * 默认激活的index
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Provide() defaultActive: any = null;

    /**
     * 当前选中主题
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Prop() selectTheme: any;

    /**
     * 默认打开的index数组
     *
     * @type {any[]}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
246
    @Provide() public defaultOpeneds: any[] = [];
247 248 249 250 251 252 253

    /**
     * 是否展开
     *
     * @type {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
254
    @Provide() public isCollapse: boolean = false;
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269

    /**
     * 触发方式,默认click
     *
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    @Provide() trigger: string = 'click';

    /**
     * 计数器数据
     *
     * @type {*}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
270
    public counterdata: any = {};
271 272 273 274 275
    /**
     * vue  生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
276
    public created() {
277 278 279 280 281 282 283 284
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof ${srfclassname('${ctrl.codeName}')}
     */    
285
    public afterCreated(){
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
        if (Object.is(this.mode, 'horizontal')) {
            this.trigger = 'hover';
        }
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                this.load(data);
            });
        }
    }

    /**
     * vue 生命周期
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
304
    public destroyed() {
305 306 307 308 309 310 311 312
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
313
    public afterDestroy() {
314 315 316 317 318 319 320 321 322 323 324 325 326
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
        <#if destroyed_block??>
        ${destroyed_block}
        </#if>
    }

<#if view.isDefaultPage?? && view.isDefaultPage()>

    /**
     * 处理菜单默认选中项
     *
327
     * @public
328 329
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
330
    public doMenuSelect(): void {
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
        if (!this.isDefaultPage) {
            return;
        }
        const appFuncs: any[] = this.menuMode.getAppFuncs();
        if (this.$route && this.$route.matched && this.$route.matched.length == 2) { // 存在二级路由
            const [{ }, matched] = this.$route.matched;
            const appfunc: any = appFuncs.find((_appfunc: any) => Object.is(_appfunc.routepath, matched.path) && Object.is(_appfunc.appfuncyype, 'APPVIEW'));
            if (appfunc) {
                this.computeMenuSelect(this.menus, appfunc.appfunctag);
            }
            return;
        } else if (this.defPSAppView && Object.keys(this.defPSAppView).length > 0) { // 存在默认视图
            const appfunc: any = appFuncs.find((_appfunc: any) => Object.is(_appfunc.routepath, this.defPSAppView.routepath) && Object.is(_appfunc.appfuncyype, 'APPVIEW'));
            if (appfunc) {
                this.computeMenuSelect(this.menus, appfunc.appfunctag);
            }
            const viewparam: any = {};
            const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, this.defPSAppView.deResParameters, this.defPSAppView.parameters, [], viewparam);
            this.$router.push(path);
            return;
        }

        this.computeMenuSelect(this.menus, '');
        let item = this.compute(this.menus, this.defaultActive);
        if (Object.keys(item).length === 0) {
            return;
        }
tony001's avatar
tony001 committed
358 359 360
        if(!item.hidden){
            this.click(item);
        }
361 362 363 364 365
    }

    /**
     * 计算菜单选中项
     *
366
     * @public
367 368 369 370 371
     * @param {any[]} items
     * @param {string} appfunctag
     * @returns {boolean}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
372
    public computeMenuSelect(items: any[], appfunctag: string): boolean {
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
        const appFuncs: any[] = this.menuMode.getAppFuncs();
        return items.some((item: any) => {
            if (Object.is(appfunctag, '') && !Object.is(item.appfunctag, '')) {
                const appfunc = appFuncs.find((_appfunc: any) => Object.is(_appfunc.appfunctag, item.appfunctag));
                if (appfunc.routepath) {
                    this.defaultActive = item.name;
                    this.setHideSideBar(item);
                    return true;
                }
            }
            if (Object.is(item.appfunctag, appfunctag)) {
                this.setHideSideBar(item);
                this.defaultActive = item.name;
                return true;
            }
            if (item.items && item.items.length > 0) {
                const state = this.computeMenuSelect(item.items, appfunctag);
                if (state) {
                    this.defaultOpeneds.push(item.name);
                    return true;
                }
            }
            return false;
        });
    }
</#if>

    /**
     * 获取菜单项数据
     *
403
     * @public
404 405 406 407 408
     * @param {any[]} items
     * @param {string} name
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
409
    public compute(items: any[], name: string) {
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
        const item: any = {};
        items.some((_item: any) => {
            if (name && Object.is(_item.name, name)) {
                Object.assign(item, _item);
                this.setHideSideBar(_item);
                return true;
            }
            if (_item.items && Array.isArray(_item.items)) {
                const subItem = this.compute(_item.items, name);
                if (Object.keys(subItem).length > 0) {
                    Object.assign(item, subItem);
                    return true;
                }
            }
            return false;
        });
        return item;
    }

    /**
     * 设置是否隐藏菜单栏
     *
432
     * @public
433 434 435
     * @param {*} item
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
436
    public setHideSideBar(item: any): void {
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
        <#if view.isDefaultPage?? && view.isDefaultPage()>
        if (item.hidesidebar) {
            this.$emit('collapsechange', true);
        }
        </#if>
    }

    /**
     * 菜单项选中处理
     *
     * @param {*} index
     * @param {any[]} indexs
     * @returns
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
452
    public select(index: any, indexs: any[]) {
453 454 455 456 457 458 459 460 461 462
        let item = this.compute(this.menus, index);
        if (Object.keys(item).length === 0) {
            return;
        }
        this.click(item);
    }

    /**
     * 菜单点击
     *
463
     * @public
464 465 466
     * @param {*} item 菜单数据
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
467
    public click(item: any) {
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
        if (item) {
            switch (item.appfunctag) {
                <#if ctrl.getPSAppFuncs()??>
                <#assign appFuncs = ctrl.getPSAppFuncs()>
                <#list appFuncs as singFuncs>
                case '${singFuncs.getCodeName()}': 
                    this.click${singFuncs.codeName}(item);
                    return;
                </#list>
                </#if>
                default:
                    console.warn('未指定应用功能');
            }
        }
    }

<#if ctrl.getPSAppFuncs()??>
<@ibizindent blank=4>
<#list ctrl.getPSAppFuncs() as singleFuncs>

${P.getLogicCode(singleFuncs,"LOGIC.vue").code}
</#list>
</@ibizindent>
</#if>

    /**
     * 数据加载
     *
     * @param {*} data
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
499
    public load(data: any) {
tony001's avatar
tony001 committed
500 501 502 503 504 505 506 507 508 509 510 511 512
        this.handleMenusResource(this.menuMode.getAppMenuItems());
    }

    /**
     * 通过统一资源标识计算菜单
     *
     * @param {*} data
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public handleMenusResource(inputMenus:Array<any>){
        if(this.$store.getters['unifiedresource/getEnablePermissionValid']){
            this.computedEffectiveMenus(inputMenus);
        }
513 514 515 516 517 518 519
        this.dataProcess(this.menuMode.getAppMenuItems());
        this.menus = this.menuMode.getAppMenuItems();
        <#if view.isDefaultPage?? && view.isDefaultPage()>
        this.doMenuSelect();
        </#if>
    }

tony001's avatar
tony001 committed
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
    /**
     * 计算有效菜单项
     *
     * @param {*} data
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    public computedEffectiveMenus(inputMenus:Array<any>){
        inputMenus.forEach((_item:any) =>{
            if(_item.resourcetag && !this.$store.getters['unifiedresource/getResourceData'](_item.resourcetag)){
                _item.hidden = true;
                if (_item.items && _item.items.length > 0) {
                    this.computedEffectiveMenus(_item.items);
                }
            }
        })
    }

537 538 539
    /**
     * 数据处理
     *
540
     * @public
541 542 543
     * @param {any[]} items
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
544
    public dataProcess(items: any[]): void {
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
        items.forEach((_item: any) => {
            if (_item.expanded) {
                this.defaultOpeneds.push(_item.name);
            }
            if (_item.items && _item.items.length > 0) {
                this.dataProcess(_item.items)
            }
        });
    }

    /**
     * 提示框主题样式
     *
     * @readonly
     * @type {string}
     * @memberof ${srfclassname('${ctrl.codeName}')}
     */
    get popperClass(): string {
        return 'app-popper-menu ' + this.selectTheme;
    }
    
<#ibizinclude>
../@MACRO/CONTROL/CONTROL_BOTTOM-BASE.vue.ftl
</#ibizinclude>

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