diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index 9c9ae61..483bc6f 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -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(); diff --git a/resources/js/chat-room/daily-sign-in.js b/resources/js/chat-room/daily-sign-in.js new file mode 100644 index 0000000..f2b135a --- /dev/null +++ b/resources/js/chat-room/daily-sign-in.js @@ -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") || "")); + } + }); +} diff --git a/resources/views/chat/partials/daily-sign-in-modal.blade.php b/resources/views/chat/partials/daily-sign-in-modal.blade.php index 724c062..ce68364 100644 --- a/resources/views/chat/partials/daily-sign-in-modal.blade.php +++ b/resources/views/chat/partials/daily-sign-in-modal.blade.php @@ -290,11 +290,11 @@ } -