sys-rolepickup-view-base.vue 18.9 KB
Newer Older
1 2
<template>
<div class="view-container depickupview sys-rolepickup-view">
3
    <app-studioaction :viewTitle="$t(model.srfCaption)" viewName="sys_rolepickupview"></app-studioaction>
4 5 6 7
    <card class='view-card view-no-caption  view-no-toolbar' :dis-hover="true" :padding="0" :bordered="false">
        <div class="content-container pickup-view">
            <view_pickupviewpanel 
                :viewState="viewState"  
8 9
                :viewparams="JSON.parse(JSON.stringify(viewparams))" 
                :context="JSON.parse(JSON.stringify(context))" 
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
                :isSingleSelect="isSingleSelect"
                :selectedData="selectedData"
                :isShowButton="isShowButton"
                name="pickupviewpanel"  
                ref='pickupviewpanel' 
                @selectionchange="pickupviewpanel_selectionchange($event)"  
                @activated="pickupviewpanel_activated($event)"  
                @load="pickupviewpanel_load($event)"  
                @closeview="closeView($event)">
            </view_pickupviewpanel>
            <card v-if="isShowButton" :dis-hover="true" :bordered="false" class="footer">
                <row :style="{ textAlign: 'right' }">
                    <i-button type="primary" :disabled="this.viewSelections.length > 0 ? false : true" @click="onClickOk">{{this.containerModel.view_okbtn.text}}</i-button>
                        &nbsp;&nbsp;
                    <i-button @click="onClickCancel">{{this.containerModel.view_cancelbtn.text}}</i-button>
                </row>
            </card>
        </div>
    </card>
</div>
</template>


<script lang='tsx'>
34
import { Vue, Component, Prop, Provide, Emit, Watch,Inject } from 'vue-property-decorator';
35
import { UIActionTool,Util } from '@/utils';
36
import NavDataService from '@/service/app/navdata-service';
37
import { Subject,Subscription } from 'rxjs';
38
import SysRoleService from '@/service/sys-role/sys-role-service';
39
import SysRoleAuthService from '@/authservice/sys-role/sys-role-auth-service';
40 41 42 43

import PickupViewEngine from '@engine/view/pickup-view-engine';


44
import SysRoleUIService from '@/uiservice/sys-role/sys-role-ui-service';
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

@Component({
    components: {
    },
})
export default class SYS_ROLEPickupViewBase extends Vue {

    /**
     * 实体服务对象
     *
     * @type {SysRoleService}
     * @memberof SYS_ROLEPickupViewBase
     */
    public appEntityService: SysRoleService = new SysRoleService;

60
    /**
61
     * 实体UI服务对象
62
     *
63
     * @type SysRoleUIService
64 65
     * @memberof SYS_ROLEPickupViewBase
     */
66
    public appUIService: SysRoleUIService = new SysRoleUIService(this.$store);
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

    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof SYS_ROLEPickupViewBase
     */    
    public counterServiceArray:Array<any> = [];
    
    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof SYS_ROLEPickupViewBase
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

    /**
     * 传入视图上下文
     *
     * @type {string}
     * @memberof SYS_ROLEPickupViewBase
     */
    @Prop() public viewdata!: string;

    /**
     * 传入视图参数
     *
     * @type {string}
     * @memberof SYS_ROLEPickupViewBase
     */
    @Prop() public viewparam!: string;

