Files
health-mp/src/utils/profile.ts
2026-09-05 16:19:56 +08:00

71 lines
1.6 KiB
TypeScript

import type {IDefaultRecordValue, IProfile} from "@/type/profile";
const PROFILE_KEY = 'user_profile'
const OVERVIEW_KEY = 'user_overview'
const PLAN_KEY = 'user_plan'
const STATS_KEY = 'user_stats'
const THEME_KEY = 'user_theme'
const DEFAULT_RECORD_VALUE_KEY = 'user_default_record_value'
function getEmptyProfile(): IProfile {
return {
id: '',
gender: '',
height: null,
birthYear: null,
occupation: '',
condition: [],
goal: '',
name: '',
}
}
export function getProfile(): IProfile {
return wx.getStorageSync(PROFILE_KEY) || getEmptyProfile()
}
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) || []
}
export function saveOverview(data: string[]) {
wx.setStorageSync(OVERVIEW_KEY, data)
}
export function getPlan(): string[] {
return wx.getStorageSync(PLAN_KEY) || []
}
export function savePlan(data: string[]) {
wx.setStorageSync(PLAN_KEY, data)
}
export function getStats(): string[] {
return wx.getStorageSync(STATS_KEY) || []
}
export function saveStats(data: string[]) {
wx.setStorageSync(STATS_KEY, data)
}
export function getThemeColor(): string {
return wx.getStorageSync(THEME_KEY) || ''
}
export function saveThemeColor(data: string) {
wx.setStorageSync(THEME_KEY, data)
}