|
|
@ -1,3 +1,5 @@ |
|
|
|
import store from '@/store/index'; |
|
|
|
|
|
|
|
/** |
|
|
|
* 等待token执行api |
|
|
|
* 没有token 就延时执行自己 直到有了token在请求 |
|
|
@ -13,49 +15,21 @@ export const waitTokenRequest = requestFn => { |
|
|
|
}; |
|
|
|
|
|
|
|
export default { |
|
|
|
/** |
|
|
|
* 获取项目列表 |
|
|
|
* @param {number} startTime 起始时间 |
|
|
|
* @param {number} endTime 截止时间 |
|
|
|
*/ |
|
|
|
getProjects(startTime, endTime, fn) { |
|
|
|
let remote = false; |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getProjectsByDay(startTime, endTime) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
|
|
|
|
waitTokenRequest(() => { |
|
|
|
// 拿到api数据后 再用api的数据
|
|
|
|
uni.$u.api |
|
|
|
.getProjects(startTime, endTime) |
|
|
|
.then(data => { |
|
|
|
remote = true; |
|
|
|
fn(null, data); |
|
|
|
// 存api到cache里
|
|
|
|
uni.$t.cache.putProjects(data); |
|
|
|
}) |
|
|
|
.catch(err => fn(err)); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 通过项目id获取角色信息 |
|
|
|
* @param {object} params 提交的参数 |
|
|
|
*/ |
|
|
|
findShowRole(params, fn) { |
|
|
|
let remote = false; |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getShowRole(params.projectId) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
|
|
|
|
if (store.getters.useStorage) { |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getShowRole(params.projectId) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
} |
|
|
|
waitTokenRequest(() => { |
|
|
|
// 拿到api数据后 再用api的数据
|
|
|
|
uni.$u.api |
|
|
@ -76,15 +50,16 @@ export default { |
|
|
|
*/ |
|
|
|
getRegularTask(params, fn) { |
|
|
|
let remote = false; |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getStorageRegularTask(params) |
|
|
|
.then(data => { |
|
|
|
console.log('cache data: ', data); |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
|
|
|
|
if (store.getters.useStorage) { |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getStorageRegularTask(params) |
|
|
|
.then(data => { |
|
|
|
console.log('cache data: ', data); |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
} |
|
|
|
waitTokenRequest(() => { |
|
|
|
// 拿到api数据后 再用api的数据
|
|
|
|
uni.$u.api |
|
|
@ -107,14 +82,15 @@ export default { |
|
|
|
*/ |
|
|
|
getPermanent(params, fn) { |
|
|
|
let remote = false; |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getStoragePermanent(params) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
|
|
|
|
if (store.getters.useStorage) { |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getStoragePermanent(params) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
} |
|
|
|
waitTokenRequest(() => { |
|
|
|
// 拿到api数据后 再用api的数据
|
|
|
|
uni.$u.api |
|
|
@ -135,14 +111,15 @@ export default { |
|
|
|
*/ |
|
|
|
getGlobal(params, fn) { |
|
|
|
let remote = false; |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getDailyTask(params) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
|
|
|
|
if (store.getters.useStorage) { |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getDailyTask(params) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
} |
|
|
|
waitTokenRequest(() => { |
|
|
|
// 拿到api数据后 再用api的数据
|
|
|
|
uni.$u.api |
|
|
@ -163,14 +140,15 @@ export default { |
|
|
|
*/ |
|
|
|
getOtherPlugin(params, fn) { |
|
|
|
let remote = false; |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getPlugin(params.pluginId) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
|
|
|
|
if (store.getters.useStorage) { |
|
|
|
// 有缓存 且 服务端数据未返回 就先返回缓存
|
|
|
|
uni.$t.cache |
|
|
|
.getPlugin(params.pluginId) |
|
|
|
.then(data => { |
|
|
|
!remote && fn(null, data); |
|
|
|
}) |
|
|
|
.catch(err => !remote && fn(err)); |
|
|
|
} |
|
|
|
waitTokenRequest(() => { |
|
|
|
// 拿到api数据后 再用api的数据
|
|
|
|
uni.$u.api |
|
|
|