task-index-view-appmenu-base.vue 17.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<template>
<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">
11
        <app-menu-item :menus="menus" :ctrlName="'taskindexview'" :isFirst="true" :counterdata="counterdata" :popperclass="popperClass"></app-menu-item>
12 13 14 15 16
    </el-menu>
</div>
</template>

<script lang='tsx'>
17
import { Vue, Component, Prop, Provide, Emit, Watch, Model,Inject } from 'vue-property-decorator';
18 19 20
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
21
import { UIActionTool,Util,ViewTool } from '@/utils';
22
import NavDataService from '@/service/app/navdata-service';
23
import AppCenterService from "@service/app/app-center-service";
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
import TaskIndexViewService from './task-index-view-appmenu-service';
import TaskIndexViewModel from './task-index-view-appmenu-model';
import { Environment } from '@/environments/environment';


@Component({
    components: {
      
    }
})
export default class TaskIndexViewBase extends Vue implements ControlInterface {

    /**
     * 名称
     *
     * @type {string}
40
     * @memberof TaskIndexViewBase
41 42 43 44 45 46 47
     */
    @Prop() public name?: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
48
     * @memberof TaskIndexViewBase
49 50 51 52 53 54 55
     */
    @Prop() public viewState!: Subject<ViewState>;

    /**
     * 应用上下文
     *
     * @type {*}
56
     * @memberof TaskIndexViewBase
57 58 59 60 61 62 63
     */
    @Prop() public context: any;

    /**
     * 视图参数
     *
     * @type {*}
64
     * @memberof TaskIndexViewBase
65 66 67 68 69 70 71 72
     */
    @Prop() public viewparams: any;

    /**
     * 视图状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
73
     * @memberof TaskIndexViewBase
74 75 76 77 78 79 80
     */
    public viewStateEvent: Subscription | undefined;

    /**
     * 获取部件类型
     *
     * @returns {string}
81
     * @memberof TaskIndexViewBase
82 83 84 85 86 87 88 89 90 91 92
     */
    public getControlType(): string {
        return 'APPMENU'
    }



    /**
     * 建构部件服务对象
     *
     * @type {TaskIndexViewService}
93
     * @memberof TaskIndexViewBase
94 95 96 97 98 99 100 101 102
     */
    public service: TaskIndexViewService = new TaskIndexViewService({ $store: this.$store });
    


