VIEW_CONTENT-BASE.vue.ftl 14.8 KB
Newer Older
1 2 3 4 5 6 7 8 9
<#ibizinclude>
./WF_VIEW_CONTENT.vue.ftl
</#ibizinclude>

    <#if view.getPSAppViewEngines()??>
    <#list view.getPSAppViewEngines() as engine>
    /**
     * 视图引擎
     *
10
     * @public
11 12 13
     * @type {Engine}
     * @memberof ${srfclassname('${view.name}')}Base
     */
14
    public ${engine.getName()?lower_case}: ${engine.getEngineType()}Engine = new ${engine.getEngineType()}Engine();
15 16 17 18 19 20
    </#list>
    </#if>

    /**
     * 引擎初始化
     *
21
     * @public
22 23
     * @memberof ${srfclassname('${view.name}')}Base
     */
24
    public engineInit(): void {
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
    <#if view.getPSAppViewEngines()??>
    <#list view.getPSAppViewEngines() as engine>
        this.${engine.getName()?lower_case}.init({
            view: this,
        <#if engine.getPSAppViewEngineParams()??>
            <#list engine.getPSAppViewEngineParams() as param>
            <#if param.getParamType() == "LOGIC" && param.getPSAppViewLogic()??>
            ${param.getName()?lower_case}: (args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) => {
                this.${param.getPSAppViewLogic().getName()}(args,fullargs, params, $event, xData);
            },
            </#if>
            <#if param.getParamType() == "CTRL" && param.getPSControl()??>
            ${param.getName()?lower_case}: this.$refs.${param.getPSControl().getName()},
            </#if>
            <#if param.getParamType() == "VALUE" && param.getValue()??>
            ${param.getName()?lower_case}: '${param.getValue()?c}',
            </#if>
            </#list>
        </#if>
        <#if de??>
            keyPSDEField: '${appde.getCodeName()?lower_case}',
            <#if appde.getMajorPSAppDEField()??>
            majorPSDEField: '${appde.getMajorPSAppDEField().getCodeName()?lower_case}',
            </#if>
        </#if>
            isLoadDefault: <#if view.isLoadDefault?? && !view.isLoadDefault()>false<#else>true</#if>,
        });
    </#list>
    </#if>
    }

56 57 58 59 60 61
    /**
     * 应用导航服务
     *
     * @type {*}
     * @memberof ${srfclassname('${view.name}')}Base
     */
62
    public  navDataService = NavDataService.getInstance(this.$store);
63

64 65 66 67 68 69 70 71 72
    /**
    * 导航服务事件
    *
    * @public
    * @type {(Subscription | undefined)}
    * @memberof ${srfclassname('${view.name}')}Base
    */
    public serviceStateEvent: Subscription | undefined;

73 74 75 76 77 78
    /**
     * 应用上下文
     *
     * @type {*}
     * @memberof ${srfclassname('${view.name}')}Base
     */
79
    public context:any = {};
80 81 82 83 84 85 86

    /**
     * 视图参数
     *
     * @type {*}
     * @memberof ${srfclassname('${view.name}')}Base
     */
87
    public viewparams:any = {};
88

tony001's avatar
tony001 committed
89 90 91 92 93 94 95 96
    /**
     * 视图缓存数据
     *
     * @type {*}
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public viewCacheData:any;

97 98 99
    /**
     * 解析视图参数
     *
100
     * @public
101 102
     * @memberof ${srfclassname('${view.name}')}Base
     */
103
    public parseViewParam(inputvalue:any = null): void {
104 105 106 107 108 109 110 111 112 113 114
        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});
            }
tony001's avatar
tony001 committed
115 116 117
            if(this.$store.getters.getAppData() && this.$store.getters.getAppData().context){
                Object.assign(this.context,this.$store.getters.getAppData().context);
            }
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
            this.handleCustomViewData();
            <#if self_viewparam??>
            ${self_viewparam}
            </#if>
            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);
136
        <#if appde??>
137 138 139
        if(inputvalue){
            Object.assign(this.context,{'${appde.getCodeName()?lower_case}':inputvalue});
        }
140
        </#if>
141 142 143 144 145 146 147 148
        if(this.$store.getters.getAppData() && this.$store.getters.getAppData().context){
            Object.assign(this.context,this.$store.getters.getAppData().context);
        }
        <#if view.isPSDEView()>
        //初始化视图唯一标识
        Object.assign(this.context,{srfsessionid:this.$util.createUUID()});
        </#if>
        this.handleCustomViewData();
149
        //初始化导航数据
