迁移节日福利领取事件
This commit is contained in:
@@ -257,26 +257,20 @@
|
||||
window.__holidayRuns = window.__holidayRuns || {};
|
||||
|
||||
/**
|
||||
* 从公屏系统消息中打开指定节日福利批次弹窗。
|
||||
* 转义按钮属性值,避免福利批次 ID 写入 data 属性时破坏 HTML。
|
||||
*
|
||||
* @param {number|string} runId
|
||||
* @param {number|string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
window.openHolidayRunFromSystemMessage = function(runId) {
|
||||
const normalizedRunId = String(runId);
|
||||
const detail = window.__holidayRuns?.[normalizedRunId];
|
||||
const el = document.getElementById('holiday-event-modal');
|
||||
|
||||
if (!el || typeof Alpine === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!detail) {
|
||||
window.chatDialog?.alert('当前福利批次信息未缓存,请等待下一轮广播或刷新页面后重试。', '提示', '#f59e0b');
|
||||
return;
|
||||
}
|
||||
|
||||
Alpine.$data(el).open(detail);
|
||||
};
|
||||
function escapeHolidayAttribute(value) {
|
||||
return String(value).replace(/[&<>"']/g, (char) => ({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
})[char]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建公屏系统消息里的领取按钮,便于多个消息场景复用一致视觉。
|
||||
@@ -290,8 +284,10 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
const safeRunId = escapeHolidayAttribute(runId);
|
||||
|
||||
return ` <button type="button"
|
||||
onclick="openHolidayRunFromSystemMessage(${JSON.stringify(String(runId))})"
|
||||
data-holiday-run-id="${safeRunId}"
|
||||
style="display:inline-flex; align-items:center; gap:4px; margin-left:8px; padding:3px 10px; border:none; border-radius:999px; background:linear-gradient(135deg,#f59e0b,#d97706); color:#fff; font-size:12px; font-weight:bold; cursor:pointer; box-shadow:0 2px 6px rgba(0,0,0,.22); vertical-align:middle;"
|
||||
title="点击领取本轮节日福利">${label}</button>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user