重构:双击用户名统一走 openUserCard 全局函数

- 新增全局 openUserCard() 函数,所有双击用户名入口统一调用
- 聊天消息区 clickableUser 的 ondblclick 改为 openUserCard
- 右侧用户列表双击简化为调用 openUserCard
- 移除输入栏底部的管理操作下拉框和执行按钮
- 管理操作统一通过双击用户名 → 名片弹窗执行
This commit is contained in:
2026-02-27 00:16:07 +08:00
parent e3cc1d2c70
commit ad8315f4a6
2 changed files with 18 additions and 42 deletions
@@ -58,33 +58,6 @@
<option value="1">上下分</option>
</select>
</label>
{{-- 管理操作(根据权限显示) --}}
@if ($user->user_level >= $levelKick || $room->master == $user->username)
<select id="admin-action-select"
style="font-size: 11px; padding: 1px 2px; border: 1px solid #8ab; border-radius: 2px; color: #c00;">
<option value="">管理操作 </option>
@if ($user->user_level >= $levelWarn || $room->master == $user->username)
<option value="warn">⚠️ 警告</option>
@endif
@if ($user->user_level >= $levelKick || $room->master == $user->username)
<option value="kick">👢 踢出房间</option>
@endif
@if ($user->user_level >= $levelMute || $room->master == $user->username)
<option value="mute">🔇 禁言</option>
@endif
@if ($user->user_level >= $levelBan)
<option value="ban">🚫 封号</option>
@endif
@if ($user->user_level >= $levelBanip)
<option value="banip">🔒 封IP</option>
@endif
@if ($user->user_level >= $levelKick || $room->master == $user->username)
<option value="whispers">🔍 查看私聊</option>
@endif
</select>
<button type="button" onclick="executeAdminAction()"
style="font-size: 11px; padding: 1px 6px; background: #c44; color: #fff; border: none; border-radius: 2px; cursor: pointer;">执行</button>
@endif
@if (
$user->user_level >= (int) \App\Models\Sysparam::getValue('level_announcement', '10') ||
+18 -15
View File
@@ -162,20 +162,8 @@
toUserSelect.value = username;
document.getElementById('content').focus();
};
// 双击打开用户名片弹窗
item.ondblclick = () => {
if (username !== window.chatContext.username) {
// 触发 Alpine.js 用户名片弹窗
const modalContainer = document.getElementById('user-modal-container');
if (modalContainer && modalContainer.__x) {
modalContainer.__x.$data.fetchUser(username);
} else if (modalContainer) {
// Alpine v3 使用 _x_dataStack
const alpineData = Alpine.$data(modalContainer);
if (alpineData) alpineData.fetchUser(username);
}
}
};
// 双击打开用户名片弹窗(全局统一入口)
item.ondblclick = () => openUserCard(username);
userList.appendChild(item);
if (username !== window.chatContext.username) {
@@ -236,6 +224,21 @@
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)显示用户基本信息
*/
@@ -288,7 +291,7 @@
if (systemUsers.includes(uName)) {
return `<span class="msg-user" style="color: ${color};">${uName}</span>`;
}
return `<span class="msg-user" style="color: ${color}; cursor: pointer;" onclick="switchTarget('${uName}')" ondblclick="showUserInfoInSay2('${uName}')">${uName}</span>`;
return `<span class="msg-user" style="color: ${color}; cursor: pointer;" onclick="switchTarget('${uName}')" ondblclick="openUserCard('${uName}')">${uName}</span>`;
};
// 获取发言者头像