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 @@