提交 34ecaf56 编写于 作者: tony001's avatar tony001

调整动态代码表上下文,参数问题

上级 de42061e
...@@ -50,6 +50,14 @@ export default class CodeListService { ...@@ -50,6 +50,14 @@ export default class CodeListService {
*/ */
public static codelistCache:Map<string,any> = new Map(); 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()??> <#if app.getAllPSAppCodeLists()??>
<#list app.getAllPSAppCodeLists() as codelist> <#list app.getAllPSAppCodeLists() as codelist>
<#if codelist.getCodeListType() == "DYNAMIC"> <#if codelist.getCodeListType() == "DYNAMIC">
...@@ -78,28 +86,16 @@ export default class CodeListService { ...@@ -78,28 +86,16 @@ export default class CodeListService {
let isEnableCache:boolean = _this[tag].isEnableCache; let isEnableCache:boolean = _this[tag].isEnableCache;
let cacheTimeout:any = _this[tag].cacheTimeout; let cacheTimeout:any = _this[tag].cacheTimeout;
return new Promise((resolve:any,reject:any) =>{ return new Promise((resolve:any,reject:any) =>{
// 如有查询参数传递过来,需直接加载,不能使用缓存
if(data && Object.keys(data).length >0){
if (_this[tag]) {
_this[tag].getItems(context,JSON.parse(JSON.stringify(data)),isloading).then((result:any) =>{
resolve(result);
}).catch((error:any) =>{
Promise.reject([]);
})
}else{
return Promise.reject([]);
}
}else{
// 启用缓存 // 启用缓存
if(isEnableCache){ if(isEnableCache){
// 加载完成,从store获取 // 加载完成,从本地缓存获取
if(this.$store && _this.$store.getters){ if(CodeListService.codelistCached.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`)){
let items:any = _this.$store.getters.getCodeListItems(tag); let items:any = CodeListService.codelistCached.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`);
if(items.length >0){ if(items.length >0){
if(cacheTimeout !== -1){ if(cacheTimeout !== -1){
if(new Date().getTime() > _this[tag].expirationTime){ if(new Date().getTime() > _this[tag].expirationTime){
_this[tag].getItems(context,data,isloading).then((result:any) =>{ _this[tag].getItems(context,data,isloading).then((result:any) =>{
_this.$store.commit('updateCodeList',{srfkey:tag,items:result}); CodeListService.codelistCached.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,{items:result});
_this[tag].expirationTime = new Date().getTime() + cacheTimeout; _this[tag].expirationTime = new Date().getTime() + cacheTimeout;
resolve(result); resolve(result);
}).catch((error:any) =>{ }).catch((error:any) =>{
...@@ -114,10 +110,11 @@ export default class CodeListService { ...@@ -114,10 +110,11 @@ export default class CodeListService {
} }
} }
if (_this[tag]) { if (_this[tag]) {
const callback:Function = (tag:string,promise:Promise<any>) =>{ const callback:Function = (context:any ={},data:any ={},tag:string,promise:Promise<any>) =>{
promise.then((result:any) =>{ promise.then((result:any) =>{
console.log()
if(result.length > 0){ if(result.length > 0){
_this.$store.commit('updateCodeList',{srfkey:tag,items:result}); CodeListService.codelistCached.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,{items:result});
return resolve(result); return resolve(result);
}else{ }else{
return resolve([]); return resolve([]);
...@@ -127,15 +124,15 @@ export default class CodeListService { ...@@ -127,15 +124,15 @@ export default class CodeListService {
}) })
} }
// 加载中,UI又需要数据,解决连续加载同一代码表问题 // 加载中,UI又需要数据,解决连续加载同一代码表问题
if(CodeListService.codelistCache.get(tag)){ if(CodeListService.codelistCache.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`)){
callback(tag,CodeListService.codelistCache.get(tag)); callback(context,data,tag,CodeListService.codelistCache.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`));
}else{ }else{
let result:Promise<any> = _this[tag].getItems(context,data,isloading); let result:Promise<any> = _this[tag].getItems(context,data,isloading);
CodeListService.codelistCache.set(tag,result); CodeListService.codelistCache.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,result);
if(cacheTimeout !== -1){ if(cacheTimeout !== -1){
_this[tag].expirationTime = new Date().getTime() + cacheTimeout; _this[tag].expirationTime = new Date().getTime() + cacheTimeout;
} }
callback(tag,result); callback(context,data,tag,result);
} }
} }
}else{ }else{
...@@ -149,7 +146,6 @@ export default class CodeListService { ...@@ -149,7 +146,6 @@ export default class CodeListService {
return Promise.reject([]); return Promise.reject([]);
} }
} }
}
}) })
} }
} }
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册