From 69ec4df7da602defe0ad29240ca2d00d6c67f5ea Mon Sep 17 00:00:00 2001 From: qiuchengw Date: Thu, 25 Sep 2025 10:19:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=BB=84=E4=BB=B6slot?= =?UTF-8?q?=E7=9A=84=E4=BD=BF=E7=94=A8=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/TaskBar.vue | 62 ++++++++++++++++++++++++------------- src/components/TaskRow.vue | 28 ++++++++++++++++- src/components/Timeline.vue | 2 +- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/components/TaskBar.vue b/src/components/TaskBar.vue index 10ba338..306010d 100644 --- a/src/components/TaskBar.vue +++ b/src/components/TaskBar.vue @@ -25,6 +25,25 @@ interface Props { currentTimeScale?: TimelineScale } +interface TaskStatus { + type: string + color: string + bgColor: string + borderColor: string +} + +interface TaskBarSlotProps { + type: string + task: Task + status: TaskStatus + statusType: string + isParent?: boolean + progress: number + currentTimeScale?: TimelineScale + rowHeight: number + dayWidth: number +} + const props = defineProps() const emit = defineEmits([ @@ -42,13 +61,17 @@ const emit = defineEmits([ 'context-menu', ]) +defineSlots<{ + 'custom-task-content'(props: TaskBarSlotProps): unknown +}>() + const slots = useSlots() const { getTranslation } = useI18n() const t = (key: string): string => { return getTranslation(key) } -const hasContentSlot = computed(() => Boolean(slots.content)) +const hasContentSlot = computed(() => Boolean(slots['custom-task-content'])) // 日期工具函数 - 处理时区安全的日期创建和操作 const createLocalDate = (dateString: string | Date | undefined | null): Date | null => { @@ -340,6 +363,19 @@ const taskStatus = computed(() => { } }) +// Slot payload for content slot - 使用 v-bind 方式传递所有属性 +const slotPayload = computed(() => ({ + type: 'task-bar', + task: props.task, + status: taskStatus.value, + statusType: taskStatus.value.type, + isParent: props.isParent ?? false, + progress: props.task.progress || 0, + currentTimeScale: props.currentTimeScale, + rowHeight: props.rowHeight, + dayWidth: props.dayWidth, +})) + // 判断是否已完成 const isCompleted = computed(() => (props.task.progress || 0) >= 100) @@ -1320,16 +1356,8 @@ onUnmounted(() => {
diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index e65cd17..7dee155 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -2750,7 +2750,7 @@ const handleAddSuccessor = (task: Task) => { @add-successor="handleAddSuccessor" @delete="handleTaskDelete" > -