提交 732bb317 编写于 作者: tony001's avatar tony001

调整消息服务基类

上级 3375076a
...@@ -116,6 +116,22 @@ export default class ViewMessageService { ...@@ -116,6 +116,22 @@ export default class ViewMessageService {
*/ */
public dynamicMode:string = "STATIC"; public dynamicMode:string = "STATIC";
/**
* 视图消息缓存(加载中)
*
* @type {Map<string,any>}
* @memberof ViewMessageService
*/
public static messageCache:Map<string,any> = new Map();
/**
* 视图消息缓存(已完成)
*
* @type {Map<string,any>}
* @memberof ViewMessageService
*/
public static messageCached:Map<string,any> = new Map();
/** /**
* 初始化实例 * 初始化实例
* *
...@@ -166,12 +182,12 @@ export default class ViewMessageService { ...@@ -166,12 +182,12 @@ export default class ViewMessageService {
* @param {viewparam:any} 导航参数 * @param {viewparam:any} 导航参数
* @memberof ViewMessageService * @memberof ViewMessageService
*/ */
public async getViewMessageByTag(tag:string,context:any,viewparam:any){ public async getViewMessageByTag(tag:string,context:any = {},viewparam:any = {}){
let messageService:any = await this.getService(tag); let messageService:any = await this.getService(tag);
if(messageService.dynamicMode && Object.is(messageService.dynamicMode,"STATIC")){ if(messageService.dynamicMode && Object.is(messageService.dynamicMode,"STATIC")){
return messageService.getStaticViewMessage(); return messageService.getStaticViewMessage();
}else{ }else{
return messageService.getDynamicViewMessage(tag,messageService,context,viewparam);
} }
} }
...@@ -200,11 +216,66 @@ export default class ViewMessageService { ...@@ -200,11 +216,66 @@ export default class ViewMessageService {
/** /**
* 获取动态模式(实体数据集合)类型视图消息 * 获取动态模式(实体数据集合)类型视图消息
* *
* @param {any} tag 视图消息标识
* @param {any} messageService 消息服务
* @param {string} context
* @returns {Promise<any[]>}
* @memberof ViewMessageService * @memberof ViewMessageService
*/ */
public async getDynamicViewMessage():Promise<Array<ViewMessage>>{ public getDynamicViewMessage(tag:string,messageService: any,context:any = {}, data: any = {}, isloading?: boolean): Promise<any[]> {
return []; if(context && context.srfsessionid){
delete context.srfsessionid;
}
return new Promise((resolve:any,reject:any) =>{
let isEnableCache:boolean = messageService.isEnableCache;
let cacheTimeout:any = messageService.cacheTimeout;
// 启用缓存
if(isEnableCache){
const callback:Function = (context:any ={},data:any ={},tag:string,promise:Promise<any>) =>{
promise.then((result:any) =>{
if(result.length > 0){
ViewMessageService.messageCached.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,{items:result});
ViewMessageService.messageCache.delete(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`);
return resolve(result);
}else{
return resolve([]);
}
}).catch((result:any) =>{
return reject(result);
})
}
// 加载完成,从本地缓存获取
if(ViewMessageService.messageCached.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`)){
let items:any = ViewMessageService.messageCached.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`).items;
if(items.length >0){
if(new Date().getTime() <= messageService.getExpirationTime()){
return resolve(items);
}
}
}
if (messageService) {
// 加载中,UI又需要数据,解决连续加载同一代码表问题
if(ViewMessageService.messageCache.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`)){
callback(context,data,tag,ViewMessageService.messageCache.get(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`));
}else{
let result:Promise<any> = messageService.getItems(context,data,isloading);
ViewMessageService.messageCache.set(`${JSON.stringify(context)}-${JSON.stringify(data)}-${tag}`,result);
messageService.setExpirationTime(new Date().getTime() + cacheTimeout);
callback(context,data,tag,result);
}
}
}else{
if (messageService) {
messageService.getItems(context,data,isloading).then((result:any) =>{
resolve(result);
}).catch((error:any) =>{
Promise.reject([]);
})
}else{
return Promise.reject([]);
}
}
})
} }
} }
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册