diff --git a/src/components/DesignForm/public/expand/datePicker.vue b/src/components/DesignForm/public/expand/datePicker.vue index 9b7143e..5a9b566 100644 --- a/src/components/DesignForm/public/expand/datePicker.vue +++ b/src/components/DesignForm/public/expand/datePicker.vue @@ -40,7 +40,7 @@ const shichangShowFlag = computed(() => { } }); -function calculateTimeDiff(startTimestamp: string, endTimestamp: string) { +/* function calculateTimeDiff(startTimestamp: string, endTimestamp: string) { // 解析时间戳为数字 const start = parseInt(startTimestamp, 10); const end = parseInt(endTimestamp, 10); @@ -70,6 +70,42 @@ 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 valueFormat = "x";