feat(ui): 移动端右滑会话行露出删除按钮 + 抽屉高亮实时更新
- 移动端:右滑会话行 → .swiped(translateX(-60px))让 conv-del 绝对定位红钮露出 阈值 60px(>= 保留为 swiped,< 弹回);不与抽屉的左缘右滑(EDGE=100)冲突 - 桌面端:hover/focus-within/focus 露出 ×(行为不变,小圆灰底);移动端默认不显 - conv-del 绝对定位 + overflow:visible(原 overflow:hidden 已覆盖) - openSession 切会话后立即 renderDrawerList,关抽屉瞬间高亮已变更新会话 不用等下次开抽屉才看到(原 bug:开 A→点 B 关闭,再开抽屉还显示 A 高亮) - 抽屉 click 后自动 collapseAllSwiped 收起所有 swiped 行,避免视觉残留
This commit is contained in:
@@ -445,21 +445,36 @@ 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; }
|
||||||
/* 会话行内的删除 ×:默认隐藏,hover/focus-within/active 露出,点击变红 */
|
/* 会话行内的删除按钮 ×:
|
||||||
|
桌面端:hover/focus-within 露出;
|
||||||
|
移动端:默认隐藏,右滑行(.conv-item.swiped)露出 */
|
||||||
|
.conv-item {
|
||||||
|
position: relative;
|
||||||
|
overflow: visible; /* 允许右滑后的删除按钮溢出到行右侧 */
|
||||||
|
transition: transform .18s ease, background .12s;
|
||||||
|
}
|
||||||
.conv-item .conv-del {
|
.conv-item .conv-del {
|
||||||
flex: none; width: 22px; height: 22px; border-radius: 50%;
|
position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
|
||||||
|
width: 36px; height: 36px; border-radius: 50%;
|
||||||
display: flex; align-items: center; justify-content: center;
|
display: flex; align-items: center; justify-content: center;
|
||||||
background: transparent; border: 0; color: var(--gray-light);
|
background: #c0392b; border: 0; color: #fff;
|
||||||
font-size: 16px; line-height: 1; padding: 0; cursor: pointer;
|
font-size: 18px; line-height: 1; padding: 0; cursor: pointer;
|
||||||
opacity: 0; transition: opacity .12s, color .12s, background .12s;
|
opacity: 0; transition: opacity .12s, transform .12s;
|
||||||
|
pointer-events: none; /* 默认不接收点击,避免未划开时误触 */
|
||||||
}
|
}
|
||||||
.conv-item:hover .conv-del, .conv-item:focus-within .conv-del, .conv-item .conv-del:focus { opacity: 1; }
|
@media (hover: hover) {
|
||||||
.conv-item .conv-del:hover, .conv-item .conv-del:active { color: #fff; background: #c0392b; }
|
/* 桌面端:hover 时 conv-del 变内联小圆按钮,不占绝对定位的大块位置 */
|
||||||
/* 移动端无 hover:用 :focus-within/active 也能在点会话名字时短暂高亮行,但为了看不见的×也可见,
|
.conv-item .conv-del {
|
||||||
在抽屉打开状态下始终让 × 微透明(以不影响未 hover 行的整洁) */
|
position: static; transform: none;
|
||||||
@media (hover: none) {
|
width: 22px; height: 22px;
|
||||||
.conv-item .conv-del { opacity: .45; }
|
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.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; }
|
||||||
|
|
||||||
/* 底部用户区 */
|
/* 底部用户区 */
|
||||||
|
|||||||
@@ -742,6 +742,7 @@
|
|||||||
state.attachments = [];
|
state.attachments = [];
|
||||||
userPaused = false;
|
userPaused = false;
|
||||||
renderAttachChips();
|
renderAttachChips();
|
||||||
|
renderDrawerList(); // 会话切换后立刻重画抽屉高亮,避免下次打开才看到更新
|
||||||
setView('chat');
|
setView('chat');
|
||||||
$('chat-view').innerHTML = '<div class="drawer-empty">加载中…</div>';
|
$('chat-view').innerHTML = '<div class="drawer-empty">加载中…</div>';
|
||||||
try {
|
try {
|
||||||
@@ -1441,15 +1442,95 @@
|
|||||||
$('drawer-list').addEventListener('click', e => {
|
$('drawer-list').addEventListener('click', e => {
|
||||||
if (e.target.closest('.conv-del')) {
|
if (e.target.closest('.conv-del')) {
|
||||||
const item = e.target.closest('.conv-item');
|
const item = e.target.closest('.conv-item');
|
||||||
if (item) deleteSession(item.dataset.id);
|
if (item) { deleteSession(item.dataset.id); collapseAllSwiped(); }
|
||||||
return; // 不打开会话
|
return; // 不打开会话
|
||||||
}
|
}
|
||||||
|
// 点击后收起其他已滑开的行
|
||||||
|
collapseAllSwiped();
|
||||||
const item = e.target.closest('.conv-item');
|
const item = e.target.closest('.conv-item');
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
openSession(item.dataset.id);
|
openSession(item.dataset.id);
|
||||||
openDrawer(false);
|
openDrawer(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---------- 移动端右滑会话行露出删除按钮(iOS 风格) ----------
|
||||||
|
function collapseAllSwiped() {
|
||||||
|
document.querySelectorAll('.conv-item.swiped').forEach(el => el.classList.remove('swiped'));
|
||||||
|
}
|
||||||
|
(function bindSwipeToDelete() {
|
||||||
|
const list = $('drawer-list');
|
||||||
|
const THRESHOLD = 60; // 滑过这个距离开
|
||||||
|
const CLOSE = 30; // 不够这个距离弹回
|
||||||
|
let g = null; // {x0, y0, t0, item, horiz, lastX, swiped}
|
||||||
|
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') };
|
||||||
|
}
|
||||||
|
function onMove(e) {
|
||||||
|
if (!g) return;
|
||||||
|
const t = e.touches[0];
|
||||||
|
const dx = t.clientX - g.x0;
|
||||||
|
const dy = t.clientY - g.y0;
|
||||||
|
// 先判断为横向手势才接管
|
||||||
|
if (!g.horiz) {
|
||||||
|
if (Math.abs(dx) < 8 && Math.abs(dy) < 8) return;
|
||||||
|
if (Math.abs(dy) > Math.abs(dx) + 6) { g = null; return; } // 竖向滚动,不接管
|
||||||
|
g.horiz = true;
|
||||||
|
// 右滑起手:收起其他已滑开的行
|
||||||
|
if (g.swiped) collapseAllSwiped();
|
||||||
|
}
|
||||||
|
// 只允许左滑出删除(dx<0)
|
||||||
|
if (dx >= 0) {
|
||||||
|
// 还在右侧:仅在原本已滑开时跟手
|
||||||
|
if (g.item.classList.contains('swiped')) {
|
||||||
|
// 从 -60 跟着手指向 0 走
|
||||||
|
const off = Math.max(-60, Math.min(0, -60 + dx));
|
||||||
|
g.item.style.transform = 'translateX(' + off + 'px)';
|
||||||
|
g.lastX = t.clientX;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 已滑开:从 -60 跟着手指走
|
||||||
|
if (g.item.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
|
||||||
|
g.item.style.transform = 'translateX(' + off + 'px)';
|
||||||
|
g.lastX = t.clientX;
|
||||||
|
}
|
||||||
|
function onUp(e) {
|
||||||
|
if (!g) return;
|
||||||
|
const t = (e.changedTouches && e.changedTouches[0]) || null;
|
||||||
|
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 接管
|
||||||
|
} else {
|
||||||
|
g.item.classList.remove('swiped');
|
||||||
|
g.item.style.transform = '';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 未识别为横向:不动(交给 click 委派处理打开)
|
||||||
|
g.item.style.transform = '';
|
||||||
|
}
|
||||||
|
g = null;
|
||||||
|
}
|
||||||
|
list.addEventListener('touchstart', onDown, { passive: true });
|
||||||
|
list.addEventListener('touchmove', onMove, { passive: true });
|
||||||
|
list.addEventListener('touchend', onUp, { passive: true });
|
||||||
|
list.addEventListener('touchcancel', onUp, { passive: true });
|
||||||
|
})();
|
||||||
|
|
||||||
// 会话页左缘右滑 → 拉出历史抽屉:跟随手指平移,超过阈值/快速右滑松手即打开。
|
// 会话页左缘右滑 → 拉出历史抽屉:跟随手指平移,超过阈值/快速右滑松手即打开。
|
||||||
(function bindEdgeSwipe() {
|
(function bindEdgeSwipe() {
|
||||||
const drawer = $('drawer'), scrim = $('scrim');
|
const drawer = $('drawer'), scrim = $('scrim');
|
||||||
|
|||||||
Reference in New Issue
Block a user