94 lines
3.0 KiB
JavaScript
94 lines
3.0 KiB
JavaScript
// 每日签到弹窗事件代理,先迁移按钮与遮罩事件,签到业务仍由 Blade 主脚本维护。
|
|
|
|
let dailySignInEventsBound = false;
|
|
|
|
/**
|
|
* 调用每日签到存量全局函数。
|
|
*
|
|
* @param {string} functionName 全局函数名
|
|
* @param {...unknown} args 参数
|
|
* @returns {void}
|
|
*/
|
|
function callDailySignInGlobal(functionName, ...args) {
|
|
// 当前模块只负责 data-* 事件到旧函数的桥接,接口请求和日历渲染暂不迁移。
|
|
if (typeof window[functionName] === "function") {
|
|
window[functionName](...args);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 读取每日签到月份翻页目标。
|
|
*
|
|
* @param {"prev"|"next"|string} direction 翻页方向
|
|
* @returns {string|null}
|
|
*/
|
|
function resolveDailySignInMonth(direction) {
|
|
if (direction === "prev") {
|
|
return window.dailySignInState?.prevMonth || null;
|
|
}
|
|
|
|
if (direction === "next") {
|
|
return window.dailySignInState?.nextMonth || null;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 绑定每日签到弹窗遮罩、关闭、签到、补签卡和月份切换事件。
|
|
*
|
|
* @returns {void}
|
|
*/
|
|
export function bindDailySignInControls() {
|
|
if (dailySignInEventsBound || typeof document === "undefined") {
|
|
return;
|
|
}
|
|
|
|
dailySignInEventsBound = true;
|
|
document.addEventListener("click", (event) => {
|
|
if (!(event.target instanceof Element)) {
|
|
return;
|
|
}
|
|
|
|
const overlay = event.target.closest("[data-daily-sign-modal-overlay]");
|
|
// 只在点击遮罩本身时关闭,避免点击弹窗内容区误触关闭。
|
|
if (overlay && event.target === overlay) {
|
|
callDailySignInGlobal("closeDailySignInModal");
|
|
return;
|
|
}
|
|
|
|
if (event.target.closest("[data-daily-sign-close]")) {
|
|
event.preventDefault();
|
|
callDailySignInGlobal("closeDailySignInModal");
|
|
return;
|
|
}
|
|
|
|
if (event.target.closest("[data-daily-sign-claim]")) {
|
|
event.preventDefault();
|
|
callDailySignInGlobal("claimDailySignInFromModal");
|
|
return;
|
|
}
|
|
|
|
if (event.target.closest("[data-daily-sign-buy-repair-card]")) {
|
|
event.preventDefault();
|
|
callDailySignInGlobal("buyDailySignRepairCard");
|
|
return;
|
|
}
|
|
|
|
const makeupButton = event.target.closest("[data-daily-sign-makeup]");
|
|
if (makeupButton) {
|
|
event.preventDefault();
|
|
// 日历格子由 Blade 主脚本动态生成,这里只读取日期并转发补签旧函数。
|
|
callDailySignInGlobal("makeupDailySignIn", makeupButton.getAttribute("data-daily-sign-makeup") || "");
|
|
return;
|
|
}
|
|
|
|
const monthButton = event.target.closest("[data-daily-sign-month]");
|
|
if (monthButton) {
|
|
event.preventDefault();
|
|
// 月份状态仍由 window.dailySignInState 维护,模块只读取方向并转发旧加载函数。
|
|
callDailySignInGlobal("loadDailySignInCalendar", resolveDailySignInMonth(monthButton.getAttribute("data-daily-sign-month") || ""));
|
|
}
|
|
});
|
|
}
|