default-drbar-base.vue 12.0 KB
Newer Older
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
<template>
<layout class='app-dr-bar'>
    <sider :width="width">
        <el-menu
            :default-openeds="defaultOpeneds"
            :default-active="items[0].id"
            @select="onSelect"
            @open="onOpen"
            @close="onClose">
            <app-sider-menus :menus="items"></app-sider-menus>
        </el-menu>
    </sider>
    <content :style="{ width: `calc(100% - ${this.width + 1}px)` }">
        <div class='main-data' v-show="Object.is(this.selection.id, 'form')">
            <slot></slot>
        </div>
        <component
          v-if="!Object.is(this.selection.id, 'form') && this.selection.view && !Object.is(this.selection.view.viewname, '')"
          :is="selection.view.viewname"
          class="viewcontainer2"
          :viewDefaultUsage="false"
          :viewdata="JSON.stringify(selection.data)"
          :viewparam="JSON.stringify(selection.param)"
          :key="this.$util.createUUID()">
        </component>
    </content>
</layout>
</template>
<script lang='tsx'>
30
import { Vue, Component, Prop, Provide, Emit, Watch, Model,Inject } from 'vue-property-decorator';
31 32 33
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
34
import { UIActionTool,Util,ViewTool } from '@/utils';
35
import NavDataService from '@/service/app/navdata-service';
36
import AppCenterService from "@service/app/app-center-service";
37 38
import SysRolePermissionService from '@/service/sys-role-permission/sys-role-permission-service';
import DefaultService from './default-drbar-service';
39
import SysRolePermissionUIService from '@/uiservice/sys-role-permission/sys-role-permission-ui-service';
40 41 42 43 44 45 46 47 48 49 50 51 52


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

    /**
     * 名称
     *
     * @type {string}
53
     * @memberof DefaultBase
54 55 56 57 58 59 60
     */
    @Prop() public name?: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
61
     * @memberof DefaultBase
62 63 64 65 66 67 68
     */
    @Prop() public viewState!: Subject<ViewState>;

    /**
     * 应用上下文
     *
     * @type {*}
69
     * @memberof DefaultBase
70 71 72 73 74 75 76
     */
    @Prop() public context: any;

    /**
     * 视图参数
     *
     * @type {*}
77
     * @memberof DefaultBase
78 79 80 81 82 83 84 85
     */
    @Prop() public viewparams: any;

    /**
     * 视图状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
86
     * @memberof DefaultBase
87 88 89 90 91 92 93
     */
    public viewStateEvent: Subscription | undefined;

    /**
     * 获取部件类型
     *
     * @returns {string}
94
     * @memberof DefaultBase
95 96 97 98 99 100 101 102 103 104 105
     */
    public getControlType(): string {
        return 'DRBAR'
    }



    /**
     * 计数器服务对象集合
     *
     * @type {Array<*>}
106
     * @memberof DefaultBase
107 108 109 110 111 112 113
     */    
    public counterServiceArray:Array<any> = [];

    /**
     * 建构部件服务对象
     *
     * @type {DefaultService}
114
     * @memberof DefaultBase
115 116 117 118 119 120 121
     */
    public service: DefaultService = new DefaultService({ $store: this.$store });

    /**
     * 实体服务对象
     *
     * @type {SysRolePermissionService}
122
     * @memberof DefaultBase
123 124 125 126 127
     */
    public appEntityService: SysRolePermissionService = new SysRolePermissionService({ $store: this.$store });
    


128 129 130 131 132 133 134 135 136 137 138 139 140
    /**
     * 转化数据
     *
     * @param {any} args
     * @memberof  DefaultBase
     */
    public transformData(args: any) {
        let _this: any = this;
        if(_this.service && _this.service.handleRequestData instanceof Function && _this.service.handleRequestData('transform',_this.context,args)){
            return _this.service.handleRequestData('transform',_this.context,args)['data'];
        }
    }

