fix: 修改遗漏bug
This commit is contained in:
parent
6866618ff6
commit
1ebc23b832
@ -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();
|
||||
});
|
||||
|
||||
// 组件卸载时移除事件监听
|
||||
|
||||
Loading…
Reference in New Issue
Block a user