tree-exp-viewtreeexpbar-treeexpbar-base.vue 13.8 KB
Newer Older
ibizdev's avatar
ibizdev committed
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
<template>
    <split id="treeexpviewtreeexpbar" class='app-tree-exp-bar' v-model="split" mode="horizontal" @on-move-end="onSplitChange">
        <div slot='left'>
            <div class='tree-exp-bar-header'>
                <div>组织</div>
            </div>
            <div class='search-content'>
                <i-input :search="true"
                    @on-change="($event) => { this.srfnodefilter = $event.target.value; }"
                    @on-search="onSearch">
                </i-input>
            </div>
            <div class='tree-exp-content'>
                            <view_treeexpbar_tree 
                :viewState="viewState"  
                :viewparams="viewparams" 
                :context="context" 
                :showBusyIndicator="true"
                updateAction='Update' 
                removeAction='Remove' 
                loadAction='Get' 
                createAction='Create' 
                :isSelectFirstDefault="true"
                :isBranchAvailable="true"
                name="treeexpbar_tree"  
                ref='treeexpbar_tree' 
                @selectionchange="treeexpbar_tree_selectionchange($event)"  
                @load="treeexpbar_tree_load($event)"  
                @closeview="closeView($event)">
            </view_treeexpbar_tree>
            </div>
        </div>
        <div slot='right'>
            <component 
              v-if="selection.view && !Object.is(this.selection.view.viewname, '')" 
              :is="selection.view.viewname"
              class="viewcontainer2"
              :viewDefaultUsage="false"
              :viewdata="JSON.stringify(selection.context)"
              :viewparam="JSON.stringify(selection.viewparam)"
              @viewdataschange="onViewDatasChange"
              @viewdatasactivated="viewDatasActivated"
              @viewload="onViewLoad">
            </component>
        </div>
    </split>
</template>
<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch, Model } from 'vue-property-decorator';
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
import { UIActionTool,Util } from '@/utils';
import PIMARCHIVESService from '@/service/pimarchives/pimarchives-service';
import TreeExpViewtreeexpbarService from './tree-exp-viewtreeexpbar-treeexpbar-service';



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

    /**
     * 名称
     *
     * @type {string}
     * @memberof TreeExpViewtreeexpbar
     */
72
    @Prop() public name?: string;
ibizdev's avatar
ibizdev committed
73 74 75 76 77 78 79

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
     * @memberof TreeExpViewtreeexpbar
     */
80
    @Prop() public viewState!: Subject<ViewState>;
ibizdev's avatar
ibizdev committed
81 82 83 84 85 86 87

    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof TreeExpViewtreeexpbar
     */
88
    @Prop() public context: any;
ibizdev's avatar
ibizdev committed
89 90 91 92 93 94 95

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof TreeExpViewtreeexpbar
     */
96
    @Prop() public viewparams: any;
ibizdev's avatar
ibizdev committed
97 98 99 100

    /**
     * 视图状态事件
     *
101
     * @public
ibizdev's avatar
ibizdev committed
102 103 104
     * @type {(Subscription | undefined)}
     * @memberof TreeExpViewtreeexpbar
     */
105
    public viewStateEvent: Subscription | undefined;
ibizdev's avatar
ibizdev committed
106 107 108 109 110 111 112

    /**
     * 获取部件类型
     *
     * @returns {string}
     * @memberof TreeExpViewtreeexpbar
     */
113
    public getControlType(): string {
ibizdev's avatar
ibizdev committed
114 115 116 117 118 119 120 121 122 123 124
        return 'TREEEXPBAR'
    }



    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
     * @memberof TreeExpViewtreeexpbar
     */    
125
    public counterServiceArray:Array<any> = [];
ibizdev's avatar
ibizdev committed
126 127 128 129 130 131 132

    /**
     * 建构部件服务对象
     *
     * @type {TreeExpViewtreeexpbarService}
     * @memberof TreeExpViewtreeexpbar
     */
133
    public service: TreeExpViewtreeexpbarService = new TreeExpViewtreeexpbarService({ $store: this.$store });
ibizdev's avatar
ibizdev committed
134 135 136 137 138 139 140

    /**
     * 实体服务对象
     *
     * @type {PIMARCHIVESService}
     * @memberof TreeExpViewtreeexpbar
     */
141
    public appEntityService: PIMARCHIVESService = new PIMARCHIVESService({ $store: this.$store });
ibizdev's avatar
ibizdev committed
142 143 144 145 146 147 148 149

    /**
     * treeexpbar_tree 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof TreeExpViewtreeexpbar
     */
150
    public treeexpbar_tree_selectionchange($event: any, $event2?: any) {
ibizdev's avatar
ibizdev committed
151 152 153 154 155 156 157 158 159 160
        this.treeexpbar_selectionchange($event, 'treeexpbar_tree', $event2);
    }

    /**
     * treeexpbar_tree 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof TreeExpViewtreeexpbar
     */
