feat: 增加存储上限提示功能
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
</view>
|
||||
|
||||
<view class="flex flex-col items-center">
|
||||
<wd-text :text="`${profileStore.storageTotal} / 1000`"></wd-text>
|
||||
<wd-text :text="`${profileStore.storageTotal} / ${profileStore.storageMax}`"></wd-text>
|
||||
<wd-progress
|
||||
:percentage="Number((profileStore.storageTotal / 1000 * 100).toFixed(2))"
|
||||
:percentage="Number((profileStore.storageTotal / profileStore.storageMax * 100).toFixed(2))"
|
||||
:color="['#00c740', '#ffb300', '#e2231a']"/>
|
||||
</view>
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<string, any>, 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) || {}
|
||||
|
||||
Reference in New Issue
Block a user