feat(ui): 侧栏会话支持在新窗口打开,地址栏常驻当前会话

- 会话行 hover 增加「在新窗口打开」按钮,走已有的 /?s=<id> 深链;触屏媒体查询下不显示
- 地址栏改为跟随当前会话:切会话写 ?s=,新建/删除回 /;原先深链消费一次就抹成 /,
  导致新窗口刷新或复制地址会丢会话
- 打开失败(会话已删/链接失效)时清回 / 并落回 welcome,不留「加载中…」和亮着的顶部按钮
This commit is contained in:
2026-11-13 09:22:57 +08:00
parent 6d4b41ebfe
commit e50015cdc1
4 changed files with 36 additions and 14 deletions
+10 -6
View File
@@ -1015,22 +1015,26 @@ body.voice-active .scroll-bottom-btn { display: none; }
}
.conv-item {
position: relative;
transition: background .12s;
transition: background .12s, padding-right .12s;
width: 100%;
}
/* 桌面端 hover 删除按钮:鼠标经过会话行时右侧显示,点击弹删除确认 modal
(触屏设备不显示,移动端删除仍走左滑手势) */
.conv-del {
position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
/* 桌面端 hover 行内按钮:右侧两个并排(新窗口 / 删除),触屏设备不显示(移动端删除走左滑手势) */
.conv-pop, .conv-del {
position: absolute; top: 50%; transform: translateY(-50%);
width: 24px; height: 24px; border-radius: 7px;
display: none; align-items: center; justify-content: center;
color: var(--gray); background: var(--surface); border: 1px solid var(--border);
z-index: 2;
}
.conv-pop { right: 8px; }
.conv-del { right: 36px; }
@media (hover: hover) and (pointer: fine) {
.conv-wrap:hover .conv-item:not(.active) { background: #f5f6f8; }
.conv-wrap:hover .conv-del { display: flex; }
/* hover 时标题让出右侧按钮位,防两个按钮压住文字 */
.conv-wrap:hover .conv-item { padding-right: 68px; }
.conv-wrap:hover .conv-pop, .conv-wrap:hover .conv-del { display: flex; }
.conv-pop:hover { color: var(--active); background: var(--active-soft); border-color: currentColor; }
.conv-del:hover { color: #c0392b; background: #fdf3f2; border-color: #eac2bd; }
}
.drawer-empty { padding: 24px 10px; font-size: 13px; color: var(--gray-light); text-align: center; }
+4 -1
View File
@@ -1093,7 +1093,10 @@
searchTimer = setTimeout(loadSessionList, 250);
});
$('drawer-list').addEventListener('click', e => {
// 桌面端 hover 删除按钮:先于打开会话处理,点击弹删除确认 modal
// 桌面端 hover 行内按钮:先于打开会话处理
const popBtn = e.target.closest('.conv-pop');
if (popBtn) { e.stopPropagation(); window.open('/?s=' + encodeURIComponent(popBtn.dataset.pop), '_blank', 'noopener'); return; }
// 删除按钮:点击弹删除确认 modal
const delBtn = e.target.closest('.conv-del');
if (delBtn) { e.stopPropagation(); deleteSession(delBtn.dataset.del); return; }
const item = e.target.closest('.conv-item');
+19 -1
View File
@@ -31,6 +31,9 @@
'<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>' +
'<button class="conv-pop" data-pop="' + esc(s.id) + '" title="在新窗口打开" aria-label="在新窗口打开">' +
'<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>' +
'</button>' +
'<button class="conv-del" data-del="' + esc(s.id) + '" title="删除会话" aria-label="删除会话">' +
'<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/></svg>' +
'</button>' +
@@ -90,6 +93,7 @@
state.renderedSigs = {};
state.streaming = false;
if (typeof clearEditState === 'function') clearEditState();
syncUrl(null);
setView('welcome'); // 复用 newChat 同样的视图切换路径
}
toast('已删除会话');
@@ -184,6 +188,11 @@
if (Date.now() - state.lastSseAt > 45000) probeSseAlive();
});
// 地址栏跟随当前会话(?s=<id>):刷新/收藏/分享都能回到同一会话;没有会话时回到干净的 /
function syncUrl(id) {
try { history.replaceState(null, '', id ? '/?s=' + encodeURIComponent(id) : '/'); } catch (_) {}
}
async function openSession(id) {
closeStream();
removeTyping();
@@ -228,8 +237,15 @@
$('deep-think-btn').classList.toggle('on', state.deepThink);
connectStream();
if (window.refreshFileTree) window.refreshFileTree();
syncUrl(id); // 详情拿到才写地址栏:坏链接不会把刷新后的页面也钉死在坏会话上
} catch (e) {
if (state.sessionId === id) toast('打开会话失败:' + e.message);
if (state.sessionId === id) {
toast('打开会话失败:' + e.message);
state.sessionId = null;
state.sessionTitle = '';
syncUrl(null);
setView('welcome'); // 会话已被删/链接失效:别把「加载中…」留在屏幕上(同时把顶部按钮置灰)
}
}
}
@@ -247,6 +263,7 @@
renderHeader();
updateHeaderActions();
connectStream();
syncUrl(s.id);
return s.id;
}
@@ -321,6 +338,7 @@
userPaused = false;
renderAttachChips();
clearUploadCards();
syncUrl(null);
setView('welcome');
$('chat-view').innerHTML = '';
$('msg-input').value = '';
+3 -6
View File
@@ -2085,11 +2085,8 @@
loadSessionList();
// 侧栏底部已是纯图标操作栏(不展示用户信息),不再需要 loadDrawerUser
// 会话深链 /?s=<session_id>:数据页面(/app/{task_id}/...)的「返回会话」FAB 用——
// task_id 即会话 id(engine 里 1:1),启动时消费一次即 replaceState 抹掉参数,
// 避免刷新/分享时被钉回该会话;会话已删则 openSession 自行报错,落在 welcome。
// task_id 即会话 id(engine 里 1:1)。地址栏常驻 ?s= 不抹掉,刷新/收藏/分享都能回到同一会话;
// 会话已删时 openSession 会自己回落到 welcome 并把 URL 清回 /。
const deep = new URLSearchParams(location.search).get('s');
if (deep) {
history.replaceState(null, '', '/');
openSession(deep);
}
if (deep) openSession(deep);
})();