Browse Source

feat: api封装

tall
song 4 years ago
parent
commit
7d4edfc92b
  1. 5
      CHANGELOG.md
  2. 2
      src/components/Roles/Roles.vue
  3. 24
      src/pages/index/index.vue
  4. 179
      src/pages/project/project.vue
  5. 17
      src/store/project/actions.js
  6. 18
      src/store/role/actions.js
  7. 44
      src/store/task/actions.js
  8. 3
      src/store/task/state.js
  9. 180
      src/utils/cache.js
  10. 103
      src/utils/cacheAndRequest.js

5
CHANGELOG.md

@ -1,4 +1,4 @@
# 0.1.0 (2021-08-18) # 0.1.0 (2021-08-20)
### 🌟 新功能 ### 🌟 新功能
范围|描述|commitId 范围|描述|commitId
@ -39,6 +39,7 @@
- | 标题栏变化 | [c0fcd9d](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c0fcd9d) - | 标题栏变化 | [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) - | 标题栏角色栏全局任务组件新建 | [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) - | 模拟接口测试 | [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) - | 添加时间轴上下滚动 | [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) - | 点击日历日期查询项目列表 | [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) - | 缓存修改 | [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) - | 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) - | 修改代码格式 | [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) - | 修改定期任务骨架屏高度 | [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) - | 插件查询及展示 | [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) - | 整理代码 | [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) - | 日历的更改 | [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) - | 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) - | !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) - | init | [c0f1deb](https://dd.tall.wiki/gitea/ccsens_fe/TALL-MUI-3/commits/c0f1deb)

2
src/components/Roles/Roles.vue

@ -56,7 +56,7 @@ export default {
}, },
methods: { methods: {
...mapActions('task', ['handleRegularTask', 'getPermanent']), ...mapActions('task', ['handleRegularTask']),
...mapMutations('role', ['setRoleId']), ...mapMutations('role', ['setRoleId']),
...mapMutations('task', ['setPermanents', 'clearEndFlag']), ...mapMutations('task', ['setPermanents', 'clearEndFlag']),

24
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); * @param { string } endTime 结束时间
this.$t.$q.findRedPoint(start, end, (err, data) => { * @param { string } startTime 开始时间
if (err) { */
console.err('err: ', err); async handleFindPoint(start, end) {
} else { try {
this.setDotList(data); 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);
}
}, },
// //

179
src/pages/project/project.vue

@ -29,8 +29,10 @@ export default {
computed: { computed: {
...mapState('user', ['user', 'token']), ...mapState('user', ['user', 'token']),
...mapState('role', ['visibleRoles', 'roleId']), ...mapState('role', ['visibleRoles', 'roleId']),
...mapState('task', ['timeNode', 'timeUnit', 'tasks']), ...mapState('task', ['timeNode', 'timeUnit', 'tasks', 'regularTask']),
...mapState('project', ['project']),
...mapGetters('task', ['timeGranularity']), ...mapGetters('task', ['timeGranularity']),
...mapGetters('project', ['projectId']),
}, },
onLoad(options) { onLoad(options) {
@ -43,10 +45,10 @@ export default {
* 重新根据时间和角色查询普通日常任务 * 重新根据时间和角色查询普通日常任务
* 永久日常任务不发生改变 * 永久日常任务不发生改变
*/ */
async timeNode(val) { timeNode(val) {
if (val && this.roleId) { if (val && this.roleId) {
// //
await this.initTasks(); this.initTasks();
} }
}, },
@ -60,7 +62,8 @@ export default {
if (val) { if (val) {
this.setTimeNode(Date.now()); this.setTimeNode(Date.now());
// //
this.getPermanent(val); const params = { roleId: val, projectId: this.projectId };
this.getPermanent(params);
} }
}, },
}, },
@ -76,8 +79,6 @@ export default {
methods: { methods: {
...mapActions('user', ['getToken']), ...mapActions('user', ['getToken']),
...mapActions('project', ['getProjectById']),
...mapActions('role', ['getRoles']),
...mapActions('task', ['getRegulars', 'getPermanent', 'getGlobal']), ...mapActions('task', ['getRegulars', 'getPermanent', 'getGlobal']),
...mapMutations('user', ['setToken']), ...mapMutations('user', ['setToken']),
...mapMutations('project', ['setProject', 'setProjectName']), ...mapMutations('project', ['setProject', 'setProjectName']),
@ -99,37 +100,63 @@ export default {
* 初始化 * 初始化
* @param {object | null} options * @param {object | null} options
*/ */
async init(options) { init(options) {
try { if (!this.token) {
if (!this.token) { // tokenuserIdtoken
// tokenuserIdtoken // token userId
// token userId if (!options || !options.u) {
if (!options || !options.u) { // u (userId)
// u (userId) this.$t.ui.showToast('缺少用户信息参数');
this.$t.ui.showToast('缺少用户信息参数'); } else {
} else { this.getToken(options.u);
await this.getToken(options.u);
}
} }
}
// //
options && options.pname && this.setProjectName(options.pname); options && options.pname && this.setProjectName(options.pname);
if (!options || !options.p) { if (!options || !options.p) {
// id // id
this.$t.ui.showToast('缺少项目信息参数'); this.$t.ui.showToast('缺少项目信息参数');
} else { } else {
// id // id
await this.getProjectById({ projectId: options.p }); this.getProjectById({ projectId: options.p });
// id }
await this.getRoles({ projectId: options.p }); },
this.setInitialRoleId(this.visibleRoles);
} /**
* 通过项目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) { } 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() { async initTasks() {
// //
@ -153,7 +180,9 @@ export default {
}); });
// //
this.setNextTasks(); this.setNextTasks();
await this.getInitTasks(); await this.getInitTasks();
// id
// storage // storage
this.$nextTick(() => { this.$nextTick(() => {
if (storageTaskId) { if (storageTaskId) {
@ -163,28 +192,31 @@ export default {
}, },
// || // ||
async getInitTasks() { getInitTasks() {
// //
await this.getTasks({ queryType: 0 }); this.getTasks({ queryType: 0 });
await this.getTasks({ queryType: 1 }); // id
this.getTasks({ queryType: 1 });
// //
const detailId = this.tasks.findIndex(task => task.detailId); // const detailId = this.tasks.findIndex(task => task.detailId);
if (detailId !== -1) { // console.log('detailId: ', detailId);
this.$nextTick(async () => { // if (detailId !== -1) {
const { tasks, timeGranularity } = this; // this.$nextTick(() => {
await this.getTasks({ timeNode: +tasks[0].planStart, queryType: 0, queryNum: 6 }); // // //
// // const { tasks, timeGranularity } = this;
const nextQueryTime = +this.$t.time.add(+tasks[tasks.length - 1].planStart, 1, timeGranularity); // this.getTasks({ timeNode: +tasks[0].planStart, queryType: 0, queryNum: 6 });
await this.getTasks({ timeNode: nextQueryTime, queryType: 1, queryNum: 6 }); // // //
}); // const nextQueryTime = +this.$t.time.add(+tasks[tasks.length - 1].planStart, 1, timeGranularity);
} else { // this.getTasks({ timeNode: nextQueryTime, queryType: 1, queryNum: 6 });
// // });
// // } else {
this.setPrevTasks(); // //
// // //
this.setNextTasks(); // this.setPrevTasks();
} // //
// this.setNextTasks();
// }
}, },
// //
@ -207,35 +239,38 @@ export default {
* @param {string} query.queryNum 查找颗粒度数量 默认3个 * @param {string} query.queryNum 查找颗粒度数量 默认3个
* @param {string} query.queryType 0向上查找 1向下查找(默认) 下查包含自己上查不包含 * @param {string} query.queryType 0向上查找 1向下查找(默认) 下查包含自己上查不包含
*/ */
async getTasks(query) { getTasks(query) {
try { this.setShowSkeleton(true);
this.setShowSkeleton(true); const { roleId, timeNode, timeUnit, projectId } = this;
const { roleId, timeNode, timeUnit } = this; const params = {
const params = { roleId,
roleId, timeNode: query.timeNode || timeNode,
timeNode: query.timeNode || timeNode, timeUnit: query.timeUnit || timeUnit,
timeUnit: query.timeUnit || timeUnit, queryNum: query.queryNum || 3,
queryNum: query.queryNum || 3, queryType: query.queryType,
queryType: query.queryType, projectId,
}; };
const res = await this.getRegulars(params); this.$t.$q.getRegularTask(params, (err, data) => {
this.setShowSkeleton(false); if (err) {
// 0 -> 1 -> this.setShowSkeleton(false);
if (res && res.length) { console.error('err: ', err);
this.replacePrevData(res, params.queryType);
} else { } 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() { getGlobalData() {
const { roleId, timeNode, timeUnit } = this; const { roleId, timeNode, timeUnit, projectId } = this;
const param = { roleId, timeNode, timeUnit }; const param = { roleId, timeNode, timeUnit, projectId };
this.getGlobal(param); this.getGlobal(param);
}, },

17
src/store/project/actions.js

@ -1,18 +1,3 @@
const actions = { 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 || '获取项目信息失败';
}
},
};
export default actions; export default actions;

18
src/store/role/actions.js

@ -1,19 +1,3 @@
const actions = { 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 || '获取角色信息失败';
}
},
};
export default actions; export default actions;

44
src/store/task/actions.js

@ -4,13 +4,14 @@ const actions = {
* @param {*} commit * @param {*} commit
* @param {string} roleId 角色id * @param {string} roleId 角色id
*/ */
async getPermanent({ commit }, roleId) { getPermanent({ commit }, param) {
try { uni.$t.$q.getPermanent(param, (err, data) => {
const data = await uni.$u.api.getPermanent({ roleId }); if (err) {
commit('setPermanents', data); console.error('err: ', err);
} catch (error) { } else {
console.log('task actions getPermanent error: ', error); commit('setPermanents', data);
} }
});
}, },
/** /**
@ -18,27 +19,14 @@ const actions = {
* @param {*} commit * @param {*} commit
* @param {object} param 请求参数 roleId, timeNode, timeUnit * @param {object} param 请求参数 roleId, timeNode, timeUnit
*/ */
async getGlobal({ commit }, param) { getGlobal({ commit }, param) {
try { uni.$t.$q.getGlobal(param, (err, data) => {
const data = await uni.$u.api.getGlobal(param); if (err) {
commit('setDailyTasks', data); console.error('err: ', err);
} catch (error) { } else {
console.log('task actions getGlobal error: ', error); commit('setDailyTasks', data);
} }
}, });
/**
* 根据时间基准点和角色查找定期任务
* @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 || '获取定期任务失败';
}
}, },
}; };

3
src/store/task/state.js

@ -16,8 +16,7 @@ const state = {
bottomEnd: false, // 时间轴向下查任务到底了 bottomEnd: false, // 时间轴向下查任务到底了
permanents: [], // 永久日常任务 permanents: [], // 永久日常任务
dailyTasks: [], // 日常任务 dailyTasks: [], // 日常任务
// 定期任务 tasks: [], // 所有的定期任务
tasks: [],
showSkeleton: false, // 定期任务骨架屏 showSkeleton: false, // 定期任务骨架屏
}; };

180
src/utils/cache.js

@ -36,8 +36,8 @@ export default {
putProjects(data) { putProjects(data) {
try { try {
if (!data || !data.length) return; // 服务端没数据不做操作 if (!data || !data.length) return; // 服务端没数据不做操作
let value = uni.$t.storage.getStorageSync('projects');
let locals = JSON.parse(uni.$t.storage.getStorageSync('projects')) || []; let locals = value ? JSON.parse(value) : [];
if (!locals || !locals.length) { if (!locals || !locals.length) {
// 本地没数据 // 本地没数据
locals = data || []; 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} startTime
* @param {number} endTime * @param {number} endTime
* @returns * @returns
*/ */
async getDotListByDay(startTime, endTime) { async getStorageRegularTask(params) {
try { try {
const data = await uni.$t.storage.getStorage('dotList'); const data = await uni.$t.storage.getStorage(`plan_task_${params.projectId}_${params.roleId}`);
return filter.projects(JSON.parse(data), startTime, endTime); return JSON.parse(data);
} catch (error) { } catch (error) {
console.error('error: ', error); console.error('error: ', error);
return []; return [];
@ -78,33 +135,132 @@ export default {
}, },
/** /**
* 小红点 * 定期任务
* @param {array} data * @param {array} data
*/ */
putDotList(data) { putStorageRegularTask(params, data) {
try { try {
if (!data || !data.length) return; // 服务端没数据不做操作 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) { if (!locals || !locals.length) {
// 本地没数据 // 本地没数据
locals = data || []; locals = data || [];
} else { } else {
// 本地有数据 // 本地有数据
data.forEach(item => { 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) { if (localData) {
// 有相同数据 就用新的data里的数据 // 有相同数据 就用新的data里的数据
localData = item; localData = item;
} else { } else {
locals.splice(index, 1);
// 没有就直接存本地 // 没有就直接存本地
locals.push(item); locals.push(item);
} }
}); });
} }
uni.$t.storage.setStorage('dotList', locals); uni.$t.storage.setStorage(`variable_tasks_${params.projectId}`, locals);
} catch (error) { } catch (error) {
console.error('error: ', error); console.error('error: ', error);
uni.$t.storage.setStorage('dotList', []); uni.$t.storage.setStorage(`variable_tasks_${params.projectId}`, []);
} }
}, },
}; };

103
src/utils/cacheAndRequest.js

@ -24,7 +24,6 @@ export default {
uni.$t.cache uni.$t.cache
.getProjectsByDay(startTime, endTime) .getProjectsByDay(startTime, endTime)
.then(data => { .then(data => {
// console.log('cache data: ', data);
!remote && fn(null, data); !remote && fn(null, data);
}) })
.catch(err => !remote && fn(err)); .catch(err => !remote && fn(err));
@ -34,7 +33,6 @@ export default {
uni.$u.api uni.$u.api
.getProjects(startTime, endTime) .getProjects(startTime, endTime)
.then(data => { .then(data => {
// console.log('api data: ', data);
remote = true; remote = true;
fn(null, data); fn(null, data);
// 存api到cache里 // 存api到cache里
@ -45,17 +43,15 @@ export default {
}, },
/** /**
* 查询小红点 * 通过项目id获取角色信息
* @param { string } endTime 结束时间 * @param {object} params 提交的参数
* @param { string } startTime 开始时间
*/ */
findRedPoint(startTime, endTime, fn) { findShowRole(params, fn) {
let remote = false; let remote = false;
// 有缓存 且 服务端数据未返回 就先返回缓存 // 有缓存 且 服务端数据未返回 就先返回缓存
uni.$t.cache uni.$t.cache
.getDotListByDay(startTime, endTime) .getShowRole(params.projectId)
.then(data => { .then(data => {
// console.log('cache data: ', data);
!remote && fn(null, data); !remote && fn(null, data);
}) })
.catch(err => !remote && fn(err)); .catch(err => !remote && fn(err));
@ -63,13 +59,98 @@ export default {
waitTokenRequest(() => { waitTokenRequest(() => {
// 拿到api数据后 再用api的数据 // 拿到api数据后 再用api的数据
uni.$u.api uni.$u.api
.findRedPoint(startTime, endTime) .findShowRole(params)
.then(data => { .then(data => {
// console.log('api data: ', data);
remote = true; remote = true;
fn(null, data); fn(null, data);
// 存api到cache里 // 存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)); .catch(err => fn(err));
}); });

Loading…
Cancel
Save