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) + } +} +