|
|
@ -30,7 +30,7 @@ export default function useGetTasks() { |
|
|
|
|
|
|
|
// 初始化 定期任务
|
|
|
|
async function initPlanTasks() { |
|
|
|
if (timeLineType.value === 1) setNextPlaceholderTasks({}); |
|
|
|
// if (timeLineType.value === 1) setNextPlaceholderTasks({});
|
|
|
|
console.log('查询定期任务11111111111111111'); |
|
|
|
await getTasks({}); // 获取初始数据
|
|
|
|
// await dataRender({});
|
|
|
@ -90,9 +90,9 @@ export default function useGetTasks() { |
|
|
|
params.queryType === 0 ? store.commit('task/setUpNextPage', arr[index].upNextPage) : store.commit('task/setDownNextPage', arr[index].downNextPage); // 下一页
|
|
|
|
|
|
|
|
// 如果第一次渲染但没有空数据则加载空数据
|
|
|
|
if (!currRoleShowTasks.value || !currRoleShowTasks.value.length && timeLineType.value === 1) { |
|
|
|
setNextPlaceholderTasks(params); |
|
|
|
} |
|
|
|
// if (!currRoleShowTasks.value || !currRoleShowTasks.value.length && timeLineType.value === 1) {
|
|
|
|
// setNextPlaceholderTasks(params);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 数据处理
|
|
|
|
dataRender(params); |
|
|
@ -177,67 +177,73 @@ export default function useGetTasks() { |
|
|
|
* 3-2-2-1、否。查找下一页数据并重复上述步骤 |
|
|
|
*/ |
|
|
|
let showTasks = currRoleShowTasks.value; // 显示的数据
|
|
|
|
let firstTime = showTasks.length > 0 ? showTasks[0].planStart : new Date().getTime(); // 显示的数据第一个数据的时间
|
|
|
|
let lastTime = showTasks.length > 0 ? showTasks[showTasks.length - 1].planStart : new Date().getTime(); // 显示的数据最后一个数据的时间
|
|
|
|
const nextPage = params.queryType === 0 ? upNextPage.value : downNextPage.value; // 下一页的值
|
|
|
|
if (centerData.length) { |
|
|
|
let centerDataTime = '', // 中间数据的时间
|
|
|
|
scaleTime = '', // 空时间节点的开始时间
|
|
|
|
centerTime = '', // 中间数据+/-15后的数据
|
|
|
|
isExceed = false; // 时间跨度是否大于15
|
|
|
|
|
|
|
|
if (params.queryType) { |
|
|
|
centerDataTime = centerData[centerData.length - 1].planStart; |
|
|
|
scaleTime = currDownTimeNode.value; |
|
|
|
centerTime = dayjs(+centerDataTime).subtract(params.pageSize, timeGranularity.value); |
|
|
|
isExceed = dayjs(+centerTime).isSame(+scaleTime, timeGranularity.value) || dayjs(+centerTime).isAfter(+scaleTime, timeGranularity.value) |
|
|
|
} else { |
|
|
|
centerDataTime = centerData[0].planStart; |
|
|
|
scaleTime = currUpTimeNode.value; |
|
|
|
centerTime = dayjs(+centerDataTime).add(params.pageSize, timeGranularity.value); |
|
|
|
isExceed = dayjs(+centerTime).isSame(+scaleTime, timeGranularity.value) || dayjs(+centerTime).isBefore(+scaleTime, timeGranularity.value) |
|
|
|
} |
|
|
|
let addNum = 0; |
|
|
|
centerData.forEach(v => { |
|
|
|
let showFirstTime = showTasks.length > 0 ? showTasks[0].planStart : new Date().getTime(); // 显示的数据第一个数据的时间
|
|
|
|
let showLastTime = new Date().getTime(); // 显示的数据最后一个数据的时间
|
|
|
|
|
|
|
|
const firstDetailIndex = showTasks.findIndex(task => task.detailId); // 显示任务中存在真实任务
|
|
|
|
const firstId = firstDetailIndex > -1 ? showTasks[firstDetailIndex].id : ''; |
|
|
|
let lastDetailIndex = -1; |
|
|
|
showTasks.forEach((item, index) => { |
|
|
|
if (item.detailId) { |
|
|
|
lastDetailIndex = index; |
|
|
|
if (showTasks.length) { |
|
|
|
showLastTime = dayjs(+showTasks[showTasks.length - 1].planStart).add(1, timeGranularity.value); |
|
|
|
} |
|
|
|
}) |
|
|
|
const lastId = lastDetailIndex > -1 ? showTasks[lastDetailIndex].id : ''; |
|
|
|
|
|
|
|
showTasks.forEach((task, index) => { |
|
|
|
const arr = centerData.filter(item => dayjs(+item.planStart).isSame(+task.planStart, timeGranularity.value)); |
|
|
|
if (arr.length) { |
|
|
|
if (params.queryType === 1 && task.id === lastId) { |
|
|
|
showTasks.splice(index + 1, 0, [...arr]) |
|
|
|
} else if (params.queryType === 0 && task.id === firstId) { |
|
|
|
showTasks.splice(index, 0, [...arr]) |
|
|
|
} else { |
|
|
|
showTasks.splice(index, 1, [...arr]) |
|
|
|
} |
|
|
|
|
|
|
|
let dayNum = 0; // 两个日期中间相差的天数
|
|
|
|
let centerTime = '', // 中间数据+/-15后的数据
|
|
|
|
isExceed = false; // 时间跨度是否大于15
|
|
|
|
|
|
|
|
if (params.queryType) { |
|
|
|
dayNum = dayjs(+v.planStart).diff(+showLastTime, timeGranularity.value, true); |
|
|
|
// if (!showTasks.length) dayNum++;
|
|
|
|
centerTime = dayjs(+v.planStart).subtract(params.pageSize, timeGranularity.value); |
|
|
|
isExceed = dayjs(+centerTime).isAfter(+showLastTime, timeGranularity.value) |
|
|
|
} else { |
|
|
|
dayNum = dayjs(+v.planStart).diff(+showFirstTime, timeGranularity.value); |
|
|
|
centerTime = dayjs(+v.planStart).add(params.pageSize, timeGranularity.value); |
|
|
|
isExceed = dayjs(+centerTime).isBefore(+showFirstTime, timeGranularity.value) |
|
|
|
} |
|
|
|
dayNum = dayjs(+'1647513785000').get('month'); |
|
|
|
console.log(dayNum, v.planStart, showLastTime); |
|
|
|
|
|
|
|
if (!isExceed) { |
|
|
|
addNum++; |
|
|
|
let time = params.queryType === 0 ? showFirstTime : showLastTime; |
|
|
|
const newTasks = uni.$task.setPlaceholderTasks(+time, !params.queryType, timeGranularity.value, dayNum); |
|
|
|
params.queryType === 0 ? showTasks.splice(0, 0, newTasks) : showTasks.splice(showTasks.length, 0, newTasks); |
|
|
|
params.queryType === 0 ? showTasks.splice(0, 0, v) : showTasks.splice(showTasks.length, 0, v); |
|
|
|
// showTasks = flatten(showTasks); // 1维拍平
|
|
|
|
console.log('isExceed', showTasks, v) |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
showTasks = flatten(showTasks); // 1维拍平
|
|
|
|
|
|
|
|
if (!isExceed) { |
|
|
|
if (centerData.length >= params.pageSize) { |
|
|
|
let len = -1; |
|
|
|
let data = params.queryType === 0 ? centerData[0] : centerData[centerData.length - 1]; |
|
|
|
showTasks.forEach((item, index) => { |
|
|
|
if (item.id === data.id) { |
|
|
|
len = index; |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
if (len > -1) { |
|
|
|
showTasks = params.queryType === 0 ? showTasks.slice(len) : showTasks.slice(0, len + 1); |
|
|
|
} |
|
|
|
} else if (nextPage > 0) { |
|
|
|
console.log('数据不为空,时间跨度小于15') |
|
|
|
if (!addNum) { |
|
|
|
params.queryType === 0 ? setPrevPlaceholderTasks(params) : setNextPlaceholderTasks(params); |
|
|
|
} else { |
|
|
|
if (addNum === centerData.length && centerData.length < params.pageSize && nextPage > 0) { |
|
|
|
getTasks({pageNum: nextPage, queryType: params.queryType}); |
|
|
|
} |
|
|
|
|
|
|
|
if (addNum < centerData.length || (addNum === centerData.length && centerData.length < params.pageSize && nextPage === 0)) { |
|
|
|
// 补齐刻度
|
|
|
|
// const obj = { tasks: showTasks, data, timeGranularity: timeGranularity.value };
|
|
|
|
// showTasks = fillPlaceholderTask(obj);
|
|
|
|
let num = ''; |
|
|
|
if (params.queryType === 0) { |
|
|
|
num = dayjs(+showTasks[0].planStart).diff(+firstTime, timeGranularity.value); |
|
|
|
} else { |
|
|
|
num = dayjs(+showTasks[showTasks.length - 1].planStart).diff(+lastTime, timeGranularity.value); |
|
|
|
} |
|
|
|
console.log('2222222222', firstTime, lastTime, num) |
|
|
|
|
|
|
|
if (addNum < centerData.length) { |
|
|
|
console.log('11111111111111111') |
|
|
|
renderScaleTask(params); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (nextPage > 0) { |
|
|
@ -251,7 +257,7 @@ export default function useGetTasks() { |
|
|
|
// if (showTasks.length > 30) {
|
|
|
|
// showTasks = params.queryType === 0 ? showTasks.slice(0, 80) : showTasks.slice(showTasks.length - 80);
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
store.commit('task/clearTasks'); |
|
|
|
params.queryType === 0 ? store.commit('task/setUpTasks', showTasks) : store.commit('task/setDownTasks', showTasks); |
|
|
|
} |
|
|
@ -284,6 +290,22 @@ export default function useGetTasks() { |
|
|
|
params.queryType === 0 ? store.commit('task/setUpTasks', showTasks) : store.commit('task/setDownTasks', showTasks); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 超出旧数据上、下限 补齐时间刻度到新数据的起始时间颗粒度 |
|
|
|
*/ |
|
|
|
function fillPlaceholderTask(obj) { |
|
|
|
const { prev, next } = uni.$task.computeFillPlaceholderTaskCount(obj); |
|
|
|
if (prev) { |
|
|
|
const newTasks = uni.$task.setPlaceholderTasks(+obj.tasks[0].planStart, true, obj.timeGranularity, prev); |
|
|
|
store.commit('task/setUpTasks', newTasks); |
|
|
|
} |
|
|
|
if (next) { |
|
|
|
const newTasks = uni.$task.setPlaceholderTasks(+obj.tasks[obj.tasks.length - 1].planStart, false, obj.timeGranularity, next); |
|
|
|
store.commit('task/setDownTasks', newTasks); |
|
|
|
} |
|
|
|
return tasks.value; |
|
|
|
} |
|
|
|
|
|
|
|
// 设置时间轴向上的空数据
|
|
|
|
function setPrevPlaceholderTasks() { |
|
|
|
store.commit('task/setTopEnd', true); |
|
|
@ -308,13 +330,13 @@ export default function useGetTasks() { |
|
|
|
startTime = dayjs(+currRoleShowTasks.value[currRoleShowTasks.value.length - 1].planStart).add(1, timeGranularity.value).valueOf(); |
|
|
|
} |
|
|
|
|
|
|
|
if (params.taskId) { |
|
|
|
currRoleRealTasks.value.forEach(item => { |
|
|
|
if (item.id === params.taskId) { |
|
|
|
startTime = Number(item.planStart); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
// if (params.taskId) {
|
|
|
|
// currRoleRealTasks.value.forEach(item => {
|
|
|
|
// if (item.id === params.taskId) {
|
|
|
|
// startTime = Number(item.planStart);
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// }
|
|
|
|
|
|
|
|
const initData = uni.$task.setPlaceholderTasks(startTime, false, timeGranularity.value); |
|
|
|
store.commit('task/setCurrDownTimeNode', startTime); |
|
|
|