From 7592618c7e0220b61a352f3e93e52fd2886aabca Mon Sep 17 00:00:00 2001 From: liwenxuan <1298531568@qq.com> Date: Tue, 26 Aug 2025 09:04:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=8E=A7=E4=BB=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lowCode/assistant/datePicker.vue | 72 ++++++++++++++++--- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/src/components/lowCode/assistant/datePicker.vue b/src/components/lowCode/assistant/datePicker.vue index fb91198..dddfcf3 100644 --- a/src/components/lowCode/assistant/datePicker.vue +++ b/src/components/lowCode/assistant/datePicker.vue @@ -38,12 +38,14 @@ const selectType = computed(() => { } }) function timestampToTargetFormat(timestamp: string) { + // 将输入转换为数字类型的时间戳(毫秒) const ms = Number(timestamp); // 创建Date对象 const date = new Date(ms); // Date对象的toString()方法恰好返回目标格式 - return date.toString(); + + return date; } @@ -397,7 +399,7 @@ const confirm = () => { } const cancel = () => { - value1.value = "" + value1.value = timestampToTargetFormat(value.value) show.value = false } @@ -418,7 +420,7 @@ const confirmStart = () => { } const cancelStart = () => { - startValue1.value = "" + startValue1.value = timestampToTargetFormat(value.value[0]) showStart.value = false } @@ -430,7 +432,7 @@ const confirmEnd = () => { } const cancelEnd = () => { - endValue1.value = "" + endValue1.value = timestampToTargetFormat(value.value[1]) showEnd.value = false } @@ -525,12 +527,62 @@ function calculateTimeDiff(startTimestamp: string, endTimestamp: string) { } } +function singleShow(){ + //console.log(value.value) + if(value1.value==""){ + value1.value = getTimestamp() + } + show.value = true +} +function rangeShowStart(){ + + if(startValue1.value==""){ + startValue1.value = getTimestamp() + } + showStart.value = true + +} + +function rangeShowEnd(){ + if(endValue1.value==""){ + endValue1.value = getTimestamp() + } + showEnd.value = true + +} + +function getTimestamp() { + + const now = new Date(); + let timestamp; + + switch(type.value) { + case 'year-month': + // 设置为当前年当前月1日0时0分1秒 + const yearMonthDate = new Date(now.getFullYear(), now.getMonth(), 1, 0, 0, 1); + timestamp = yearMonthDate + break; + case 'date': + // 设置为当前年当前月当前日0时0分1秒 + const dateDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1); + timestamp = dateDate + break; + case 'datetime': + // 返回当前时刻的时间戳 + timestamp = now + break; + default: + throw new Error('参数必须是"year-month"、"date"或"datetime"之一'); + } + + return timestamp; +}