diff --git a/src/components/Profile/StoragePopup.vue b/src/components/Profile/StoragePopup.vue
index 2fa75a2..30375be 100644
--- a/src/components/Profile/StoragePopup.vue
+++ b/src/components/Profile/StoragePopup.vue
@@ -10,9 +10,9 @@
-
+
diff --git a/src/pages/user/index.vue b/src/pages/user/index.vue
index 4530f2a..91c9e1d 100644
--- a/src/pages/user/index.vue
+++ b/src/pages/user/index.vue
@@ -48,7 +48,7 @@ import { getOverview, getPlan, getProfile } from '@/utils/profile'
import { useProfileStore } from '@/store/profile'
import { useAppStore } from "@/store/app";
import type { IProfile } from "@/type/profile";
-import { countRecordsByMonth, getTotalCount } from "@/utils/record";
+import { countRecordsByMonth, getMaxRecord, getTotalCount } from "@/utils/record";
const profileStore = useProfileStore()
const appStore = useAppStore()
@@ -87,6 +87,7 @@ function openPlanPopup() {
function openStoragePopup() {
profileStore.storageStats = countRecordsByMonth()
profileStore.storageTotal = getTotalCount()
+ profileStore.storageMax = getMaxRecord()
profileStore.showStoragePopup = true
}
diff --git a/src/store/profile.ts b/src/store/profile.ts
index 799f7ae..6cec452 100644
--- a/src/store/profile.ts
+++ b/src/store/profile.ts
@@ -15,6 +15,7 @@ export const useProfileStore = defineStore('profile', {
} as IProfile,
storageStats: [] as IStats[],
storageTotal: 0,
+ storageMax: 1000,
overviewList: [] as string[],
planList: [] as string[],
isRefresh: false,
diff --git a/src/utils/record.ts b/src/utils/record.ts
index 7df51fb..c20bc08 100644
--- a/src/utils/record.ts
+++ b/src/utils/record.ts
@@ -2,9 +2,13 @@ import { getProfile } from '@/utils/profile'
import type { IGroupHealthRecord, IHealthRecord, IRecordMeta, IRecordStats } from "@/type/record";
import type { IStats } from "@/type";
-const MONTH_KEEP = 12
+const MAX_RECORD = 1000;
const RECORD_PREFIX = 'health_'
+export function getMaxRecord() {
+ return MAX_RECORD
+}
+
function getMonthKey(timestamp: number) {
return `${RECORD_PREFIX}${getMonthStr(timestamp)}`
}
@@ -26,18 +30,6 @@ export function getTimeStr(timestamp: number) {
return d.toTimeString().slice(0, 5)
}
-function cleanOldMonths() {
- const cutoff = new Date()
- cutoff.setMonth(cutoff.getMonth() - MONTH_KEEP)
- const cutoffKey = `${RECORD_PREFIX}${cutoff.getFullYear()}-${String(cutoff.getMonth() + 1).padStart(2, '0')}`
- const keys = wx.getStorageInfoSync().keys
- keys.forEach((key: string) => {
- if (key.startsWith(RECORD_PREFIX) && key < cutoffKey) {
- wx.removeStorageSync(key)
- }
- })
-}
-
/**
* 新增记录
* @param type 类型
@@ -45,6 +37,16 @@ function cleanOldMonths() {
* @param timestamp 时间戳
*/
function addRecord(type: string, data: Record, timestamp: number) {
+ if (getTotalCount() >= MAX_RECORD) {
+ wx.showModal({
+ title: '提示',
+ content: `本地记录已超过 ${MAX_RECORD} 条,请先删除部分记录后再继续操作`,
+ confirmText: '我知道了',
+ showCancel: false
+ })
+ return
+ }
+
// 键为月份 例如 health_2026-08
const key = getMonthKey(timestamp)
const all = wx.getStorageSync(key) || {}