feat:增加健康模块睡眠时间监控

This commit is contained in:
2025-11-17 19:58:59 +08:00
parent 4d7946759c
commit f5e75b745f
15 changed files with 108 additions and 611 deletions

View File

@@ -49,6 +49,40 @@
<span style="margin-left: 5px;">千克</span>
</el-form-item>
<el-form-item>
<template #label>
<i class="fa-solid fa-moon"></i>
<span>睡眠开始时间</span>
</template>
<el-date-picker
v-model="healthStore.currentHealth.sleepStartTime"
type="datetime" clearable
placeholder="选择时间"
style="width: 180px"
format="YYYY-MM-DD HH:mm"
value-format="YYYY-MM-DD HH:mm:ss"
@clear="healthStore.currentHealth.sleepStartTime = ''"
/>
</el-form-item>
<el-form-item>
<template #label>
<i class="fa-solid fa-sun"></i>
<span>睡眠结束时间</span>
</template>
<el-date-picker
v-model="healthStore.currentHealth.sleepEndTime"
type="datetime" clearable
placeholder="选择时间"
style="width: 180px"
format="YYYY-MM-DD HH:mm"
value-format="YYYY-MM-DD HH:mm:ss"
@clear="healthStore.currentHealth.sleepEndTime = ''"
/>
</el-form-item>
<el-form-item style="align-self: center;">
<el-button type="primary" @click="onSubmit"
:disabled="isBeforeDate(formatDate(new Date()), healthStore.selectDate)">
@@ -68,8 +102,10 @@ const healthStore = useHealthStore()
const projectList = ['羽毛球', '乒乓球', '跑步', '其他']
const onSubmit = async () => {
const { sportProject, sportDuration, weight } = healthStore.currentHealth
if (sportProject === '' && sportDuration === 0 && weight === 0) {
const { sportProject, sportDuration, weight,
sleepStartTime, sleepEndTime } = healthStore.currentHealth
if (sportProject === '' && sportDuration === 0 && weight === 0
&& sleepStartTime === '' && sleepEndTime === '') {
return
}
@@ -80,6 +116,11 @@ const onSubmit = async () => {
}
}
if (sleepStartTime && sleepEndTime && !sleepStartTime && sleepEndTime) {
ElMessage.error('睡眠结束时间应大于睡眠开始时间')
return
}
await healthStore.updateHealthDay()
healthStore.currentHealth = healthStore.getHealthDay(healthStore.selectDate)
}