From 098fa9e583e8d2130f9448bbb06d3d616fa09e98 Mon Sep 17 00:00:00 2001 From: liwenxuan <1298531568@qq.com> Date: Tue, 4 Nov 2025 14:22:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Diphone=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=85=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lowCode/assistant/datePicker.vue | 87 +++++++++++++++---- 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/src/components/lowCode/assistant/datePicker.vue b/src/components/lowCode/assistant/datePicker.vue index 5cf15c7..d27020f 100644 --- a/src/components/lowCode/assistant/datePicker.vue +++ b/src/components/lowCode/assistant/datePicker.vue @@ -621,6 +621,57 @@ function getTimestamp() { return timestamp; } + + + + + +// 使用 computed 替代方法调用 +const displayText = computed(() => { + if (!props.modelValue) { + hasValue.value = false + return "请选择时间" + } + + const val = new Date(parseInt(props.modelValue, 10)) + if (isNaN(val.getTime())) { + hasValue.value = false + return "请选择时间" + } + + hasValue.value = true + return formatDate(val, props.data.control.type, props.data.control.valueFormat) +}) + +// 提取格式化逻辑到独立函数 +function formatDate(date: Date, group: string, format: string) { + const validDate = dayJs(date) + if (!validDate.isValid()) return "请选择时间" + + switch (group) { + case "year": + return format === "x" + ? validDate.format('YYYY') + "年" + : validDate.format(format) + "年" + case "month": + return format === "x" + ? validDate.format('YYYY年MM月') + : validDate.format(format) + "月" + case "datetime": + return format === "x" + ? validDate.format('YYYY年MM月DD日 HH时mm分ss秒') + : validDate.format(format) + case "week": + return format === "x" + ? validDate.format('YYYY年 第ww周') + : validDate.format(format) + default: + return format === "x" + ? validDate.format('YYYY年MM月DD日') + : validDate.format(format) + } +} +