|
@ -27,16 +27,62 @@ export const filter = { |
|
|
* @param {number} timeNode 时间基准点 ms |
|
|
* @param {number} timeNode 时间基准点 ms |
|
|
* @param {number} queryNum 颗粒度数量 |
|
|
* @param {number} queryNum 颗粒度数量 |
|
|
* @param {number} timeUnit 时间颗粒度 |
|
|
* @param {number} timeUnit 时间颗粒度 |
|
|
|
|
|
* @param {number} queryType 0向上查找 1向下查找(默认) 下查包含自己,上查不包含 |
|
|
* @returns |
|
|
* @returns |
|
|
*/ |
|
|
*/ |
|
|
planTask(data, timeNode, queryNum, timeUnit) { |
|
|
planTask(data, timeNode, queryNum, timeUnit, queryType) { |
|
|
if (!data || !data.length) return []; |
|
|
if (!data || !data.length) return []; |
|
|
// 计算颗粒度 对应的 dayjs add 的单位
|
|
|
if (queryType === 0) { |
|
|
const target = uni.$t.timeConfig.timeUnits.find(item => item.id === timeUnit); |
|
|
// 计算颗粒度 对应的 dayjs add 的单位
|
|
|
// TODO: 缺少通过时间颗粒度筛选数据 任务没有返回时间颗粒度标签
|
|
|
let target = uni.$t.timeConfig.timeUnits.find(item => item.id === timeUnit); |
|
|
const start = uni.$t.time.add(timeNode, -queryNum, target.granularity).valueOf(); |
|
|
// TODO: 缺少通过时间颗粒度筛选数据 任务没有返回时间颗粒度标签
|
|
|
const end = uni.$t.time.add(timeNode, +queryNum - 1, target.granularity).valueOf(); |
|
|
let start = uni.$t.time.add(+timeNode, -queryNum, target.granularity).valueOf(); |
|
|
return data.filter(item => start <= +item.endTime && end >= +item.startTime); |
|
|
let arr = []; |
|
|
|
|
|
arr = data.filter(item => start <= +item.planStart && +timeNode > +item.planEnd); |
|
|
|
|
|
|
|
|
|
|
|
if (!arr || !arr.length) { |
|
|
|
|
|
// 开始时间往前推
|
|
|
|
|
|
let resultS = []; |
|
|
|
|
|
let againStart = uni.$t.time.add(start, -1, target.granularity).valueOf(); |
|
|
|
|
|
let againArr = data.filter(item => againStart >= +item.planStart); |
|
|
|
|
|
if (againArr && againArr.length) { |
|
|
|
|
|
let sTime = uni.$t.time.setTimestampToStr(+againArr[0].planStart); |
|
|
|
|
|
data.forEach(item => { |
|
|
|
|
|
if (uni.$t.time.isSame(uni.$moment(sTime.date).valueOf(), +item.planStart, target.granularity)) { |
|
|
|
|
|
resultS.push(item); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
return resultS; |
|
|
|
|
|
} else { |
|
|
|
|
|
return arr; |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 计算颗粒度 对应的 dayjs add 的单位
|
|
|
|
|
|
let target = uni.$t.timeConfig.timeUnits.find(item => item.id === timeUnit); |
|
|
|
|
|
// TODO: 缺少通过时间颗粒度筛选数据 任务没有返回时间颗粒度标签
|
|
|
|
|
|
let end = uni.$t.time.add(timeNode, +queryNum - 1, target.granularity).valueOf(); |
|
|
|
|
|
let arr = []; |
|
|
|
|
|
arr = data.filter(item => end >= +item.planEnd && +timeNode <= +item.planStart); |
|
|
|
|
|
|
|
|
|
|
|
if (!arr || !arr.length) { |
|
|
|
|
|
// 结束时间往后推
|
|
|
|
|
|
let resultE = []; |
|
|
|
|
|
let againEnd = uni.$t.time.add(end, 1, target.granularity).valueOf(); |
|
|
|
|
|
let againEndArr = data.filter(item => againEnd <= +item.planStart); |
|
|
|
|
|
if (againEndArr) { |
|
|
|
|
|
let eTime = uni.$t.time.setTimestampToStr(+againEndArr[againEndArr.length - 1].planStart); |
|
|
|
|
|
data.forEach(item => { |
|
|
|
|
|
if (uni.$t.time.isSame(uni.$moment(eTime.date).valueOf(), +item.planEnd, target.granularity)) { |
|
|
|
|
|
resultE.push(item); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
return resultE; |
|
|
|
|
|
} else { |
|
|
|
|
|
return arr; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -114,7 +160,6 @@ export default { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
uni.$t.cache.checkCapacity(); |
|
|
|
|
|
uni.$t.storage.setStorage('projects', locals); |
|
|
uni.$t.storage.setStorage('projects', locals); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('error: ', error); |
|
|
console.error('error: ', error); |
|
@ -172,7 +217,6 @@ export default { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
uni.$t.cache.checkCapacity(); |
|
|
|
|
|
uni.$t.storage.setStorage(`roles_${projectId}`, locals); |
|
|
uni.$t.storage.setStorage(`roles_${projectId}`, locals); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('error: ', error); |
|
|
console.error('error: ', error); |
|
@ -189,7 +233,7 @@ export default { |
|
|
async getStorageRegularTask(params) { |
|
|
async getStorageRegularTask(params) { |
|
|
try { |
|
|
try { |
|
|
const data = await uni.$t.storage.getStorage(`plan_task_${params.projectId}_${params.roleId}`); |
|
|
const data = await uni.$t.storage.getStorage(`plan_task_${params.projectId}_${params.roleId}`); |
|
|
return filter.planTask(JSON.parse(data), params.timeNode, params.queryNum, params.timeUnit); |
|
|
return filter.planTask(JSON.parse(data), params.timeNode, params.queryNum, params.timeUnit, params.queryType); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('error: ', error); |
|
|
console.error('error: ', error); |
|
|
return []; |
|
|
return []; |
|
@ -221,7 +265,6 @@ export default { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
uni.$t.cache.checkCapacity(); |
|
|
|
|
|
uni.$t.storage.setStorage(`plan_task_${params.projectId}_${params.roleId}`, locals); |
|
|
uni.$t.storage.setStorage(`plan_task_${params.projectId}_${params.roleId}`, locals); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('error: ', error); |
|
|
console.error('error: ', error); |
|
@ -271,7 +314,6 @@ export default { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
uni.$t.cache.checkCapacity(); |
|
|
|
|
|
uni.$t.storage.setStorage(`fixed_tasks_${params.projectId}_${params.roleId}`, locals); |
|
|
uni.$t.storage.setStorage(`fixed_tasks_${params.projectId}_${params.roleId}`, locals); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('error: ', error); |
|
|
console.error('error: ', error); |
|
@ -319,7 +361,6 @@ export default { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
uni.$t.cache.checkCapacity(); |
|
|
|
|
|
uni.$t.storage.setStorage(`variable_tasks_${params.projectId}_${params.roleId}`, locals); |
|
|
uni.$t.storage.setStorage(`variable_tasks_${params.projectId}_${params.roleId}`, locals); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('error: ', error); |
|
|
console.error('error: ', error); |
|
@ -359,24 +400,10 @@ export default { |
|
|
// 本地有数据
|
|
|
// 本地有数据
|
|
|
locals = data; |
|
|
locals = data; |
|
|
} |
|
|
} |
|
|
uni.$t.cache.checkCapacity(); |
|
|
|
|
|
uni.$t.storage.setStorage(`plugin_${pluginId}`, locals); |
|
|
uni.$t.storage.setStorage(`plugin_${pluginId}`, locals); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
console.error('error: ', error); |
|
|
console.error('error: ', error); |
|
|
uni.$t.storage.setStorage(`plugin_${pluginId}`, null); |
|
|
uni.$t.storage.setStorage(`plugin_${pluginId}`, null); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
// 检测local Storage容量
|
|
|
|
|
|
checkCapacity() { |
|
|
|
|
|
// if (window.localStorage) {
|
|
|
|
|
|
// console.log('浏览器不支持localStorage ');
|
|
|
|
|
|
// const capacity = JSON.stringify(localStorage).length;
|
|
|
|
|
|
// console.log('capacity: ', capacity);
|
|
|
|
|
|
// let max = 1024 * 1024 * 5;
|
|
|
|
|
|
// if (capacity >= max) {
|
|
|
|
|
|
// uni.$t.storage.clearStorage();
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
}, |
|
|
|
|
|
}; |
|
|
}; |
|
|