ibzorganization-option-view-base.vue 14.8 KB
Newer Older
ibizdev's avatar
ibizdev committed
1
<template>
ibizdev's avatar
ibizdev committed
2
<div class="view-container deoptview ibzorganization-option-view">
ibizdev's avatar
ibizdev committed
3
    <app-studioaction :viewTitle="$t(model.srfTitle)" viewName="ibzorganizationoptionview"></app-studioaction>
ibizdev's avatar
ibizdev committed
4
    <card class='view-card  view-no-caption  view-no-toolbar' dis-hover :padding="0" :bordered="false">
ibizdev's avatar
ibizdev committed
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
        <div class="content-container">
            <view_form 
                :viewState="viewState"  
                :viewparams="viewparams" 
                :context="context" 
                :autosave="false" 
                :viewtag="viewtag"
                :showBusyIndicator="true"
                updateAction="Update"
                removeAction="Remove"
                loaddraftAction="GetDraft"
                loadAction="Get"
                createAction="Create"
                WFSubmitAction=""
                WFStartAction=""
                style='' 
                name="form"  
                ref='form' 
                @save="form_save($event)"  
                @remove="form_remove($event)"  
                @load="form_load($event)"  
                @closeview="closeView($event)">
            </view_form>
        </div>
        <card dis-hover :bordered="false" class='footer'>
          <row style=" text-align: right ">
            <i-button type='primary' @click="onClickOk">{{ containerModel.view_okbtn.text }}</i-button>
              &nbsp;&nbsp;
            <i-button @click="onClickCancel">{{ containerModel.view_cancelbtn.text }}</i-button>
          </row>
        </card>
    </card>
</div>
</template>

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { UIActionTool,Util } from '@/utils';
import { Subject } from 'rxjs';
import IBZOrganizationService from '@/service/ibzorganization/ibzorganization-service';

import OptionViewEngine from '@engine/view/option-view-engine';



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

    /**
     * 实体服务对象
     *
     * @type {IBZOrganizationService}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
62
    public appEntityService: IBZOrganizationService = new IBZOrganizationService;
ibizdev's avatar
ibizdev committed
63 64 65 66 67 68 69 70


    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof IBZOrganizationOptionViewBase
     */    
ibizdev's avatar
ibizdev committed
71
    public counterServiceArray:Array<any> = [];
ibizdev's avatar
ibizdev committed
72 73 74 75 76 77 78 79 80
    
    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof IBZOrganizationOptionViewBase
     */
    @Emit() 
ibizdev's avatar
ibizdev committed
81
    public viewDatasChange(val: any):any {
ibizdev's avatar
ibizdev committed
82 83 84 85 86 87 88 89 90
        return val;
    }

    /**
     * 传入视图上下文
     *
     * @type {string}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
91
    @Prop() public viewdata!: string;
ibizdev's avatar
ibizdev committed
92 93 94 95 96 97 98

    /**
     * 传入视图参数
     *
     * @type {string}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
99
    @Prop() public viewparam!: string;
ibizdev's avatar
ibizdev committed
100 101 102 103 104 105 106

    /**
     * 视图默认使用
     *
     * @type {boolean}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
107
    @Prop({ default: true }) public viewDefaultUsage!: boolean;
ibizdev's avatar
ibizdev committed
108 109 110 111 112 113 114

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof IBZOrganizationOptionViewBase
	 */
ibizdev's avatar
ibizdev committed
115
	public viewtag: string = '995d26f289a30e31573d557a5f5ba254';
ibizdev's avatar
ibizdev committed
116 117 118 119 120 121 122

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof IBZOrganizationOptionViewBase
	 */
