feat: 增加各个模块
This commit is contained in:
154
src/store/record.ts
Normal file
154
src/store/record.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { addBloodPressure, addBloodSugar, addSleep, addSport, addTemperature, addWeight } from '@/utils/record'
|
||||
|
||||
export const useRecordStore = defineStore('record', {
|
||||
state: () => ({
|
||||
showFab: true,
|
||||
showRecordPopup: false, // 指标选择弹窗
|
||||
showWeightPopup: false,
|
||||
showSleepPopup: false,
|
||||
showSportPopup: false,
|
||||
showBpPopup: false,
|
||||
showGlucosePopup: false,
|
||||
showTempPopup: false,
|
||||
weightForm: {
|
||||
value: 0,
|
||||
note: '',
|
||||
time: Date.now(),
|
||||
},
|
||||
sleepForm: {
|
||||
startTime: Date.now(),
|
||||
endTime: Date.now(),
|
||||
duration: 0,
|
||||
note: '',
|
||||
time: Date.now(),
|
||||
},
|
||||
sportForm: {
|
||||
category: '',
|
||||
duration: 0,
|
||||
note: '',
|
||||
time: Date.now(),
|
||||
},
|
||||
bpForm: {
|
||||
systolic: 0,
|
||||
diastolic: 0,
|
||||
heartRate: 0,
|
||||
note: '',
|
||||
time: Date.now(),
|
||||
},
|
||||
glucoseForm: {
|
||||
value: 0,
|
||||
period: '',
|
||||
note: '',
|
||||
time: Date.now(),
|
||||
},
|
||||
tempForm: {
|
||||
value: 36.5,
|
||||
location: '',
|
||||
note: '',
|
||||
time: Date.now(),
|
||||
},
|
||||
isRecord: false,
|
||||
}),
|
||||
actions: {
|
||||
openWeight() {
|
||||
this.resetWeight()
|
||||
this.showWeightPopup = true
|
||||
},
|
||||
openSleep() {
|
||||
this.resetSleep()
|
||||
this.showSleepPopup = true
|
||||
},
|
||||
openSport() {
|
||||
this.resetSport()
|
||||
this.showSportPopup = true
|
||||
},
|
||||
openBp() {
|
||||
this.resetBp()
|
||||
this.showBpPopup = true
|
||||
},
|
||||
openGlucose() {
|
||||
this.resetGlucose()
|
||||
this.showGlucosePopup = true
|
||||
},
|
||||
openTemp() {
|
||||
this.resetTemp()
|
||||
this.showTempPopup = 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
|
||||
},
|
||||
submitBp() {
|
||||
addBloodPressure(
|
||||
this.bpForm.systolic,
|
||||
this.bpForm.diastolic,
|
||||
this.bpForm.heartRate,
|
||||
this.bpForm.note,
|
||||
this.bpForm.time,
|
||||
)
|
||||
this.showBpPopup = false
|
||||
this.isRecord = !this.isRecord
|
||||
},
|
||||
submitGlucose() {
|
||||
addBloodSugar(
|
||||
this.glucoseForm.value,
|
||||
this.glucoseForm.period,
|
||||
this.glucoseForm.note,
|
||||
this.glucoseForm.time,
|
||||
)
|
||||
this.showGlucosePopup = false
|
||||
this.isRecord = !this.isRecord
|
||||
},
|
||||
submitTemp() {
|
||||
addTemperature(
|
||||
this.tempForm.value,
|
||||
this.tempForm.location,
|
||||
this.tempForm.note,
|
||||
this.tempForm.time,
|
||||
)
|
||||
this.showTempPopup = false
|
||||
this.isRecord = !this.isRecord
|
||||
},
|
||||
resetWeight() {
|
||||
this.weightForm = { value: 70, note: '', time: Date.now() }
|
||||
},
|
||||
resetSleep() {
|
||||
this.sleepForm = { startTime: Date.now() - 8 * 60 * 60 * 1000, endTime: Date.now(), duration: 8, note: '', time: Date.now() }
|
||||
},
|
||||
resetSport() {
|
||||
this.sportForm = { category: '跑步', duration: 30, note: '', time: Date.now() }
|
||||
},
|
||||
resetBp() {
|
||||
this.bpForm = { systolic: 120, diastolic: 70, heartRate: 80, note: '', time: Date.now() }
|
||||
},
|
||||
resetGlucose() {
|
||||
this.glucoseForm = { value: 5.4, period: '空腹', note: '', time: Date.now() }
|
||||
},
|
||||
resetTemp() {
|
||||
this.tempForm = { value: 36.5, location: '腋下', note: '', time: Date.now() }
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user