fix 4
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ChevronDown, Check, ArrowRightLeft, Trash2, FileText, Plus, Loader2, Send, User, Type, Copy, Save } from 'lucide-vue-next';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import { useSettingsStore, LANGUAGES, SPEAKER_IDENTITY_OPTIONS, TONE_REGISTER_OPTIONS } from '../stores/settings';
|
||||
import { useHistoryStore } from '../stores/history';
|
||||
import { useLogsStore } from '../stores/logs';
|
||||
import { useTranslationWorkspaceStore } from '../stores/translation-workspace';
|
||||
import { cn } from '../lib/utils';
|
||||
import { useClipboard } from '../composables/useClipboard';
|
||||
import {
|
||||
@@ -12,7 +14,6 @@ import {
|
||||
extractAssistantContent,
|
||||
resolveModelConfig,
|
||||
tryParseEvaluationResult,
|
||||
type EvaluationResult,
|
||||
type TranslationChunkEvent,
|
||||
type TranslationPayload,
|
||||
} from '../lib/translation-service';
|
||||
@@ -20,7 +21,21 @@ import {
|
||||
const settings = useSettingsStore();
|
||||
const historyStore = useHistoryStore();
|
||||
const logsStore = useLogsStore();
|
||||
const workspaceStore = useTranslationWorkspaceStore();
|
||||
const { activeCopyId, copyWithFeedback } = useClipboard();
|
||||
const {
|
||||
sourceText,
|
||||
context,
|
||||
targetText,
|
||||
isTranslating,
|
||||
currentHistoryId,
|
||||
evaluationResult,
|
||||
isEvaluating,
|
||||
isRefining,
|
||||
selectedSuggestionIds,
|
||||
appliedSuggestionIds,
|
||||
activeStreamRequestId,
|
||||
} = storeToRefs(workspaceStore);
|
||||
|
||||
const sourceDropdownOpen = ref(false);
|
||||
const targetDropdownOpen = ref(false);
|
||||
@@ -57,26 +72,6 @@ const handleGlobalClick = (e: MouseEvent) => {
|
||||
onMounted(() => window.addEventListener('click', handleGlobalClick));
|
||||
onUnmounted(() => window.removeEventListener('click', handleGlobalClick));
|
||||
|
||||
const sourceText = ref('');
|
||||
const context = ref('');
|
||||
const targetText = ref('');
|
||||
const isTranslating = ref(false);
|
||||
const currentHistoryId = ref<string | null>(null);
|
||||
|
||||
const evaluationResult = ref<EvaluationResult | null>(null);
|
||||
const isEvaluating = ref(false);
|
||||
const isRefining = ref(false);
|
||||
const selectedSuggestionIds = ref<number[]>([]);
|
||||
const appliedSuggestionIds = ref<number[]>([]);
|
||||
const activeStreamRequestId = ref<string | null>(null);
|
||||
|
||||
const toggleSuggestion = (id: number) => {
|
||||
if (!selectedSuggestionIds.value) selectedSuggestionIds.value = [];
|
||||
const index = selectedSuggestionIds.value.indexOf(id);
|
||||
if (index > -1) selectedSuggestionIds.value.splice(index, 1);
|
||||
else selectedSuggestionIds.value.push(id);
|
||||
};
|
||||
|
||||
let unlisten: (() => void) | null = null;
|
||||
onMounted(async () => {
|
||||
unlisten = await listen<TranslationChunkEvent>('translation-chunk', (event) => {
|
||||
@@ -110,17 +105,17 @@ const swapLanguages = () => {
|
||||
};
|
||||
|
||||
const clearSource = () => {
|
||||
sourceText.value = '';
|
||||
targetText.value = '';
|
||||
evaluationResult.value = null;
|
||||
workspaceStore.clearWorkspace();
|
||||
};
|
||||
|
||||
const toggleSuggestion = (id: number) => {
|
||||
workspaceStore.toggleSuggestion(id);
|
||||
};
|
||||
|
||||
const evaluateTranslation = async () => {
|
||||
if (!targetText.value) return;
|
||||
isEvaluating.value = true;
|
||||
evaluationResult.value = null;
|
||||
selectedSuggestionIds.value = [];
|
||||
appliedSuggestionIds.value = [];
|
||||
workspaceStore.resetEvaluationState();
|
||||
|
||||
const modelConfig = resolveModelConfig({
|
||||
apiBaseUrl: settings.apiBaseUrl,
|
||||
|
||||
53
src/stores/translation-workspace.ts
Normal file
53
src/stores/translation-workspace.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import type { EvaluationResult } from '../lib/translation-service';
|
||||
|
||||
export const useTranslationWorkspaceStore = defineStore('translationWorkspace', () => {
|
||||
const sourceText = ref('');
|
||||
const context = ref('');
|
||||
const targetText = ref('');
|
||||
const isTranslating = ref(false);
|
||||
const currentHistoryId = ref<string | null>(null);
|
||||
|
||||
const evaluationResult = ref<EvaluationResult | null>(null);
|
||||
const isEvaluating = ref(false);
|
||||
const isRefining = ref(false);
|
||||
const selectedSuggestionIds = ref<number[]>([]);
|
||||
const appliedSuggestionIds = ref<number[]>([]);
|
||||
const activeStreamRequestId = ref<string | null>(null);
|
||||
|
||||
const resetEvaluationState = () => {
|
||||
evaluationResult.value = null;
|
||||
selectedSuggestionIds.value = [];
|
||||
appliedSuggestionIds.value = [];
|
||||
};
|
||||
|
||||
const clearWorkspace = () => {
|
||||
sourceText.value = '';
|
||||
targetText.value = '';
|
||||
resetEvaluationState();
|
||||
};
|
||||
|
||||
const toggleSuggestion = (id: number) => {
|
||||
const index = selectedSuggestionIds.value.indexOf(id);
|
||||
if (index > -1) selectedSuggestionIds.value.splice(index, 1);
|
||||
else selectedSuggestionIds.value.push(id);
|
||||
};
|
||||
|
||||
return {
|
||||
sourceText,
|
||||
context,
|
||||
targetText,
|
||||
isTranslating,
|
||||
currentHistoryId,
|
||||
evaluationResult,
|
||||
isEvaluating,
|
||||
isRefining,
|
||||
selectedSuggestionIds,
|
||||
appliedSuggestionIds,
|
||||
activeStreamRequestId,
|
||||
resetEvaluationState,
|
||||
clearWorkspace,
|
||||
toggleSuggestion,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user