修复红包领取三重问题:①getOnlineUserIds 兼容旧版用户(fallback数据库查询) ②聊天领取按钮用全局Map替代内嵌JSON避免HTML属性破坏 ③doClaim改判 data.ok 而非不存在的 data.status

This commit is contained in:
2026-03-01 19:36:44 +08:00
parent 23fca927d5
commit a37b04aca0
2 changed files with 31 additions and 8 deletions
@@ -1225,7 +1225,7 @@
})
});
const data = await res.json();
if (data.status === 'success') {
if (data.ok) {
this.claimed = true;
this.claimedAmount = data.amount || 0;
} else {
@@ -1327,14 +1327,18 @@
const amount = detail.total_amount ? Number(detail.total_amount).toLocaleString() : '?';
const ceremonyId = detail.ceremony_id;
// 公屏追加带按钮的系统消息
// 将 detail 存入全局 Map,避免 onclick 属性内嵌 JSON 被双引号破坏
if (!window._weddingEnvelopes) window._weddingEnvelopes = {};
window._weddingEnvelopes[ceremonyId] = detail;
// 公屏追加带按钮的系统消息(按钮通过 ceremonyId 引用全局 Map
if (typeof appendSystemMessage === 'function') {
const claimBtn = `<button onclick="(function(){const el=document.getElementById('wedding-envelope-modal');if(el)Alpine.$data(el).open(${JSON.stringify(detail)});})()"
style="display:inline-block; margin-left:10px; padding:3px 12px; border-radius:20px;
background:linear-gradient(135deg,#fcd34d,#f59e0b); color:#92400e;
const claimBtn = `<button onclick="(function(){var d=window._weddingEnvelopes[${ceremonyId}];var el=document.getElementById('wedding-envelope-modal');if(el&&d)Alpine.$data(el).open(d);})()"
style="display:inline-block; margin-left:10px; padding:4px 14px; border-radius:20px;
background:#d97706; color:#fff;
border:none; font-size:12px; font-weight:bold; cursor:pointer;
vertical-align:middle; line-height:1.8;"
title="点击领取婚礼红包">🎁 点击领取红包</button>`;
vertical-align:middle; line-height:1.8; box-shadow:0 2px 8px rgba(0,0,0,.3);"
title="点击领取婚礼红包">🧧 点击领取红包</button>`;
appendSystemMessage(
`${tierIcon} ${groomName} 与 ${brideName} 举办了【${tierName}】!总金额 🪙${amount} 金币,快来抢红包!${claimBtn}`
);
@@ -1343,6 +1347,7 @@
// 同时弹出全屏红包弹窗
const el = document.getElementById('wedding-envelope-modal');
if (el) Alpine.$data(el).open(detail);
});