From 0d587ac241fc390f29719b2d0c6d23d09fb970db Mon Sep 17 00:00:00 2001 From: Cxx0822 <1556464090@qq.com> Date: Sun, 23 Aug 2026 21:56:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Home/SleepPopup.vue | 19 +-- src/pages/index/index.vue | 112 +++++++++++++++--- src/pages/record/record.vue | 181 +++++++++++------------------ src/store/record.ts | 22 ++-- src/utils/record.ts | 119 +++++++++++++++++-- 5 files changed, 292 insertions(+), 161 deletions(-) diff --git a/src/components/Home/SleepPopup.vue b/src/components/Home/SleepPopup.vue index cc4a697..8514367 100644 --- a/src/components/Home/SleepPopup.vue +++ b/src/components/Home/SleepPopup.vue @@ -39,7 +39,7 @@ - {{ sleepDuration }} + {{ sleepDuration }} 小时 @@ -106,22 +106,14 @@ const sleepDuration = computed(() => { const end = recordStore.sleepForm.endTime if (!start || !end) - return '请选择开始和结束时间' + return 0 const diffMs = new Date(end).getTime() - new Date(start).getTime() if (diffMs <= 0) - return '结束时间需晚于开始时间' + return 0 - const totalMinutes = Math.floor(diffMs / 60000) - const hours = Math.floor(totalMinutes / 60) - const minutes = totalMinutes % 60 - - if (hours > 0 && minutes > 0) - return `${hours}小时${minutes}分钟` - if (hours > 0) - return `${hours}小时` - return `${minutes}分钟` + return Math.round((diffMs / 3600000) * 10) / 10 }) function handeClosePopup() { @@ -131,7 +123,7 @@ function handeClosePopup() { } function saveSleep() { - const { startTime, endTime, time, note } = recordStore.sleepForm + const { startTime, endTime, time } = recordStore.sleepForm if (!startTime) { uni.showToast({ title: '请选择开始时间', icon: 'none' }) @@ -150,6 +142,7 @@ function saveSleep() { return } + recordStore.sleepForm.duration = sleepDuration.value recordStore.submitSleep() uni.showToast({ title: '睡眠记录成功', icon: 'success' }) diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index df6e971..6cc2f6e 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -79,7 +79,8 @@