pickup-viewpickupviewpanel-pickupviewpanel-base.vue 8.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<template>
    <div class='pickupviewpanel'>
        <component 
          v-if="inited && view.viewname && !Object.is(view.viewname, '')" 
          :is="view.viewname"
          class="viewcontainer3"
          :openMode="openMode"
          :viewdata="viewdata"
          :viewparam="viewparam"
          :viewDefaultUsage="false"
          :isSingleSelect="isSingleSelect"
          :selectedData="selectedData"
          :isShowButton="isShowButton"
          @viewdataschange="onViewDatasChange"
          @viewdatasactivated="viewDatasActivated"
          @viewload="onViewLoad">
        </component>
    </div>
</template>

<script lang='tsx'>
22
import { Vue, Component, Prop, Provide, Emit, Watch, Model,Inject } from 'vue-property-decorator';
23 24 25 26
import { CreateElement } from 'vue';
import { Subject, Subscription } from 'rxjs';
import { ControlInterface } from '@/interface/control';
import { UIActionTool,Util } from '@/utils';
27
import NavDataService from '@/service/app/navdata-service';
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
import EMAssetClassService from '@/service/emasset-class/emasset-class-service';
import PickupViewpickupviewpanelService from './pickup-viewpickupviewpanel-pickupviewpanel-service';

import PickupViewpickupviewpanelModel from './pickup-viewpickupviewpanel-pickupviewpanel-model';


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

    /**
     * 名称
     *
     * @type {string}
45
     * @memberof PickupViewpickupviewpanelBase
46 47 48 49 50 51 52
     */
    @Prop() public name?: string;

    /**
     * 视图通讯对象
     *
     * @type {Subject<ViewState>}
53
     * @memberof PickupViewpickupviewpanelBase
54 55 56 57 58 59 60
     */
    @Prop() public viewState!: Subject<ViewState>;

    /**
     * 应用上下文
     *
     * @type {*}
61
     * @memberof PickupViewpickupviewpanelBase
62 63 64 65 66 67 68
     */
    @Prop() public context: any;

    /**
     * 视图参数
     *
     * @type {*}
69
     * @memberof PickupViewpickupviewpanelBase
70 71 72 73 74 75 76 77
     */
    @Prop() public viewparams: any;

    /**
     * 视图状态事件
     *
     * @public
     * @type {(Subscription | undefined)}
78
     * @memberof PickupViewpickupviewpanelBase
79 80 81 82 83 84 85
     */
    public viewStateEvent: Subscription | undefined;

    /**
     * 获取部件类型
     *
     * @returns {string}
86
     * @memberof PickupViewpickupviewpanelBase
87 88 89 90 91 92 93 94 95 96 97
     */
    public getControlType(): string {
        return 'PICKUPVIEWPANEL'
    }



    /**
     * 建构部件服务对象
     *
     * @type {PickupViewpickupviewpanelService}
98
     * @memberof PickupViewpickupviewpanelBase
99 100 101 102 103 104 105
     */
    public service: PickupViewpickupviewpanelService = new PickupViewpickupviewpanelService({ $store: this.$store });

    /**
     * 实体服务对象
     *
     * @type {EMAssetClassService}
106
     * @memberof PickupViewpickupviewpanelBase
107 108 109 110 111 112 113 114 115
     */
    public appEntityService: EMAssetClassService = new EMAssetClassService({ $store: this.$store });
    


    /**
     * 关闭视图
     *
     * @param {any} args
116
     * @memberof PickupViewpickupviewpanelBase
117 118 119 120 121 122 123 124 125
     */
    public closeView(args: any): void {
        let _this: any = this;
        _this.$emit('closeview', [args]);
    }

    /**
     *  计数器刷新
     *
126
     * @memberof PickupViewpickupviewpanelBase
127 128 129 130 131 132 133 134 135 136 137 138
     */
    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();
                }
            })
        }
    }

139 140


141 142 143 144 145 146 147 148 149 150 151 152 153 154
    /**
     * 视图打开模式
     *
     * @protected
     * @type {('DEFAULT' | 'MODAL')}
     * @memberof PickupViewpickupviewpanel
     */
    @Prop({ default: 'DEFAULT' })
    protected openMode!: 'DEFAULT' | 'MODAL';

    /**
     * 选中数据字符串
     *
     * @type {string}
155
     * @memberof PickupViewpickupviewpanelBase
156
     */
157
    @Prop() public selectedData?: string;
158 159 160 161 162

    /**
     * 获取多项数据
     *
     * @returns {any[]}
163
     * @memberof PickupViewpickupviewpanelBase
164 165 166 167 168 169 170 171 172
     */
    public getDatas(): any[] {
        return [];
    }

    /**
     * 获取单项树
     *
     * @returns {*}
173
     * @memberof PickupViewpickupviewpanelBase
174 175 176 177 178 179 180 181 182
     */
    public getData(): any {
        return {};
    }

    /**
     * 视图名称
     *
     * @type {*}
183
     * @memberof PickupViewpickupviewpanelBase
184
     */
