support history

This commit is contained in:
Julian Freeman
2026-03-25 13:21:31 -04:00
parent e0dd17bfff
commit 352047c123
6 changed files with 253 additions and 7 deletions

View File

@@ -114,6 +114,19 @@ export interface ApiProfile {
modelName: string;
}
export interface HistoryItem {
id: string;
timestamp: string;
sourceLang: Language;
targetLang: Language;
sourceText: string;
targetText: string;
context: string;
speakerIdentity: string;
toneRegister: string;
modelName: string;
}
export const useSettingsStore = defineStore('settings', () => {
const isDark = useLocalStorage('is-dark', false);
const apiBaseUrl = useLocalStorage('api-base-url', 'http://localhost:11434/v1');
@@ -147,6 +160,7 @@ export const useSettingsStore = defineStore('settings', () => {
});
const logs = ref<{ timestamp: string; type: 'request' | 'response' | 'error'; content: any }[]>([]);
const history = useLocalStorage<HistoryItem[]>('translation-history-v1', []);
const addLog = (type: 'request' | 'response' | 'error', content: any) => {
const now = new Date();
@@ -160,6 +174,22 @@ export const useSettingsStore = defineStore('settings', () => {
if (logs.value.length > 20) logs.value.pop();
};
const addHistory = (item: Omit<HistoryItem, 'id' | 'timestamp'>) => {
const now = new Date();
const timestamp = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}:${String(now.getSeconds()).padStart(2, '0')}`;
history.value.unshift({
...item,
id: crypto.randomUUID(),
timestamp
});
// 限制 100 条
if (history.value.length > 100) {
history.value = history.value.slice(0, 100);
}
};
return {
isDark,
apiBaseUrl,
@@ -177,6 +207,8 @@ export const useSettingsStore = defineStore('settings', () => {
speakerIdentity,
toneRegister,
logs,
addLog
history,
addLog,
addHistory
};
});