From 89f344bd2984ff4a1dbe83bf9fd2e9786ec47c38 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sat, 25 Apr 2026 08:04:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=A4=B4=E5=83=8F=E5=92=8C?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=BC=B9=E7=AA=97=E4=BA=8B=E4=BB=B6=E7=BB=91?= =?UTF-8?q?=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/profile-controls.js | 114 ++++++++++++++++++ .../chat/partials/layout/toolbar.blade.php | 27 ++--- 3 files changed, 131 insertions(+), 14 deletions(-) create mode 100644 resources/js/chat-room/profile-controls.js diff --git a/resources/js/chat-room.js b/resources/js/chat-room.js index f74e12c..8c810f9 100644 --- a/resources/js/chat-room.js +++ b/resources/js/chat-room.js @@ -20,6 +20,7 @@ export { submitBaccaratLossCoverEvent, } from "./chat-room/baccarat-loss-cover-admin.js"; export { bindFishingControls } from "./chat-room/fishing.js"; +export { bindProfileControls } from "./chat-room/profile-controls.js"; export { BLOCKABLE_SYSTEM_SENDERS, BLOCKED_SYSTEM_SENDERS_STORAGE_KEY, @@ -64,6 +65,7 @@ import { submitBaccaratLossCoverEvent, } from "./chat-room/baccarat-loss-cover-admin.js"; import { bindFishingControls } from "./chat-room/fishing.js"; +import { bindProfileControls } from "./chat-room/profile-controls.js"; import { BLOCKABLE_SYSTEM_SENDERS, BLOCKED_SYSTEM_SENDERS_STORAGE_KEY, @@ -114,6 +116,7 @@ if (typeof window !== "undefined") { openAdminBaccaratLossCoverModal, submitBaccaratLossCoverEvent, bindFishingControls, + bindProfileControls, CHAT_FONT_SIZE_STORAGE_KEY, restoreChatFontSize, closeChatImageLightbox, @@ -162,6 +165,7 @@ if (typeof window !== "undefined") { bindAdminMenuControls(); bindBaccaratLossCoverAdminControls(); bindFishingControls(); + bindProfileControls(); bindChatRightPanelControls(); bindMobileDrawerControls(); bindWelcomeMenuControls(); diff --git a/resources/js/chat-room/profile-controls.js b/resources/js/chat-room/profile-controls.js new file mode 100644 index 0000000..e6c8aae --- /dev/null +++ b/resources/js/chat-room/profile-controls.js @@ -0,0 +1,114 @@ +// 头像选择与个人设置弹窗事件绑定,替代 toolbar 中的内联 onclick/onchange。 + +let profileControlEventsBound = false; + +/** + * 触发存量全局函数,保持当前头像与设置业务逻辑不变。 + * + * @param {string} functionName 全局函数名 + * @param {...unknown} args 参数 + * @returns {void} + */ +function callGlobal(functionName, ...args) { + if (typeof window[functionName] === "function") { + window[functionName](...args); + } +} + +/** + * 绑定头像选择器和个人设置弹窗事件。 + * + * @returns {void} + */ +export function bindProfileControls() { + if (profileControlEventsBound || typeof document === "undefined") { + return; + } + + profileControlEventsBound = true; + document.addEventListener("click", (event) => { + if (!(event.target instanceof Element)) { + return; + } + + if (event.target.closest("[data-avatar-picker-close]")) { + event.preventDefault(); + callGlobal("closeAvatarPicker"); + return; + } + + if (event.target.closest("[data-avatar-save]")) { + event.preventDefault(); + callGlobal("saveAvatar"); + return; + } + + if (event.target.closest("[data-avatar-upload-trigger]")) { + event.preventDefault(); + // 上传按钮只负责打开隐藏的 file input,上传校验仍由存量 handleAvatarUpload 负责。 + document.getElementById("avatar-upload-input")?.click(); + return; + } + + if (event.target.closest("[data-settings-modal-close]")) { + event.preventDefault(); + callGlobal("closeSettingsModal"); + return; + } + + if (event.target.closest("[data-settings-save-password]")) { + event.preventDefault(); + callGlobal("savePassword"); + return; + } + + if (event.target.closest("[data-settings-send-email-code]")) { + event.preventDefault(); + callGlobal("sendEmailCode"); + return; + } + + if (event.target.closest("[data-settings-copy-wechat-code]")) { + event.preventDefault(); + callGlobal("copyWechatBindCode"); + return; + } + + if (event.target.closest("[data-settings-generate-wechat-code]")) { + event.preventDefault(); + callGlobal("generateWechatBindCode"); + return; + } + + if (event.target.closest("[data-settings-unbind-wechat]")) { + event.preventDefault(); + callGlobal("unbindWechat"); + return; + } + + if (event.target.closest("[data-settings-save-profile]")) { + event.preventDefault(); + callGlobal("saveSettings"); + return; + } + + if (event.target.closest("[data-settings-modal-panel]")) { + event.stopPropagation(); + return; + } + + // 只在点击设置弹窗遮罩时关闭,避免内容区点击被误判。 + if (event.target.closest("[data-settings-modal-overlay]")) { + callGlobal("closeSettingsModal"); + } + }); + + document.addEventListener("change", (event) => { + if (!(event.target instanceof HTMLInputElement) || !event.target.matches("[data-avatar-upload-input]")) { + return; + } + + // 保留原上传函数的文件大小校验、接口请求和在线名单刷新逻辑。 + callGlobal("handleAvatarUpload", event.target); + }); +} diff --git a/resources/views/chat/partials/layout/toolbar.blade.php b/resources/views/chat/partials/layout/toolbar.blade.php index 985f03f..e7ee2ee 100644 --- a/resources/views/chat/partials/layout/toolbar.blade.php +++ b/resources/views/chat/partials/layout/toolbar.blade.php @@ -55,7 +55,7 @@ style="background:#336699; color:#fff; padding:10px 16px; font-size:14px; font-weight:bold; display:flex; justify-content:space-between; align-items:center;"> 🖼 修改头像(原版风格) - + {{-- 预览区 --}} @@ -65,14 +65,14 @@ {{ $user->usersf ?: '未设置' }} -
自定义头像上传(112x112): - -
@@ -87,11 +87,10 @@ {{-- ═══════════ 个人设置弹窗 ═══════════ --}} - - @@ -149,7 +148,7 @@ - @@ -195,11 +194,11 @@
- - @@ -208,7 +207,7 @@ @else
已绑定微信,可接收提醒通知。 - +
@endif
@@ -221,7 +220,7 @@ {{-- 保存按钮 --}} -