app-form-druipart.vue 12.0 KB
Newer Older
ibizdev's avatar
ibizdev committed
1 2 3 4 5
<template>
 <div class='form-druipart'>
    <component 
      :is="viewname" 
      class="viewcontainer2" 
6 7
      :viewdata ="viewdata"
      :viewparam="viewparam"
ibizdev's avatar
ibizdev committed
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
      :viewDefaultUsage="false"
      :formDruipart="formDruipart"
      :isformDruipart="true"
      @mditemsload="mditemsload" 
      @drdatasaved="drdatasaved"  
      @drdatachange="drdatachange"  
      @viewdataschange="viewdataschange"  
      @viewload="viewload">
    </component> 
    <spin v-if="blockUI" class='app-druipart-spin' fix >{{ $t('components.appFormDRUIPart.blockUITipInfo') }}</spin>            
  </div>
</template>
<script lang = 'ts'>
import { Vue, Component, Prop, Watch } from 'vue-property-decorator';
import { Subject, Unsubscribable } from 'rxjs';
@Component({
})
export default class AppFormDRUIPart extends Vue {

    /**
     * 表单数据
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop() public data!: string;

    /**
     * 关联视图
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop() public viewname?: string;

43 44 45 46 47 48 49 50
    /**
     * 临时数据模式:从数据模式:"2"、主数据模式:"1"、无临时数据模式:"0"
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */    
    @Prop({default:"0"}) public tempMode?:string;

ibizdev's avatar
ibizdev committed
51 52 53 54 55 56 57 58
    /**
     * 刷新关系项
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop({ default: '' }) public refreshitems!: string;

ibizdev's avatar
ibizdev committed
59 60 61 62 63 64 65 66
    /**
     * 禁止加载
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop({ default: false }) public isForbidLoad!: boolean;

ibizdev's avatar
ibizdev committed
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
    /**
     * 关系视图类型
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop() public refviewtype?: string;

    /**
     * 父数据
     *
     * @type {*}
     * @memberof AppFormDRUIPart
     */
    @Prop() public parentdata!: any;

    /**
     * 传入参数项名称
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop() public paramItem!: string;

    /**
     * 是否忽略表单项值变化
     *
     * @type {boolean}
     * @memberof AppFormDRUIPart
     */
    @Prop() public ignorefieldvaluechange!: boolean;

    /**
     * 表单状态
     *
     * @type {Subject<any>}
     * @memberof AppFormDRUIPart
     */
    @Prop() public formState!: Subject<any>;

    /**
     * 视图参数
     *
     * @type {any[]}
     * @memberof AppFormDRUIPart
     */
    @Prop() public parameters!: any[];

    /**
     * 视图上下文
     *
     * @type {*}
     * @memberof AppFormDRUIPart
     */
    @Prop() public context!: any;

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof AppFormDRUIPart
     */
    @Prop() public viewparams!: any;

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    /**
     * 局部上下文
     *
     * @type {*}
     * @memberof AppFormDRUIPart
     */
    @Prop() public localContext!:any;

    /**
     * 局部参数
     *
     * @type {*}
     * @memberof AppFormDRUIPart
     */
    @Prop() public localParam!:any;

ibizdev's avatar
ibizdev committed
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 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 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
    /**
     * 应用实体参数名称
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop() public parameterName!: string;

    /**
     * 应用实体参数名称(区分大小写)
     *
     * @type {string}
     * @memberof AppFormDRUIPart
     */
    @Prop() public parentName!: string;

    /**
     * 关系界面向视图下发指令对象
     *
     * @private
     * @type {Subject<any>}
     * @memberof AppFormDRUIPart
     */
    private formDruipart: Subject<any> = new Subject<any>();

    /**
     * 表单状态事件
     *
     * @private
     * @type {(Unsubscribable | undefined)}
     * @memberof AppFormDRUIPart
     */
    private formStateEvent: Unsubscribable | undefined;

    /**
     * 监控值
     *
     * @param {*} newVal
     * @param {*} oldVal
     * @memberof AppFormDRUIPart
     */
    @Watch('data')
    onActivedataChange(newVal: any, oldVal: any) {

        if (this.ignorefieldvaluechange) {
            return;
        }
        if (Object.is(newVal, oldVal)) {
            return;
        }
        const newFormData: any = JSON.parse(newVal);
        const oldDormData: any = JSON.parse(oldVal);
        let refreshRefview = false;
        this.hookItems.some((_hookItem: any) => {
            if (!Object.is(newFormData[_hookItem], oldDormData[_hookItem])) {
                refreshRefview = true;
                return refreshRefview;
            }
            return refreshRefview;
        });
        if (refreshRefview) {
            this.refreshDRUIPart();
        }
    }

