ouindex-view-appmenu-base.vue 18.5 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="'ouindexview'" :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
import OUIndexViewService from './ouindex-view-appmenu-service';
import OUIndexViewModel from './ouindex-view-appmenu-model';
26
import { Environment } from '@/environments/environment';
27 28 29 30 31 32 33 34 35 36 37 38 39


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

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

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

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

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

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

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



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


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

    /**
     *  计数器刷新
     *
113
     * @memberof OUIndexViewBase
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 OUIndexViewBase
132 133 134 135 136 137 138 139 140
     */
    public getDatas(): any[] {
        return [];
    }

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

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

    /**
     * 视图标识
     *
     * @type {string}
159
     * @memberof OUIndexViewBase
160 161 162
     */
    @Prop() public viewtag!:string;

163 164 165 166 167
    /**
     * 菜单模型
     *
     * @public
     * @type {OUIndexViewModel}
168
     * @memberof OUIndexViewBase
169 170 171 172 173 174 175
     */
    public menuMode: OUIndexViewModel = new OUIndexViewModel();

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

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

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

    /**
     * 监听菜单收缩
     *
     * @param {*} newVal
     * @param {*} oldVal
203
     * @memberof OUIndexViewBase
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 OUIndexViewBase
217 218 219 220
     */
    @Prop() mode: any;

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

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

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

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

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

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

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

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

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

    /**
     * 执行created后的逻辑
     *
303
     *  @memberof OUIndexViewBase
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 OUIndexViewBase
323 324 325 326 327 328 329 330
     */
    public destroyed() {
        this.afterDestroy();
    }

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


    /**
     * 处理菜单默认选中项
     *
     * @public
344
     * @memberof OUIndexViewBase
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 OUIndexViewBase
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 OUIndexViewBase
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 OUIndexViewBase
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 OUIndexViewBase
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 OUIndexViewBase
479 480 481
     */
    public click(item: any) {
        if (item) {
482 483 484 485
            let navDataService = NavDataService.getInstance(this.$store);
            if(Object.is(this.navModel,"route")){
                navDataService.removeNavData(this.viewtag);
            }
486
            switch (item.appfunctag) {
487 488
                case 'Auto6': 
                    this.clickAuto6(item);
489
                    return;
490 491
                case 'Auto5': 
                    this.clickAuto5(item);
492 493 494 495
                    return;
                case 'Auto3': 
                    this.clickAuto3(item);
                    return;
496 497
                case 'Auto7': 
                    this.clickAuto7(item);
498
                    return;
499 500
                case 'Auto4': 
                    this.clickAuto4(item);
501 502 503 504 505 506 507 508
                    return;
                default:
                    console.warn('未指定应用功能');
            }
        }
    }

    
509 510 511 512 513 514
    /**
     * 岗位管理
     *
     * @param {*} [item={}]
     * @memberof OUIndexView
     */
515
    public clickAuto6(item: any = {}) {
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'ibzposts', parameterName: 'ibzpost' },
            { pathName: 'gridview', parameterName: 'gridview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
        if(Object.is(this.$route.fullPath,path)){
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
    }
    
532 533 534 535 536 537
    /**
     * 组织树
     *
     * @param {*} [item={}]
     * @memberof OUIndexView
     */
538
    public clickAuto5(item: any = {}) {
539 540 541 542 543 544 545 546
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'ibzorganizations', parameterName: 'ibzorganization' },
            { pathName: 'treeexpview', parameterName: 'treeexpview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
547 548 549 550 551 552
        if(Object.is(this.$route.fullPath,path)){
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569
    }
    
    /**
     * 单位管理
     *
     * @param {*} [item={}]
     * @memberof OUIndexView
     */
    public clickAuto3(item: any = {}) {
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'ibzorganizations', parameterName: 'ibzorganization' },
            { pathName: 'gridview', parameterName: 'gridview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
570 571 572 573 574 575
        if(Object.is(this.$route.fullPath,path)){
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
576 577
    }
    
578 579 580 581 582 583
    /**
     * 组管理
     *
     * @param {*} [item={}]
     * @memberof OUIndexView
     */
584
    public clickAuto7(item: any = {}) {
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'ibzteams', parameterName: 'ibzteam' },
            { pathName: 'gridview', parameterName: 'gridview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
        if(Object.is(this.$route.fullPath,path)){
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
    }
    
601 602 603 604 605 606
    /**
     * 部门树
     *
     * @param {*} [item={}]
     * @memberof OUIndexView
     */
607
    public clickAuto4(item: any = {}) {
608 609 610 611 612 613 614 615
        const viewparam: any = {};
        Object.assign(viewparam, {});
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'ibzdepartments', parameterName: 'ibzdepartment' },
            { pathName: 'treeexpview', parameterName: 'treeexpview' },
        ];
        const path: string = this.$viewTool.buildUpRoutePath(this.$route, {}, deResParameters, parameters, [], viewparam);
616 617 618 619 620 621
        if(Object.is(this.$route.fullPath,path)){
            return;
        }
        this.$nextTick(function(){
            this.$router.push(path);
        })
622 623 624 625 626 627
    }

    /**
     * 数据加载
     *
     * @param {*} data
628
     * @memberof OUIndexViewBase
629 630 631 632 633 634 635 636 637
     */
    public load(data: any) {
        this.handleMenusResource(this.menuMode.getAppMenuItems());
    }

    /**
     * 通过统一资源标识计算菜单
     *
     * @param {*} data
638
     * @memberof OUIndexViewBase
639 640
     */
    public handleMenusResource(inputMenus:Array<any>){
641
        if(Environment.enablePermissionValid){
642
            this.computedEffectiveMenus(inputMenus);
643
            this.computeParentMenus(inputMenus);
644
        }
645 646
        this.dataProcess(inputMenus);
        this.menus = inputMenus;
647 648 649 650 651 652
        this.doMenuSelect();
    }

    /**
     * 计算有效菜单项
     *
653
     * @param {*} inputMenus
654
     * @memberof OUIndexViewBase
655 656 657
     */
    public computedEffectiveMenus(inputMenus:Array<any>){
        inputMenus.forEach((_item:any) =>{
658
            if(!this.$store.getters['authresource/getAuthMenu'](_item)){
659 660 661 662 663 664 665 666
                _item.hidden = true;
                if (_item.items && _item.items.length > 0) {
                    this.computedEffectiveMenus(_item.items);
                }
            }
        })
    }

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
    /**
     * 计算父项菜单项是否隐藏
     *
     * @param {*} inputMenus
     * @memberof OUIndexViewBase
     */
    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);
                        }
                    })
                }
            })
        }
    }

690 691 692 693 694
    /**
     * 数据处理
     *
     * @public
     * @param {any[]} items
695
     * @memberof OUIndexViewBase
696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
     */
    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}
713
     * @memberof OUIndexViewBase
714 715 716 717 718 719 720 721 722 723 724
     */
    get popperClass(): string {
        return 'app-popper-menu ' + this.selectTheme;
    }
    
}
</script>

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