    /**
     * 视图默认使用
     *
     * @type {boolean}
     * @memberof SYS_ROLEPickupViewBase
     */
    @Prop({ default: true }) public viewDefaultUsage!: boolean;

113 114 115 116 117 118
    /**
     * 视图默认使用
     *
     * @type {string}
     * @memberof SYS_ROLEPickupViewBase
     */
119
    @Inject({from:'navModel',default: 'tab'})
120 121
    public navModel!:string;

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 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 180 181 182 183 184 185 186 187 188 189 190 191 192
	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof SYS_ROLEPickupViewBase
	 */
	public viewtag: string = '8a32be8cf2c1e224867a93bb5fc90b67';

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof SYS_ROLEPickupViewBase
	 */
    public customViewNavContexts:any ={
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof SYS_ROLEPickupViewBase
	 */
    public customViewParams:any ={
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof SYS_ROLEPickupViewBase
     */
    public model: any = {
        srfCaption: 'entities.sysrole.views.pickupview.caption',
        srfTitle: 'entities.sysrole.views.pickupview.title',
        srfSubTitle: 'entities.sysrole.views.pickupview.subtitle',
        dataInfo: ''
    }

    /**
     * 视图参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof SYS_ROLEPickupViewBase
     */
    @Watch('viewparam',{immediate: true, deep: true})
    onParamData(newVal: any, oldVal: any) {
        if(newVal){
            for(let key in this.viewparams){
                delete this.viewparams[key];
            }
            Object.assign(this.viewparams, JSON.parse(this.viewparam));
            if(this.viewparams.selectedData){
                this.selectedData = JSON.stringify(this.viewparams.selectedData);
            }

        } 
    }

    /**
     * 处理应用上下文变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof SYS_ROLEPickupViewBase
     */
    @Watch('viewdata')
    onViewData(newVal: any, oldVal: any) {
        const _this: any = this;
        if (!Object.is(newVal, oldVal) && _this.engine) {
193 194 195 196 197
            this.$nextTick(()=>{
              _this.parseViewParam();
              _this.engine.load();
              
            });
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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
        }
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof SYS_ROLEPickupViewBase
     */
    public containerModel: any = {
        view_pickupviewpanel: { name: 'pickupviewpanel', type: 'PICKUPVIEWPANEL' },
        view_okbtn: { name: 'okbtn', type: 'button', text: '确定', disabled: true },
        view_cancelbtn: { name: 'cancelbtn', type: 'button', text: '取消', disabled: false },
        view_leftbtn: { name: 'leftbtn', type: 'button', text: '左移', disabled: true },
        view_rightbtn: { name: 'rightbtn', type: 'button', text: '右移', disabled: true },
        view_allleftbtn: { name: 'allleftbtn', type: 'button', text: '全部左移', disabled: true },
        view_allrightbtn: { name: 'allrightbtn', type: 'button', text: '全部右移', disabled: true },
    };

    /**
     *  计数器刷新
     *
     * @memberof SYS_ROLEPickupViewBase
     */
    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();
                }
            })
        }
    }

    /**
     * 视图状态订阅对象
     *
     * @public
     * @type {Subject<{action: string, data: any}>}
     * @memberof SYS_ROLEPickupViewBase
     */
    public viewState: Subject<ViewState> = new Subject();



    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof SYS_ROLEPickupViewBase
     */
    public engine: PickupViewEngine = new PickupViewEngine();

    /**
     * 引擎初始化
     *
     * @public
     * @memberof SYS_ROLEPickupViewBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            pickupviewpanel: this.$refs.pickupviewpanel,
            keyPSDEField: 'sysrole',
            majorPSDEField: 'rolename',
            isLoadDefault: true,
        });
    }

269 270 271 272 273 274 275 276
    /**
     * 应用导航服务
     *
     * @type {*}
     * @memberof SYS_ROLEPickupViewBase
     */
    public  navDataService = NavDataService.getInstance(this.$store);

277 278 279 280 281 282 283 284 285
    /**
    * 导航服务事件
    *
    * @public
    * @type {(Subscription | undefined)}
    * @memberof SYS_ROLEPickupViewBase
    */
    public serviceStateEvent: Subscription | undefined;

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof SYS_ROLEPickupViewBase
     */
    public context:any = {};

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof SYS_ROLEPickupViewBase
     */
    public viewparams:any = {};

302 303 304 305 306 307 308 309
    /**
     * 视图缓存数据
     *
     * @type {*}
     * @memberof SYS_ROLEPickupViewBase
     */
    public viewCacheData:any;

310 311 312 313 314 315
    /**
     * 解析视图参数
     *
     * @public
     * @memberof SYS_ROLEPickupViewBase
     */