141 142 143 144
    /**
     * 关闭视图
     *
     * @param {any} args
145
     * @memberof DefaultBase
146 147 148 149 150 151 152 153 154
     */
    public closeView(args: any): void {
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

    /**
     *  计数器刷新
     *
155
     * @memberof DefaultBase
156 157 158 159 160 161 162 163 164 165 166 167 168
     */
    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();
                }
            })
        }
    }


169

170 171 172 173
    /**
     * 获取多项数据
     *
     * @returns {any[]}
174
     * @memberof DefaultBase
175 176 177 178 179 180 181 182 183
     */
    public getDatas(): any[] {
        return this.items;
    }

    /**
     * 获取单项树
     *
     * @returns {*}
184
     * @memberof DefaultBase
185 186 187 188 189 190 191 192 193
     */
    public getData(): any {
        return this.selection;
    }

    /**
     * 加载行为
     *
     * @type {string}
194
     * @memberof DefaultBase
195 196 197
     */
    @Prop() public loadAction?: string;

198 199 200 201 202 203 204 205
    /**
     *  表单数据
     *
     * @type {*}
     * @memberof DefaultBase
     */
    @Prop({default:{}}) public formData?:any;

206 207 208 209
    /**
     * 数据选中项
     *
     * @type {*}
210
     * @memberof DefaultBase
211 212 213 214 215 216 217
     */
    public selection: any = {};

    /**
     * 关系栏数据项
     *
     * @type {any[]}
218
     * @memberof DefaultBase
219 220 221 222 223 224 225 226 227
     */
    public items: any[] = [
        {
            text: "主表单",
            disabled: false,
            id: "form",
        },
    ];

228 229 230 231 232 233 234 235 236
    /**
     * 关系栏数据项导航参数集合
     *
     * @type {any[]}
     * @memberof DefaultBase
     */
    public navParamsArray:Array<any> = [
    ];

237 238 239 240
    /**
     * 默认打开项
     *
     * @type {string[]}
241
     * @memberof DefaultBase
242 243 244 245 246 247 248 249
     */
    public defaultOpeneds: string[] = [];

    /**
     * 父数据
     *
     * @public
     * @type {*}
250
     * @memberof DefaultBase
251 252 253 254 255 256 257
     */
    public parentData: any = {};

    /**
     * 宽度
     *
     * @type {number}
258
     * @memberof DefaultBase
259 260 261 262 263 264
     */
    public width: number = 240;

    /**
     * 生命周期
     *
265
     * @memberof DefaultBase
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
     */
    public created(): void {
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('state', action)) {
                    const state = !this.context.sysrolepermission ? true : false;
                    this.setItemDisabled(this.items, state);
                }
            });
        }
        this.$nextTick(() => {
            this.onSelect(this.items[0].id)
            this.$emit('selectionchange', [this.items[0]]);
        });
    }

    /**
     * vue 生命周期
     *
288
     * @memberof DefaultBase
289 290 291 292 293 294 295 296 297 298 299 300 301
     */
    public destroyed() {
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
    }

    /**
     * 获取关系项
     *
     * @public
     * @param {*} [arg={}]
     * @returns {*}
302
     * @memberof DefaultBase
303 304 305 306 307 308 309 310 311 312 313 314 315 316
     */
    public getDRBarItem(arg: any = {}): any {
        let expmode = arg.nodetype;
        if (!expmode) {
            expmode = '';
        }
        return undefined;
    }

    /**
     * 处理数据
     *
     * @public
     * @param {any[]} items
317
     * @memberof DefaultBase
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
     */
    public dataProcess(items: any[]): void {
        items.forEach((_item: any) => {
            if (_item.expanded) {
                this.defaultOpeneds.push(_item.id);
            }

            _item.disabled = false;
            if (_item.items && Array.isArray(_item.items) && _item.items.length > 0) {
                this.dataProcess(_item.items);
            }
        });
    }

    /**
     * 获取子项
     *
     * @param {any[]} items
     * @param {string} id
     * @returns {*}
338
     * @memberof DefaultBase
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
     */
    public getItem(items: any[], id: string): any {
        const item: any = {};
        items.some((_item: any) => {
            if (Object.is(_item.id, id)) {
                Object.assign(item, _item);
                return true;
            }
            if (_item.items && _item.items.length > 0) {
                const subItem = this.getItem(_item.items, id);
                if (Object.keys(subItem).length > 0) {
                    Object.assign(item, subItem);
                    return true;
                }
            }
            return false;
        });
        return item;
    }

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
    /**
     * 初始化导航参数
     *
     * @param {*} drItem
     * @memberof DefaultBase
     */
    public initNavParam(drItem:any){
        let returnNavParam:any = {};
        if(drItem && drItem.id){
            let curDRItem:any = this.navParamsArray.find((item:any) =>{
                return Object.is(item.id,drItem.id);
            })
            if(curDRItem){
                let localContext:any = curDRItem.localContext;
                let localViewParam:any = curDRItem.localViewParam;
                if(localContext && Object.keys(localContext).length >0){
                    let _context:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localContext);
                    returnNavParam.localContext = _context;
                }
                if(localViewParam && Object.keys(localViewParam).length >0){
                    let _params:any = this.$util.computedNavData(this.formData,this.context,this.viewparams,localViewParam);
                    returnNavParam.localViewParam = _params;
                }
                return returnNavParam;
            }else{
                return null;
            }
        }
    }

