3 Commits
Author SHA1 Message Date
kicer 4c4076ba13 feat(ui): 侧栏面板模式写进地址栏,刷新后保持文件树/会话列表
- syncUrl 改为无参,按 state.sessionId + #drawer 的 drawer-mode-files 拼 ?s=<id>[&files=1]
- setDrawerPane 切换成功后同步地址栏:点底部文件树图标、切回列表都会改写 URL
- 新窗口带 files=1 进来落地即文件树,F5 不再退回会话列表;窄屏 setDrawerPane 直接 return,地址栏不会写上 files=1
2026-11-13 09:27:47 +08:00
kicer 65d05d2656 feat(ui): 新窗口打开落地即进文件树,调换行内按钮顺序
- 行内按钮改为删除在最右、新窗口在它左边(误触删除的概率更低)
- 会话行新窗口链接带 files=1,打开会话后把侧栏切到文件树,省一次点击
- 手机端本来就不显示行内按钮(hover:hover + pointer:fine),窄屏 setDrawerPane 也会拒绝切文件树
2026-11-13 09:25:22 +08:00
kicer e50015cdc1 feat(ui): 侧栏会话支持在新窗口打开,地址栏常驻当前会话
- 会话行 hover 增加「在新窗口打开」按钮,走已有的 /?s=<id> 深链;触屏媒体查询下不显示
- 地址栏改为跟随当前会话:切会话写 ?s=,新建/删除回 /;原先深链消费一次就抹成 /,
  导致新窗口刷新或复制地址会丢会话