    /**
     * 是否启用遮罩
     *
     * @type {boolean}
     * @memberof AppFormDRUIPart
     */
    public blockUI: boolean = false;

    /**
     * 是否刷新关系数据
     *
     * @private
     * @type {boolean}
     * @memberof AppFormDRUIPart
     */
    private isRelationalData: boolean = true;

    /**
     * 刷新节点
     *
     * @private
     * @type {string[]}
     * @memberof AppFormDRUIPart
     */
    private hookItems: string[] = [];

    /**
     * 父数据
     *
     * @type {*}
     * @memberof AppFormDRUIPart
     */
    public viewdata: any = {};

    /**
     * 父视图参数
     *
     * @type {*}
     * @memberof AppFormDRUIPart
     */
    public viewparam: any = {};

    /**
     * 刷新关系页面
     *
     * @private
     * @returns {void}
     * @memberof AppFormDRUIPart
     */
    private refreshDRUIPart(data?:any): void {

        if (Object.is(this.parentdata.SRFPARENTTYPE, 'CUSTOM')) {
            this.isRelationalData = false;
        }
        const formData: any = data?data:JSON.parse(this.data);
        const _paramitem = formData[this.paramItem];
268 269 270
        let tempContext:any = {};
        let tempParam:any = {};
        Object.assign(tempContext, this.$viewTool.getIndexViewParam());
ibizdev's avatar
ibizdev committed
271 272 273 274
        const _parameters: any[] = [...this.$viewTool.getIndexParameters(), ...this.parameters];
        _parameters.forEach((parameter: any) => {
            const { pathName, parameterName }: { pathName: string, parameterName: string } = parameter;
            if (formData[parameterName] && !Object.is(formData[parameterName], '')) {
275
                Object.assign(tempContext, { [parameterName]: formData[parameterName] });
ibizdev's avatar
ibizdev committed
276 277
            }
        });
278
        Object.assign(tempContext, { [this.paramItem]: _paramitem });
ibizdev's avatar
ibizdev committed
279
        //设置顶层视图唯一标识
280 281
        Object.assign(tempContext,this.context);
        Object.assign(tempContext,{srfparentdename:this.parentName,srfparentkey:_paramitem});
282
        Object.assign(tempParam,{srfparentdename:this.parentName,srfparentkey:_paramitem});
283 284 285 286 287 288 289 290 291 292 293
        // 设置局部上下文
        if(this.localContext && Object.keys(this.localContext).length >0){
            let _context:any = this.$util.computedNavData(formData,tempContext,this.viewparams,this.localContext);
            Object.assign(tempContext,_context);
        }
        this.viewdata = JSON.stringify(tempContext);
        // 设置局部参数
        if(this.localParam && Object.keys(this.localParam).length >0){
            let _param:any = this.$util.computedNavData(formData,tempContext,this.viewparams,this.localParam);
            Object.assign(tempParam,_param);
        }
294
        if(this.viewparams.hasOwnProperty('copymode')) Object.assign(tempParam,{copymode:this.viewparams.copymode});
295
        this.viewparam = JSON.stringify(tempParam);
ibizdev's avatar
ibizdev committed
296
        if (this.isRelationalData) {
297 298
            // 从数据模式无遮罩层
            if(this.tempMode && Object.is(this.tempMode,"2")){
ibizdev's avatar
ibizdev committed
299
                this.blockUIStop();
300 301 302 303 304 305 306
            }else{
                if (!_paramitem || _paramitem == null || Object.is(_paramitem, '')) {
                    this.blockUIStart();
                    return;
                } else {
                    this.blockUIStop();
                }
ibizdev's avatar
ibizdev committed
307 308
            }
        }
ibizdev's avatar
ibizdev committed
309
        if(!this.isForbidLoad){
310
            setTimeout(() => {
ibizdev's avatar
ibizdev committed
311
                this.formDruipart.next({action:'load',data:{srfparentdename:this.parentName,srfparentkey:_paramitem}});
312
            }, 0);
ibizdev's avatar
ibizdev committed
313
        }
ibizdev's avatar
ibizdev committed
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    }

