迁移用户名快捷操作脚本
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -12,63 +12,7 @@
|
||||
@version 1.0.0
|
||||
--}}
|
||||
|
||||
{{-- ═══════════ 全局交互函数 ═══════════ --}}
|
||||
<script>
|
||||
/**
|
||||
* 全局函数:单击用户名 → 切换聊天目标
|
||||
*
|
||||
* 将「对...说」下拉选中为该用户,方便直接发悄悄话。
|
||||
* 若用户已离线不在下拉列表中,临时添加一个 option。
|
||||
*/
|
||||
function switchTarget(username) {
|
||||
const toUserSelect = document.getElementById('to_user');
|
||||
if (!toUserSelect) return;
|
||||
|
||||
const options = toUserSelect.options;
|
||||
let found = false;
|
||||
for (let i = 0; i < options.length; i++) {
|
||||
if (options[i].value === username) {
|
||||
toUserSelect.value = username;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 如果不在列表中(可能已离线),临时添加
|
||||
if (!found && username !== '大家') {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = username;
|
||||
opt.textContent = username;
|
||||
toUserSelect.appendChild(opt);
|
||||
toUserSelect.value = username;
|
||||
}
|
||||
// 切换目标后自动聚焦输入框,方便直接输入
|
||||
document.getElementById('content').focus();
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局函数:双击用户名 → 打开名片弹窗
|
||||
*
|
||||
* 聊天消息区和右侧用户列表统一调用此函数。
|
||||
* 通过 Alpine.js 的 fetchUser 方法加载用户资料并显示弹窗。
|
||||
*/
|
||||
function openUserCard(username) {
|
||||
// 剥除可能从消息内容带入的装饰括号(如 【username】 → username)
|
||||
username = String(username).replace(/^[\u3010\[【\s]+|[\u3011\]】\s]+$/g, '').trim();
|
||||
if (!username) return;
|
||||
|
||||
// Alpine.js 使用 defer 异步加载,检查是否已完成初始化
|
||||
if (!window.Alpine) {
|
||||
console.warn('[openUserCard] Alpine.js 尚未初始化,请稍后再试');
|
||||
return;
|
||||
}
|
||||
|
||||
const el = document.getElementById('user-modal-container');
|
||||
if (el) {
|
||||
const data = window.Alpine.$data(el);
|
||||
if (data) data.fetchUser(username);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{{-- 全局 switchTarget/openUserCard 已迁移到 resources/js/chat-room/user-target-actions.js --}}
|
||||
|
||||
{{-- ═══════════ 用户名片弹窗 (Alpine.js) ═══════════ --}}
|
||||
@php $gifts = \App\Models\Gift::activeList(); @endphp
|
||||
|
||||
Reference in New Issue
Block a user