迁移头像和设置弹窗事件绑定
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user