217 lines
7.8 KiB
TypeScript
217 lines
7.8 KiB
TypeScript
import { defineStore } from 'pinia'
|
||
import { addBloodPressure, addBloodSugar, addSleep, addSport, addTemperature, addWeight } from '@/utils/record'
|
||
import { getDefaultRecordValue } from "@/utils/profile";
|
||
import type { IAiReport } from "@/type/report";
|
||
|
||
export const useRecordStore = defineStore('record', {
|
||
state: () => ({
|
||
showFab: true,
|
||
showRecordPopup: false, // 指标选择弹窗
|
||
showWeightPopup: false,
|
||
showSleepPopup: false,
|
||
showSportPopup: false,
|
||
showBloodPressurePopup: false,
|
||
showBloodSugarPopup: false,
|
||
showTemperaturePopup: false,
|
||
weightForm: {
|
||
value: 0,
|
||
note: '',
|
||
time: Date.now(),
|
||
},
|
||
sleepForm: {
|
||
startTime: Date.now() - 8 * 60 * 60 * 1000,
|
||
endTime: Date.now(),
|
||
duration: 0,
|
||
note: '',
|
||
time: Date.now(),
|
||
},
|
||
sportForm: {
|
||
category: '',
|
||
duration: 0,
|
||
note: '',
|
||
time: Date.now(),
|
||
},
|
||
bloodPressureForm: {
|
||
systolic: 0,
|
||
diastolic: 0,
|
||
heartRate: 0,
|
||
note: '',
|
||
time: Date.now(),
|
||
},
|
||
bloodSugarForm: {
|
||
value: 0,
|
||
period: '',
|
||
note: '',
|
||
time: Date.now(),
|
||
},
|
||
temperatureForm: {
|
||
value: 36.5,
|
||
location: '',
|
||
note: '',
|
||
time: Date.now(),
|
||
},
|
||
isRecord: false,
|
||
isAnalyzing: false,
|
||
showAIResultPopup: false,
|
||
showAIButton: true,
|
||
aiResult: {
|
||
title: "Cxx的健康月报 · 2026年9月",
|
||
greeting: "Cxx你好!这个月你完成了3天的健康数据记录,虽然覆盖还不算全面,但坚持记录就是好的开始。当前体重约69.9kg,BMI约24.2,略高于标准上限,结合你的均衡饮食目标,可以先从调整饮食和增加活动入手。本月亮点是睡眠达标且空腹血糖正常,但血压呈现升高趋势,需要多加留意。",
|
||
sections: [
|
||
{
|
||
type: "weight",
|
||
emoji: "⚖️",
|
||
title: "体重",
|
||
hasAbnormal: false,
|
||
data: "体重从70kg降至69.7kg,整体平稳,平均69.9kg,波动幅度仅0.3kg。根据身高170cm计算,BMI约24.2,略超标准范围上限。",
|
||
suggestion: "结合均衡饮食目标,继续保持清淡饮食,减少高油高糖食物,并配合适量运动。"
|
||
},
|
||
{
|
||
type: "sleep",
|
||
emoji: "😴",
|
||
title: "睡眠",
|
||
hasAbnormal: false,
|
||
data: "本月记录1次睡眠,时长8小时,达标率100%,睡眠质量表现很好。",
|
||
suggestion: "保持规律的作息时间,尽量在固定时间就寝和起床,让好习惯延续下去。"
|
||
},
|
||
{
|
||
type: "sport",
|
||
emoji: "🏃",
|
||
title: "运动",
|
||
hasAbnormal: true,
|
||
data: "运动记录7次,实际运动1天,总时长30分钟,运动频率14.3%,最长连续不运动2天。考虑到你久坐少动的状态,运动量还需要提升。",
|
||
suggestion: "建议每周累计至少150分钟中等强度运动,可以从快走、跑步等开始,每小时起身活动5分钟。"
|
||
},
|
||
{
|
||
type: "bloodPressure",
|
||
emoji: "❤️",
|
||
title: "血压",
|
||
hasAbnormal: true,
|
||
data: "收缩压从120升至145mmHg,舒张压从70升至97mmHg,平均血压约132.5/83.5mmHg,异常率50%;心率平均80次/分。血压升高明显,需要重视。",
|
||
suggestion: "请尽快复测血压并咨询医生,同时注意低盐饮食、避免熬夜、减轻压力,并坚持每日监测。"
|
||
},
|
||
{
|
||
type: "bloodSugar",
|
||
emoji: "🩸",
|
||
title: "血糖",
|
||
hasAbnormal: false,
|
||
data: "空腹血糖5.4mmol/L,处于正常范围,餐前、餐后及睡前血糖暂无记录。",
|
||
suggestion: "继续保持均衡饮食,控制精制糖和甜食摄入,后续可完善餐后血糖记录。"
|
||
}
|
||
],
|
||
tips: [
|
||
"血压是本月的重点预警项:高压和低压均有明显上升,建议尽快就医复测,并在医生指导下规律监测。",
|
||
"结合久坐少动的工作特点,每坐1小时就起身活动几分钟,下班后安排30分钟快走或慢跑,逐渐增加运动频率。",
|
||
"把均衡饮食落到实处:减少盐和油,多吃蔬菜水果,少吃腌制食品和外卖,帮助体重和血压一起改善。"
|
||
],
|
||
ending: "健康管理是一场长跑,不必追求完美,只要持续用心就好。下个月继续一起关注血压和运动,期待你更好的状态!"
|
||
} as IAiReport
|
||
}),
|
||
actions: {
|
||
openWeight() {
|
||
this.resetWeight()
|
||
this.showWeightPopup = true
|
||
},
|
||
openSleep() {
|
||
this.resetSleep()
|
||
this.showSleepPopup = true
|
||
},
|
||
openSport() {
|
||
this.resetSport()
|
||
this.showSportPopup = true
|
||
},
|
||
openBloodPressure() {
|
||
this.resetBloodPressure()
|
||
this.showBloodPressurePopup = true
|
||
},
|
||
openBloodSugar() {
|
||
this.resetBloodSugar()
|
||
this.showBloodSugarPopup = true
|
||
},
|
||
openTemperature() {
|
||
this.resetTemperature()
|
||
this.showTemperaturePopup = true
|
||
},
|
||
submitWeight() {
|
||
addWeight(this.weightForm.value, this.weightForm.note, this.weightForm.time)
|
||
this.showWeightPopup = false
|
||
this.isRecord = !this.isRecord
|
||
},
|
||
submitSleep() {
|
||
addSleep(
|
||
this.sleepForm.startTime,
|
||
this.sleepForm.endTime,
|
||
this.sleepForm.duration,
|
||
this.sleepForm.note,
|
||
this.sleepForm.time,
|
||
)
|
||
this.showSleepPopup = false
|
||
this.isRecord = !this.isRecord
|
||
},
|
||
submitSport() {
|
||
addSport(
|
||
this.sportForm.category,
|
||
this.sportForm.duration,
|
||
this.sportForm.note,
|
||
this.sportForm.time,
|
||
)
|
||
this.showSportPopup = false
|
||
this.isRecord = !this.isRecord
|
||
},
|
||
submitBloodPressure() {
|
||
addBloodPressure(
|
||
this.bloodPressureForm.systolic,
|
||
this.bloodPressureForm.diastolic,
|
||
this.bloodPressureForm.heartRate,
|
||
this.bloodPressureForm.note,
|
||
this.bloodPressureForm.time,
|
||
)
|
||
this.showBloodPressurePopup = false
|
||
this.isRecord = !this.isRecord
|
||
},
|
||
submitBloodSugar() {
|
||
addBloodSugar(
|
||
this.bloodSugarForm.value,
|
||
this.bloodSugarForm.period,
|
||
this.bloodSugarForm.note,
|
||
this.bloodSugarForm.time,
|
||
)
|
||
this.showBloodSugarPopup = false
|
||
this.isRecord = !this.isRecord
|
||
},
|
||
submitTemperature() {
|
||
addTemperature(
|
||
this.temperatureForm.value,
|
||
this.temperatureForm.location,
|
||
this.temperatureForm.note,
|
||
this.temperatureForm.time,
|
||
)
|
||
this.showTemperaturePopup = false
|
||
this.isRecord = !this.isRecord
|
||
},
|
||
resetWeight() {
|
||
const { weightValue } = getDefaultRecordValue()
|
||
this.weightForm = { value: weightValue, note: '', time: Date.now() }
|
||
},
|
||
resetSleep() {
|
||
this.sleepForm = { startTime: Date.now() - 8 * 60 * 60 * 1000, endTime: Date.now(), duration: 8, note: '', time: Date.now() }
|
||
},
|
||
resetSport() {
|
||
const { sportDuration } = getDefaultRecordValue()
|
||
this.sportForm = { category: '跑步', duration: sportDuration, note: '', time: Date.now() }
|
||
},
|
||
resetBloodPressure() {
|
||
const { bloodPressureSystolic, bloodPressureDiastolic, bloodPressureHeartRate } = getDefaultRecordValue()
|
||
this.bloodPressureForm = { systolic: bloodPressureSystolic, diastolic: bloodPressureDiastolic, heartRate: bloodPressureHeartRate, note: '', time: Date.now() }
|
||
},
|
||
resetBloodSugar() {
|
||
const { bloodSugarValue } = getDefaultRecordValue()
|
||
this.bloodSugarForm = { value: bloodSugarValue, period: '空腹', note: '', time: Date.now() }
|
||
},
|
||
resetTemperature() {
|
||
const { temperatureValue } = getDefaultRecordValue()
|
||
this.temperatureForm = { value: temperatureValue, location: '腋下', note: '', time: Date.now() }
|
||
},
|
||
},
|
||
})
|