    /**
     * vue  生命周期
     *
     * @memberof AppFormDRUIPart
     */
    public created(): void {
        this.hookItems = [...this.refreshitems.split(';')];
        if (!this.formState) {
            return;
        }
        if (!Object.is(this.paramItem, this.parameterName)) {
            this.hookItems.push(this.paramItem);
        }
        this.formStateEvent = this.formState.subscribe(($event: any) => {
            // 表单加载完成
            if (Object.is($event.type, 'load')) {
                this.refreshDRUIPart($event.data);
            }
             // 表单保存之前
            if (Object.is($event.type, 'beforesave')) {
336 337 338 339 340 341 342 343 344 345 346 347
                // 支持嵌入视图类型:嵌入视图本身抛drdatasaved的视图,如:DEMEDITVIEW9,DEGRIDVIEW9,DEGRIDVIEW等
                // 从数据模式直接通知保存 
                // 临时补充,todo
               if(Object.is(this.refviewtype,'DEMEDITVIEW9') || Object.is(this.refviewtype,'DEGRIDVIEW9') || Object.is(this.refviewtype,'DEGRIDVIEW')){
                if(this.tempMode && Object.is(this.tempMode,"2")){
                    this.formDruipart.next({action:'save',data:$event.data});
                }else{
                    if($event.data && !Object.is($event.data.srfuf,"0")){
                        this.formDruipart.next({action:'save',data:$event.data});
                    }else{
                        this.$emit('drdatasaved',$event);
                    }
ibizdev's avatar
ibizdev committed
348
                }
349 350 351
               }else{
                   this.$emit('drdatasaved',$event);
               }
ibizdev's avatar
ibizdev committed
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 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
            }
            // 表单保存完成
            if (Object.is($event.type, 'save')) {
                this.refreshDRUIPart($event.data);
            }
            // 表单项更新
            if (Object.is($event.type, 'updateformitem')) {
                if (!$event.data) {
                    return;
                }
                let refreshRefview = false;
                Object.keys($event.data).some((name: string) => {
                    const index = this.hookItems.findIndex((_name: string) => Object.is(_name, name));
                    refreshRefview = index !== -1 ? true : false;
                    return refreshRefview;
                });
                if (refreshRefview) {
                    this.refreshDRUIPart();
                }
            }
        });
        this.refreshDRUIPart();
    }

    /**
     * 部件销毁
     *
     * @memberof AppFormDRUIPart
     */
    public destroyed(): void {
        if (this.formStateEvent) {
            this.formStateEvent.unsubscribe();
        }
    }

    /**
     * 开启遮罩
     *
     * @private
     * @memberof AppFormDRUIPart
     */
    private blockUIStart(): void {
        this.blockUI = true;
    }

    /**
     * 关闭遮罩
     *
     * @private
     * @memberof AppFormDRUIPart
     */
    private blockUIStop(): void {
        this.blockUI = false;
    }

     /**
     * 多数据视图加载完成
     *
     * @public
     * @memberof AppFormDRUIPart
     */
    public mditemsload(){
414
        console.log((this.$t('components.appFormDRUIPart.viewLoadComp') as string));
ibizdev's avatar
ibizdev committed
415 416 417 418 419 420 421 422 423 424
    }

    /**
     * DEMEDITVIEW9 关系数据保存完成
     *
     * @public
     * @memberof AppFormDRUIPart
     */
    public drdatasaved($event:any){
        this.$emit('drdatasaved',$event);
425
        console.log(this.viewname+(this.$t('components.appFormDRUIPart.save') as string));
ibizdev's avatar
ibizdev committed
426 427 428 429 430 431 432 433 434
    }

    /**
     * DEMEDITVIEW9 关系数据值变化
     *
     * @public
     * @memberof AppFormDRUIPart
     */
    public drdatachange(){
435
        console.log('DEMEDITVIEW9 '+(this.$t('components.appFormDRUIPart.change') as string));
ibizdev's avatar
ibizdev committed
436 437 438 439 440 441 442 443 444
    }

     /**
     * 视图数据变化
     *
     * @public
     * @memberof AppFormDRUIPart
     */
    public viewdataschange(){
445
        console.log((this.$t('components.appFormDRUIPart.change1') as string));
ibizdev's avatar
ibizdev committed
446 447 448 449 450 451 452 453 454
    }

    /**
     * 视图加载完成
     *
     * @public
     * @memberof AppFormDRUIPart
     */
    public viewload(){
455
        console.log((this.$t('components.appFormDRUIPart.loadComp') as string));
ibizdev's avatar
ibizdev committed
456 457 458 459 460 461
    }
}
</script>
<style lang = "less">
@import './app-form-druipart.less';
</style>