fix(ui): 修复移动端抽屉删除按钮的两个 bug

Bug1:移动端每行下面仍显 × -> conv-del 默认 display:none(不渲染)
Bug2:右滑后不显删除按钮 -> swiped transform 误把 conv-del 带出可见区
  重构:把 conv-del 拆为两个互斥按钮
  - .conv-del(大红外钮)放在 .conv-item 兄弟节点 conv-wrap 里
    绝对定位 right:0 + overflow:hidden,swiped 时 display:flex
    因为不在 .conv-item 的 transform 子树内,不会被 translateX 带走
  - .conv-del-inline(小灰内钮)仍在 .conv-item 内,桌面端 hover 才 display:flex
  JS:click 委派同时拦 conv-del 和 conv-del-inline;滑动类加到 .conv-wrap
This commit is contained in:
2026-09-03 20:15:45 +08:00
parent c75917560e
commit 3610c82c69
2 changed files with 62 additions and 42 deletions
+26 -21
View File
@@ -676,10 +676,13 @@
for (const s of list) {
const g = groupLabel(s.updated_at);
if (g !== lastGroup) { html += '<div class="group-label">' + esc(g) + '</div>'; lastGroup = g; }
html += '<button class="conv-item' + (s.id === state.sessionId ? ' active' : '') + '" data-id="' + esc(s.id) + '">' +
'<span class="conv-title">' + esc(s.title || s.id) + '</span>' + drawerStatusDot(s) +
html += '<div class="conv-wrap">' +
'<button class="conv-item' + (s.id === state.sessionId ? ' active' : '') + '" data-id="' + esc(s.id) + '">' +
'<span class="conv-title">' + esc(s.title || s.id) + '</span>' + drawerStatusDot(s) +
'<button class="conv-del-inline" type="button" aria-label="删除会话" title="删除会话">×</button>' +
'</button>' +
'<button class="conv-del" type="button" aria-label="删除会话" title="删除会话">×</button>' +
'</button>';
'</div>';
}
box.innerHTML = html;
}
@@ -1440,8 +1443,9 @@
searchTimer = setTimeout(loadSessionList, 250);
});
$('drawer-list').addEventListener('click', e => {
if (e.target.closest('.conv-del')) {
const item = e.target.closest('.conv-item');
if (e.target.closest('.conv-del, .conv-del-inline')) {
const wrap = e.target.closest('.conv-wrap');
const item = wrap && wrap.querySelector('.conv-item');
if (item) { deleteSession(item.dataset.id); collapseAllSwiped(); }
return; // 不打开会话
}
@@ -1455,19 +1459,22 @@
// ---------- 移动端右滑会话行露出删除按钮(iOS 风格) ----------
function collapseAllSwiped() {
document.querySelectorAll('.conv-item.swiped').forEach(el => el.classList.remove('swiped'));
document.querySelectorAll('.conv-wrap.swiped').forEach(el => {
el.classList.remove('swiped');
const it = el.querySelector('.conv-item'); if (it) it.style.transform = '';
});
}
(function bindSwipeToDelete() {
const list = $('drawer-list');
const THRESHOLD = 60; // 滑过这个距离开
const CLOSE = 30; // 不够这个距离弹回
let g = null; // {x0, y0, t0, item, horiz, lastX, swiped}
let g = null; // {x0, y0, t0, wrap, item, horiz, lastX, wasSwiped}
function onDown(e) {
if (e.touches.length !== 1) { g = null; return; }
const t = e.touches[0];
const item = e.target.closest('.conv-item');
if (!item) { g = null; return; }
g = { x0: t.clientX, y0: t.clientY, t0: Date.now(), item, horiz: false, lastX: t.clientX, swiped: item.classList.contains('swiped') };
const wrap = e.target.closest('.conv-wrap');
if (!item || !wrap) { g = null; return; }
g = { x0: t.clientX, y0: t.clientY, t0: Date.now(), wrap, item, horiz: false, lastX: t.clientX, wasSwiped: wrap.classList.contains('swiped') };
}
function onMove(e) {
if (!g) return;
@@ -1480,13 +1487,12 @@
if (Math.abs(dy) > Math.abs(dx) + 6) { g = null; return; } // 竖向滚动,不接管
g.horiz = true;
// 右滑起手:收起其他已滑开的行
if (g.swiped) collapseAllSwiped();
if (g.wasSwiped) collapseAllSwiped();
}
// 只允许左滑出删除(dx<0)
if (dx >= 0) {
// 还在右侧:仅在原本已滑开时跟手
if (g.item.classList.contains('swiped')) {
// 从 -60 跟着手指向 0 走
// 还在右侧:仅在原本已滑开时跟手往回
if (g.wrap.classList.contains('swiped')) {
const off = Math.max(-60, Math.min(0, -60 + dx));
g.item.style.transform = 'translateX(' + off + 'px)';
g.lastX = t.clientX;
@@ -1494,14 +1500,14 @@
return;
}
// 已滑开:从 -60 跟着手指走
if (g.item.classList.contains('swiped')) {
if (g.wrap.classList.contains('swiped')) {
const off = Math.max(-60, Math.min(0, -60 + dx));
g.item.style.transform = 'translateX(' + off + 'px)';
g.lastX = t.clientX;
return;
}
// 未滑开:左滑逐渐出
const off = Math.max(-60, dx); // 不超过 -60
// 未滑开:左滑逐渐出,上限 -60
const off = Math.max(-60, dx);
g.item.style.transform = 'translateX(' + off + 'px)';
g.lastX = t.clientX;
}
@@ -1511,12 +1517,11 @@
const dx = t ? t.clientX - g.x0 : (g.lastX - g.x0);
const moved = Math.abs(dx);
if (g.horiz) {
// 当前是否滑开:阈值判断
if (moved >= THRESHOLD) {
g.item.classList.add('swiped');
g.item.style.transform = ''; // CSS 接管
g.wrap.classList.add('swiped');
g.item.style.transform = ''; // CSS 接管到 -60
} else {
g.item.classList.remove('swiped');
g.wrap.classList.remove('swiped');
g.item.style.transform = '';
}
} else {