diff --git a/src/locales/en.ts b/src/locales/en.ts index 62412256..27de02b9 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -4654,6 +4654,7 @@ export default { warningCompleteDeviceDate: 'Please complete device, start date and end date', warningValidTime: 'Please select a valid time', warningEndBeforeStart: 'End time cannot be earlier than start time', + warningDragOutOfRange: 'Drag out of date range, reverted to original position', columnTaskName: 'Task Name', columnDeviceName: 'Device Name', columnPlanInfo: 'Plan Info', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index c8c0f053..3f79dd51 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -4865,6 +4865,7 @@ export default { warningCompleteDeviceDate: '请完善设备、计划开始日期和计划结束日期', warningValidTime: '请选择有效的时间', warningEndBeforeStart: '结束时间不能早于开始时间', + warningDragOutOfRange: '拖拽超出日期范围,已恢复原位', columnTaskName: '任务名称', columnDeviceName: '设备名称', columnPlanInfo: '计划信息', diff --git a/src/views/mes/tasksummary/components/ScheduleGanttPanelEditable.vue b/src/views/mes/tasksummary/components/ScheduleGanttPanelEditable.vue index 8a9bf268..639b13ab 100644 --- a/src/views/mes/tasksummary/components/ScheduleGanttPanelEditable.vue +++ b/src/views/mes/tasksummary/components/ScheduleGanttPanelEditable.vue @@ -462,11 +462,18 @@ const attachPlanBarDrag = (bar: HTMLElement, plan: any, task: any) => { if (!moved) return moved = false - saveUndoSnapshot() - const dx = e.clientX - startX const newLeft = Math.max(0, startLeft + dx) const newStartDate = gantt.dateFromPos(newLeft) + + if (!newStartDate || !dayjs(newStartDate).isValid()) { + message.warning(t('GanttChart.GanttPanel.warningDragOutOfRange')) + initGanttPreview() + return + } + + saveUndoSnapshot() + const planDuration = dayjs(plan.planEndTimeStr).diff(dayjs(plan.planStartTimeStr), 'millisecond') const newEndDate = new Date(newStartDate.getTime() + planDuration) @@ -568,13 +575,19 @@ const attachPlanBarResize = (bar: HTMLElement, plan: any, task: any) => { resizing = false bar.style.zIndex = '2' - saveUndoSnapshot() - const newLeft = parseFloat(bar.style.left) || startLeft const newWidth = parseFloat(bar.style.width) || startWidth const newStartDate = gantt.dateFromPos(newLeft) const newEndDate = gantt.dateFromPos(newLeft + newWidth) + if (!newStartDate || !newEndDate || !dayjs(newStartDate).isValid() || !dayjs(newEndDate).isValid()) { + message.warning(t('GanttChart.GanttPanel.warningDragOutOfRange')) + initGanttPreview() + return + } + + saveUndoSnapshot() + const identity = makePlanIdentity(plan) const original = findOriginalPlan(identity) if (original) {