feat(ui): 侧栏会话支持在新窗口打开,地址栏常驻当前会话
- 会话行 hover 增加「在新窗口打开」按钮,走已有的 /?s=<id> 深链;触屏媒体查询下不显示 - 地址栏改为跟随当前会话:切会话写 ?s=,新建/删除回 /;原先深链消费一次就抹成 /, 导致新窗口刷新或复制地址会丢会话 - 打开失败(会话已删/链接失效)时清回 / 并落回 welcome,不留「加载中…」和亮着的顶部按钮
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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 = '';
|
||||
|
||||
@@ -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);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user