提交 c4fdbf25 编写于 作者: KK's avatar KK

Revert "代码表服务构造器调整"

This reverts commit e69b65ed.
上级 3c1a6a5e
...@@ -102,7 +102,6 @@ export default class ${srfclassname('${item.getCodeName()}')} { ...@@ -102,7 +102,6 @@ export default class ${srfclassname('${item.getCodeName()}')} {
Object.assign(itemdata,{id:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>}); Object.assign(itemdata,{id:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>});
Object.assign(itemdata,{value:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>}); Object.assign(itemdata,{value:item.<#if item.getValuePSAppDEField()??>${item.getValuePSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getKeyPSAppDEField().codeName?lower_case}</#if>});
Object.assign(itemdata,{text:item.<#if item.getTextPSAppDEField()??>${item.getTextPSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getMajorPSAppDEField().codeName?lower_case}</#if>}); Object.assign(itemdata,{text:item.<#if item.getTextPSAppDEField()??>${item.getTextPSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getMajorPSAppDEField().codeName?lower_case}</#if>});
Object.assign(itemdata,{label:item.<#if item.getTextPSAppDEField()??>${item.getTextPSAppDEField().getCodeName()?lower_case}<#else>${item.getPSAppDataEntity().getMajorPSAppDEField().codeName?lower_case}</#if>});
<#if item.getPValuePSAppDEField()??>Object.assign(itemdata,{pvalue:item.${item.getPValuePSAppDEField().getCodeName()?lower_case}});</#if> <#if item.getPValuePSAppDEField()??>Object.assign(itemdata,{pvalue:item.${item.getPValuePSAppDEField().getCodeName()?lower_case}});</#if>
_items.push(itemdata); _items.push(itemdata);
}); });
......
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
<#if app.getAllPSAppCodeLists()??>
<#list app.getAllPSAppCodeLists() as codelist>
<#if codelist.getCodeListType() == "DYNAMIC">
import ${srfclassname('${codelist.codeName}')} from '@/app-core/code-list/${srffilepath2(codelist.codeName)}';
</#if>
</#list>
</#if>
import { Store } from 'vuex';
/**
* 动态代码表服务类
*
* @export
* @class CodeListService
*/
export class CodeListService {
/**
* Vue 状态管理器
*
* @private
* @type {(any | null)}
* @memberof CodeListService
*/
private $store: Store<any> | null = null;
constructor(opts: any = {}) {
this.$store = opts.$store;
}
/**
* 获取状态管理器
*
* @returns {(any | null)}
* @memberof CodeListService
*/
public getStore(): Store<any> | null {
return this.$store;
}
/**
* 动态代码表缓存(加载中)
*
* @type {Map<string,any>}
* @memberof CodeListService
*/
public static codelistCache:Map<string,any> = new Map();
/**
* 动态代码表缓存(已完成)
*
* @type {Map<string,any>}
* @memberof CodeListService
*/
public static codelistCached:Map<string,any> = new Map();
<#if app.getAllPSAppCodeLists()??>
<#list app.getAllPSAppCodeLists() as codelist>
<#if codelist.getCodeListType() == "DYNAMIC">
/**
* 代码表--${codelist.getName()}
*
* @type {${srfclassname('${codelist.codeName}')}}
* @memberof CodeListService
*/
public ${codelist.codeName}: ${srfclassname('${codelist.codeName}')} = new ${srfclassname('${codelist.codeName}')}();
</#if>
</#list>
</#if>
/**
* 获取动态代码表
*
* @param {string} tag 代码表标识
* @param {string} context
* @returns {Promise<any[]>}
* @memberof CodeListService
*/
<#noparse>public getItems(tag: string,context:any = {}, data?: any, isloading?: boolean,): Promise<any[]> {
if(!tag){
return new Promise((resolve:any,reject:any) =>{
return resolve([]);
})
}
let _this: any = this;
if(context && context.srfsessionid){
delete context.srfsessionid;
}
let isEnableCache:boolean = _this[tag].isEnableCache;
let cacheTimeout:any = _this[tag].cacheTimeout;
return new Promise((resolve:any,reject:any) =>{
// 启用缓存
if(isEnableCache){
// 加载完成,从本地缓存获取
if(CodeListService.codelistCached.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`)){
let items:any = CodeListService.codelistCached.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`);
if(items.length >0){
if(cacheTimeout !== -1){
if(new Date().getTime() > _this[tag].expirationTime){
_this[tag].getItems(context,data,isloading).then((result:any) =>{
CodeListService.codelistCached.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,{items:result});
_this[tag].expirationTime = new Date().getTime() + cacheTimeout;
resolve(result);
}).catch((error:any) =>{
Promise.reject([]);
})
}else{
return resolve(items);
}
}else{
return resolve(items);
}
}
}
if (_this[tag]) {
const callback:Function = (context:any ={},data:any ={},tag:string,promise:Promise<any>) =>{
promise.then((result:any) =>{
console.log()
if(result.length > 0){
CodeListService.codelistCached.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,{items:result});
return resolve(result);
}else{
return resolve([]);
}
}).catch((result:any) =>{
return reject(result);
})
}
// 加载中,UI又需要数据,解决连续加载同一代码表问题
if(CodeListService.codelistCache.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`)){
callback(context,data,tag,CodeListService.codelistCache.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`));
}else{
let result:Promise<any> = _this[tag].getItems(context,data,isloading);
CodeListService.codelistCache.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,result);
if(cacheTimeout !== -1){
_this[tag].expirationTime = new Date().getTime() + cacheTimeout;
}
callback(context,data,tag,result);
}
}
}else{
if (_this[tag]) {
_this[tag].getItems(context,data,isloading).then((result:any) =>{
resolve(result);
}).catch((error:any) =>{
Promise.reject([]);
})
}else{
return Promise.reject([]);
}
}
})
}</#noparse>
}
\ No newline at end of file
@@ -0,0 +1,89 @@
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
/**
* 代码表服务注册中心
*
* @export
* @class CodeListConstructor
*/
export class CodeListConstructor extends ServiceConstructorBase {
/**
* 初始化
*
* @protected
* @memberof CodeListConstructor
*/
protected init(): void {
<#if app.getAllPSAppCodeLists()??>
<#list app.getAllPSAppCodeLists() as codelist>
<#if codelist.getCodeListType() == "DYNAMIC">
this.allCodeList.set('${codelist.codeName}', () => import('@/app-core/code-list/${srffilepath2(codelist.codeName)}'));
</#if>
</#list>
</#if>
}
}
export const codeListConstructor: CodeListConstructor = new CodeListConstructor();
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册