diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index dbac1f8..3efa48b 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -368,6 +368,7 @@ {{-- ═══════════ 聊天室交互脚本(独立文件维护) ═══════════ --}} + @include('chat.partials.user-actions') @include('chat.partials.scripts') {{-- ═══════════ 头像选择弹窗 ═══════════ --}} diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index 569b6c9..d79f823 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -202,74 +202,6 @@ } // ── 点击消息中的用户名,切换发言对象 ────────── - function switchTarget(username) { - 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) { - if (username === window.chatContext.username) return; - const el = document.getElementById('user-modal-container'); - if (el) { - const data = Alpine.$data(el); - if (data) data.fetchUser(username); - } - } - - /** - * 双击用户名 → 在包厢窗口(say2)显示用户基本信息 - */ - async function showUserInfoInSay2(username) { - try { - const res = await fetch('/user/' + encodeURIComponent(username)); - const info = await res.json(); - - const sexText = info.sex == 2 ? '女' : (info.sex == 1 ? '男' : '保密'); - const level = info.user_level || 0; - const exp = info.exp_num || 0; - const jjb = info.jjb || 0; - const sign = info.qianming || info.sign || '暂无'; - - const lines = [ - `══════ ${info.username || username} 的资料 ══════`, - `性别:${sexText} 等级:${level} 经验:${exp} 金币:${jjb}`, - `签名:${sign}`, - `════════════════════════` - ]; - - lines.forEach(text => { - const div = document.createElement('div'); - div.className = 'msg-line'; - div.innerHTML = `${text}`; - container2.appendChild(div); - }); - container2.scrollTop = container2.scrollHeight; - } catch (e) { - console.error('获取用户资料失败:', e); - } } /** diff --git a/resources/views/chat/partials/user-actions.blade.php b/resources/views/chat/partials/user-actions.blade.php new file mode 100644 index 0000000..9d20dc2 --- /dev/null +++ b/resources/views/chat/partials/user-actions.blade.php @@ -0,0 +1,56 @@ +{{-- + 文件功能:用户交互全局函数(单击选择目标、双击打开名片弹窗) + + 聊天消息区和右侧用户列表统一调用此文件中的函数。 + 从 scripts.blade.php 中抽取,保持代码职责清晰。 + + @author ChatRoom Laravel + @version 1.0.0 +--}} +