tony001's avatar
tony001 committed
150
        this.initNavDataWithRoute();
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
    }

    /**
     * 处理自定义视图数据
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
	public handleCustomViewData(){
        <#if view.getPSDER1N?? && view.getPSDER1N()??>
        this.handleviewRes();
        </#if>
		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 ${srfclassname('${view.name}')}Base
     */
	public handleCustomDataLogic(curNavData:any,tempData:any,item:string){
		// 直接值直接赋值
		if(curNavData.isRawValue){
			if(Object.is(curNavData.value,"null") || Object.is(curNavData.value,"")){
189
                Object.defineProperty(tempData, item.toLowerCase(), {
190 191 192 193 194 195
                    value: null,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }else{
196
                Object.defineProperty(tempData, item.toLowerCase(), {
197 198 199 200 201 202 203 204
                    value: curNavData.value,
                    writable : true,
                    enumerable : true,
                    configurable : true
                });
            }
		}else{
			// 先从导航上下文取数,没有再从导航参数(URL)取数,如果导航上下文和导航参数都没有则为null
205
			if(this.context[(curNavData.value).toLowerCase()]){
206
				Object.defineProperty(tempData, item.toLowerCase(), {
207
					value: this.context[(curNavData.value).toLowerCase()],
208 209 210 211 212
					writable : true,
					enumerable : true,
					configurable : true
				});
			}else{
213
				if(this.viewparams[(curNavData.value).toLowerCase()]){
214
					Object.defineProperty(tempData, item.toLowerCase(), {
215
						value: this.viewparams[(curNavData.value).toLowerCase()],
216 217 218 219 220
						writable : true,
						enumerable : true,
						configurable : true
					});
				}else{
221
					Object.defineProperty(tempData, item.toLowerCase(), {
222 223 224 225 226 227 228 229 230
						value: null,
						writable : true,
						enumerable : true,
						configurable : true
					});
				}
			}
		}
	}
231 232

    /**
tony001's avatar
tony001 committed
233
     * 初始化导航数据(路由模式)
234 235 236
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
237 238
    public initNavDataWithRoute(data:any = null, isNew:boolean = false,  isAlways:boolean = false){
        if( isAlways || (this.viewDefaultUsage && Object.is(this.navModel,"route")) ){
239
            this.navDataService.addNavData({id:'${srffilepath2(view.getCodeName())}',tag:this.viewtag,srfkey:isNew ? null : <#if appde??>this.context.${appde.getCodeName()?lower_case}<#else>null</#if>,title:this.$t(this.model.srfTitle),data:data,context:this.context,viewparams:this.viewparams,path:this.$route.fullPath});
tony001's avatar
tony001 committed
240 241 242 243 244 245 246 247
        }
    }

    /**
     * 初始化导航数据(分页模式)
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
248 249
    public initNavDataWithTab(data:any = null,isOnlyAdd:boolean = true, isAlways:boolean = false){
        if( isAlways || (this.viewDefaultUsage && !Object.is(this.navModel,"route")) ){
tony001's avatar
tony001 committed
250
            this.navDataService.addNavDataByOnly({id:'${srffilepath2(view.getCodeName())}',tag:this.viewtag,srfkey:<#if appde??>this.context.${appde.getCodeName()?lower_case}<#else>null</#if>,title:this.$t(this.model.srfTitle),data:data,context:this.context,viewparams:this.viewparams,path:this.$route.fullPath},isOnlyAdd);
251 252
        }
    }
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
	
    <#if view.getPSDER1N?? && view.getPSDER1N()??>
    /**
     * 处理指定视图控制关系将父键转为父实体上下文
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
    public handleviewRes(){
    <#assign viewRes = view.getPSDER1N()/>
    <#if viewRes.getMajorPSDataEntity()??>
    <#assign majorAppDataEntity = viewRes.getMajorPSDataEntity() />
    if(this.context.srfparentkey){
        Object.assign(this.context,{'${majorAppDataEntity.getCodeName()?lower_case}':this.context.srfparentkey});
    }
    </#if>
    }
    </#if>

    /**
     * Vue声明周期
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
276
    public created() {
277 278 279 280 281 282 283 284
        this.afterCreated();
    }

    /**
     * 执行created后的逻辑
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */    
285
    public afterCreated(){
286
        let _this:any = this;
287 288 289 290
        const secondtag = _this.$util.createUUID();
        _this.$store.commit('viewaction/createdView', { viewtag: _this.viewtag, secondtag: secondtag });
        _this.viewtag = secondtag;
        _this.parseViewParam();
291 292 293 294
        _this.serviceStateEvent = _this.navDataService.serviceState.subscribe(({ action,name, data }:{ action:string,name:any,data:any }) => {
            if(!Object.is(name,'${srffilepath2(view.getCodeName())}')){
                return;
            }
295
            if (Object.is(action, 'viewrefresh')) {
296 297 298 299
                _this.$nextTick(()=>{
                    _this.parseViewParam(data);
                    if(_this.engine){
                        _this.engine.load();
300 301 302 303
                    }
                }); 
            }
        });
304 305 306 307 308 309 310 311
        <#if created_block??>${created_block}</#if>
    }

    /**
     * 销毁之前
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
312
    public beforeDestroy() {
313 314 315 316 317 318 319 320
        this.$store.commit('viewaction/removeView', this.viewtag);
    }

    /**
     * Vue声明周期(组件初始化完毕)
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
321
    public mounted() {
322 323 324 325 326 327 328 329
        this.afterMounted();
    }

    /**
     * 执行mounted后的逻辑
     * 
     * @memberof ${srfclassname('${view.name}')}Base
     */
330
    public afterMounted(){
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        const _this: any = this;
        <#if view.getPSAppViewEngines()??>
        _this.engineInit();
        </#if>
        if (_this.loadModel && _this.loadModel instanceof Function) {
            _this.loadModel();
        }
        <#if mounted_block??>${mounted_block}</#if>
    }

    <#if view.getPSControls()??>
    <#list view.getPSControls() as ctrl>
    <#if ctrl.getControlType()??>
    <#if ctrl.getHookEventNames()??>
    <#list ctrl.getHookEventNames() as eventName>

    /**
     * ${ctrl.name} 部件 ${eventName?lower_case} 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof ${srfclassname('${view.name}')}Base
     */
354
    public ${ctrl.name}_${eventName?lower_case}($event: any, $event2?: any) {
355 356 357 358 359 360 361
    <#if ctrl.getPSControlLogics(eventName)??>
    <#list ctrl.getPSControlLogics(eventName) as ctrlLogic>
    <#if ctrlLogic.getLogicType() == "APPVIEWENGINE" && ctrlLogic.getPSAppViewEngine()??>
        this.${ctrlLogic.getPSAppViewEngine().getName()}.onCtrlEvent('${ctrl.name}', '${eventName?lower_case}', $event);
    <#else>
        <#if ctrlLogic.getEventArg()?? && ctrlLogic.getEventArg()?length gt 0>
        if (Object.is($event.tag, '${ctrlLogic.getEventArg()}')) {
tony001's avatar
tony001 committed
362
            this.${ctrlLogic.name}(null, '', $event2);
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
        }
        <#else>
        this.${ctrlLogic.name}($event, '', $event2);
        </#if>
    </#if>
    </#list>
    </#if>
    }

    </#list>
    </#if>
    </#if>
    </#list>
    </#if>

<#if view.getPSAppViewLogics()??>
<#list view.getPSAppViewLogics() as logic>
<#if logic.getLogicTrigger() == "CUSTOM" || logic.getLogicTrigger() == "CTRLEVENT">

${P.getLogicCode(logic, "LOGIC.vue").code}
</#if>
</#list>
</#if>

<#if view.getPSAppViewUIActions()??>
<#list view.getPSAppViewUIActions() as viewUIAction>
<#if viewUIAction.getPSUIAction()?? >
<#assign uiAction = viewUIAction.getPSUIAction()/>
<#if !P.exists("importService", uiAction.getFullCodeName(), "")>
<#-- 系统预置界面行为输入start -->
<#if !(uiAction.getPSAppDataEntity?? && uiAction.getPSAppDataEntity()??)>
${P.getLogicCode(uiAction, "LOGIC.vue").code}
</#if>
<#-- 系统预置界面行为输入end -->
</#if>
</#if>
</#list>
</#if>

    /**
     * 关闭视图
     *
     * @param {any[]} args
     * @memberof ${srfclassname('${view.name}')}Base
     */
408
    public closeView(args: any[]): void {
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
        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);
        }
    }
    <#if view.isPSDEView()>
    <#if view.getPSAppDataEntity()??>
    <#assign appDataEntity = view.getPSAppDataEntity() />
    <#if appDataEntity.isMajor()>

    /**
     * 销毁视图回调
     *
     * @memberof ${srfclassname('${view.name}')}Base
     */
427
    public destroyed(){
428 429 430 431 432 433 434 435
        this.afterDestroyed();
    }

    /**
     * 执行destroyed后的逻辑
     * 
     * @memberof ${srfclassname('${view.name}')}Base
     */
436
    public afterDestroyed(){
437 438 439 440 441 442 443 444 445
        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);
                }
                })
            }
446 447 448
            if(Object.is(this.navModel,"tab")){
                this.navDataService.removeNavDataByTag(this.viewtag);
            }
449 450 451
            if (this.serviceStateEvent) {
                this.serviceStateEvent.unsubscribe();
            }
452 453 454 455 456 457 458 459 460 461
        }
    }
    </#if>
    </#if>
    </#if>
    <#--  视图独立定义的内容start  -->
    <#if self_content??>
    ${self_content}
    </#if>
    <#--  视图独立定义的内容end  -->