161
    public treeexpbar_tree_load($event: any, $event2?: any) {
ibizdev's avatar
ibizdev committed
162 163 164 165 166 167 168 169 170 171 172
        this.treeexpbar_load($event, 'treeexpbar_tree', $event2);
    }
    


    /**
     * 关闭视图
     *
     * @param {any} args
     * @memberof TreeExpViewtreeexpbar
     */
173
    public closeView(args: any): void {
ibizdev's avatar
ibizdev committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

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


    /**
     * 视图唯一标识
     *
     * @type {boolean}
     * @memberof TreeExpViewtreeexpbarBase
     */
201
    @Prop() public viewUID!:string;
ibizdev's avatar
ibizdev committed
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

    /**
     * 获取多项数据
     *
     * @returns {any[]}
     * @memberof TreeExpViewtreeexpbarBase
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
     * @memberof TreeExpViewtreeexpbarBase
     */
    public getData(): any {
        return {};
    }

    /**
     * 选中数据
     *
     * @type {*}
     * @memberof TreeExpViewtreeexpbarBase
     */
229
    public selection: any = {};
ibizdev's avatar
ibizdev committed
230 231 232 233 234 235 236

    /**
     * 控件宽度
     *
     * @type {number}
     * @memberof TreeExpViewtreeexpbarBase
     */
237
    public ctrlWidth:number = 0;
ibizdev's avatar
ibizdev committed
238 239 240 241 242 243 244

    /**
     * 过滤值
     *
     * @type {string}
     * @memberof TreeExpViewtreeexpbarBase
     */
245
    public srfnodefilter: string = '';
ibizdev's avatar
ibizdev committed
246 247 248 249

    /**
     * 刷新标识
     *
250
     * @public
ibizdev's avatar
ibizdev committed
251 252 253
     * @type {number}
     * @memberof TreeExpViewtreeexpbarBase
     */
254
    public counter:number = 0;
ibizdev's avatar
ibizdev committed
255 256 257 258

    /**
     * 是否加载默认关联视图
     *
259
     * @public
ibizdev's avatar
ibizdev committed
260 261 262
     * @type {boolean}
     * @memberof TreeExpViewtreeexpbarBase
     */
263
    public istLoadDefaultRefView: boolean = false;
ibizdev's avatar
ibizdev committed
264 265 266 267 268 269 270

    /**
     * 分割宽度
     *
     * @type {number}
     * @memberof TreeExpViewtreeexpbarBase
     */
271
    public split: number = 0.2;
ibizdev's avatar
ibizdev committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290

    /**
     * split值变化事件
     *
     * @memberof TreeExpViewtreeexpbarBase
     */
    public onSplitChange() {
        if(this.split){
          this.$store.commit("setViewSplit",{viewUID:this.viewUID,viewSplit:this.split});
        }
    }

    /**
     * 获取关系项视图
     *
     * @param {*} [arg={}]
     * @returns {*}
     * @memberof TreeExpViewtreeexpbarBase
     */
291
    public getExpItemView(arg: any = {}): any {
ibizdev's avatar
ibizdev committed
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
        let expmode = arg.nodetype.toUpperCase();
        if (!expmode) {
            expmode = '';
        }
        if (Object.is(expmode, 'ORMORG')) {
            return {  
                viewname: 'pimarchivesgrid-view', 
                parentdata: {"srfparentdefname":"n_ormorgid_eq","srfparentdename":"ORMORG","srfparentmode":"DER1N_PIMARCHIVES_ORMORG_ORMORGID3"},
                deKeyField:'pimarchives'
			};
        }
        if (Object.is(expmode, 'SUBORG')) {
            return {  
                viewname: 'pimarchivesgrid-view', 
                parentdata: {"srfparentdefname":"n_ormorgid_eq","srfparentdename":"ORMORG","srfparentmode":"DER1N_PIMARCHIVES_ORMORG_ORMORGID3"},
                deKeyField:'pimarchives'
			};
        }
        return null;
    }

    /**
     * 树导航选中
     *
     * @param {any []} args
     * @param {string} [tag]
     * @param {*} [$event2]
     * @returns {void}
     * @memberof TreeExpViewtreeexpbarBase
     */
322
    public treeexpbar_selectionchange(args: any [], tag?: string, $event2?: any): void {
ibizdev's avatar
ibizdev committed
323 324 325 326 327 328 329 330 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 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
        if (args.length === 0) {
            return ;
        }
        const arg:any = args[0];
        if (!arg.id) {
            return;
        }
        const nodetype = arg.id.split(';')[0];
        const refview = this.getExpItemView({ nodetype: nodetype });
        if (!refview) {
            return;
        }
        let tempViewparam:any = {};
        let tempContext:any ={};
        if(arg && arg.navfilter){
            this.counter += 1;
            Object.defineProperty(tempViewparam, arg.navfilter, {
                value : arg.srfkey,
                writable : true,
                enumerable : true,
                configurable : true
            })
            Object.assign(tempContext,{srfcounter:this.counter});
        }
        if(arg && arg.navparams){
            let curNavParams:any = JSON.parse(arg.navparams);
            if(Object.keys(curNavParams).length >0){
                Object.keys(curNavParams).forEach((name:any) =>{
                    if (!name) {
                        return;
                    }
                    let value: string | null = curNavParams[name];
                    if (value && value.startsWith('%') && value.endsWith('%')) {
                        const key = value.substring(1, value.length - 1);
                        if (arg && arg.hasOwnProperty(key)) {
                            value = (arg[key] !== null && arg[key] !== undefined) ? arg[key] : null;
                        } else {
                            value = null;
                        }
                    }
                    Object.assign(tempViewparam, { [name]: value });
                })
                this.counter += 1;
                Object.assign(tempContext,{srfcounter:this.counter});
            }
        }
        Object.assign(tempContext,JSON.parse(JSON.stringify(this.context)));
        if(arg.srfappctx){
            Object.assign(tempContext,JSON.parse(JSON.stringify(arg.srfappctx)));
        }
        if(arg.srfparentdename){
            Object.assign(tempContext,{srfparentdename:arg.srfparentdename});
        }
        if(arg.srfparentkey){
            Object.assign(tempContext,{srfparentkey:arg.srfparentkey});
        }
        this.selection = {};
        Object.assign(this.selection, { view: { viewname: refview.viewname } });
        Object.assign(this.selection,{'viewparam':tempViewparam,'context':tempContext});
        this.$emit('selectionchange',args);
        this.$forceUpdate();
    }

    /**
     * 树加载完成
     *
     * @param {any[]} args
     * @param {string} [tag]
     * @param {*} [$event2]
     * @returns {void}
     * @memberof TreeExpViewtreeexpbarBase
     */
395
    public treeexpbar_load(args: any[], tag?: string, $event2?: any): void {
ibizdev's avatar
ibizdev committed
396 397 398 399 400 401 402 403
        this.$emit('load',args);
    }

    /**
     * 执行搜索
     *
     * @memberof TreeExpViewtreeexpbarBase
     */
404
    public onSearch(): void {
ibizdev's avatar
ibizdev committed
405 406 407 408 409 410 411 412 413 414 415 416
        if (!this.viewState) {
            return;
        }
        this.istLoadDefaultRefView = false;
        this.viewState.next({ tag: 'treeexpbar_tree', action: 'filter', data: { srfnodefilter: this.srfnodefilter } });
    }

    /**
     * vue 声明周期
     *
     * @memberof @memberof TreeExpViewtreeexpbarBase
     */
417
    public created() {
ibizdev's avatar
ibizdev committed
418 419 420 421 422 423 424 425
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     *  @memberof TreeExpViewtreeexpbarBase
     */    
426
    public afterCreated(){
ibizdev's avatar
ibizdev committed
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                this.istLoadDefaultRefView = false;
                this.viewState.next({ tag: 'treeexpbar_tree', action: action, data: data });
            });
        }
    }

    /**
    * Vue声明周期(组件渲染完毕)
    *
    * @memberof TreeExpViewtreeexpbarBase
    */
    public mounted() {
        this.afterMounted();     
    }

    /**
    * 执行mounted后的逻辑
    *
    * @memberof TreeExpViewtreeexpbarBase
    */
    public afterMounted(){ 
        if(this.$store.getters.getViewSplit(this.viewUID)){
            this.split = this.$store.getters.getViewSplit(this.viewUID);
        }else{
            let containerWidth:number = (document.getElementById("treeexpviewtreeexpbar") as any).offsetWidth;
            if(this.ctrlWidth){
                    this.split = this.ctrlWidth/containerWidth;
            }
            this.$store.commit("setViewSplit",{viewUID:this.viewUID,viewSplit:this.split}); 
        }  
    }


    /**
     * vue 生命周期
     *
     * @memberof TreeExpViewtreeexpbarBase
     */
