refactor(frontend): 重构前端第二版

This commit is contained in:
sophie committed 2026-06-11 13:47:06 +08:00
1 parent 2631f78b00
commit 4b562cfa82
205 files changed
+15399 -12015

No files matched your search

@@ -1,21 +1,58 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { ChatSessionItem } from '../types/chat.types';
/**
* features/chat/stores/chat.store.ts
* 聊天域共享状态:当前 agent、侧栏折叠等(会话列表逐步迁入)。
* 聊天域跨页面共享状态:当前 Agent、侧栏折叠、按 Agent 缓存的会话列表。
*/
export const useChatStore = defineStore('chat', () => {
const currentAgentId = ref<number | null>(null);
/** 桌面端 ChatSidebar 是否收起 */
const sidebarCollapsed = ref(false);
/** 按 Agent ID 缓存侧栏会话列表,切换回来时先展示缓存再后台刷新 */
const sessionHistoryByAgent = ref<Record<number, ChatSessionItem[]>>({});
const setCurrentAgentId = (agentId: number | null): void => {
currentAgentId.value = agentId;
};
const getSessionHistory = (agentId: number): ChatSessionItem[] | null => {
const items = sessionHistoryByAgent.value[agentId];
return Array.isArray(items) ? items : null;
};
const setSessionHistory = (agentId: number, items: ChatSessionItem[]): void => {
sessionHistoryByAgent.value = {
...sessionHistoryByAgent.value,
[agentId]: items,
};
};
const patchSessionHistory = (agentId: number, items: ChatSessionItem[]): void => {
setSessionHistory(agentId, items);
};
const clearSessionHistoryForAgent = (agentId: number): void => {
const next = { ...sessionHistoryByAgent.value };
delete next[agentId];
sessionHistoryByAgent.value = next;
};
/** Agent 切换或离开对话页时重置页面级 UI 偏好 */
const resetPageUiState = () => {
sidebarCollapsed.value = false;
};
return {
currentAgentId,
sidebarCollapsed,
sessionHistoryByAgent,
setCurrentAgentId,
getSessionHistory,
setSessionHistory,
patchSessionHistory,
clearSessionHistoryForAgent,
resetPageUiState,
};
});