185
    public view: any = {
186 187 188 189 190
        viewname: 'emassetclasspickup-grid-view',
        data: {},
    }

    /**
191 192 193 194 195 196 197 198 199
     * 局部上下文
     *
     * @type {*}
     * @memberof PickupViewpickupviewpanelBase
     */
    public localContext: any = null;

    /**
     * 局部视图参数
200 201 202 203
     *
     * @type {*}
     * @memberof PickupViewpickupviewpanel
     */
204 205 206 207 208 209 210 211 212
    public localViewParam: any = null;

    /**
     * 视图数据
     *
     * @type {*}
     * @memberof PickupViewpickupviewpanelBase
     */
    public viewdata: string  = JSON.stringify(this.context);
213 214 215 216 217 218 219

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof PickupViewpickupviewpanel
     */
220
    public viewparam: string  = JSON.stringify(this.viewparams);
221 222 223 224 225

    /**
     * 是否显示按钮
     *
     * @type {boolean}
226
     * @memberof PickupViewpickupviewpanelBase
227
     */
228
    @Prop({default: true}) public isShowButton!: boolean;
229 230 231 232 233

    /**
     * 是否单选
     *
     * @type {boolean}
234
     * @memberof PickupViewpickupviewpanelBase
235
     */
236
    @Prop() public isSingleSelect?: boolean;
237 238 239 240 241

    /**
     * 初始化完成
     *
     * @type {boolean}
242
     * @memberof PickupViewpickupviewpanelBase
243
     */
244
    public inited: boolean = false;
245 246 247 248 249

    /**
     * 视图数据变化
     *
     * @param {*} $event
250
     * @memberof PickupViewpickupviewpanelBase
251
     */
252
    public onViewDatasChange($event: any): void {
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
        if($event.length>0){
          $event.forEach((item:any,index:any) => {
              let srfmajortext = item['emassetclassname'];
              if(srfmajortext){
                Object.assign($event[index],{srfmajortext: srfmajortext});
              }
          });
        }
        this.$emit('selectionchange', $event);
    }

    /**
     * 视图数据被激活
     *
     * @param {*} $event
268
     * @memberof PickupViewpickupviewpanelBase
269
     */
270
    public viewDatasActivated($event: any): void {
271 272 273 274 275 276 277
        this.$emit('activated', $event);
    }

    /**
     * 视图加载完成
     *
     * @param {*} $event
278
     * @memberof PickupViewpickupviewpanelBase
279
     */
280
    public onViewLoad($event: any): void {
281 282 283 284 285 286
        this.$emit('load', $event);
    }

    /**
     * vue 生命周期
     *
287
     * @memberof PickupViewpickupviewpanelBase
288
     */
289
    public created() {
290 291 292 293 294 295
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
296
     *  @memberof PickupViewpickupviewpanelBase
297
     */    
298 299
    public afterCreated(){
        this.initNavParam();
300 301 302 303 304 305 306 307 308 309 310 311 312 313
        if (this.viewState) {
            this.viewStateEvent = this.viewState.subscribe(({ tag, action, data }) => {
                if (!Object.is(tag, this.name)) {
                    return;
                }
                if (Object.is('load', action)) {
                    this.viewdata = JSON.stringify(this.context);
                    this.viewparam = JSON.stringify(Object.assign(data, this.viewparams));
                    this.inited = true;
                }
            });
        }
    }

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
    /**
     * 初始化导航参数
     *
     *  @memberof PickupViewpickupviewpanelBase
     */  
    public initNavParam(){
        if(this.localContext && Object.keys(this.localContext).length >0){
            let _context:any = this.$util.computedNavData({},this.context,this.viewparams,this.localContext);
            Object.assign(this.context,_context);
        }
        if(this.localViewParam && Object.keys(this.localViewParam).length >0){
            let _param:any = this.$util.computedNavData({},this.context,this.viewparams,this.localViewParam);
            Object.assign(this.viewparams,_param);
        }
        this.viewdata = JSON.stringify(this.context);
        this.viewparam = JSON.stringify(this.viewparams);
    }


333 334 335
    /**
     * vue 生命周期
     *
336
     * @memberof PickupViewpickupviewpanelBase
337
     */
338
    public destroyed() {
339 340 341 342 343 344
        this.afterDestroy();
    }

    /**
     * 执行destroyed后的逻辑
     *
345
     * @memberof PickupViewpickupviewpanelBase
346
     */
347
    public afterDestroy() {
348 349 350 351 352 353 354 355 356 357 358
        if (this.viewStateEvent) {
            this.viewStateEvent.unsubscribe();
        }
    }

}
</script>

<style lang='less'>
@import './pickup-viewpickupviewpanel-pickupviewpanel.less';
</style>