迁移全局弹窗按钮事件绑定
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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?.();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -44,13 +44,13 @@
|
||||
|
||||
{{-- 按钮区 --}}
|
||||
<div style="display:flex; gap:10px; padding:0 18px 16px;">
|
||||
<button id="global-dialog-cancel-btn" onclick="window.chatDialog._cancel()"
|
||||
<button id="global-dialog-cancel-btn" data-chat-dialog-action="cancel"
|
||||
style="flex:1; padding:9px; background:#f3f4f6; color:#555;
|
||||
border:1px solid #d1d5db; border-radius:6px;
|
||||
font-size:13px; cursor:pointer; transition:background .15s;">
|
||||
取消
|
||||
</button>
|
||||
<button id="global-dialog-confirm-btn" onclick="window.chatDialog._confirm()"
|
||||
<button id="global-dialog-confirm-btn" data-chat-dialog-action="confirm"
|
||||
style="flex:1; padding:9px; color:#fff; border:none;
|
||||
border-radius:6px; font-size:13px; font-weight:bold;
|
||||
cursor:pointer; transition:opacity .15s;">
|
||||
|
||||
Reference in New Issue
Block a user