From 3610c82c690811c92a69c415d3d0b5039f4d9076 Mon Sep 17 00:00:00 2001 From: kicer Date: Thu, 3 Sep 2026 20:15:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E4=BF=AE=E5=A4=8D=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=AB=AF=E6=8A=BD=E5=B1=89=E5=88=A0=E9=99=A4=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E7=9A=84=E4=B8=A4=E4=B8=AA=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/server/public/css/style.css | 57 +++++++++++++++++++++------------ app/server/public/index.html | 47 +++++++++++++++------------ 2 files changed, 62 insertions(+), 42 deletions(-) diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index d6347ea..f71192b 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -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.active { background: #1c7a2e; animation: pill-pulse 1.2s ease-in-out infinite; } .conv-item .st-dot.held { background: #b8860b; } -/* 会话行内的删除按钮 ×: - 桌面端:hover/focus-within 露出; - 移动端:默认隐藏,右滑行(.conv-item.swiped)露出 */ +/* 会话行包装:负责裁剪 + 提供 conv-del 绝对定位的参照 + conv-del(外层大红按钮)是 conv-item 的兄弟(不在 transform 子树内), + 这样 swiped 状态 transform:translateX(-60px) 不会一起带走删除按钮 + conv-del-inline 是 conv-item 的子元素,仅桌面端 hover/focus-within 露出 */ +.conv-wrap { + position: relative; + overflow: hidden; + border-radius: 12px; +} .conv-item { position: relative; - overflow: visible; /* 允许右滑后的删除按钮溢出到行右侧 */ transition: transform .18s ease, background .12s; + width: 100%; } -.conv-item .conv-del { - position: absolute; right: 10px; top: 50%; transform: translateY(-50%); - width: 36px; height: 36px; border-radius: 50%; - display: flex; align-items: center; justify-content: center; +.conv-wrap.swiped .conv-item { transform: translateX(-60px); } + +/* 移动端右滑用的大红钮:默认完全不渲染,swiped 才露 */ +.conv-wrap .conv-del { + display: none; + position: absolute; right: 0; top: 0; bottom: 0; + width: 60px; background: #c0392b; border: 0; color: #fff; font-size: 18px; line-height: 1; padding: 0; cursor: pointer; - opacity: 0; transition: opacity .12s, transform .12s; - pointer-events: none; /* 默认不接收点击,避免未划开时误触 */ + align-items: center; justify-content: center; + 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) { - /* 桌面端:hover 时 conv-del 变内联小圆按钮,不占绝对定位的大块位置 */ - .conv-item .conv-del { - position: static; transform: none; - width: 22px; height: 22px; - background: transparent; color: var(--gray-light); - font-size: 16px; pointer-events: auto; - } - .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 .conv-del-inline { display: flex; } + .conv-item:hover .conv-del-inline, + .conv-item:focus-within .conv-del-inline, + .conv-item .conv-del-inline:focus { color: var(--ink); } + .conv-item .conv-del-inline:hover, + .conv-item .conv-del-inline: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; } /* 底部用户区 */ diff --git a/app/server/public/index.html b/app/server/public/index.html index ca7d205..e026afc 100644 --- a/app/server/public/index.html +++ b/app/server/public/index.html @@ -676,10 +676,13 @@ for (const s of list) { const g = groupLabel(s.updated_at); if (g !== lastGroup) { html += '
' + esc(g) + '
'; lastGroup = g; } - html += '' + + '' + '' + - ''; + ''; } 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 {