diff --git a/src/components/lowCode/assistant/datePicker.vue b/src/components/lowCode/assistant/datePicker.vue index b2a590b..1c5f867 100644 --- a/src/components/lowCode/assistant/datePicker.vue +++ b/src/components/lowCode/assistant/datePicker.vue @@ -496,7 +496,7 @@ const shichang = computed(() => { let a = calculateTimeDiff(start, end) return a }) -function calculateTimeDiff(startTimestamp: string, endTimestamp: string) { +/* function calculateTimeDiff(startTimestamp: string, endTimestamp: string) { // 解析时间戳为数字 const start = parseInt(startTimestamp, 10); const end = parseInt(endTimestamp, 10); @@ -526,6 +526,41 @@ function calculateTimeDiff(startTimestamp: string, endTimestamp: string) { } return `${days} 天 ${remainingHours} 小时`; } +} */ + +function calculateTimeDiff(startTimestamp: string, endTimestamp: string) { + // 解析时间戳为数字 + const start = parseInt(startTimestamp, 10); + const end = parseInt(endTimestamp, 10); + + // 计算时间差(毫秒)并取绝对值 + const diffMs = Math.abs(end - start); + + // 计算总分钟数并向下取整 + const totalMinutes = Math.floor(diffMs / 60000); + + // 计算天数和剩余小时数 + const days = Math.floor(totalMinutes / 1440); // 1440分钟 = 24小时 + const remainingMinutesAfterDays = totalMinutes % 1440; + const hours = Math.floor(remainingMinutesAfterDays / 60); + const minutes = remainingMinutesAfterDays % 60; + + // 构建返回字符串 + let result = ''; + + if (days > 0) { + result += `${days} 天 `; + } + + if (hours > 0) { + result += `${hours} 小时 `; + } + + if (minutes >= 0) { // 包含0分钟的情况 + result += `${minutes} 分钟`; + } + + return result.trim(); // 去除末尾空格 } const types = props.types; function singleShow() {