470
    public destroyed() {
ibizdev's avatar
ibizdev committed
471 472 473 474 475 476 477 478
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
     * @memberof TreeExpViewtreeexpbarBase
     */
479
    public afterDestroy() {
ibizdev's avatar
ibizdev committed
480 481 482 483 484 485 486 487 488 489 490
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
    }

    /**
     * 视图数据变化
     *
     * @param {*} $event
     * @memberof TreeExpViewtreeexpbarBase
     */
491
    public onViewDatasChange($event: any): void {
ibizdev's avatar
ibizdev committed
492 493 494 495 496 497 498 499 500
        this.$emit('selectionchange', $event);
    }

    /**
     * 视图数据被激活
     *
     * @param {*} $event
     * @memberof TreeExpViewtreeexpbarBase
     */
501
    public viewDatasActivated($event: any): void {
ibizdev's avatar
ibizdev committed
502 503 504 505 506 507 508 509 510
        this.$emit('activated', $event);
    }

    /**
     * 视图数据加载完成
     *
     * @param {*} $event
     * @memberof TreeExpViewtreeexpbarBase
     */
511
    public onViewLoad($event: any): void {
ibizdev's avatar
ibizdev committed
512 513 514 515 516 517 518 519 520
        this.$emit('load', $event);
    }
    
}
</script>

<style lang='less'>
@import './tree-exp-viewtreeexpbar-treeexpbar.less';
</style>