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