|
|
|
|
@ -90,9 +90,11 @@ const props = withDefaults(
|
|
|
|
|
defineProps<{
|
|
|
|
|
scheduleList: any[]
|
|
|
|
|
height?: string
|
|
|
|
|
editable?: boolean
|
|
|
|
|
}>(),
|
|
|
|
|
{
|
|
|
|
|
height: '800px'
|
|
|
|
|
height: '800px',
|
|
|
|
|
editable: false
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -109,6 +111,18 @@ const taskAdjustForm = reactive({
|
|
|
|
|
endDate: ''
|
|
|
|
|
})
|
|
|
|
|
const editingPlanIdentity = ref<string | null>(null)
|
|
|
|
|
const undoStack = ref<string[]>([])
|
|
|
|
|
|
|
|
|
|
const saveUndoSnapshot = () => {
|
|
|
|
|
const data = previewScheduleList.value.map((device: any) => ({
|
|
|
|
|
deviceId: device.deviceId,
|
|
|
|
|
deviceName: device.deviceName,
|
|
|
|
|
capacityType: device.capacityType,
|
|
|
|
|
ratedCapacity: device.ratedCapacity,
|
|
|
|
|
plans: (device.plans ?? []).map((plan: any) => ({ ...plan }))
|
|
|
|
|
}))
|
|
|
|
|
undoStack.value.push(JSON.stringify(data))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getCapacityTypeLabel = (value: any) => {
|
|
|
|
|
if (value === undefined || value === null) return '-'
|
|
|
|
|
@ -288,7 +302,7 @@ const renderCustomPlanBars = () => {
|
|
|
|
|
height: ${barHeight}px;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
|
|
|
cursor: ${isCurrent ? 'grab' : 'pointer'};
|
|
|
|
|
cursor: ${isCurrent && props.editable ? 'grab' : 'pointer'};
|
|
|
|
|
z-index: 2;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
@ -352,12 +366,12 @@ const renderCustomPlanBars = () => {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
bar.addEventListener('contextmenu', (e) => {
|
|
|
|
|
if (!isCurrent) { e.preventDefault(); return }
|
|
|
|
|
if (!isCurrent || !props.editable) { e.preventDefault(); return }
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
openTaskAdjustDialogForPlan(plan, task._deviceData)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (isCurrent) {
|
|
|
|
|
if (isCurrent && props.editable) {
|
|
|
|
|
attachPlanBarDrag(bar, plan, task)
|
|
|
|
|
attachPlanBarResize(bar, plan, task)
|
|
|
|
|
}
|
|
|
|
|
@ -420,6 +434,8 @@ 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)
|
|
|
|
|
@ -524,6 +540,8 @@ 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)
|
|
|
|
|
@ -562,6 +580,8 @@ const handleTaskAdjustSubmit = () => {
|
|
|
|
|
}
|
|
|
|
|
if (!editingPlanIdentity.value) return
|
|
|
|
|
|
|
|
|
|
saveUndoSnapshot()
|
|
|
|
|
|
|
|
|
|
const targetDevice = previewScheduleList.value.find(
|
|
|
|
|
(d: any) => `device-${d.deviceId}` === taskAdjustForm.deviceTaskId
|
|
|
|
|
)
|
|
|
|
|
@ -719,6 +739,7 @@ const initGanttPreview = () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
undoStack.value = []
|
|
|
|
|
await nextTick()
|
|
|
|
|
initGanttPreview()
|
|
|
|
|
})
|
|
|
|
|
@ -737,6 +758,30 @@ watch(
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
destroyGantt()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const undo = () => {
|
|
|
|
|
if (!undoStack.value.length) return
|
|
|
|
|
const saved = JSON.parse(undoStack.value.pop()!)
|
|
|
|
|
for (const savedDevice of saved) {
|
|
|
|
|
const originalDevice = previewScheduleList.value.find(
|
|
|
|
|
(d: any) => d.deviceId === savedDevice.deviceId
|
|
|
|
|
)
|
|
|
|
|
if (originalDevice) {
|
|
|
|
|
originalDevice.plans.splice(0, originalDevice.plans.length, ...savedDevice.plans)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
initGanttPreview()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.editable,
|
|
|
|
|
async () => {
|
|
|
|
|
await nextTick()
|
|
|
|
|
renderCustomPlanBars()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
defineExpose({ undo })
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|