From 04ee32e4d5d09a48f63c9a10583c57951bd28475 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 03:54:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=85=A8=E5=B1=80=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E6=8C=89=E9=92=AE=E4=BA=8B=E4=BB=B6=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/chat-room.js | 4 ++ resources/js/chat-room/dialog.js | 38 +++++++++++++++++++ .../chat/partials/global-dialog.blade.php | 4 +- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 resources/js/chat-room/dialog.js diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index ed0b71f..0c6b10f 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -1,6 +1,7 @@ // 聊天室 Vite 入口,集中导出从 Blade 内联脚本迁移出的纯前端工具。 export { escapeHtml, escapeHtmlWithLineBreaks } from "./chat-room/html.js"; +export { bindGlobalDialogControls } from "./chat-room/dialog.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 { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js"; @@ -32,6 +33,7 @@ export { export { createMessageQueue } from "./chat-room/message-queue.js"; import { escapeHtml, escapeHtmlWithLineBreaks } from "./chat-room/html.js"; +import { bindGlobalDialogControls } from "./chat-room/dialog.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 { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js"; @@ -66,6 +68,7 @@ if (typeof window !== "undefined") { window.ChatRoomTools = { escapeHtml, escapeHtmlWithLineBreaks, + bindGlobalDialogControls, applyFontSize, bindChatFontSizeControl, bindChatImageUploadControl, @@ -101,6 +104,7 @@ if (typeof window !== "undefined") { window.closeChatImageLightbox = closeChatImageLightbox; window.openChatImageLightbox = openChatImageLightbox; window.applyFontSize = applyFontSize; + bindGlobalDialogControls(); bindChatFontSizeControl(); bindChatImageUploadControl(); bindChatRightPanelControls(); diff --git a/resources/js/chat-room/dialog.js b/resources/js/chat-room/dialog.js new file mode 100644 index 0000000..816a674 --- /dev/null +++ b/resources/js/chat-room/dialog.js @@ -0,0 +1,38 @@ +// 聊天室全局弹窗事件绑定,替代 Blade 内联 onclick。 + +let globalDialogEventsBound = false; + +/** + * 绑定全局弹窗确认与取消按钮。 + * + * @returns {void} + */ +export function bindGlobalDialogControls() { + if (globalDialogEventsBound || typeof document === "undefined") { + return; + } + + globalDialogEventsBound = true; + document.addEventListener("click", (event) => { + if (!(event.target instanceof Element)) { + return; + } + + const actionButton = event.target.closest("[data-chat-dialog-action]"); + if (!actionButton) { + return; + } + + event.preventDefault(); + + const action = actionButton.getAttribute("data-chat-dialog-action"); + if (action === "confirm") { + window.chatDialog?._confirm?.(); + return; + } + + if (action === "cancel") { + window.chatDialog?._cancel?.(); + } + }); +} diff --git a/resources/views/chat/partials/global-dialog.blade.php b/resources/views/chat/partials/global-dialog.blade.php index fd8cd05..234522c 100644 --- a/resources/views/chat/partials/global-dialog.blade.php +++ b/resources/views/chat/partials/global-dialog.blade.php @@ -44,13 +44,13 @@ {{-- 按钮区 --}}
- -