迁移每日签到弹窗事件绑定
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// 统一转发各子模块导出,方便测试或后续模块继续复用同一组工具。
|
||||
export { escapeHtml, escapeHtmlWithLineBreaks } from "./chat-room/html.js";
|
||||
export { bindGlobalDialogControls } from "./chat-room/dialog.js";
|
||||
export { bindDailySignInControls } from "./chat-room/daily-sign-in.js";
|
||||
export { applyFontSize, bindChatFontSizeControl, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize } from "./chat-room/font-size.js";
|
||||
export { bindChatImageUploadControl } from "./chat-room/image-upload.js";
|
||||
export { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel } from "./chat-room/friend-panel.js";
|
||||
@@ -71,6 +72,7 @@ export { createMessageQueue } from "./chat-room/message-queue.js";
|
||||
|
||||
import { escapeHtml, escapeHtmlWithLineBreaks } from "./chat-room/html.js";
|
||||
import { bindGlobalDialogControls } from "./chat-room/dialog.js";
|
||||
import { bindDailySignInControls } from "./chat-room/daily-sign-in.js";
|
||||
import { applyFontSize, bindChatFontSizeControl, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize } from "./chat-room/font-size.js";
|
||||
import { bindChatImageUploadControl } from "./chat-room/image-upload.js";
|
||||
import { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel } from "./chat-room/friend-panel.js";
|
||||
@@ -143,6 +145,7 @@ if (typeof window !== "undefined") {
|
||||
escapeHtml,
|
||||
escapeHtmlWithLineBreaks,
|
||||
bindGlobalDialogControls,
|
||||
bindDailySignInControls,
|
||||
applyFontSize,
|
||||
bindChatFontSizeControl,
|
||||
bindChatImageUploadControl,
|
||||
@@ -238,6 +241,7 @@ if (typeof window !== "undefined") {
|
||||
|
||||
// 页面加载后立即注册事件委托,具体业务逻辑仍由各子模块负责。
|
||||
bindGlobalDialogControls();
|
||||
bindDailySignInControls();
|
||||
bindChatFontSizeControl();
|
||||
bindChatImageUploadControl();
|
||||
bindFriendPanelControls();
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
// 每日签到弹窗事件代理,先迁移按钮与遮罩事件,签到业务仍由 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 monthButton = event.target.closest("[data-daily-sign-month]");
|
||||
if (monthButton) {
|
||||
event.preventDefault();
|
||||
// 月份状态仍由 window.dailySignInState 维护,模块只读取方向并转发旧加载函数。
|
||||
callDailySignInGlobal("loadDailySignInCalendar", resolveDailySignInMonth(monthButton.getAttribute("data-daily-sign-month") || ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -290,11 +290,11 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<div id="daily-sign-modal" class="daily-sign-modal-overlay" onclick="if(event.target === this) closeDailySignInModal()">
|
||||
<div id="daily-sign-modal" class="daily-sign-modal-overlay" data-daily-sign-modal-overlay>
|
||||
<div class="daily-sign-modal">
|
||||
<div class="daily-sign-modal-head">
|
||||
<div class="daily-sign-modal-title">✅ 每日签到</div>
|
||||
<button type="button" class="daily-sign-modal-close" onclick="closeDailySignInModal()">×</button>
|
||||
<button type="button" class="daily-sign-modal-close" data-daily-sign-close>×</button>
|
||||
</div>
|
||||
<div class="daily-sign-modal-body">
|
||||
<div class="daily-sign-summary">
|
||||
@@ -308,13 +308,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="daily-sign-actions">
|
||||
<button type="button" id="daily-sign-claim-btn" class="daily-sign-action-btn" onclick="claimDailySignInFromModal()">今日签到</button>
|
||||
<button type="button" id="daily-sign-buy-card-btn" class="daily-sign-action-btn secondary" onclick="buyDailySignRepairCard()">购买补签卡</button>
|
||||
<button type="button" id="daily-sign-claim-btn" class="daily-sign-action-btn" data-daily-sign-claim>今日签到</button>
|
||||
<button type="button" id="daily-sign-buy-card-btn" class="daily-sign-action-btn secondary" data-daily-sign-buy-repair-card>购买补签卡</button>
|
||||
</div>
|
||||
<div class="daily-sign-month-bar">
|
||||
<button type="button" onclick="loadDailySignInCalendar(window.dailySignInState?.prevMonth)">上月</button>
|
||||
<button type="button" data-daily-sign-month="prev">上月</button>
|
||||
<div id="daily-sign-month-label" class="daily-sign-month-label">本月</div>
|
||||
<button type="button" onclick="loadDailySignInCalendar(window.dailySignInState?.nextMonth)">下月</button>
|
||||
<button type="button" data-daily-sign-month="next">下月</button>
|
||||
</div>
|
||||
<div class="daily-sign-weekdays">
|
||||
<div class="daily-sign-weekday">日</div>
|
||||
|
||||
Reference in New Issue
Block a user