fix: 第三轮修复 — 前端Session切换、DevTools UI刷新保持、头像背景替换

1. 修复前端清空对话无反应 (clearMainSessionMessages 链路)
2. 修复清除所有对话后侧边栏残留 + 重复新增按钮
3. 修复侧边栏点击无法切换会话 (Zustand 竞态 + URL hash)
4. 修复 URL 不显示 session ID (hash 同步链)
5. DevTools 会话监看刷新保持展开/折叠状态
6. 首页性能仪表盘去重 + 资源使用卡片 60s sparkline
7. DevTools 全局刷新改为 DOM 局部增量更新
8. 替换前端昔涟头像、聊天背景、用户头像为实际图片
9. 修复图片文件名 (双.png + 目录拼写)
This commit is contained in:
2026-05-17 20:32:42 +08:00
parent e7b7eff0d8
commit d00a8313ad
18 changed files with 799 additions and 343 deletions
+39 -6
View File
@@ -66,9 +66,10 @@ export const useSessionStore = create<SessionStore>((set, get) => ({
messages: state.currentSessionId === id ? [] : state.messages,
})),
setCurrentSessionId: (id) => {
const oldId = get().currentSessionId;
set({ currentSessionId: id });
// 切换会话时清空旧消息,等待加载
if (id !== get().currentSessionId) {
if (id !== oldId) {
set({ messages: [], loading: true });
useChatStore.getState().clearMessages();
}
@@ -141,22 +142,31 @@ export const useSessionStore = create<SessionStore>((set, get) => ({
if (!ok) return;
const state = get();
const remaining = state.sessions.filter((s) => s.id !== id);
const wasCurrent = state.currentSessionId === id;
// 更新本地列表
set({ sessions: remaining });
// 从服务端重新加载会话列表,保证侧边栏同步
await get().loadSessionsFromServer(userId);
const refreshed = get().sessions;
if (wasCurrent) {
if (remaining.length > 0) {
if (refreshed.length > 0) {
// 切换到列表中的第一个会话
const nextId = remaining[0].id;
const nextId = refreshed[0].id;
set({ currentSessionId: nextId });
await get().loadMessagesFromServer(nextId);
} else {
// 没有会话了:管理员回到主对话,普通用户创建新对话
set({ currentSessionId: null, messages: [] });
useChatStore.getState().clearMessages();
// 管理员:自动创建主对话
if (isAdminUser(userId)) {
const mainSession = await get().ensureMainSession(userId);
if (mainSession) {
set({ currentSessionId: mainSession.id });
useChatStore.getState().clearMessages();
}
}
}
}
},
@@ -168,8 +178,31 @@ export const useSessionStore = create<SessionStore>((set, get) => ({
const ok = await apiDeleteAllSessions(userId);
if (!ok) return;
// 从服务端重新加载会话列表
await get().loadSessionsFromServer(userId);
const refreshed = get().sessions;
if (refreshed.length > 0) {
// 服务端仍有会话(不应该发生,但做防御性处理)
const latest = refreshed[0];
set({ currentSessionId: latest.id, messages: [] });
useChatStore.getState().clearMessages();
await get().loadMessagesFromServer(latest.id);
return;
}
// 所有会话已删除
set({ sessions: [], currentSessionId: null, messages: [] });
useChatStore.getState().clearMessages();
// 管理员:自动创建主对话
if (isAdminUser(userId)) {
const mainSession = await get().ensureMainSession(userId);
if (mainSession) {
set({ currentSessionId: mainSession.id });
useChatStore.getState().clearMessages();
}
}
},
/**