5 changed files with 139 additions and 20 deletions
@ -0,0 +1,63 @@ |
|||
import dayjs from 'dayjs'; |
|||
|
|||
/** |
|||
* 设置时间轴空数据 |
|||
* @param {number} startTime |
|||
* @param {boolean} isUp true 向上加载,false 向下加载 |
|||
* @param {string} timeGranularity 颗粒度 |
|||
* @param {number} pageCount 加载的颗粒度数量 默认值是10 |
|||
*/ |
|||
const setPlaceholderTasks = (startTime, isUp, timeGranularity, pageCount) => { |
|||
const result = []; |
|||
pageCount = pageCount || 10; |
|||
for (let i = 0; i < pageCount; i++) { |
|||
const delta = isUp ? `-${i + 1}` - 0 : i; |
|||
|
|||
const item = { |
|||
id: Math.random() * 1000000000000000000, |
|||
panel: {}, |
|||
plugins: [], |
|||
process: 4, |
|||
planStart: dayjs(+startTime) |
|||
.add(+delta, timeGranularity) |
|||
.valueOf(), |
|||
}; |
|||
console.log('11111111', item); |
|||
// console.log('isup: ', isUp, 'result:', new Date(item.planStart).toLocaleDateString());
|
|||
|
|||
isUp ? result.unshift(item) : result.push(item); |
|||
} |
|||
return result; |
|||
}; |
|||
|
|||
/** |
|||
* 超出旧数据上、下限 补齐时间刻度到新数据的起始时间颗粒度 |
|||
* @param {object} option |
|||
* @param {array} option.tasks 旧的已有的任务书籍 |
|||
* @param {array} option.data 新拿到的任务数据 空值已经过滤过了 |
|||
* @param {string} option.timeGranularity 颗粒度 |
|||
*/ |
|||
const computeFillPlaceholderTaskCount = obj => { |
|||
const { tasks, data, timeGranularity } = obj; |
|||
const result = { prev: 0, next: 0 }; |
|||
// 新数据的开始时间 < 旧数据的开始时间
|
|||
// 超出了上限 补上限的时间刻度
|
|||
// 补上 新数据开始时间 到 旧数据开始时间 的刻度
|
|||
if (+data[0].planStart < +tasks[0].planStart) { |
|||
// 找出来需要补几组颗粒度
|
|||
result.prev = dayjs(+tasks[0].planStart).diff(+data[0].planStart, timeGranularity) + 1; |
|||
} |
|||
|
|||
// 新数据的结束时间 > 旧数据的结束时间
|
|||
// 超出了下线 补下限的时间刻度
|
|||
// 补上 旧数据截止时间 到 新数据截止时间 的刻度
|
|||
if (+data[data.length - 1].planStart > +tasks[tasks.length - 1].planStart) { |
|||
result.next = dayjs(+data[data.length - 1].planStart).diff(+tasks[tasks.length - 1].planStart, timeGranularity) + 1; |
|||
} |
|||
return result; |
|||
}; |
|||
|
|||
export default { |
|||
setPlaceholderTasks, |
|||
computeFillPlaceholderTaskCount, |
|||
}; |
|||
@ -0,0 +1,17 @@ |
|||
export default { |
|||
timeUnits: [ |
|||
// 时间颗粒度
|
|||
{ id: 0, value: '毫秒', format: 'x', cycle: 'YY-M-D HH:mm:ss', granularity: 'millisecond' }, |
|||
{ id: 1, value: '秒', format: 'x', cycle: 'YY-M-D HH:mm:ss', granularity: 'second' }, |
|||
{ id: 2, value: '分', format: 'ss', cycle: 'YY-M-D HH:mm', granularity: 'minute' }, |
|||
{ id: 3, value: '时', format: 'mm', cycle: 'YY-M-D HH时', granularity: 'hour' }, |
|||
{ id: 4, value: '天', format: 'M月D日 HH:mm', cycle: 'YY-M-D', granularity: 'day' }, |
|||
{ id: 5, value: '周', format: 'M月D日 HH:mm', cycle: '', granularity: 'week' }, |
|||
{ id: 6, value: '月', format: 'M月D日 H:m', cycle: 'YYYY年', granularity: 'month' }, |
|||
{ id: 7, value: '季度', format: '', cycle: 'YYYY年', granularity: 'quarter' }, |
|||
{ id: 8, value: '年', format: 'YYYY', cycle: '', granularity: 'year' }, |
|||
{ id: 9, value: '年代', format: '', cycle: '', granularity: '' }, |
|||
{ id: 10, value: '世纪', format: '', cycle: '', granularity: '' }, |
|||
{ id: 11, value: '千年', format: '', cycle: '', granularity: '' }, |
|||
], |
|||
}; |
|||
Loading…
Reference in new issue