diff --git a/CHANGELOG.md b/CHANGELOG.md index 53eb312..ba83601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.1.0 (2021-08-18) +# 0.1.0 (2021-08-20) ### 🌟 新功能 范围|描述|commitId @@ -39,6 +39,7 @@ - | 标题栏变化 | [c0fcd9d](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c0fcd9d) - | 标题栏角色栏全局任务组件新建 | [0500cb4](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/0500cb4) - | 模拟接口测试 | [69e7931](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/69e7931) + - | 添加子任务插件 子项目插件 | [7bda7e2](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/7bda7e2) - | 添加时间轴上下滚动 | [2b81bbc](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/2b81bbc) - | 点击日历日期查询项目列表 | [c458385](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c458385) - | 缓存修改 | [63e1f0d](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/63e1f0d) @@ -171,6 +172,7 @@ - | 1.时间轴筛选相同的时间替换数据 2.整理代码 | [e082ccb](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/e082ccb) - | 修改代码格式 | [14123d7](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/14123d7) - | 修改定期任务骨架屏高度 | [909a734](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/909a734) + - | 小红点api缓存修改 | [e992343](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/e992343) - | 插件查询及展示 | [4dba770](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/4dba770) - | 整理代码 | [7a55315](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/7a55315) - | 日历的更改 | [7353ac8](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/7353ac8) @@ -204,3 +206,4 @@ - | style:index | [978f272](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/978f272) - | !2 基础模板v1.1.0 | [f5e61dd](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/f5e61dd) - | init | [c0f1deb](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c0f1deb) + diff --git a/src/components/Roles/Roles.vue b/src/components/Roles/Roles.vue index 6bf350f..6aacb13 100644 --- a/src/components/Roles/Roles.vue +++ b/src/components/Roles/Roles.vue @@ -56,7 +56,7 @@ export default { }, methods: { - ...mapActions('task', ['handleRegularTask', 'getPermanent']), + ...mapActions('task', ['handleRegularTask']), ...mapMutations('role', ['setRoleId']), ...mapMutations('task', ['setPermanents', 'clearEndFlag']), diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 9337ec7..fcb8ce5 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -63,16 +63,20 @@ export default { }); }, - // 查询小红点 - handleFindPoint(start = this.$moment().startOf('day').valueOf(), end = this.$moment().endOf('day').valueOf()) { - // const data = await this.$u.api.findRedPoint(startTime, endTime); - this.$t.$q.findRedPoint(start, end, (err, data) => { - if (err) { - console.err('err: ', err); - } else { - this.setDotList(data); - } - }); + /** + * 查询小红点 + * @param { string } endTime 结束时间 + * @param { string } startTime 开始时间 + */ + async handleFindPoint(start, end) { + try { + const startTime = start || this.$moment().startOf('month').valueOf(); + const endTime = end || this.$moment().endOf('month').valueOf(); + const data = await this.$u.api.findRedPoint(startTime, endTime); + this.setDotList(data); + } catch (error) { + console.log('error: ', error); + } }, // 点击了某个日期 diff --git a/src/pages/project/project.vue b/src/pages/project/project.vue index 9ea4c29..ad150fe 100644 --- a/src/pages/project/project.vue +++ b/src/pages/project/project.vue @@ -29,8 +29,10 @@ export default { computed: { ...mapState('user', ['user', 'token']), ...mapState('role', ['visibleRoles', 'roleId']), - ...mapState('task', ['timeNode', 'timeUnit', 'tasks']), + ...mapState('task', ['timeNode', 'timeUnit', 'tasks', 'regularTask']), + ...mapState('project', ['project']), ...mapGetters('task', ['timeGranularity']), + ...mapGetters('project', ['projectId']), }, onLoad(options) { @@ -43,10 +45,10 @@ export default { * 重新根据时间和角色查询普通日常任务 * 永久日常任务不发生改变 */ - async timeNode(val) { + timeNode(val) { if (val && this.roleId) { // 根据时间和角色查找日常任务 - await this.initTasks(); + this.initTasks(); } }, @@ -60,7 +62,8 @@ export default { if (val) { this.setTimeNode(Date.now()); // 根据角色查找永久的日常任务 - this.getPermanent(val); + const params = { roleId: val, projectId: this.projectId }; + this.getPermanent(params); } }, }, @@ -76,8 +79,6 @@ export default { methods: { ...mapActions('user', ['getToken']), - ...mapActions('project', ['getProjectById']), - ...mapActions('role', ['getRoles']), ...mapActions('task', ['getRegulars', 'getPermanent', 'getGlobal']), ...mapMutations('user', ['setToken']), ...mapMutations('project', ['setProject', 'setProjectName']), @@ -99,37 +100,63 @@ export default { * 初始化 * @param {object | null} options */ - async init(options) { - try { - if (!this.token) { - // 不论有没有token都直接从userId获取token - // token有过期时间 从本地获取可能是过期 干脆直接从userId获取 - if (!options || !options.u) { - // 参数里没有u (userId)提示 - this.$t.ui.showToast('缺少用户信息参数'); - } else { - await this.getToken(options.u); - } + init(options) { + if (!this.token) { + // 不论有没有token都直接从userId获取token + // token有过期时间 从本地获取可能是过期 干脆直接从userId获取 + if (!options || !options.u) { + // 参数里没有u (userId)提示 + this.$t.ui.showToast('缺少用户信息参数'); + } else { + this.getToken(options.u); } + } - // 参数里有项目名称 就设置标题里的项目名称 - options && options.pname && this.setProjectName(options.pname); + // 参数里有项目名称 就设置标题里的项目名称 + options && options.pname && this.setProjectName(options.pname); - if (!options || !options.p) { - // 没有项目id参数 - this.$t.ui.showToast('缺少项目信息参数'); - } else { - // 根据项目id获取项目信息 - await this.getProjectById({ projectId: options.p }); - // 根据项目id获取角色列表 - await this.getRoles({ projectId: options.p }); - this.setInitialRoleId(this.visibleRoles); - } + if (!options || !options.p) { + // 没有项目id参数 + this.$t.ui.showToast('缺少项目信息参数'); + } else { + // 根据项目id获取项目信息 + this.getProjectById({ projectId: options.p }); + } + }, + + /** + * 通过项目id获取项目信息 + * @param {string} projectId + * @param {object} params 提交的参数 + */ + async getProjectById(params) { + try { + const data = await uni.$u.api.findProjectById(params); + this.setProject(data); + // 根据项目id获取角色列表 + this.getRoles(params); } catch (error) { - console.error('project init function:', error); + console.log('error: ', error || '获取项目信息失败'); } }, + /** + * 通过项目id获取角色信息 + * @param {string} projectId + * @param {object} params 提交的参数 + */ + getRoles(params) { + this.$t.$q.findShowRole(params, (err, data) => { + if (err) { + console.error('err: ', err || '获取角色信息失败'); + } else { + this.setInvisibleRoles(data ? data.invisibleList : []); + this.setVisibleRoles(data ? data.visibleList : []); + this.setInitialRoleId(data ? data.visibleList : []); + } + }); + }, + // 初始化 时间轴 async initTasks() { // 清空日常任务的数据 @@ -153,7 +180,9 @@ export default { }); // 向下加载空数据 this.setNextTasks(); + await this.getInitTasks(); + // 根据项目id获取角色列表 // 从详情页返回时跳转到之前的位置 storage有存储值 this.$nextTick(() => { if (storageTaskId) { @@ -163,28 +192,31 @@ export default { }, // 切换了 颗粒度 || 角色时候 获取初始定期任务 - async getInitTasks() { + getInitTasks() { // 根据时间基准点和角色查找定期任务 - await this.getTasks({ queryType: 0 }); - await this.getTasks({ queryType: 1 }); + this.getTasks({ queryType: 0 }); + // 根据项目id获取角色列表 + this.getTasks({ queryType: 1 }); // 预加载 上下的定期任务 - const detailId = this.tasks.findIndex(task => task.detailId); - if (detailId !== -1) { - this.$nextTick(async () => { - const { tasks, timeGranularity } = this; - await this.getTasks({ timeNode: +tasks[0].planStart, queryType: 0, queryNum: 6 }); // 向上拿数据 - // 向下查的时候要再最后一个任务的开始时间的基础上 多加一个时间颗粒度 - const nextQueryTime = +this.$t.time.add(+tasks[tasks.length - 1].planStart, 1, timeGranularity); - await this.getTasks({ timeNode: nextQueryTime, queryType: 1, queryNum: 6 }); // 向下拿数据 - }); - } else { - // 没有任务 上下显示时间刻度 - // 向上加载 - this.setPrevTasks(); - // 向下加载 - this.setNextTasks(); - } + // const detailId = this.tasks.findIndex(task => task.detailId); + // console.log('detailId: ', detailId); + // if (detailId !== -1) { + // this.$nextTick(() => { + // // 向上拿数据 + // const { tasks, timeGranularity } = this; + // this.getTasks({ timeNode: +tasks[0].planStart, queryType: 0, queryNum: 6 }); + // // 向下拿数据 + // const nextQueryTime = +this.$t.time.add(+tasks[tasks.length - 1].planStart, 1, timeGranularity); + // this.getTasks({ timeNode: nextQueryTime, queryType: 1, queryNum: 6 }); + // }); + // } else { + // // 没有任务 上下显示时间刻度 + // // 向上加载 + // this.setPrevTasks(); + // // 向下加载 + // this.setNextTasks(); + // } }, // 设置 初始显示角色信息 @@ -207,35 +239,38 @@ export default { * @param {string} query.queryNum 查找颗粒度数量 默认3个 * @param {string} query.queryType 0向上查找 1向下查找(默认) 下查包含自己,上查不包含 */ - async getTasks(query) { - try { - this.setShowSkeleton(true); - const { roleId, timeNode, timeUnit } = this; - const params = { - roleId, - timeNode: query.timeNode || timeNode, - timeUnit: query.timeUnit || timeUnit, - queryNum: query.queryNum || 3, - queryType: query.queryType, - }; - const res = await this.getRegulars(params); - this.setShowSkeleton(false); - // 0 -> 向上 1 -> 向下 - if (res && res.length) { - this.replacePrevData(res, params.queryType); + getTasks(query) { + this.setShowSkeleton(true); + const { roleId, timeNode, timeUnit, projectId } = this; + const params = { + roleId, + timeNode: query.timeNode || timeNode, + timeUnit: query.timeUnit || timeUnit, + queryNum: query.queryNum || 3, + queryType: query.queryType, + projectId, + }; + this.$t.$q.getRegularTask(params, (err, data) => { + if (err) { + this.setShowSkeleton(false); + console.error('err: ', err); } else { - params.queryType === 0 ? this.setPrevTasks() : this.setNextTasks(); + this.setShowSkeleton(false); + // 0 -> 向上 1 -> 向下 + if (data && data.length) { + console.log('data: ', data); + this.replacePrevData(data, params.queryType); + } else { + params.queryType === 0 ? this.setPrevTasks() : this.setNextTasks(); + } } - } catch (error) { - this.setShowSkeleton(false); - console.error('error: ', error); - } + }); }, // 获取可变全局任务 getGlobalData() { - const { roleId, timeNode, timeUnit } = this; - const param = { roleId, timeNode, timeUnit }; + const { roleId, timeNode, timeUnit, projectId } = this; + const param = { roleId, timeNode, timeUnit, projectId }; this.getGlobal(param); }, diff --git a/src/store/project/actions.js b/src/store/project/actions.js index 57b1c9b..5dfa3d4 100644 --- a/src/store/project/actions.js +++ b/src/store/project/actions.js @@ -1,18 +1,3 @@ -const actions = { - /** - * 通过项目id获取项目信息 - * @param {any} commit - * @param {object} params 提交的参数 - */ - async getProjectById({ commit }, params) { - try { - const data = await uni.$u.api.findProjectById(params); - commit('setProject', data); - return data; - } catch (error) { - throw error || '获取项目信息失败'; - } - }, -}; +const actions = {}; export default actions; diff --git a/src/store/role/actions.js b/src/store/role/actions.js index 7ceb712..5dfa3d4 100644 --- a/src/store/role/actions.js +++ b/src/store/role/actions.js @@ -1,19 +1,3 @@ -const actions = { - /** - * 通过项目id获取角色信息 - * @param {any} commit - * @param {object} params 提交的参数 - */ - async getRoles({ commit }, params) { - try { - const res = await uni.$u.api.findShowRole(params); - commit('setInvisibleRoles', res.invisibleList); - commit('setVisibleRoles', res.visibleList); - return res; - } catch (error) { - throw error || '获取角色信息失败'; - } - }, -}; +const actions = {}; export default actions; diff --git a/src/store/task/actions.js b/src/store/task/actions.js index b8dfbfb..40cdb31 100644 --- a/src/store/task/actions.js +++ b/src/store/task/actions.js @@ -4,13 +4,14 @@ const actions = { * @param {*} commit * @param {string} roleId 角色id */ - async getPermanent({ commit }, roleId) { - try { - const data = await uni.$u.api.getPermanent({ roleId }); - commit('setPermanents', data); - } catch (error) { - console.log('task actions getPermanent error: ', error); - } + getPermanent({ commit }, param) { + uni.$t.$q.getPermanent(param, (err, data) => { + if (err) { + console.error('err: ', err); + } else { + commit('setPermanents', data); + } + }); }, /** @@ -18,27 +19,14 @@ const actions = { * @param {*} commit * @param {object} param 请求参数 roleId, timeNode, timeUnit */ - async getGlobal({ commit }, param) { - try { - const data = await uni.$u.api.getGlobal(param); - commit('setDailyTasks', data); - } catch (error) { - console.log('task actions getGlobal error: ', error); - } - }, - - /** - * 根据时间基准点和角色查找定期任务 - * @param {object} param 查询参数 - * @param {number} param.queryType 必填 0 -> 向上 1 -> 向下 - */ - // eslint-disable-next-line - async getRegulars({ commit }, param) { - try { - return await uni.$u.api.getRegularTask(param); - } catch (error) { - throw error || '获取定期任务失败'; - } + getGlobal({ commit }, param) { + uni.$t.$q.getGlobal(param, (err, data) => { + if (err) { + console.error('err: ', err); + } else { + commit('setDailyTasks', data); + } + }); }, }; diff --git a/src/store/task/state.js b/src/store/task/state.js index c2ed496..a4b4fab 100644 --- a/src/store/task/state.js +++ b/src/store/task/state.js @@ -16,8 +16,7 @@ const state = { bottomEnd: false, // 时间轴向下查任务到底了 permanents: [], // 永久日常任务 dailyTasks: [], // 日常任务 - // 定期任务 - tasks: [], + tasks: [], // 所有的定期任务 showSkeleton: false, // 定期任务骨架屏 }; diff --git a/src/utils/cache.js b/src/utils/cache.js index 7bb7ee9..ad64da3 100644 --- a/src/utils/cache.js +++ b/src/utils/cache.js @@ -36,8 +36,8 @@ export default { putProjects(data) { try { if (!data || !data.length) return; // 服务端没数据不做操作 - - let locals = JSON.parse(uni.$t.storage.getStorageSync('projects')) || []; + let value = uni.$t.storage.getStorageSync('projects'); + let locals = value ? JSON.parse(value) : []; if (!locals || !locals.length) { // 本地没数据 locals = data || []; @@ -62,15 +62,72 @@ export default { }, /** - * 小红点 获取 + * 当前显示的角色信息 获取 + * @param {object} params + * @returns + */ + async getShowRole(projectId) { + try { + const data = await uni.$t.storage.getStorage(`roles_${projectId}`); + return JSON.parse(data); + } catch (error) { + console.error('error: ', error); + return null; + } + }, + + /** + * 当前显示的角色信息 存 + * @param {array} data + */ + putShowRole(projectId, data) { + try { + if (!data || !data.visibleList || !data.visibleList.length) return; // 服务端没数据不做操作 + let value = uni.$t.storage.getStorageSync(`roles_${projectId}`); + let locals = value ? JSON.parse(value) : null; + if (!locals || !locals.length) { + // 本地没数据 + locals = data || null; + } else { + // 本地有数据 + data.invisibleList.forEach(item => { + let invisibleListLocalData = locals.invisibleList.find(local => item.id === local.id); + if (invisibleListLocalData) { + // 有相同数据 就用新的data里的数据 + invisibleListLocalData = item; + } else { + // 没有就直接存本地 + locals.invisibleList.push(item); + } + }); + data.visibleList.forEach(item => { + let localData = locals.visibleList.find(local => item.id === local.id); + if (localData) { + // 有相同数据 就用新的data里的数据 + localData = item; + } else { + // 没有就直接存本地 + locals.visibleList.push(item); + } + }); + } + uni.$t.storage.setStorage(`roles_${projectId}`, locals); + } catch (error) { + console.error('error: ', error); + uni.$t.storage.setStorage(`roles_${projectId}`, []); + } + }, + + /** + * 定期任务 获取 * @param {number} startTime * @param {number} endTime * @returns */ - async getDotListByDay(startTime, endTime) { + async getStorageRegularTask(params) { try { - const data = await uni.$t.storage.getStorage('dotList'); - return filter.projects(JSON.parse(data), startTime, endTime); + const data = await uni.$t.storage.getStorage(`plan_task_${params.projectId}_${params.roleId}`); + return JSON.parse(data); } catch (error) { console.error('error: ', error); return []; @@ -78,33 +135,132 @@ export default { }, /** - * 小红点 存 + * 定期任务 存 * @param {array} data */ - putDotList(data) { + putStorageRegularTask(params, data) { try { if (!data || !data.length) return; // 服务端没数据不做操作 - let locals = JSON.parse(uni.$t.storage.getStorageSync('dotList')) || []; + let value = uni.$t.storage.getStorageSync(`plan_task_${params.projectId}_${params.roleId}`); + let locals = value ? JSON.parse(value) : []; if (!locals || !locals.length) { // 本地没数据 locals = data || []; } else { // 本地有数据 data.forEach(item => { - let localData = locals.find(local => item === local); + let localData = locals.find(local => item.id === local.id); + if (localData) { + // 有相同数据 就用新的data里的数据 + localData = item; + } else { + // 没有就直接存本地 + locals.push(item); + } + }); + } + uni.$t.storage.setStorage(`plan_task_${params.projectId}_${params.roleId}`, locals); + } catch (error) { + console.error('error: ', error); + uni.$t.storage.setStorage(`plan_task_${params.projectId}_${params.roleId}`, []); + } + }, + + /** + * 永久的日常任务 获取 + * @param {number} startTime + * @param {number} endTime + * @returns + */ + async getStoragePermanent(params) { + try { + const data = await uni.$t.storage.getStorage(`fixed_tasks_${params.projectId}`); + return JSON.parse(data); + } catch (error) { + console.error('error: ', error); + return []; + } + }, + + /** + * 永久的日常任务 存 + * @param {array} data + */ + putStoragePermanent(params, data) { + try { + if (!data || !data.length) return; // 服务端没数据不做操作 + let value = uni.$t.storage.getStorageSync(`fixed_tasks_${params.projectId}`); + let locals = value ? JSON.parse(value) : []; + if (!locals || !locals.length) { + // 本地没数据 + locals = data || []; + } else { + // 本地有数据 + data.forEach((item, index) => { + let localData = locals.find(local => item.detailId === local.detailId); + if (localData) { + // 有相同数据 就用新的data里的数据 + localData = item; + } else { + locals.splice(index, 1); + // 没有就直接存本地 + locals.push(item); + } + }); + } + uni.$t.storage.setStorage(`fixed_tasks_${params.projectId}`, locals); + } catch (error) { + console.error('error: ', error); + uni.$t.storage.setStorage(`fixed_tasks_${params.projectId}`, []); + } + }, + + /** + * 日常任务 获取 + * @param {number} startTime + * @param {number} endTime + * @returns + */ + async getDailyTask(params) { + try { + const data = await uni.$t.storage.getStorage(`variable_tasks_${params.projectId}`); + return JSON.parse(data); + } catch (error) { + console.error('error: ', error); + return []; + } + }, + + /** + * 日常任务 存 + * @param {array} data + */ + putDailyTask(params, data) { + try { + if (!data || !data.length) return; // 服务端没数据不做操作 + let value = uni.$t.storage.getStorageSync(`variable_tasks_${params.projectId}`); + let locals = value ? JSON.parse(value) : []; + if (!locals || !locals.length) { + // 本地没数据 + locals = data || []; + } else { + // 本地有数据 + data.forEach((item, index) => { + let localData = locals.find(local => item.detailId === local.detailId); if (localData) { // 有相同数据 就用新的data里的数据 localData = item; } else { + locals.splice(index, 1); // 没有就直接存本地 locals.push(item); } }); } - uni.$t.storage.setStorage('dotList', locals); + uni.$t.storage.setStorage(`variable_tasks_${params.projectId}`, locals); } catch (error) { console.error('error: ', error); - uni.$t.storage.setStorage('dotList', []); + uni.$t.storage.setStorage(`variable_tasks_${params.projectId}`, []); } }, }; diff --git a/src/utils/cacheAndRequest.js b/src/utils/cacheAndRequest.js index 8662055..1701342 100644 --- a/src/utils/cacheAndRequest.js +++ b/src/utils/cacheAndRequest.js @@ -24,7 +24,6 @@ export default { uni.$t.cache .getProjectsByDay(startTime, endTime) .then(data => { - // console.log('cache data: ', data); !remote && fn(null, data); }) .catch(err => !remote && fn(err)); @@ -34,7 +33,6 @@ export default { uni.$u.api .getProjects(startTime, endTime) .then(data => { - // console.log('api data: ', data); remote = true; fn(null, data); // 存api到cache里 @@ -45,17 +43,15 @@ export default { }, /** - * 查询小红点 - * @param { string } endTime 结束时间 - * @param { string } startTime 开始时间 + * 通过项目id获取角色信息 + * @param {object} params 提交的参数 */ - findRedPoint(startTime, endTime, fn) { + findShowRole(params, fn) { let remote = false; // 有缓存 且 服务端数据未返回 就先返回缓存 uni.$t.cache - .getDotListByDay(startTime, endTime) + .getShowRole(params.projectId) .then(data => { - // console.log('cache data: ', data); !remote && fn(null, data); }) .catch(err => !remote && fn(err)); @@ -63,13 +59,98 @@ export default { waitTokenRequest(() => { // 拿到api数据后 再用api的数据 uni.$u.api - .findRedPoint(startTime, endTime) + .findShowRole(params) .then(data => { - // console.log('api data: ', data); remote = true; fn(null, data); // 存api到cache里 - uni.$t.cache.putDotList(data); + uni.$t.cache.putShowRole(params.projectId, data); + }) + .catch(err => fn(err)); + }); + }, + + /** + * 根据时间基准点和角色查找定期任务 + * @param {object} params 提交的参数 + */ + 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)); + + waitTokenRequest(() => { + // 拿到api数据后 再用api的数据 + uni.$u.api + .getRegularTask(params) + .then(data => { + console.log('api data: ', data); + remote = true; + fn(null, data); + // 存api到cache里 + uni.$t.cache.putStorageRegularTask(params, data); + }) + .catch(err => fn(err)); + }); + }, + + /** + * 根据角色查找永久的日常任务 + * @param {object} params 提交的参数 + */ + getPermanent(params, fn) { + let remote = false; + // 有缓存 且 服务端数据未返回 就先返回缓存 + uni.$t.cache + .getStoragePermanent(params) + .then(data => { + !remote && fn(null, data); + }) + .catch(err => !remote && fn(err)); + + waitTokenRequest(() => { + // 拿到api数据后 再用api的数据 + uni.$u.api + .getPermanent(params) + .then(data => { + remote = true; + fn(null, data); + // 存api到cache里 + uni.$t.cache.putStoragePermanent(data); + }) + .catch(err => fn(err)); + }); + }, + + /** + * 根据时间和角色查找日常任务 + * @param {object} params 提交的参数 + */ + getGlobal(params, fn) { + let remote = false; + // 有缓存 且 服务端数据未返回 就先返回缓存 + uni.$t.cache + .getDailyTask(params) + .then(data => { + !remote && fn(null, data); + }) + .catch(err => !remote && fn(err)); + + waitTokenRequest(() => { + // 拿到api数据后 再用api的数据 + uni.$u.api + .getGlobal(params) + .then(data => { + remote = true; + fn(null, data); + // 存api到cache里 + uni.$t.cache.putDailyTask(data); }) .catch(err => fn(err)); });