修复手机端双触发弹窗:名单 item 和消息名字均支持 touchend double-tap 弹出用户名片
This commit is contained in:
@@ -311,18 +311,25 @@
|
||||
document.getElementById('content').focus();
|
||||
}, 250);
|
||||
};
|
||||
// 双击打开用户名片弹窗(全局统一入口);手机端同时关闭名单抽屉
|
||||
item.ondblclick = () => {
|
||||
// 取消尚未执行的单击定时器
|
||||
if (_clickTimer) {
|
||||
clearTimeout(_clickTimer);
|
||||
_clickTimer = null;
|
||||
}
|
||||
if (typeof closeMobileDrawer === 'function') {
|
||||
closeMobileDrawer();
|
||||
}
|
||||
// 双击 / 手机端双触发 打开用户名片弹窗
|
||||
const _openCardFromList = () => {
|
||||
if (_clickTimer) { clearTimeout(_clickTimer); _clickTimer = null; }
|
||||
if (typeof closeMobileDrawer === 'function') { closeMobileDrawer(); }
|
||||
openUserCard(username);
|
||||
};
|
||||
item.ondblclick = _openCardFromList;
|
||||
// 手机端:检测 300ms 内两次 touchend 触发双击
|
||||
let _tapTime = 0;
|
||||
item.addEventListener('touchend', (e) => {
|
||||
const now = Date.now();
|
||||
if (now - _tapTime < 300) {
|
||||
e.preventDefault();
|
||||
_openCardFromList();
|
||||
_tapTime = 0;
|
||||
} else {
|
||||
_tapTime = now;
|
||||
}
|
||||
}, { passive: false });
|
||||
targetContainer.appendChild(item);
|
||||
});
|
||||
}
|
||||
@@ -490,7 +497,7 @@
|
||||
if (systemUsers.includes(uName) || isGameLabel(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="openUserCard('${uName}')">${uName}</span>`;
|
||||
return `<span class="msg-user" data-u="${uName}" style="color: ${color}; cursor: pointer;" onclick="switchTarget('${uName}')" ondblclick="openUserCard('${uName}')">${uName}</span>`;
|
||||
};
|
||||
|
||||
// 系统播报用户(不包含 AI小班长)使用军号图标,AI小班长用专属图,普通用户用头像
|
||||
@@ -663,6 +670,30 @@
|
||||
if (typeof window.initChat === 'function') {
|
||||
window.initChat(window.chatContext.roomId);
|
||||
}
|
||||
|
||||
// 手机端:在公屏(say1)和包厢(say2)容器上注册 touchend 委托
|
||||
// 检测 300ms 内两次触摸同一 [data-u] 用户名 span,触发 openUserCard
|
||||
let _msgTapTarget = null;
|
||||
let _msgTapTime = 0;
|
||||
['say1', 'say2'].forEach(id => {
|
||||
const el = document.getElementById(id);
|
||||
if (!el) { return; }
|
||||
el.addEventListener('touchend', (e) => {
|
||||
const span = e.target.closest('[data-u]');
|
||||
if (!span) { return; }
|
||||
const uName = span.dataset.u;
|
||||
const now = Date.now();
|
||||
if (uName === _msgTapTarget && now - _msgTapTime < 300) {
|
||||
e.preventDefault();
|
||||
openUserCard(uName);
|
||||
_msgTapTarget = null;
|
||||
_msgTapTime = 0;
|
||||
} else {
|
||||
_msgTapTarget = uName;
|
||||
_msgTapTime = now;
|
||||
}
|
||||
}, { passive: false });
|
||||
});
|
||||
});
|
||||
|
||||
// ── WebSocket 事件监听 ────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user