    /**
     * 关闭视图
     *
     * @param {any} args
103
     * @memberof TaskIndexViewBase
104 105 106 107 108 109 110 111 112
     */
    public closeView(args: any): void {
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

    /**
     *  计数器刷新
     *
113
     * @memberof TaskIndexViewBase
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
     */
    public counterRefresh(){
        const _this:any =this;
        if(_this.counterServiceArray && _this.counterServiceArray.length >0){
            _this.counterServiceArray.forEach((item:any) =>{
                if(item.refreshData && item.refreshData instanceof Function){
                    item.refreshData();
                }
            })
        }
    }


    /**
     * 获取多项数据
     *
     * @returns {any[]}
131
     * @memberof TaskIndexViewBase
132 133 134 135 136 137 138 139 140
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
141
     * @memberof TaskIndexViewBase
142 143 144 145 146 147 148 149 150
     */
    public getData(): any {
        return null;
    }

    /**
     * 导航模式(route:面包屑模式、tab:分页导航模式)
     *
     * @type {string}
151
     * @memberof TaskIndexViewBase
152 153 154 155 156 157 158
     */
    @Prop({default:'tab'}) public navModel?:string;

    /**
     * 视图标识
     *
     * @type {string}
159
     * @memberof TaskIndexViewBase
160 161 162 163 164 165 166 167
     */
    @Prop() public viewtag!:string;

    /**
     * 菜单模型
     *
     * @public
     * @type {TaskIndexViewModel}
168
     * @memberof TaskIndexViewBase
169 170 171 172 173 174 175
     */
    public menuMode: TaskIndexViewModel = new TaskIndexViewModel();

    /**
     * 显示处理提示
     *
     * @type {boolean}
176
     * @memberof TaskIndexViewBase
177 178 179 180 181 182 183 184
     */
    @Prop({ default: true }) public showBusyIndicator?: boolean;

    /**
     * 菜单数据
     *
     * @public
     * @type {any[]}
185
     * @memberof TaskIndexViewBase
186 187 188 189 190 191 192 193
     */
    @Provide()
    public menus: any[] = [];

    /**
     * 菜单收缩改变
     *
     * @type {boolean}
194
     * @memberof TaskIndexViewBase
195 196 197 198 199 200 201 202
     */
    @Model() public collapsechange?: boolean;

    /**
     * 监听菜单收缩
     *
     * @param {*} newVal
     * @param {*} oldVal
203
     * @memberof TaskIndexViewBase
204 205 206 207 208 209 210 211 212 213 214 215
     */
    @Watch('collapsechange')
    onCollapsechangeChange(newVal: any, oldVal: any) {
        if (newVal !== this.isCollapse) {
            this.isCollapse = !this.isCollapse;
        }
    }

    /**
     * 当前模式,菜单在顶部还是在底部
     *
     * @type {*}
216
     * @memberof TaskIndexViewBase
217 218 219 220
     */
    @Prop() mode: any;

    /**
221
     * 应用起始页面
222
     *
223
     * @type {boolean}
224
     * @memberof TaskIndexViewBase
225 226 227
     */
    @Prop({ default: false }) isDefaultPage?: boolean;

228 229 230 231 232 233 234 235
    /**
     * 空白视图模式
     *
     * @type {boolean}
     * @memberof TaskIndexViewBase
     */
    @Prop({ default: false }) isBlankMode?:boolean;

236 237 238 239
    /**
     * 默认打开视图
     *
     * @type {*}
240
     * @memberof TaskIndexViewBase
241 242 243 244 245 246 247
     */
    @Prop() defPSAppView: any;

    /**
     * 默认激活的index
     *
     * @type {*}
248
     * @memberof TaskIndexViewBase
249 250 251 252 253 254 255
     */
    @Provide() defaultActive: any = null;

    /**
     * 当前选中主题
     *
     * @type {*}
256
     * @memberof TaskIndexViewBase
257 258 259 260 261 262 263
     */
    @Prop() selectTheme: any;

    /**
     * 默认打开的index数组
     *
     * @type {any[]}
264
     * @memberof TaskIndexViewBase
265 266 267 268 269 270 271
     */
    @Provide() public defaultOpeneds: any[] = [];

    /**
     * 是否展开
     *
     * @type {boolean}
272
     * @memberof TaskIndexViewBase
273 274 275 276 277 278 279
     */
    @Provide() public isCollapse: boolean = false;

    /**
     * 触发方式,默认click
     *
     * @type {string}
280
     * @memberof TaskIndexViewBase
281 282 283 284 285 286 287
     */
    @Provide() trigger: string = 'click';

    /**
     * 计数器数据
     *
     * @type {*}
288
     * @memberof TaskIndexViewBase
289 290 291 292 293
     */
    public counterdata: any = {};
    /**
     * vue  生命周期
     *
294
     * @memberof TaskIndexViewBase
295 296 297 298 299 300 301 302
     */
    public created() {
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
303
     *  @memberof TaskIndexViewBase
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
     */    
    public afterCreated(){
        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 生命周期
     *
322
     * @memberof TaskIndexViewBase
323 324 325 326 327 328 329 330
     */
    public destroyed() {
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
331
     * @memberof TaskIndexViewBase
332 333 334 335 336 337 338 339 340 341 342 343
     */
    public afterDestroy() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
    }


    /**
     * 处理菜单默认选中项
     *
     * @public
344
     * @memberof TaskIndexViewBase
345 346
     */
    public doMenuSelect(): void {
347
        if (!this.isDefaultPage || this.isBlankMode) {
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
            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;
        }
        if(!item.hidden){
            this.click(item);
        }
    }

    /**
     * 计算菜单选中项
     *
     * @public
     * @param {any[]} items
     * @param {string} appfunctag
     * @returns {boolean}
386
     * @memberof TaskIndexViewBase
387 388 389 390
     */
    public computeMenuSelect(items: any[], appfunctag: string): boolean {
        const appFuncs: any[] = this.menuMode.getAppFuncs();
        return items.some((item: any) => {
391
            if (Object.is(appfunctag, '') && !Object.is(item.appfunctag, '') && item.opendefault) {
392 393 394 395 396 397 398
                const appfunc = appFuncs.find((_appfunc: any) => Object.is(_appfunc.appfunctag, item.appfunctag));
                if (appfunc.routepath) {
                    this.defaultActive = item.name;
                    this.setHideSideBar(item);
                    return true;
                }
            }
399
            if (Object.is(item.appfunctag, appfunctag) && item.opendefault) {
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
                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;
        });
    }

    /**
     * 获取菜单项数据
     *
     * @public
     * @param {any[]} items
     * @param {string} name
     * @returns
422
     * @memberof TaskIndexViewBase
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
     */
    public compute(items: any[], name: string) {
        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;
    }

    /**
     * 设置是否隐藏菜单栏
     *
     * @public
     * @param {*} item
449
     * @memberof TaskIndexViewBase
450 451 452 453 454 455 456 457 458 459 460 461 462
     */
    public setHideSideBar(item: any): void {
        if (item.hidesidebar) {
            this.$emit('collapsechange', true);
        }
    }

    /**
     * 菜单项选中处理
     *
     * @param {*} index
     * @param {any[]} indexs
     * @returns
463
     * @memberof TaskIndexViewBase
464 465 466 467 468 469 470 471 472 473 474 475 476 477
     */
    public select(index: any, indexs: any[]) {
        let item = this.compute(this.menus, index);
        if (Object.keys(item).length === 0) {
            return;
        }
        this.click(item);
    }

    /**
     * 菜单点击
     *
     * @public
     * @param {*} item 菜单数据
478
     * @memberof TaskIndexViewBase
479 480 481
     */
    public click(item: any) {
        if (item) {
482
            let navDataService = NavDataService.getInstance(this.$store);
483 484 485
            if(Object.is(this.navModel,"route")){
                navDataService.removeNavData(this.viewtag);
            }
486
            switch (item.appfunctag) {
487 488
                case 'Auto3': 
                    this.clickAuto3(item);
489
                    return;
490 491
                case 'Auto2': 
                    this.clickAuto2(item);
492
                    return;
493 494
                case 'Auto1': 
                    this.clickAuto1(item);
495
                    return;
496 497 498 499 500 501 502 503 504 505 506 507 508
                default:
                    console.warn('未指定应用功能');
            }
        }
    }

    
    /**
     * 任务
     *
     * @param {*} [item={}]
     * @memberof TaskIndexView
     */
509
    public clickAuto3(item: any = {}) {
510 511 512 513 514 515 516 517
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'jobsinfos', parameterName: 'jobsinfo' },
            { pathName: 'gridview', parameterName: 'gridview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
518
        if(Object.is(this.$route.fullPath,path)){
519 520 521 522 523
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
524 525 526
    }
    
    /**
527
     * 任务调度日志
528 529 530 531
     *
     * @param {*} [item={}]
     * @memberof TaskIndexView
     */
532
    public clickAuto2(item: any = {}) {
533 534 535 536
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
537
            { pathName: 'jobslogs', parameterName: 'jobslog' },
538 539 540
            { pathName: 'gridview', parameterName: 'gridview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
541
        if(Object.is(this.$route.fullPath,path)){
542 543 544 545 546
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
547 548 549
    }
    
    /**
550
     * 任务注册
551 552 553 554
     *
     * @param {*} [item={}]
     * @memberof TaskIndexView
     */
555
    public clickAuto1(item: any = {}) {
556 557 558 559
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
560
            { pathName: 'jobsregistries', parameterName: 'jobsregistry' },
561 562 563
            { pathName: 'gridview', parameterName: 'gridview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
564
        if(Object.is(this.$route.fullPath,path)){
565 566 567 568 569
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
570 571 572 573 574 575
    }

    /**
     * 数据加载
     *
     * @param {*} data
576
     * @memberof TaskIndexViewBase
577 578 579 580 581 582 583 584 585
     */
    public load(data: any) {
        this.handleMenusResource(this.menuMode.getAppMenuItems());
    }

    /**
     * 通过统一资源标识计算菜单
     *
     * @param {*} data
586
     * @memberof TaskIndexViewBase
587 588 589 590
     */
    public handleMenusResource(inputMenus:Array<any>){
        if(Environment.enablePermissionValid){
            this.computedEffectiveMenus(inputMenus);
591
            this.computeParentMenus(inputMenus);
592 593 594 595 596 597 598 599 600
        }
        this.dataProcess(inputMenus);
        this.menus = inputMenus;
        this.doMenuSelect();
    }

    /**
     * 计算有效菜单项
     *
601
     * @param {*} inputMenus
602
     * @memberof TaskIndexViewBase
603 604 605 606 607 608 609 610 611 612 613 614
     */
    public computedEffectiveMenus(inputMenus:Array<any>){
        inputMenus.forEach((_item:any) =>{
            if(!this.$store.getters['authresource/getAuthMenu'](_item)){
                _item.hidden = true;
                if (_item.items && _item.items.length > 0) {
                    this.computedEffectiveMenus(_item.items);
                }
            }
        })
    }

615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
    /**
     * 计算父项菜单项是否隐藏
     *
     * @param {*} inputMenus
     * @memberof TaskIndexViewBase
     */
    public computeParentMenus(inputMenus:Array<any>){
        if(inputMenus && inputMenus.length >0){
            inputMenus.forEach((item:any) =>{
                if(item.hidden && item.items && item.items.length >0){
                    item.items.map((singleItem:any) =>{
                        if(!singleItem.hidden){
                            item.hidden = false;
                        }
                        if(singleItem.items && singleItem.items.length >0){
                            this.computeParentMenus(singleItem.items);
                        }
                    })
                }
            })
        }
    }

638 639 640 641 642
    /**
     * 数据处理
     *
     * @public
     * @param {any[]} items
643
     * @memberof TaskIndexViewBase
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
     */
    public dataProcess(items: any[]): void {
        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}
661
     * @memberof TaskIndexViewBase
662 663 664 665 666 667 668 669 670 671 672
     */
    get popperClass(): string {
        return 'app-popper-menu ' + this.selectTheme;
    }
    
}
</script>

<style lang='less'>
@import './task-index-view-appmenu.less';
</style>