fix: 修改遗漏bug

This commit is contained in:
zerosaturation 2026-04-22 18:14:56 +08:00
parent 6866618ff6
commit 1ebc23b832

View File

@ -176,6 +176,8 @@ const handleAvatarUpdate = (data) => {
const handleUserInfoUpdate = () => {
loadUserInfo();
avatarKey.value += 1;
//
checkAndReportDailyLogin();
};
//
@ -187,6 +189,42 @@ const handleBalanceUpdate = (data) => {
}
};
//
function checkAndReportDailyLogin() {
// 5
const now = new Date()
const currentHour = now.getHours()
if (currentHour < 5) return // 5
const today = now.toISOString().split('T')[0]
const starId = uni.getStorageSync('star_id')
if (!starId) return
// ID
const userStr = uni.getStorageSync('user')
let userId = null
if (userStr) {
try {
const user = JSON.parse(userStr)
userId = user?.uid || null
} catch (e) {}
}
if (!userId) return
//
const dailyLoginKey = `daily_login_completed_${today}_${userId}_${starId}`
if (!uni.getStorageSync(dailyLoginKey)) {
reportEvent('daily_login', starId).then(() => {
//
uni.setStorageSync(dailyLoginKey, true)
const yesterday = new Date(now.getTime() - 86400000).toISOString().split('T')[0]
uni.removeStorageSync(`daily_login_completed_${yesterday}_${userId}_${starId}`)
}).catch(err => {
console.error('上报登录事件失败:', err)
})
}
}
//
onMounted(() => {
loadUserInfo();
@ -195,25 +233,7 @@ onMounted(() => {
uni.$on('balanceUpdated', handleBalanceUpdate);
// 5
// 5
const now = new Date()
const currentHour = now.getHours()
if (currentHour < 5) return // 5
const today = now.toISOString().split('T')[0]
const dailyLoginKey = `daily_login_completed_${today}`
// star_id
const starId = uni.getStorageSync('star_id')
if (starId && !uni.getStorageSync(dailyLoginKey)) {
reportEvent('daily_login', starId).then(() => {
//
uni.setStorageSync(dailyLoginKey, true)
const yesterday = new Date(now.getTime() - 86400000).toISOString().split('T')[0]
uni.removeStorageSync(`daily_login_completed_${yesterday}`)
}).catch(err => {
console.error('上报登录事件失败:', err)
})
}
checkAndReportDailyLogin();
});
//