fix :修复缓存逻辑,避免无限增加

feat:新增前端限制修改昵称和头像需要7天
This commit is contained in:
tsui110 2026-01-03 09:26:03 +08:00
parent 58d9edc766
commit 8d5cf5ee17
2 changed files with 43 additions and 0 deletions

View File

@ -38,6 +38,13 @@ onMounted(() => {
splashData = {}
}
//
const cleanedSplashData = {}
if (splashData[dateStr]) {
cleanedSplashData[dateStr] = splashData[dateStr]
}
splashData = cleanedSplashData
//
const todayCount = splashData[dateStr] || 0

View File

@ -585,6 +585,21 @@ export default {
if (!this.checkPhoneBound()) return
//
const cooldownKey = 'avatar_update_cooldown'
const lastUpdate = uni.getStorageSync(cooldownKey)
const now = Date.now()
const cooldownDays = 7
if (lastUpdate && now - lastUpdate < cooldownDays * 24 * 60 * 60 * 1000) {
const daysRemaining = Math.ceil((cooldownDays * 24 * 60 * 60 * 1000 - (now - lastUpdate)) / (24 * 60 * 60 * 1000))
uni.showToast({
title: `头像修改冷却中,还需${daysRemaining}`,
icon: 'none'
})
return
}
uni.chooseImage({
count: 1,
sizeType: ['compressed'], //
@ -615,6 +630,9 @@ export default {
userInfo.avatar = data.avatar || base64
uni.setStorageSync('user_info', userInfo)
// 7
uni.setStorageSync('avatar_update_cooldown', Date.now())
uni.hideLoading()
uni.showToast({ title: '头像修改成功', icon: 'success' })
} catch (err) {
@ -653,6 +671,21 @@ export default {
return
}
//
const cooldownKey = 'nickname_update_cooldown'
const lastUpdate = uni.getStorageSync(cooldownKey)
const now = Date.now()
const cooldownDays = 7
if (lastUpdate && now - lastUpdate < cooldownDays * 24 * 60 * 60 * 1000) {
const daysRemaining = Math.ceil((cooldownDays * 24 * 60 * 60 * 1000 - (now - lastUpdate)) / (24 * 60 * 60 * 1000))
uni.showToast({
title: `昵称修改冷却中,还需${daysRemaining}`,
icon: 'none'
})
return
}
uni.showModal({
title: '修改昵称',
editable: true,
@ -685,6 +718,9 @@ export default {
userInfo.nickname = data.nickname || newNickname
uni.setStorageSync('user_info', userInfo)
// 7
uni.setStorageSync('nickname_update_cooldown', Date.now())
uni.hideLoading()
uni.showToast({ title: '昵称修改成功', icon: 'success' })
} catch (err) {