迁移用户名快捷操作脚本
This commit is contained in:
@@ -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