mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2025-12-19 12:06:44 +08:00
Jeecg-Boot 2.2.0 版本发布 | 重磅升级
This commit is contained in:
30
ant-design-vue-jeecg/src/api/GroupRequest.js
Normal file
30
ant-design-vue-jeecg/src/api/GroupRequest.js
Normal file
@ -0,0 +1,30 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
/**
|
||||
* 将一个请求分组
|
||||
*
|
||||
* @param getPromise 传入一个可以获取到Promise对象的方法
|
||||
* @param groupId 分组ID,如果不传或者为空则不分组
|
||||
* @param expire 过期时间,默认 半分钟
|
||||
*/
|
||||
export function httpGroupRequest(getPromise, groupId, expire = 1000 * 30) {
|
||||
if (groupId == null || groupId === '') {
|
||||
console.log("--------popup----------getFrom DB-------with---no--groupId ")
|
||||
return getPromise()
|
||||
}
|
||||
|
||||
if (Vue.ls.get(groupId)) {
|
||||
console.log("---------popup--------getFrom Cache--------groupId = " + groupId)
|
||||
return Promise.resolve(Vue.ls.get(groupId));
|
||||
} else {
|
||||
console.log("--------popup----------getFrom DB---------groupId = " + groupId)
|
||||
}
|
||||
|
||||
// 还没有发出请求,就发出第一次的请求
|
||||
return getPromise().then(res => {
|
||||
Vue.ls.set(groupId, res, expire);
|
||||
return Promise.resolve(res);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user