修复手机端双触发用户信息弹窗:名单item补touchend双击检测,消息名字加事件委托

This commit is contained in:
2026-03-18 20:58:33 +08:00
parent b63b709032
commit afd02b38e3
@@ -37,6 +37,33 @@
const onlineCount = document.getElementById('online-count');
const onlineCountBottom = document.getElementById('online-count-bottom');
// ── 消息区:手机端双触发打开用户名片(PC 端靠 ondblclick 内联属性)──
// span[data-u] 由 clickableUser() 生成,touchend 委托至容器避免每条消息单独绑定
(function _bindMsgDoubleTap() {
let _lastTapTarget = null;
let _lastTapTime = 0;
/** touchend 委托处理函数 */
function _onMsgTouch(e) {
const span = e.target.closest('[data-u]');
if (!span) return;
const now = Date.now();
if (span === _lastTapTarget && now - _lastTapTime < 300) {
e.preventDefault();
openUserCard(span.dataset.u);
_lastTapTarget = null;
_lastTapTime = 0;
} else {
_lastTapTarget = span;
_lastTapTime = now;
}
}
// 两个聊天容器(公屏 + 包厢)都绑定
[container, container2].forEach(c => {
if (c) { c.addEventListener('touchend', _onMsgTouch, { passive: false }); }
});
})();
let onlineUsers = {};
let autoScroll = true;
let _maxMsgId = 0; // 记录当前收到的最大消息 ID