|
|
|
@ -89,6 +89,20 @@ const formatGanttDate = (value: unknown) => {
|
|
|
|
return date.format('YYYY-MM-DD HH:mm')
|
|
|
|
return date.format('YYYY-MM-DD HH:mm')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDeviceTaskRangeByChildren = (planTasks: any[]) => {
|
|
|
|
|
|
|
|
const starts = planTasks.map((item: any) => dayjs(item?.start_date)).filter((item: any) => item.isValid())
|
|
|
|
|
|
|
|
const ends = planTasks.map((item: any) => dayjs(item?.end_date)).filter((item: any) => item.isValid())
|
|
|
|
|
|
|
|
if (!starts.length || !ends.length) return undefined
|
|
|
|
|
|
|
|
const earliestStart = starts.reduce((min: any, current: any) => (current.valueOf() < min.valueOf() ? current : min))
|
|
|
|
|
|
|
|
const latestEnd = ends.reduce((max: any, current: any) => (current.valueOf() > max.valueOf() ? current : max))
|
|
|
|
|
|
|
|
const duration = Math.max(latestEnd.endOf('day').diff(earliestStart.startOf('day'), 'day') + 1, 1)
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
start_date: earliestStart.toDate(),
|
|
|
|
|
|
|
|
end_date: latestEnd.toDate(),
|
|
|
|
|
|
|
|
duration
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const buildPreviewGanttData = (scheduleList: any[]) => {
|
|
|
|
const buildPreviewGanttData = (scheduleList: any[]) => {
|
|
|
|
const tasks: any[] = []
|
|
|
|
const tasks: any[] = []
|
|
|
|
const links: any[] = []
|
|
|
|
const links: any[] = []
|
|
|
|
@ -105,19 +119,23 @@ const buildPreviewGanttData = (scheduleList: any[]) => {
|
|
|
|
.filter((plan: any) => plan._start.isValid() && plan._end.isValid())
|
|
|
|
.filter((plan: any) => plan._start.isValid() && plan._end.isValid())
|
|
|
|
.sort((a: any, b: any) => a._start.valueOf() - b._start.valueOf())
|
|
|
|
.sort((a: any, b: any) => a._start.valueOf() - b._start.valueOf())
|
|
|
|
const firstPlan = validPlans[0]
|
|
|
|
const firstPlan = validPlans[0]
|
|
|
|
const lastPlan = validPlans[validPlans.length - 1]
|
|
|
|
const deviceRange = getDeviceTaskRangeByChildren(
|
|
|
|
const parentDuration =
|
|
|
|
validPlans.map((item: any) => ({
|
|
|
|
firstPlan && lastPlan ? Math.max(lastPlan._end.endOf('day').diff(firstPlan._start.startOf('day'), 'day') + 1, 1) : 1
|
|
|
|
start_date: item?._start,
|
|
|
|
|
|
|
|
end_date: item?._end
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
tasks.push({
|
|
|
|
tasks.push({
|
|
|
|
id: deviceId,
|
|
|
|
id: deviceId,
|
|
|
|
text: `${device.deviceName ?? '-'}`,
|
|
|
|
text: `${device.deviceName ?? '-'}`,
|
|
|
|
start_date: formatGanttDate(firstPlan?._start),
|
|
|
|
start_date: formatGanttDate(deviceRange?.start_date ?? firstPlan?._start),
|
|
|
|
end_date: formatGanttDate(lastPlan?._end),
|
|
|
|
end_date: formatGanttDate(deviceRange?.end_date ?? firstPlan?._end),
|
|
|
|
duration: parentDuration,
|
|
|
|
duration: deviceRange?.duration ?? 1,
|
|
|
|
parent: 0,
|
|
|
|
parent: 0,
|
|
|
|
progress: 0,
|
|
|
|
progress: 0,
|
|
|
|
open: true,
|
|
|
|
open: true,
|
|
|
|
|
|
|
|
readonly: true,
|
|
|
|
deviceName: device.deviceName ?? '-',
|
|
|
|
deviceName: device.deviceName ?? '-',
|
|
|
|
_deviceData: device
|
|
|
|
_deviceData: device
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@ -181,6 +199,23 @@ const syncPlanTimeFromTask = (task: any) => {
|
|
|
|
activePreviewDevice.value = task._deviceData
|
|
|
|
activePreviewDevice.value = task._deviceData
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const syncDeviceTaskRangeFromChildren = (task: any) => {
|
|
|
|
|
|
|
|
if (!task?._planData) return
|
|
|
|
|
|
|
|
const deviceTaskId = task.parent
|
|
|
|
|
|
|
|
if (!deviceTaskId) return
|
|
|
|
|
|
|
|
const childTaskIds = gantt.getChildren(deviceTaskId)
|
|
|
|
|
|
|
|
if (!Array.isArray(childTaskIds) || !childTaskIds.length) return
|
|
|
|
|
|
|
|
const childTasks = childTaskIds.map((childId: string | number) => gantt.getTask(childId)).filter((item: any) => item?._planData)
|
|
|
|
|
|
|
|
if (!childTasks.length) return
|
|
|
|
|
|
|
|
const deviceRange = getDeviceTaskRangeByChildren(childTasks)
|
|
|
|
|
|
|
|
if (!deviceRange) return
|
|
|
|
|
|
|
|
const deviceTask = gantt.getTask(deviceTaskId)
|
|
|
|
|
|
|
|
deviceTask.start_date = deviceRange.start_date
|
|
|
|
|
|
|
|
deviceTask.end_date = deviceRange.end_date
|
|
|
|
|
|
|
|
deviceTask.duration = deviceRange.duration
|
|
|
|
|
|
|
|
gantt.updateTask(deviceTaskId)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const refreshTimelineRangeByTasks = () => {
|
|
|
|
const refreshTimelineRangeByTasks = () => {
|
|
|
|
let minStart = Number.POSITIVE_INFINITY
|
|
|
|
let minStart = Number.POSITIVE_INFINITY
|
|
|
|
let maxEnd = Number.NEGATIVE_INFINITY
|
|
|
|
let maxEnd = Number.NEGATIVE_INFINITY
|
|
|
|
@ -318,18 +353,28 @@ const initGanttPreview = () => {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const beforeDragEventId = gantt.attachEvent('onBeforeTaskDrag', (id) => {
|
|
|
|
|
|
|
|
const task = gantt.getTask(id)
|
|
|
|
|
|
|
|
if (!task?._planData) return false
|
|
|
|
|
|
|
|
return String(task?._planData?.sourceType ?? '').toUpperCase() === 'CURRENT'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const dragEventId = gantt.attachEvent('onAfterTaskDrag', (id) => {
|
|
|
|
const dragEventId = gantt.attachEvent('onAfterTaskDrag', (id) => {
|
|
|
|
syncPlanTimeFromTask(gantt.getTask(id))
|
|
|
|
const task = gantt.getTask(id)
|
|
|
|
|
|
|
|
syncPlanTimeFromTask(task)
|
|
|
|
|
|
|
|
syncDeviceTaskRangeFromChildren(task)
|
|
|
|
refreshTimelineRangeByTasks()
|
|
|
|
refreshTimelineRangeByTasks()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const updateEventId = gantt.attachEvent('onAfterTaskUpdate', (id) => {
|
|
|
|
const updateEventId = gantt.attachEvent('onAfterTaskUpdate', (id) => {
|
|
|
|
syncPlanTimeFromTask(gantt.getTask(id))
|
|
|
|
const task = gantt.getTask(id)
|
|
|
|
|
|
|
|
syncPlanTimeFromTask(task)
|
|
|
|
|
|
|
|
syncDeviceTaskRangeFromChildren(task)
|
|
|
|
refreshTimelineRangeByTasks()
|
|
|
|
refreshTimelineRangeByTasks()
|
|
|
|
gantt.refreshTask(id)
|
|
|
|
gantt.refreshTask(id)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
ganttEventIds.value.push(clickEventId, dragEventId, updateEventId)
|
|
|
|
ganttEventIds.value.push(clickEventId, beforeDragEventId, dragEventId, updateEventId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handlePreviewSave = async () => {
|
|
|
|
const handlePreviewSave = async () => {
|
|
|
|
|