389 390 391 392
    /**
     * 节点选中
     *
     * @param {*} $event
393
     * @memberof DefaultBase
394 395 396 397 398 399 400
     */
    public onSelect($event: any): void {
        const item = this.getItem(this.items, $event);
        if (Object.is(item.id, this.selection.id)) {
            return;
        }
        this.$emit('selectionchange', [item]);
401
        let localNavParam:any = this.initNavParam(item);
402 403 404
        const refview = this.getDRBarItem({ nodetype: item.id });
        this.selection = {};
        const _context: any = { ...JSON.parse(JSON.stringify(this.context)) };
405 406 407 408 409 410 411
        if(localNavParam && localNavParam.localContext){
            Object.assign(_context,localNavParam.localContext);
        }
        const _params: any = {};
        if(localNavParam && localNavParam.localViewParam){
            Object.assign(_params,localNavParam.localViewParam);
        }
412 413 414 415 416 417 418 419 420 421 422
        if (refview && refview.parentdatajo) {
            Object.assign(_context, refview.parentdatajo);
            Object.assign(this.selection, { view: { viewname: refview.viewname }, data: _context, param: _params });
        }
        Object.assign(this.selection, item);
    }

    /**
     * 子节点打开
     *
     * @param {*} $event
423
     * @memberof DefaultBase
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
     */
    public onOpen($event: any): void {
        const item = this.getItem(this.items, $event);
        if (Object.is(item.id, this.selection.id)) {
            return;
        }
        this.selection = {};
        Object.assign(this.selection, item);
        if (Object.is(item.id, 'form') || (item.viewname && !Object.is(item.viewname, ''))) {
            this.$emit('selectionchange', [this.selection]);
        }
    }

    /**
     * 子节点关闭
     *
     * @param {*} $event
441
     * @memberof DefaultBase
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
     */
    public onClose($event: any): void {
        const item = this.getItem(this.items, $event);
        if (Object.is(item.id, this.selection.id)) {
            return;
        }
        this.selection = {};
        Object.assign(this.selection, item);
        if (Object.is(item.id, 'form') || (item.viewname && !Object.is(item.viewname, ''))) {
            this.$emit('selectionchange', [this.selection]);
        }
    }

    /**
     * 设置关系项状态
     *
     * @param {any[]} items
     * @param {boolean} state
460
     * @memberof DefaultBase
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478
     */
    public setItemDisabled(items: any[], state: boolean) {
        items.forEach((item: any) => {
            if (!Object.is(item.id, 'form')) {
                item.disabled = state;
            }
            if (item.items && Array.isArray(item.items)) {
                this.setItemDisabled(item.items, state);
            }
        });
    }

}
</script>

<style lang='less'>
@import './default-drbar.less';
</style>