316
    public parseViewParam(inputvalue:any = null): void {
317 318 319 320 321 322 323 324 325 326 327
        for(let key in this.context){
            delete this.context[key];
        }
        if (!this.viewDefaultUsage && this.viewdata && !Object.is(this.viewdata, '')) {
            Object.assign(this.context, JSON.parse(this.viewdata));
            if(this.context && this.context.srfparentdename){
                Object.assign(this.viewparams,{srfparentdename:this.context.srfparentdename});
            }
            if(this.context && this.context.srfparentkey){
                Object.assign(this.viewparams,{srfparentkey:this.context.srfparentkey});
            }
328 329 330
            if(this.$store.getters.getAppData() && this.$store.getters.getAppData().context){
                Object.assign(this.context,this.$store.getters.getAppData().context);
            }
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
            this.handleCustomViewData();
            return;
        }
        const path = (this.$route.matched[this.$route.matched.length - 1]).path;
        const keys: Array<any> = [];
        const curReg = this.$pathToRegExp.pathToRegexp(path, keys);
        const matchArray = curReg.exec(this.$route.path);
        let tempValue: Object = {};
        keys.forEach((item: any, index: number) => {
            Object.defineProperty(tempValue, item.name, {
                enumerable: true,
                value: matchArray[index + 1]
            });
        });
        this.$viewTool.formatRouteParams(tempValue,this.$route,this.context,this.viewparams);
346 347 348
        if(inputvalue){
            Object.assign(this.context,{'sysrole':inputvalue});
        }
349 350 351 352 353 354
        if(this.$store.getters.getAppData() && this.$store.getters.getAppData().context){
            Object.assign(this.context,this.$store.getters.getAppData().context);
        }
        //初始化视图唯一标识
        Object.assign(this.context,{srfsessionid:this.$util.createUUID()});
        this.handleCustomViewData();
355
        //初始化导航数据
356
        this.initNavDataWithRoute();
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 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
    }

    /**
     * 处理自定义视图数据
     *
     * @memberof SYS_ROLEPickupViewBase
     */
	public handleCustomViewData(){
		if(Object.keys(this.customViewNavContexts).length > 0){
			Object.keys(this.customViewNavContexts).forEach((item:any) =>{
				let tempContext:any = {};
				let curNavContext:any = this.customViewNavContexts[item];
				this.handleCustomDataLogic(curNavContext,tempContext,item);
				Object.assign(this.context,tempContext);
			})
		}
		if(Object.keys(this.customViewParams).length > 0){
			Object.keys(this.customViewParams).forEach((item:any) =>{
				let tempParam:any = {};
				let curNavParam:any = this.customViewParams[item];
				this.handleCustomDataLogic(curNavParam,tempParam,item);
				Object.assign(this.viewparams,tempParam);
			})
		}
	}

    /**
     * 处理自定义视图数据逻辑
     *
     * @memberof SYS_ROLEPickupViewBase
     */
	public handleCustomDataLogic(curNavData:any,tempData:any,item:string){
		// 直接值直接赋值
		if(curNavData.isRawValue){
			if(Object.is(curNavData.value,"null") || Object.is(curNavData.value,"")){
                Object.defineProperty(tempData, item.toLowerCase(), {
                    value: null,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }else{
                Object.defineProperty(tempData, item.toLowerCase(), {
                    value: curNavData.value,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }
		}else{
			// 先从导航上下文取数,没有再从导航参数(URL)取数,如果导航上下文和导航参数都没有则为null
408
			if(this.context[(curNavData.value).toLowerCase()] != null){
409 410 411 412 413 414 415
				Object.defineProperty(tempData, item.toLowerCase(), {
					value: this.context[(curNavData.value).toLowerCase()],
					writable : true,
					enumerable : true,
					configurable : true
				});
			}else{
416
				if(this.viewparams[(curNavData.value).toLowerCase()] != null){
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
					Object.defineProperty(tempData, item.toLowerCase(), {
						value: this.viewparams[(curNavData.value).toLowerCase()],
						writable : true,
						enumerable : true,
						configurable : true
					});
				}else{
					Object.defineProperty(tempData, item.toLowerCase(), {
						value: null,
						writable : true,
						enumerable : true,
						configurable : true
					});
				}
			}
		}
	}
434 435

    /**
436
     * 初始化导航数据(路由模式)
437 438 439
     *
     * @memberof SYS_ROLEPickupViewBase
     */
440 441
    public initNavDataWithRoute(data:any = null, isNew:boolean = false,  isAlways:boolean = false){
        if( isAlways || (this.viewDefaultUsage && Object.is(this.navModel,"route")) ){
442
            this.navDataService.addNavData({id:'sys-rolepickup-view',tag:this.viewtag,srfkey:isNew ? null : this.context.sysrole,title:this.$t(this.model.srfCaption),data:data,context:this.context,viewparams:this.viewparams,path:this.$route.fullPath});
443 444 445 446 447 448 449 450
        }
    }

    /**
     * 初始化导航数据(分页模式)
     *
     * @memberof SYS_ROLEPickupViewBase
     */
451 452
    public initNavDataWithTab(data:any = null,isOnlyAdd:boolean = true, isAlways:boolean = false){
        if( isAlways || (this.viewDefaultUsage && !Object.is(this.navModel,"route")) ){
453
            this.navDataService.addNavDataByOnly({id:'sys-rolepickup-view',tag:this.viewtag,srfkey:this.context.sysrole,title:this.$t(this.model.srfCaption),data:data,context:this.context,viewparams:this.viewparams,path:this.$route.fullPath},isOnlyAdd);
454 455
        }
    }
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
	

    /**
     * Vue声明周期
     *
     * @memberof SYS_ROLEPickupViewBase
     */
    public created() {
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     * @memberof SYS_ROLEPickupViewBase
     */    
    public afterCreated(){
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
        let _this:any = this;
        const secondtag = _this.$util.createUUID();
        _this.$store.commit('viewaction/createdView', { viewtag: _this.viewtag, secondtag: secondtag });
        _this.viewtag = secondtag;
        _this.parseViewParam();
        _this.serviceStateEvent = _this.navDataService.serviceState.subscribe(({ action,name, data }:{ action:string,name:any,data:any }) => {
            if(!Object.is(name,'sys-rolepickup-view')){
                return;
            }
            if (Object.is(action, 'viewrefresh')) {
                _this.$nextTick(()=>{
                    _this.parseViewParam(data);
                    if(_this.engine){
                        _this.engine.load();
                    }
                }); 
            }
        });
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 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 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
        
    }

    /**
     * 销毁之前
     *
     * @memberof SYS_ROLEPickupViewBase
     */
    public beforeDestroy() {
        this.$store.commit('viewaction/removeView', this.viewtag);
    }

    /**
     * Vue声明周期(组件初始化完毕)
     *
     * @memberof SYS_ROLEPickupViewBase
     */
    public mounted() {
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     * 
     * @memberof SYS_ROLEPickupViewBase
     */
    public afterMounted(){
        const _this: any = this;
        _this.engineInit();
        if (_this.loadModel && _this.loadModel instanceof Function) {
            _this.loadModel();
        }
        if(this.viewparams.selectedData){
            this.engine.onCtrlEvent('pickupviewpanel', 'selectionchange', this.viewparams.selectedData);
        }

    }


    /**
     * pickupviewpanel 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof SYS_ROLEPickupViewBase
     */
    public pickupviewpanel_selectionchange($event: any, $event2?: any) {
        this.engine.onCtrlEvent('pickupviewpanel', 'selectionchange', $event);
    }


    /**
     * pickupviewpanel 部件 activated 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof SYS_ROLEPickupViewBase
     */
    public pickupviewpanel_activated($event: any, $event2?: any) {
        this.engine.onCtrlEvent('pickupviewpanel', 'activated', $event);
    }


    /**
     * pickupviewpanel 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof SYS_ROLEPickupViewBase
     */
    public pickupviewpanel_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('pickupviewpanel', 'load', $event);
    }




    /**
     * 关闭视图
     *
     * @param {any[]} args
     * @memberof SYS_ROLEPickupViewBase
     */
    public closeView(args: any[]): void {
        let _view: any = this;
        if (_view.viewdata) {
            _view.$emit('viewdataschange', [args]);
            _view.$emit('close', [args]);
        } else if (_view.$tabPageExp) {
            _view.$tabPageExp.onClose(_view.$route.fullPath);
        }
    }

    /**
     * 销毁视图回调
     *
     * @memberof SYS_ROLEPickupViewBase
     */
    public destroyed(){
        this.afterDestroyed();
    }

    /**
     * 执行destroyed后的逻辑
     * 
     * @memberof SYS_ROLEPickupViewBase
     */
    public afterDestroyed(){
        if(this.viewDefaultUsage){
            let localStoreLength = Object.keys(localStorage);
            if(localStoreLength.length > 0){
                localStoreLength.forEach((item:string) =>{
                if(item.startsWith(this.context.srfsessionid)){
                    localStorage.removeItem(item);
                }
                })
            }
608 609 610
            if(Object.is(this.navModel,"tab")){
                this.navDataService.removeNavDataByTag(this.viewtag);
            }
611 612 613
            if (this.serviceStateEvent) {
                this.serviceStateEvent.unsubscribe();
            }
614 615 616 617 618 619
        }
    }
    /**
     * 选中数据的字符串
     *
     * @type {string}
620
     * @memberof SYS_ROLEPickupViewBase
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
     */
    public selectedData: string = "";

    /**
     * 视图选中数据
     *
     * @type {any[]}
     * @memberof SYS_ROLEPickupViewBase
     */
    public viewSelections:any[] = [];

    /**
     * 是否显示按钮
     *
     * @type {boolean}
     * @memberof SYS_ROLEPickupViewBase
     */
    @Prop({default: true}) public isShowButton!: boolean;

    /**
     * 是否单选
     *
     * @type {boolean}
     * @memberof SYS_ROLEPickupViewBase
     */
    public isSingleSelect: boolean = true;

    /**
     * 确定
     *
     * @memberof SYS_ROLEPickupViewBase
     */
    public onClickOk(): void {
        this.$emit('viewdataschange', this.viewSelections);
        this.$emit('close', null);
    }

    /**
     * 取消
     *
     * @memberof SYS_ROLEPickupViewBase
     */
    public onClickCancel(): void {
664
        this.$emit('viewdataschange', null);
665 666 667 668 669 670 671 672 673
        this.$emit('close', null);
    }

}
</script>

<style lang='less'>
@import './sys-rolepickup-view.less';
</style>