ibizdev's avatar
ibizdev committed
123
    public customViewNavContexts:any ={
ibizdev's avatar
ibizdev committed
124 125 126 127 128 129 130 131
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof IBZOrganizationOptionViewBase
	 */
ibizdev's avatar
ibizdev committed
132
    public customViewParams:any ={
ibizdev's avatar
ibizdev committed
133 134 135 136 137 138 139 140
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
141
    public model: any = {
ibizdev's avatar
ibizdev committed
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
        srfCaption: 'entities.ibzorganization.views.optionview.caption',
        srfTitle: 'entities.ibzorganization.views.optionview.title',
        srfSubTitle: 'entities.ibzorganization.views.optionview.subtitle',
        dataInfo: ''
    }

    /**
     * 视图参数变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof IBZOrganizationOptionViewBase
     */
    @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));
            
        } 
    }

    /**
     * 处理应用上下文变化
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof IBZOrganizationOptionViewBase
     */
    @Watch('viewdata')
    onViewData(newVal: any, oldVal: any) {
        const _this: any = this;
        if (!Object.is(newVal, oldVal) && _this.engine) {
            _this.parseViewParam();
            _this.engine.load();
        }
        
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
189
    public containerModel: any = {
ibizdev's avatar
ibizdev committed
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
        view_form: { name: 'form', type: 'FORM' },
        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 IBZOrganizationOptionViewBase
     */
    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();
                }
            })
        }
    }

    /**
     * 视图状态订阅对象
     *
ibizdev's avatar
ibizdev committed
218
     * @public
ibizdev's avatar
ibizdev committed
219 220 221
     * @type {Subject<{action: string, data: any}>}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
222
    public viewState: Subject<ViewState> = new Subject();
ibizdev's avatar
ibizdev committed
223 224 225 226 227 228



    /**
     * 视图引擎
     *
ibizdev's avatar
ibizdev committed
229
     * @public
ibizdev's avatar
ibizdev committed
230 231 232
     * @type {Engine}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
233
    public engine: OptionViewEngine = new OptionViewEngine();
ibizdev's avatar
ibizdev committed
234 235 236 237

    /**
     * 引擎初始化
     *
ibizdev's avatar
ibizdev committed
238
     * @public
ibizdev's avatar
ibizdev committed
239 240
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
241
    public engineInit(): void {
ibizdev's avatar
ibizdev committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
        this.engine.init({
            view: this,
            form: this.$refs.form,
            p2k: '0',
            keyPSDEField: 'ibzorganization',
            majorPSDEField: 'orgname',
            isLoadDefault: true,
        });
    }

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
258
    public context:any = {};
ibizdev's avatar
ibizdev committed
259 260 261 262 263 264 265

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
266
    public viewparams:any = {};
ibizdev's avatar
ibizdev committed
267 268 269 270

    /**
     * 解析视图参数
     *
ibizdev's avatar
ibizdev committed
271
     * @public
ibizdev's avatar
ibizdev committed
272 273
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
274
    public parseViewParam(): void {
ibizdev's avatar
ibizdev committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
        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});
            }
            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);
        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();
    }

    /**
     * 处理自定义视图数据
     *
     * @memberof IBZOrganizationOptionViewBase
     */
	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 IBZOrganizationOptionViewBase
     */
	public handleCustomDataLogic(curNavData:any,tempData:any,item:string){
		// 直接值直接赋值
		if(curNavData.isRawValue){
			if(Object.is(curNavData.value,"null") || Object.is(curNavData.value,"")){
ibizdev's avatar
ibizdev committed
342
                Object.defineProperty(tempData, item.toLowerCase(), {
ibizdev's avatar
ibizdev committed
343 344 345 346 347 348
                    value: null,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }else{
ibizdev's avatar
ibizdev committed
349
                Object.defineProperty(tempData, item.toLowerCase(), {
ibizdev's avatar
ibizdev committed
350 351 352 353 354 355 356 357
                    value: curNavData.value,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }
		}else{
			// 先从导航上下文取数,没有再从导航参数(URL)取数,如果导航上下文和导航参数都没有则为null
ibizdev's avatar
ibizdev committed
358
			if(this.context[(curNavData.value).toLowerCase()]){
ibizdev's avatar
ibizdev committed
359
				Object.defineProperty(tempData, item.toLowerCase(), {
ibizdev's avatar
ibizdev committed
360
					value: this.context[(curNavData.value).toLowerCase()],
ibizdev's avatar
ibizdev committed
361 362 363 364 365
					writable : true,
					enumerable : true,
					configurable : true
				});
			}else{
ibizdev's avatar
ibizdev committed
366
				if(this.viewparams[(curNavData.value).toLowerCase()]){
ibizdev's avatar
ibizdev committed
367
					Object.defineProperty(tempData, item.toLowerCase(), {
ibizdev's avatar
ibizdev committed
368
						value: this.viewparams[(curNavData.value).toLowerCase()],
ibizdev's avatar
ibizdev committed
369 370 371 372 373
						writable : true,
						enumerable : true,
						configurable : true
					});
				}else{
ibizdev's avatar
ibizdev committed
374
					Object.defineProperty(tempData, item.toLowerCase(), {
ibizdev's avatar
ibizdev committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
						value: null,
						writable : true,
						enumerable : true,
						configurable : true
					});
				}
			}
		}
	}
	

    /**
     * Vue声明周期
     *
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
391
    public created() {
ibizdev's avatar
ibizdev committed
392 393 394 395 396 397 398 399
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     * @memberof IBZOrganizationOptionViewBase
     */    
ibizdev's avatar
ibizdev committed
400
    public afterCreated(){
ibizdev's avatar
ibizdev committed
401 402 403 404 405 406 407 408 409 410 411 412
        const secondtag = this.$util.createUUID();
        this.$store.commit('viewaction/createdView', { viewtag: this.viewtag, secondtag: secondtag });
        this.viewtag = secondtag;
        this.parseViewParam();
        
    }

    /**
     * 销毁之前
     *
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
413
    public beforeDestroy() {
ibizdev's avatar
ibizdev committed
414 415 416 417 418 419 420 421
        this.$store.commit('viewaction/removeView', this.viewtag);
    }

    /**
     * Vue声明周期(组件初始化完毕)
     *
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
422
    public mounted() {
ibizdev's avatar
ibizdev committed
423 424 425 426 427 428 429 430
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     * 
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
431
    public afterMounted(){
ibizdev's avatar
ibizdev committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
        const _this: any = this;
        _this.engineInit();
        if (_this.loadModel && _this.loadModel instanceof Function) {
            _this.loadModel();
        }
        
    }


    /**
     * form 部件 save 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
448
    public form_save($event: any, $event2?: any) {
ibizdev's avatar
ibizdev committed
449 450 451 452 453 454 455 456 457 458 459
        this.engine.onCtrlEvent('form', 'save', $event);
    }


    /**
     * form 部件 remove 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
460
    public form_remove($event: any, $event2?: any) {
ibizdev's avatar
ibizdev committed
461 462 463 464 465 466 467 468 469 470 471
        this.engine.onCtrlEvent('form', 'remove', $event);
    }


    /**
     * form 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
472
    public form_load($event: any, $event2?: any) {
ibizdev's avatar
ibizdev committed
473 474 475 476 477 478 479 480 481 482 483 484
        this.engine.onCtrlEvent('form', 'load', $event);
    }




    /**
     * 关闭视图
     *
     * @param {any[]} args
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
485
    public closeView(args: any[]): void {
ibizdev's avatar
ibizdev committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499
        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 IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
500
    public destroyed(){
ibizdev's avatar
ibizdev committed
501 502 503 504 505 506 507 508
        this.afterDestroyed();
    }

    /**
     * 执行destroyed后的逻辑
     * 
     * @memberof IBZOrganizationOptionViewBase
     */
ibizdev's avatar
ibizdev committed
509
    public afterDestroyed(){
ibizdev's avatar
ibizdev committed
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
        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);
                }
                })
            }
        }
    }

    /**
     * 确定
     *
     * @memberof IBZOrganizationOptionViewBase
     */
    public onClickOk(): void {
        const form: any = this.$refs.form;
        if (!form) return;
        form.save().then((res:any) =>{
            if(res.status == 200){
                this.$emit('close',[res.data]);
            }
        });
    }

    /**
     * 取消
     *
     * @memberof IBZOrganizationOptionViewBase
     */
    public onClickCancel(): void {
        this.$emit('close', null);
    }

}
</script>

<style lang='less'>
@import './ibzorganization-option-view.less';
</style>