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:
@@ -453,36 +453,51 @@ footer { flex: none; padding: 8px 12px calc(10px + env(safe-area-inset-bottom, 0
|
|||||||
.conv-item .st-dot.queued { background: var(--active); }
|
.conv-item .st-dot.queued { background: var(--active); }
|
||||||
.conv-item .st-dot.active { background: #1c7a2e; animation: pill-pulse 1.2s ease-in-out infinite; }
|
.conv-item .st-dot.active { background: #1c7a2e; animation: pill-pulse 1.2s ease-in-out infinite; }
|
||||||
.conv-item .st-dot.held { background: #b8860b; }
|
.conv-item .st-dot.held { background: #b8860b; }
|
||||||
/* 会话行内的删除按钮 ×:
|
/* 会话行包装:负责裁剪 + 提供 conv-del 绝对定位的参照
|
||||||
桌面端:hover/focus-within 露出;
|
conv-del(外层大红按钮)是 conv-item 的兄弟(不在 transform 子树内),
|
||||||
移动端:默认隐藏,右滑行(.conv-item.swiped)露出 */
|
这样 swiped 状态 transform:translateX(-60px) 不会一起带走删除按钮
|
||||||
|
conv-del-inline 是 conv-item 的子元素,仅桌面端 hover/focus-within 露出 */
|
||||||
|
.conv-wrap {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
.conv-item {
|
.conv-item {
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: visible; /* 允许右滑后的删除按钮溢出到行右侧 */
|
|
||||||
transition: transform .18s ease, background .12s;
|
transition: transform .18s ease, background .12s;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
.conv-item .conv-del {
|
.conv-wrap.swiped .conv-item { transform: translateX(-60px); }
|
||||||
position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
|
|
||||||
width: 36px; height: 36px; border-radius: 50%;
|
/* 移动端右滑用的大红钮:默认完全不渲染,swiped 才露 */
|
||||||
display: flex; align-items: center; justify-content: center;
|
.conv-wrap .conv-del {
|
||||||
|
display: none;
|
||||||
|
position: absolute; right: 0; top: 0; bottom: 0;
|
||||||
|
width: 60px;
|
||||||
background: #c0392b; border: 0; color: #fff;
|
background: #c0392b; border: 0; color: #fff;
|
||||||
font-size: 18px; line-height: 1; padding: 0; cursor: pointer;
|
font-size: 18px; line-height: 1; padding: 0; cursor: pointer;
|
||||||
opacity: 0; transition: opacity .12s, transform .12s;
|
align-items: center; justify-content: center;
|
||||||
pointer-events: none; /* 默认不接收点击,避免未划开时误触 */
|
border-radius: 0 12px 12px 0;
|
||||||
|
}
|
||||||
|
.conv-wrap.swiped .conv-del { display: flex; }
|
||||||
|
.conv-wrap .conv-del:active { background: #a83224; }
|
||||||
|
|
||||||
|
/* 桌面端用的内联小 ×:默认隐藏,hover/focus 露出 */
|
||||||
|
.conv-item .conv-del-inline {
|
||||||
|
display: none;
|
||||||
|
flex: none; width: 22px; height: 22px; border-radius: 50%;
|
||||||
|
background: transparent; border: 0; color: var(--gray-light);
|
||||||
|
font-size: 16px; line-height: 1; padding: 0; cursor: pointer;
|
||||||
|
align-items: center; justify-content: center;
|
||||||
}
|
}
|
||||||
@media (hover: hover) {
|
@media (hover: hover) {
|
||||||
/* 桌面端:hover 时 conv-del 变内联小圆按钮,不占绝对定位的大块位置 */
|
.conv-item .conv-del-inline { display: flex; }
|
||||||
.conv-item .conv-del {
|
.conv-item:hover .conv-del-inline,
|
||||||
position: static; transform: none;
|
.conv-item:focus-within .conv-del-inline,
|
||||||
width: 22px; height: 22px;
|
.conv-item .conv-del-inline:focus { color: var(--ink); }
|
||||||
background: transparent; color: var(--gray-light);
|
.conv-item .conv-del-inline:hover,
|
||||||
font-size: 16px; pointer-events: auto;
|
.conv-item .conv-del-inline:active { color: #fff; background: #c0392b; }
|
||||||
}
|
}
|
||||||
.conv-item:hover .conv-del, .conv-item:focus-within .conv-del, .conv-item .conv-del:focus { opacity: 1; }
|
|
||||||
.conv-item .conv-del:hover, .conv-item .conv-del:active { color: #fff; background: #c0392b; }
|
|
||||||
}
|
|
||||||
.conv-item.swiped { transform: translateX(-60px); }
|
|
||||||
.conv-item.swiped .conv-del { opacity: 1; pointer-events: auto; }
|
|
||||||
.drawer-empty { padding: 24px 10px; font-size: 13px; color: var(--gray-light); text-align: center; }
|
.drawer-empty { padding: 24px 10px; font-size: 13px; color: var(--gray-light); text-align: center; }
|
||||||
|
|
||||||
/* 底部用户区 */
|
/* 底部用户区 */
|
||||||
|
|||||||
@@ -676,10 +676,13 @@
|
|||||||
for (const s of list) {
|
for (const s of list) {
|
||||||
const g = groupLabel(s.updated_at);
|
const g = groupLabel(s.updated_at);
|
||||||
if (g !== lastGroup) { html += '<div class="group-label">' + esc(g) + '</div>'; lastGroup = g; }
|
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) + '">' +
|
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) +
|
'<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 class="conv-del" type="button" aria-label="删除会话" title="删除会话">×</button>' +
|
||||||
'</button>';
|
'</div>';
|
||||||
}
|
}
|
||||||
box.innerHTML = html;
|
box.innerHTML = html;
|
||||||
}
|
}
|
||||||
@@ -1440,8 +1443,9 @@
|
|||||||
searchTimer = setTimeout(loadSessionList, 250);
|
searchTimer = setTimeout(loadSessionList, 250);
|
||||||
});
|
});
|
||||||
$('drawer-list').addEventListener('click', e => {
|
$('drawer-list').addEventListener('click', e => {
|
||||||
if (e.target.closest('.conv-del')) {
|
if (e.target.closest('.conv-del, .conv-del-inline')) {
|
||||||
const item = e.target.closest('.conv-item');
|
const wrap = e.target.closest('.conv-wrap');
|
||||||
|
const item = wrap && wrap.querySelector('.conv-item');
|
||||||
if (item) { deleteSession(item.dataset.id); collapseAllSwiped(); }
|
if (item) { deleteSession(item.dataset.id); collapseAllSwiped(); }
|
||||||
return; // 不打开会话
|
return; // 不打开会话
|
||||||
}
|
}
|
||||||
@@ -1455,19 +1459,22 @@
|
|||||||
|
|
||||||
// ---------- 移动端右滑会话行露出删除按钮(iOS 风格) ----------
|
// ---------- 移动端右滑会话行露出删除按钮(iOS 风格) ----------
|
||||||
function collapseAllSwiped() {
|
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() {
|
(function bindSwipeToDelete() {
|
||||||
const list = $('drawer-list');
|
const list = $('drawer-list');
|
||||||
const THRESHOLD = 60; // 滑过这个距离开
|
const THRESHOLD = 60; // 滑过这个距离开
|
||||||
const CLOSE = 30; // 不够这个距离弹回
|
let g = null; // {x0, y0, t0, wrap, item, horiz, lastX, wasSwiped}
|
||||||
let g = null; // {x0, y0, t0, item, horiz, lastX, swiped}
|
|
||||||
function onDown(e) {
|
function onDown(e) {
|
||||||
if (e.touches.length !== 1) { g = null; return; }
|
if (e.touches.length !== 1) { g = null; return; }
|
||||||
const t = e.touches[0];
|
const t = e.touches[0];
|
||||||
const item = e.target.closest('.conv-item');
|
const item = e.target.closest('.conv-item');
|
||||||
if (!item) { g = null; return; }
|
const wrap = e.target.closest('.conv-wrap');
|
||||||
g = { x0: t.clientX, y0: t.clientY, t0: Date.now(), item, horiz: false, lastX: t.clientX, swiped: item.classList.contains('swiped') };
|
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) {
|
function onMove(e) {
|
||||||
if (!g) return;
|
if (!g) return;
|
||||||
@@ -1480,13 +1487,12 @@
|
|||||||
if (Math.abs(dy) > Math.abs(dx) + 6) { g = null; return; } // 竖向滚动,不接管
|
if (Math.abs(dy) > Math.abs(dx) + 6) { g = null; return; } // 竖向滚动,不接管
|
||||||
g.horiz = true;
|
g.horiz = true;
|
||||||
// 右滑起手:收起其他已滑开的行
|
// 右滑起手:收起其他已滑开的行
|
||||||
if (g.swiped) collapseAllSwiped();
|
if (g.wasSwiped) collapseAllSwiped();
|
||||||
}
|
}
|
||||||
// 只允许左滑出删除(dx<0)
|
// 只允许左滑出删除(dx<0)
|
||||||
if (dx >= 0) {
|
if (dx >= 0) {
|
||||||
// 还在右侧:仅在原本已滑开时跟手
|
// 还在右侧:仅在原本已滑开时跟手往回
|
||||||
if (g.item.classList.contains('swiped')) {
|
if (g.wrap.classList.contains('swiped')) {
|
||||||
// 从 -60 跟着手指向 0 走
|
|
||||||
const off = Math.max(-60, Math.min(0, -60 + dx));
|
const off = Math.max(-60, Math.min(0, -60 + dx));
|
||||||
g.item.style.transform = 'translateX(' + off + 'px)';
|
g.item.style.transform = 'translateX(' + off + 'px)';
|
||||||
g.lastX = t.clientX;
|
g.lastX = t.clientX;
|
||||||
@@ -1494,14 +1500,14 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 已滑开:从 -60 跟着手指走
|
// 已滑开:从 -60 跟着手指走
|
||||||
if (g.item.classList.contains('swiped')) {
|
if (g.wrap.classList.contains('swiped')) {
|
||||||
const off = Math.max(-60, Math.min(0, -60 + dx));
|
const off = Math.max(-60, Math.min(0, -60 + dx));
|
||||||
g.item.style.transform = 'translateX(' + off + 'px)';
|
g.item.style.transform = 'translateX(' + off + 'px)';
|
||||||
g.lastX = t.clientX;
|
g.lastX = t.clientX;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 未滑开:左滑逐渐出
|
// 未滑开:左滑逐渐出,上限 -60
|
||||||
const off = Math.max(-60, dx); // 不超过 -60
|
const off = Math.max(-60, dx);
|
||||||
g.item.style.transform = 'translateX(' + off + 'px)';
|
g.item.style.transform = 'translateX(' + off + 'px)';
|
||||||
g.lastX = t.clientX;
|
g.lastX = t.clientX;
|
||||||
}
|
}
|
||||||
@@ -1511,12 +1517,11 @@
|
|||||||
const dx = t ? t.clientX - g.x0 : (g.lastX - g.x0);
|
const dx = t ? t.clientX - g.x0 : (g.lastX - g.x0);
|
||||||
const moved = Math.abs(dx);
|
const moved = Math.abs(dx);
|
||||||
if (g.horiz) {
|
if (g.horiz) {
|
||||||
// 当前是否滑开:阈值判断
|
|
||||||
if (moved >= THRESHOLD) {
|
if (moved >= THRESHOLD) {
|
||||||
g.item.classList.add('swiped');
|
g.wrap.classList.add('swiped');
|
||||||
g.item.style.transform = ''; // CSS 接管
|
g.item.style.transform = ''; // CSS 接管到 -60
|
||||||
} else {
|
} else {
|
||||||
g.item.classList.remove('swiped');
|
g.wrap.classList.remove('swiped');
|
||||||
g.item.style.transform = '';
|
g.item.style.transform = '';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user