diff --git a/src/App.vue b/src/App.vue index 683141e..b5885c1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,8 +1,26 @@ diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 2a13341..10d928c 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -89,7 +89,7 @@ import BloodSugarPopup from "@/components/Home/BloodSugarPopup.vue"; import TemperaturePopup from "@/components/Home/TemperaturePopup.vue"; import { ref, computed, watch } from 'vue' import { useRecordStore } from '@/store/record' -import {getDateStr, getDayRecords, getTimeStr} from '@/utils/record' +import { getDateStr, getDayRecords, getTimeStr } from '@/utils/record' import type { IHealthRecord } from "@/type/record"; import { onShow } from "@dcloudio/uni-app"; import { getOverview, getPlan, getProfile } from "@/utils/profile"; diff --git a/src/pages/user/index.vue b/src/pages/user/index.vue index 91c9e1d..e60b7a9 100644 --- a/src/pages/user/index.vue +++ b/src/pages/user/index.vue @@ -21,6 +21,7 @@ + @@ -35,6 +36,8 @@ + + @@ -44,11 +47,12 @@ import StoragePopup from "@/components/Profile/StoragePopup.vue"; import OverviewPopup from "@/components/Profile/OverviewPopup.vue"; import PlanPopup from "@/components/Profile/PlanPopup.vue"; import { computed, ref, watch } from 'vue' -import { getOverview, getPlan, getProfile } from '@/utils/profile' +import {getDefaultRecordValue, getOverview, getPlan, getProfile} from '@/utils/profile' import { useProfileStore } from '@/store/profile' import { useAppStore } from "@/store/app"; import type { IProfile } from "@/type/profile"; import { countRecordsByMonth, getMaxRecord, getTotalCount } from "@/utils/record"; +import DefaultPopup from "@/components/Profile/DefaultPopup.vue"; const profileStore = useProfileStore() const appStore = useAppStore() @@ -74,6 +78,11 @@ function openProfile() { profileStore.showProfilePopup = true } +function openDefaultPopup() { + profileStore.defaultRecordValueForm = getDefaultRecordValue() + profileStore.showDefaultRecordValuePopup = true +} + function openOverviewPopup() { profileStore.overviewList = getOverview() profileStore.showOverviewPopup = true diff --git a/src/store/app.ts b/src/store/app.ts index 75dc013..84e6e9b 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -2,7 +2,7 @@ import { defineStore } from 'pinia' export const useAppStore = defineStore('app', { state: () => ({ - version: '1.0.1', + version: '1.1.0', viewRecordType: 'calendar', }), actions: { diff --git a/src/store/profile.ts b/src/store/profile.ts index 6cec452..0170834 100644 --- a/src/store/profile.ts +++ b/src/store/profile.ts @@ -1,5 +1,5 @@ import { defineStore } from 'pinia' -import type { IProfile } from "@/type/profile"; +import type {IDefaultRecordValue, IProfile} from "@/type/profile"; import type {IStats} from "@/type"; export const useProfileStore = defineStore('profile', { @@ -8,16 +8,27 @@ export const useProfileStore = defineStore('profile', { showStoragePopup: false, showOverviewPopup: false, showPlanPopup: false, + showDefaultRecordValuePopup: false, profileForm: { gender: '', height: 0, name: '', } as IProfile, + defaultRecordValueForm: { + weightValue: 70, + sportDuration: 30, + bloodPressureSystolic: 120, + bloodPressureDiastolic: 70, + bloodPressureHeartRate: 80, + bloodSugarValue: 5.4, + temperatureValue: 36.5, + } as IDefaultRecordValue, storageStats: [] as IStats[], storageTotal: 0, storageMax: 1000, overviewList: [] as string[], planList: [] as string[], + defaultList: [], isRefresh: false, }), actions: { diff --git a/src/store/record.ts b/src/store/record.ts index a062c83..856cfbe 100644 --- a/src/store/record.ts +++ b/src/store/record.ts @@ -1,5 +1,6 @@ import { defineStore } from 'pinia' import { addBloodPressure, addBloodSugar, addSleep, addSport, addTemperature, addWeight } from '@/utils/record' +import {getDefaultRecordValue} from "@/utils/profile"; export const useRecordStore = defineStore('record', { state: () => ({ @@ -133,22 +134,27 @@ export const useRecordStore = defineStore('record', { this.isRecord = !this.isRecord }, resetWeight() { - this.weightForm = { value: 70, note: '', time: Date.now() } + 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() { - this.sportForm = { category: '跑步', duration: 30, note: '', time: Date.now() } + const { sportDuration } = getDefaultRecordValue() + this.sportForm = { category: '跑步', duration: sportDuration, note: '', time: Date.now() } }, resetBloodPressure() { - this.bloodPressureForm = { systolic: 120, diastolic: 70, heartRate: 80, note: '', time: Date.now() } + const { bloodPressureSystolic, bloodPressureDiastolic, bloodPressureHeartRate } = getDefaultRecordValue() + this.bloodPressureForm = { systolic: bloodPressureSystolic, diastolic: bloodPressureDiastolic, heartRate: bloodPressureHeartRate, note: '', time: Date.now() } }, resetBloodSugar() { - this.bloodSugarForm = { value: 5.4, period: '空腹', note: '', time: Date.now() } + const { bloodSugarValue } = getDefaultRecordValue() + this.bloodSugarForm = { value: bloodSugarValue, period: '空腹', note: '', time: Date.now() } }, resetTemperature() { - this.temperatureForm = { value: 36.5, location: '腋下', note: '', time: Date.now() } + const { temperatureValue } = getDefaultRecordValue() + this.temperatureForm = { value: temperatureValue, location: '腋下', note: '', time: Date.now() } }, }, }) diff --git a/src/type/profile.ts b/src/type/profile.ts index 516c1b1..22ea9ee 100644 --- a/src/type/profile.ts +++ b/src/type/profile.ts @@ -17,3 +17,13 @@ export interface IPlan { label: string done: boolean } + +export interface IDefaultRecordValue { + weightValue: number + sportDuration: number + bloodPressureSystolic: number + bloodPressureDiastolic: number + bloodPressureHeartRate: number + bloodSugarValue: number + temperatureValue: number +} \ No newline at end of file diff --git a/src/utils/profile.ts b/src/utils/profile.ts index 970adbb..a6a76ad 100644 --- a/src/utils/profile.ts +++ b/src/utils/profile.ts @@ -1,8 +1,9 @@ -import type { IProfile } from "@/type/profile"; +import type {IDefaultRecordValue, IProfile} from "@/type/profile"; const PROFILE_KEY = 'user_profile' const OVERVIEW_KEY = 'user_overview' const PLAN_KEY = 'user_plan' +const DEFAULT_RECORD_VALUE_KEY = 'user_default_record_value' function getEmptyProfile(): IProfile { return { @@ -20,6 +21,14 @@ export function saveProfile(data: IProfile) { wx.setStorageSync(PROFILE_KEY, data) } +export function getDefaultRecordValue(): IDefaultRecordValue { + return wx.getStorageSync(DEFAULT_RECORD_VALUE_KEY) +} + +export function saveDefaultRecordValue(data: IDefaultRecordValue) { + wx.setStorageSync(DEFAULT_RECORD_VALUE_KEY, data) +} + export function getOverview(): string[] { return wx.getStorageSync(OVERVIEW_KEY) || [] } diff --git a/src/utils/record.ts b/src/utils/record.ts index c20bc08..c746752 100644 --- a/src/utils/record.ts +++ b/src/utils/record.ts @@ -13,9 +13,12 @@ function getMonthKey(timestamp: number) { return `${RECORD_PREFIX}${getMonthStr(timestamp)}` } -export function getDateStr(timestamp: number) { +export function getDateStr(timestamp: number): string { const d = new Date(timestamp) - return d.toISOString().slice(0, 10) + const y = d.getFullYear() + const m = String(d.getMonth() + 1).padStart(2, '0') + const day = String(d.getDate()).padStart(2, '0') + return `${y}-${m}-${day}` } export function getMonthStr(timestamp: number): string {