迁移用户名快捷操作脚本

This commit is contained in:
2026-04-25 13:57:12 +08:00
parent 1e9f6673cc
commit ed2d60a24e
3 changed files with 87 additions and 57 deletions
+8
View File
@@ -24,6 +24,7 @@ export {
} from "./chat-room/mobile-drawer.js";
export { bindMarriageStatusControls } from "./chat-room/marriage-status.js";
export { bindToolbarControls, runFeatureShortcut, runToolbarAction } from "./chat-room/toolbar.js";
export { bindUserTargetActions, openUserCard, switchTarget } from "./chat-room/user-target-actions.js";
export { bindWelcomeMenuControls } from "./chat-room/welcome-menu.js";
export { bindAdminMenuControls } from "./chat-room/admin-menu.js";
export {
@@ -102,6 +103,7 @@ import {
} from "./chat-room/mobile-drawer.js";
import { bindMarriageStatusControls } from "./chat-room/marriage-status.js";
import { bindToolbarControls, runFeatureShortcut, runToolbarAction } from "./chat-room/toolbar.js";
import { bindUserTargetActions, openUserCard, switchTarget } from "./chat-room/user-target-actions.js";
import { bindWelcomeMenuControls } from "./chat-room/welcome-menu.js";
import { bindAdminMenuControls } from "./chat-room/admin-menu.js";
import {
@@ -189,6 +191,9 @@ if (typeof window !== "undefined") {
bindToolbarControls,
runFeatureShortcut,
runToolbarAction,
bindUserTargetActions,
openUserCard,
switchTarget,
bindWelcomeMenuControls,
bindAdminMenuControls,
bindBaccaratLossCoverAdminControls,
@@ -254,10 +259,12 @@ if (typeof window !== "undefined") {
window.closeMobileDrawer = closeMobileDrawer;
window.loadMobileRoomList = loadMobileRoomList;
window.openMobileDrawer = openMobileDrawer;
window.openUserCard = openUserCard;
window.renderMobileRoomList = renderMobileRoomList;
window.renderMobileUserList = renderMobileUserList;
window.scheduleRenderMobileUserList = scheduleRenderMobileUserList;
window.switchMobileTab = switchMobileTab;
window.switchTarget = switchTarget;
window.runFeatureShortcut = runFeatureShortcut;
window.runToolbarAction = runToolbarAction;
window.openHolidayRunFromSystemMessage = openHolidayRunFromSystemMessage;
@@ -286,6 +293,7 @@ if (typeof window !== "undefined") {
bindChatToast();
bindFriendPanelControls();
bindToolbarControls();
bindUserTargetActions();
bindAdminMenuControls();
bindBaccaratLossCoverAdminControls();
bindBaccaratLossCoverControls();
@@ -0,0 +1,78 @@
// 聊天室用户名快捷操作,提供 switchTarget/openUserCard 全局兼容函数。
/**
* 将聊天目标切换到指定用户,离线用户会临时补入下拉框。
*
* @param {string} username
* @returns {void}
*/
export function switchTarget(username) {
const toUserSelect = document.getElementById("to_user");
if (!toUserSelect) {
return;
}
const options = toUserSelect.options;
let found = false;
for (let index = 0; index < options.length; index += 1) {
if (options[index].value === username) {
toUserSelect.value = username;
found = true;
break;
}
}
// 已离线用户不在下拉列表时,临时加入一次,方便直接发起悄悄话。
if (!found && username !== "大家") {
const option = document.createElement("option");
option.value = username;
option.textContent = username;
toUserSelect.appendChild(option);
toUserSelect.value = username;
}
document.getElementById("content")?.focus();
}
/**
* 打开指定用户的名片弹窗。
*
* @param {string} username
* @returns {void}
*/
export function openUserCard(username) {
const normalizedUsername = String(username)
.replace(/^[\u3010\[【\s]+|[\u3011\]】\s]+$/g, "")
.trim();
if (!normalizedUsername) {
return;
}
if (!window.Alpine) {
console.warn("[openUserCard] Alpine.js 尚未初始化,请稍后再试");
return;
}
const container = document.getElementById("user-modal-container");
if (!container) {
return;
}
window.Alpine.$data(container)?.fetchUser?.(normalizedUsername);
}
/**
* 暴露用户名快捷操作给存量 Blade 调用点。
*
* @returns {void}
*/
export function bindUserTargetActions() {
if (typeof window === "undefined") {
return;
}
window.switchTarget = switchTarget;
window.openUserCard = openUserCard;
}