diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index 7bcbf07..3c8ef9a 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -6,6 +6,7 @@ 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 { bindChatComposerControls } from "./chat-room/composer.js"; export { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel, quickFriendAction } from "./chat-room/friend-panel.js"; export { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js"; export { @@ -76,6 +77,7 @@ 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 { bindChatComposerControls } from "./chat-room/composer.js"; import { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel, quickFriendAction } from "./chat-room/friend-panel.js"; import { closeChatImageLightbox, initChatImageLightboxEvents, openChatImageLightbox } from "./chat-room/lightbox.js"; import { @@ -151,6 +153,7 @@ if (typeof window !== "undefined") { applyFontSize, bindChatFontSizeControl, bindChatImageUploadControl, + bindChatComposerControls, bindFriendPanelControls, closeFriendPanel, friendSearch, @@ -253,6 +256,7 @@ if (typeof window !== "undefined") { bindDailySignInControls(); bindChatFontSizeControl(); bindChatImageUploadControl(); + bindChatComposerControls(); bindFriendPanelControls(); bindToolbarControls(); bindAdminMenuControls(); diff --git a/resources/js/chat-room/composer.js b/resources/js/chat-room/composer.js new file mode 100644 index 0000000..a38d7b7 --- /dev/null +++ b/resources/js/chat-room/composer.js @@ -0,0 +1,29 @@ +// 聊天输入区事件绑定,逐步替代底部输入栏内联提交事件。 + +let chatComposerEventsBound = false; + +/** + * 绑定聊天表单提交事件。 + * 发送主流程仍由 Blade 主脚本的 sendMessage 维护,这里只统一 submit 入口。 + * + * @returns {void} + */ +export function bindChatComposerControls() { + if (chatComposerEventsBound || typeof document === "undefined") { + return; + } + + chatComposerEventsBound = true; + document.addEventListener("submit", (event) => { + const form = event.target; + if (!(form instanceof HTMLFormElement) || !form.matches("[data-chat-form]")) { + return; + } + + event.preventDefault(); + + if (typeof window.sendMessage === "function") { + void window.sendMessage(event); + } + }); +} diff --git a/resources/views/chat/partials/layout/input-bar.blade.php b/resources/views/chat/partials/layout/input-bar.blade.php index 1a3c6fb..80dafb8 100644 --- a/resources/views/chat/partials/layout/input-bar.blade.php +++ b/resources/views/chat/partials/layout/input-bar.blade.php @@ -19,7 +19,7 @@ @endphp