From f0269c7c173762ed9ba15c5a98178fed28dbce00 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 19:52:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=81=8A=E5=A4=A9=E5=8A=A8?= =?UTF-8?q?=E4=BD=9C=E9=80=89=E6=8B=A9=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/js/chat-room.js | 6 ++-- resources/js/chat-room/composer.js | 29 +++++++++++++++++++ .../views/chat/partials/scripts.blade.php | 12 -------- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index 4a4e713..654c461 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -67,7 +67,7 @@ export { bindDailySignInControls } from "./chat-room/daily-sign-in.js"; export { bindEarnPanelControls, createEarnPanelData } from "./chat-room/earn-panel.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 { bindChatComposerControls, setChatComposerAction } from "./chat-room/composer.js"; export { bindChatToast } from "./chat-room/toast.js"; export { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel, quickFriendAction } from "./chat-room/friend-panel.js"; export { bindFriendNotificationControls, setupBannerNotification, setupFriendNotification, showFriendBanner } from "./chat-room/friend-notifications.js"; @@ -269,7 +269,7 @@ import { bindDailySignInControls } from "./chat-room/daily-sign-in.js"; import { bindEarnPanelControls, createEarnPanelData } from "./chat-room/earn-panel.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 { bindChatComposerControls, setChatComposerAction } from "./chat-room/composer.js"; import { bindChatToast } from "./chat-room/toast.js"; import { bindFriendPanelControls, closeFriendPanel, friendSearch, loadFriends, openFriendPanel, quickFriendAction } from "./chat-room/friend-panel.js"; import { bindFriendNotificationControls, setupBannerNotification, setupFriendNotification, showFriendBanner } from "./chat-room/friend-notifications.js"; @@ -489,6 +489,7 @@ if (typeof window !== "undefined") { bindChatFontSizeControl, bindChatImageUploadControl, bindChatComposerControls, + setChatComposerAction, bindChatToast, bindFriendPanelControls, bindFriendNotificationControls, @@ -702,6 +703,7 @@ if (typeof window !== "undefined") { window.isExpiredChatImageMessage = isExpiredChatImageMessage; window.localClearScreen = localClearScreen; window.normalizeSafeChatUrl = normalizeSafeChatUrl; + window.setAction = setChatComposerAction; window.syncAutoScrollControls = syncAutoScrollControls; window.openChatImageLightbox = openChatImageLightbox; window.closeFriendPanel = closeFriendPanel; diff --git a/resources/js/chat-room/composer.js b/resources/js/chat-room/composer.js index a38d7b7..d208f70 100644 --- a/resources/js/chat-room/composer.js +++ b/resources/js/chat-room/composer.js @@ -27,3 +27,32 @@ export function bindChatComposerControls() { } }); } + +/** + * 设置聊天动作并把焦点带回输入框。 + * 该入口兼容旧模板可能存在的 `setAction(...)` 调用,切换右侧标签仍交给 Blade 里的 switchTab 处理。 + * + * @param {string} action 动作名称 + * @param {(tab:string) => void} switchTabHandler 右侧标签切换函数 + * @returns {void} + */ +export function setChatComposerAction( + action, + switchTabHandler = typeof window !== "undefined" ? window.switchTab : null, +) { + const actionSelect = document.getElementById("action"); + const contentInput = document.getElementById("content"); + + if (actionSelect) { + actionSelect.value = action; + } + + // 右侧在线名单切换仍在 Blade 主脚本内,模块只通过兼容入口调用。 + if (typeof switchTabHandler === "function") { + switchTabHandler("users"); + } + + if (contentInput) { + contentInput.focus(); + } +} diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index a3221fc..03c8154 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -1743,18 +1743,6 @@ } }); - // ── 动作选择 ────────────────────────────────────── - /** - * 设置发言动作并聚焦输入框 - * - * @param {string} act 动作名称 - */ - function setAction(act) { - document.getElementById('action').value = act; - switchTab('users'); - document.getElementById('content').focus(); - } - // ── 自动滚屏 ────────────────────────────────────── const autoScrollEl = document.getElementById('auto_scroll'); if (autoScrollEl) {