fix :修复缓存逻辑,避免无限增加
feat:新增前端限制修改昵称和头像需要7天
This commit is contained in:
parent
58d9edc766
commit
8d5cf5ee17
@ -38,6 +38,13 @@ onMounted(() => {
|
|||||||
splashData = {}
|
splashData = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 清理不是今天的缓存,只保留今天的记录
|
||||||
|
const cleanedSplashData = {}
|
||||||
|
if (splashData[dateStr]) {
|
||||||
|
cleanedSplashData[dateStr] = splashData[dateStr]
|
||||||
|
}
|
||||||
|
splashData = cleanedSplashData
|
||||||
|
|
||||||
// 获取今天的显示次数
|
// 获取今天的显示次数
|
||||||
const todayCount = splashData[dateStr] || 0
|
const todayCount = splashData[dateStr] || 0
|
||||||
|
|
||||||
|
|||||||
@ -585,6 +585,21 @@ export default {
|
|||||||
|
|
||||||
if (!this.checkPhoneBound()) return
|
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({
|
uni.chooseImage({
|
||||||
count: 1,
|
count: 1,
|
||||||
sizeType: ['compressed'], // 选择压缩图
|
sizeType: ['compressed'], // 选择压缩图
|
||||||
@ -615,6 +630,9 @@ export default {
|
|||||||
userInfo.avatar = data.avatar || base64
|
userInfo.avatar = data.avatar || base64
|
||||||
uni.setStorageSync('user_info', userInfo)
|
uni.setStorageSync('user_info', userInfo)
|
||||||
|
|
||||||
|
// 记录修改时间(7天冷却)
|
||||||
|
uni.setStorageSync('avatar_update_cooldown', Date.now())
|
||||||
|
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
uni.showToast({ title: '头像修改成功', icon: 'success' })
|
uni.showToast({ title: '头像修改成功', icon: 'success' })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@ -653,6 +671,21 @@ export default {
|
|||||||
return
|
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({
|
uni.showModal({
|
||||||
title: '修改昵称',
|
title: '修改昵称',
|
||||||
editable: true,
|
editable: true,
|
||||||
@ -685,6 +718,9 @@ export default {
|
|||||||
userInfo.nickname = data.nickname || newNickname
|
userInfo.nickname = data.nickname || newNickname
|
||||||
uni.setStorageSync('user_info', userInfo)
|
uni.setStorageSync('user_info', userInfo)
|
||||||
|
|
||||||
|
// 记录修改时间(7天冷却)
|
||||||
|
uni.setStorageSync('nickname_update_cooldown', Date.now())
|
||||||
|
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
uni.showToast({ title: '昵称修改成功', icon: 'success' })
|
uni.showToast({ title: '昵称修改成功', icon: 'success' })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user