重构:双击用户名统一走 openUserCard 全局函数
- 新增全局 openUserCard() 函数,所有双击用户名入口统一调用 - 聊天消息区 clickableUser 的 ondblclick 改为 openUserCard - 右侧用户列表双击简化为调用 openUserCard - 移除输入栏底部的管理操作下拉框和执行按钮 - 管理操作统一通过双击用户名 → 名片弹窗执行
This commit is contained in:
@@ -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>`;
|
||||
};
|
||||
|
||||
// 获取发言者头像
|
||||
|
||||
Reference in New Issue
Block a user