- 打开失败(会话已删/链接失效)时清回 / 并落回 welcome,不留「加载中…」和亮着的顶部按钮
2026-11-13 09:22:57 +08:00
4 changed files with 56 additions and 13 deletions
+10 -6
View File
@@ -1015,22 +1015,26 @@ body.voice-active .scroll-bottom-btn { display: none; }
} }
.conv-item { .conv-item {
position: relative; position: relative;
transition: background .12s; transition: background .12s, padding-right .12s;
width: 100%; width: 100%;
} }
/* 桌面端 hover 删除按钮:鼠标经过会话行时右侧显示,点击弹删除确认 modal /* 桌面端 hover 行内按钮:右侧两个并排(新窗口 / 删除),触屏设备不显示(移动端删除走左滑手势) */
(触屏设备不显示,移动端删除仍走左滑手势) */ .conv-pop, .conv-del {
.conv-del { position: absolute; top: 50%; transform: translateY(-50%);
position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
width: 24px; height: 24px; border-radius: 7px; width: 24px; height: 24px; border-radius: 7px;
display: none; align-items: center; justify-content: center; display: none; align-items: center; justify-content: center;
color: var(--gray); background: var(--surface); border: 1px solid var(--border); color: var(--gray); background: var(--surface); border: 1px solid var(--border);
z-index: 2; z-index: 2;
} }
.conv-pop { right: 36px; }
.conv-del { right: 8px; }
@media (hover: hover) and (pointer: fine) { @media (hover: hover) and (pointer: fine) {
.conv-wrap:hover .conv-item:not(.active) { background: #f5f6f8; } .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; } .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; } .drawer-empty { padding: 24px 10px; font-size: 13px; color: var(--gray-light); text-align: center; }
+11 -1
View File
@@ -1093,7 +1093,15 @@
searchTimer = setTimeout(loadSessionList, 250); searchTimer = setTimeout(loadSessionList, 250);
}); });
$('drawer-list').addEventListener('click', e => { $('drawer-list').addEventListener('click', e => {
// 桌面端 hover 删除按钮:先于打开会话处理,点击弹删除确认 modal // 桌面端 hover 行内按钮:先于打开会话处理
const popBtn = e.target.closest('.conv-pop');
if (popBtn) {
e.stopPropagation();
// files=1 让新窗口开局直接把侧栏切到文件树(打开后即被 syncUrl 抹掉)
window.open('/?s=' + encodeURIComponent(popBtn.dataset.pop) + '&files=1', '_blank', 'noopener');
return;
}
// 删除按钮:点击弹删除确认 modal
const delBtn = e.target.closest('.conv-del'); const delBtn = e.target.closest('.conv-del');
if (delBtn) { e.stopPropagation(); deleteSession(delBtn.dataset.del); return; } if (delBtn) { e.stopPropagation(); deleteSession(delBtn.dataset.del); return; }
const item = e.target.closest('.conv-item'); const item = e.target.closest('.conv-item');
@@ -1251,6 +1259,8 @@
if (!changed) return; if (!changed) return;
if (files) window.showFileTree(); if (files) window.showFileTree();
else loadSessionList(); else loadSessionList();
// 地址栏跟着侧栏模式走(?s=<id>&files=1):刷新后还停在同一面板
if (typeof syncUrl === 'function') syncUrl();
} }
$('da-files').addEventListener('click', () => { $('da-files').addEventListener('click', () => {
setDrawerPane(!$('drawer').classList.contains('drawer-mode-files')); setDrawerPane(!$('drawer').classList.contains('drawer-mode-files'));
+26 -1
View File
@@ -31,6 +31,9 @@
'<button class="conv-item' + (s.id === state.sessionId ? ' active' : '') + '" data-id="' + esc(s.id) + '">' + '<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>' + '</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="删除会话">' + '<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>' + '<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>' + '</button>' +
@@ -90,6 +93,7 @@
state.renderedSigs = {}; state.renderedSigs = {};
state.streaming = false; state.streaming = false;
if (typeof clearEditState === 'function') clearEditState(); if (typeof clearEditState === 'function') clearEditState();
syncUrl();
setView('welcome'); // 复用 newChat 同样的视图切换路径 setView('welcome'); // 复用 newChat 同样的视图切换路径
} }
toast('已删除会话'); toast('已删除会话');
@@ -184,6 +188,18 @@
if (Date.now() - state.lastSseAt > 45000) probeSseAlive(); if (Date.now() - state.lastSseAt > 45000) probeSseAlive();
}); });
// 地址栏跟随当前会话与侧栏模式:?s=<id>[&files=1],刷新/收藏/分享都能回到同一屏
function syncUrl() {
const id = state.sessionId;
let url = '/';
if (id) {
url = '/?s=' + encodeURIComponent(id);
// 侧栏停在文件树时带上 files=1:刷新后还是文件树,不会莫名退回会话列表
if ($('drawer').classList.contains('drawer-mode-files')) url += '&files=1';
}
try { history.replaceState(null, '', url); } catch (_) {}
}
async function openSession(id) { async function openSession(id) {
closeStream(); closeStream();
removeTyping(); removeTyping();
@@ -228,8 +244,15 @@
$('deep-think-btn').classList.toggle('on', state.deepThink); $('deep-think-btn').classList.toggle('on', state.deepThink);
connectStream(); connectStream();
if (window.refreshFileTree) window.refreshFileTree(); if (window.refreshFileTree) window.refreshFileTree();
syncUrl(); // 详情拿到才写地址栏:坏链接不会把刷新后的页面也钉死在坏会话上
} catch (e) { } catch (e) {
if (state.sessionId === id) toast('打开会话失败:' + e.message); if (state.sessionId === id) {
toast('打开会话失败:' + e.message);
state.sessionId = null;
state.sessionTitle = '';
syncUrl();
setView('welcome'); // 会话已被删/链接失效:别把「加载中…」留在屏幕上(同时把顶部按钮置灰)
}
} }
} }
@@ -247,6 +270,7 @@
renderHeader(); renderHeader();
updateHeaderActions(); updateHeaderActions();
connectStream(); connectStream();
syncUrl();
return s.id; return s.id;
} }
@@ -321,6 +345,7 @@
userPaused = false; userPaused = false;
renderAttachChips(); renderAttachChips();
clearUploadCards(); clearUploadCards();
syncUrl();
setView('welcome'); setView('welcome');
$('chat-view').innerHTML = ''; $('chat-view').innerHTML = '';
$('msg-input').value = ''; $('msg-input').value = '';
+9 -5
View File
@@ -2085,11 +2085,15 @@
loadSessionList(); loadSessionList();
// 侧栏底部已是纯图标操作栏(不展示用户信息),不再需要 loadDrawerUser // 侧栏底部已是纯图标操作栏(不展示用户信息),不再需要 loadDrawerUser
// 会话深链 /?s=<session_id>:数据页面(/app/{task_id}/...)的「返回会话」FAB 用—— // 会话深链 /?s=<session_id>:数据页面(/app/{task_id}/...)的「返回会话」FAB 用——
// task_id 即会话 id(engine 里 1:1),启动时消费一次即 replaceState 抹掉参数, // task_id 即会话 id(engine 里 1:1)。地址栏常驻 ?s= 不抹掉,刷新/收藏/分享都能回到同一会话;
// 避免刷新/分享时被钉回该会话;会话已删则 openSession 自行报错,落在 welcome。 // 会话已删时 openSession 会自己回落到 welcome 并把 URL 清回 /。
const deep = new URLSearchParams(location.search).get('s'); const params = new URLSearchParams(location.search);
const deep = params.get('s');
if (deep) { if (deep) {
history.replaceState(null, '', '/'); openSession(deep).then(() => {
openSession(deep); // 从侧栏「在新窗口打开」进来(带 files=1):开局直接把侧栏切到文件树;
// 窄屏/无会话/文件树未加载时 setDrawerPane 内部会自行忽略
if (params.get('files') === '1' && typeof setDrawerPane === 'function') setDrawerPane(true);
});
} }
})(); })();