diff --git a/frontend/src/api/auth/index.ts b/frontend/src/api/auth/index.ts index 45856dc1..c2be39ac 100644 --- a/frontend/src/api/auth/index.ts +++ b/frontend/src/api/auth/index.ts @@ -1,4 +1,7 @@ import { post, get, put } from '@/utils/request' +import i18n from '@/i18n' + +const t = (key: string) => i18n.global.t(key) // 用户登录接口 export interface LoginRequest { @@ -122,7 +125,7 @@ export async function login(data: LoginRequest): Promise { } catch (error: any) { return { success: false, - message: error.message || '登录失败' + message: error.message || t('error.auth.loginFailed') } } } @@ -137,7 +140,7 @@ export async function register(data: RegisterRequest): Promise } catch (error: any) { return { success: false, - message: error.message || '注册失败' + message: error.message || t('error.auth.registerFailed') } } } @@ -152,7 +155,7 @@ export async function getCurrentUser(): Promise<{ success: boolean; data?: { use } catch (error: any) { return { success: false, - message: error.message || '获取用户信息失败' + message: error.message || t('error.auth.getUserFailed') } } } @@ -167,7 +170,7 @@ export async function getCurrentTenant(): Promise<{ success: boolean; data?: Ten } catch (error: any) { return { success: false, - message: error.message || '获取租户信息失败' + message: error.message || t('error.auth.getTenantFailed') } } } @@ -193,12 +196,12 @@ export async function refreshToken(refreshToken: string): Promise<{ success: boo // 其他情况直接返回原始消息 return { success: false, - message: response?.message || '刷新Token失败' + message: response?.message || t('error.auth.refreshTokenFailed') } } catch (error: any) { return { success: false, - message: error.message || '刷新Token失败' + message: error.message || t('error.auth.refreshTokenFailed') } } } @@ -215,7 +218,7 @@ export async function logout(): Promise<{ success: boolean; message?: string }> } catch (error: any) { return { success: false, - message: error.message || '登出失败' + message: error.message || t('error.auth.logoutFailed') } } } @@ -231,7 +234,7 @@ export async function validateToken(): Promise<{ success: boolean; valid?: boole return { success: false, valid: false, - message: error.message || 'Token验证失败' + message: error.message || t('error.auth.validateTokenFailed') } } } diff --git a/frontend/src/api/chat/streame.ts b/frontend/src/api/chat/streame.ts index 0b765e01..479c7ba1 100644 --- a/frontend/src/api/chat/streame.ts +++ b/frontend/src/api/chat/streame.ts @@ -1,6 +1,7 @@ import { fetchEventSource } from '@microsoft/fetch-event-source' import { ref, type Ref, onUnmounted, nextTick } from 'vue' import { generateRandomString } from '@/utils/index'; +import i18n from '@/i18n'; @@ -41,7 +42,7 @@ export function useStream() { // 获取JWT Token const token = localStorage.getItem('weknora_token'); if (!token) { - error.value = "未找到登录令牌,请重新登录"; + error.value = i18n.global.t('error.tokenNotFound'); stopStream(); return; } @@ -143,7 +144,7 @@ export function useStream() { }, onerror: (err) => { - throw new Error(`流式连接失败: ${err}`); + throw new Error(`${i18n.global.t('error.streamFailed')}: ${err}`); }, onclose: () => { diff --git a/frontend/src/api/initialization/index.ts b/frontend/src/api/initialization/index.ts index 87f30e2d..21640130 100644 --- a/frontend/src/api/initialization/index.ts +++ b/frontend/src/api/initialization/index.ts @@ -1,4 +1,7 @@ import { get, post, put } from '../../utils/request'; +import i18n from '@/i18n' + +const t = (key: string) => i18n.global.t(key) // 初始化配置数据类型 export interface InitializationConfig { @@ -107,14 +110,14 @@ export interface KBModelConfigRequest { export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Promise { return new Promise((resolve, reject) => { - console.log('开始知识库配置更新(简化版)...', kbId, config); + console.log('Starting KB config update (simplified)...', kbId, config); put(`/api/v1/initialization/config/${kbId}`, config) .then((response: any) => { - console.log('知识库配置更新完成', response); + console.log('KB config update completed', response); resolve(response); }) .catch((error: any) => { - console.error('知识库配置更新失败:', error); + console.error('Failed to update KB config:', error); reject(error.error || error); }); }); @@ -123,14 +126,14 @@ export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Prom // 根据知识库ID执行配置更新(旧版,保留兼容性) export function initializeSystemByKB(kbId: string, config: InitializationConfig): Promise { return new Promise((resolve, reject) => { - console.log('开始知识库配置更新...', kbId, config); + console.log('Starting KB config update...', kbId, config); post(`/api/v1/initialization/initialize/${kbId}`, config) .then((response: any) => { - console.log('知识库配置更新完成', response); + console.log('KB config update completed', response); resolve(response); }) .catch((error: any) => { - console.error('知识库配置更新失败:', error); + console.error('Failed to update KB config:', error); reject(error.error || error); }); }); @@ -144,8 +147,8 @@ export function checkOllamaStatus(): Promise<{ available: boolean; version?: str resolve(response.data || { available: false }); }) .catch((error: any) => { - console.error('检查Ollama状态失败:', error); - resolve({ available: false, error: error.message || '检查失败' }); + console.error('Failed to check Ollama status:', error); + resolve({ available: false, error: error.message || t('error.initialization.checkFailed') }); }); }); } @@ -166,7 +169,7 @@ export function listOllamaModels(): Promise { resolve((response.data && response.data.models) || []); }) .catch((error: any) => { - console.error('获取 Ollama 模型列表失败:', error); + console.error('Failed to list Ollama models:', error); resolve([]); }); }); @@ -180,7 +183,7 @@ export function checkOllamaModels(models: string[]): Promise<{ models: Record { - console.error('检查Ollama模型状态失败:', error); + console.error('Failed to check Ollama models:', error); reject(error); }); }); @@ -194,7 +197,7 @@ export function downloadOllamaModel(modelName: string): Promise<{ taskId: string resolve(response.data || { taskId: '', modelName, status: 'failed', progress: 0 }); }) .catch((error: any) => { - console.error('启动Ollama模型下载失败:', error); + console.error('Failed to start Ollama model download:', error); reject(error); }); }); @@ -208,7 +211,7 @@ export function getDownloadProgress(taskId: string): Promise { resolve(response.data); }) .catch((error: any) => { - console.error('查询下载进度失败:', error); + console.error('Failed to get download progress:', error); reject(error); }); }); @@ -222,7 +225,7 @@ export function listDownloadTasks(): Promise { resolve(response.data || []); }) .catch((error: any) => { - console.error('获取下载任务列表失败:', error); + console.error('Failed to list download tasks:', error); reject(error); }); }); @@ -236,7 +239,7 @@ export function getCurrentConfigByKB(kbId: string): Promise { - console.error('获取知识库配置失败:', error); + console.error('Failed to get KB config:', error); reject(error); }); }); @@ -257,7 +260,7 @@ export function checkRemoteModel(modelConfig: { resolve(response.data || {}); }) .catch((error: any) => { - console.error('检查远程模型失败:', error); + console.error('Failed to check remote model:', error); reject(error); }); }); @@ -278,7 +281,7 @@ export function testEmbeddingModel(modelConfig: { resolve(response.data || {}); }) .catch((error: any) => { - console.error('测试Embedding模型失败:', error); + console.error('Failed to test Embedding model:', error); reject(error); }); }); @@ -299,7 +302,7 @@ export function checkRerankModel(modelConfig: { resolve(response.data || {}); }) .catch((error: any) => { - console.error('检查Rerank模型失败:', error); + console.error('Failed to check Rerank model:', error); reject(error); }); }); @@ -395,11 +398,11 @@ export function testMultimodalFunction(testData: { if (data.success) { resolve(data.data || {}); } else { - resolve({ success: false, message: data.message || '测试失败' }); + resolve({ success: false, message: data.message || t('error.initialization.testFailed') }); } }) .catch((error: any) => { - console.error('多模态测试失败:', error); + console.error('Failed multimodal test:', error); reject(error); }); }); @@ -443,7 +446,7 @@ export function extractTextRelations(request: TextRelationExtractionRequest): Pr resolve(response.data || { nodes: [], relations: [] }); }) .catch((error: any) => { - console.error('文本内容关系提取失败:', error); + console.error('Failed to extract text relations:', error); reject(error); }); }); @@ -466,7 +469,7 @@ export function fabriText(request: FabriTextRequest): Promise resolve(response.data || { text: '' }); }) .catch((error: any) => { - console.error('文本内容生成失败:', error); + console.error('Failed to generate text:', error); reject(error); }); }); @@ -488,7 +491,7 @@ export function fabriTag(request: FabriTagRequest): Promise { resolve(response.data || { tags: [] as string[] }); }) .catch((error: any) => { - console.error('标签生成失败:', error); + console.error('Failed to generate tags:', error); reject(error); }); }); @@ -514,7 +517,7 @@ export function listModelProviders(modelType?: string): Promise { - console.error('获取模型厂商列表失败:', error); + console.error('Failed to list model providers:', error); resolve([]); // 失败时返回空数组,前端可以回退到默认值 }); }); diff --git a/frontend/src/api/model/index.ts b/frontend/src/api/model/index.ts index 8b5ffa4c..e683ceb8 100644 --- a/frontend/src/api/model/index.ts +++ b/frontend/src/api/model/index.ts @@ -1,4 +1,7 @@ import { get, post, put, del } from '../../utils/request'; +import i18n from '@/i18n' + +const t = (key: string) => i18n.global.t(key) // 模型类型定义 export interface ModelConfig { @@ -36,11 +39,11 @@ export function createModel(data: ModelConfig): Promise { if (response.success && response.data) { resolve(response.data); } else { - reject(new Error(response.message || '创建模型失败')); + reject(new Error(response.message || t('error.model.createFailed'))); } }) .catch((error: any) => { - console.error('创建模型失败:', error); + console.error('Failed to create model:', error); reject(error); }); }); @@ -62,7 +65,7 @@ export function listModels(type?: string): Promise { } }) .catch((error: any) => { - console.error('获取模型列表失败:', error); + console.error('Failed to list models:', error); resolve([]); }); }); @@ -76,11 +79,11 @@ export function getModel(id: string): Promise { if (response.success && response.data) { resolve(response.data); } else { - reject(new Error(response.message || '获取模型失败')); + reject(new Error(response.message || t('error.model.getFailed'))); } }) .catch((error: any) => { - console.error('获取模型失败:', error); + console.error('Failed to get model:', error); reject(error); }); }); @@ -94,11 +97,11 @@ export function updateModel(id: string, data: Partial): Promise { - console.error('更新模型失败:', error); + console.error('Failed to update model:', error); reject(error); }); }); @@ -112,11 +115,11 @@ export function deleteModel(id: string): Promise { if (response.success) { resolve(); } else { - reject(new Error(response.message || '删除模型失败')); + reject(new Error(response.message || t('error.model.deleteFailed'))); } }) .catch((error: any) => { - console.error('删除模型失败:', error); + console.error('Failed to delete model:', error); reject(error); }); }); diff --git a/frontend/src/api/tenant/index.ts b/frontend/src/api/tenant/index.ts index 1bf1e608..1f99d467 100644 --- a/frontend/src/api/tenant/index.ts +++ b/frontend/src/api/tenant/index.ts @@ -1,4 +1,7 @@ import { get } from '@/utils/request' +import i18n from '@/i18n' + +const t = (key: string) => i18n.global.t(key) // 租户信息接口 export interface TenantInfo { @@ -45,7 +48,7 @@ export async function listAllTenants(): Promise<{ success: boolean; data?: { ite } catch (error: any) { return { success: false, - message: error.message || '获取租户列表失败' + message: error.message || t('error.tenant.listFailed') } } } @@ -76,7 +79,7 @@ export async function searchTenants(params: SearchTenantsParams = {}): Promise

{{ $t('organization.share.title') }}

-

{{ $t('organization.share.agentShareDesc') || '将智能体共享到空间,空间成员可使用该智能体' }}

+

{{ $t('organization.share.agentShareDesc') }}

diff --git a/frontend/src/components/ModelSelector.vue b/frontend/src/components/ModelSelector.vue index 4b6225bb..eab371f9 100644 --- a/frontend/src/components/ModelSelector.vue +++ b/frontend/src/components/ModelSelector.vue @@ -19,7 +19,7 @@
{{ model.name }} - 内置 + {{ $t('model.builtinTag') }} {{ $t('model.defaultTag') }}
diff --git a/frontend/src/components/PromptTemplateSelector.vue b/frontend/src/components/PromptTemplateSelector.vue index c69b7aac..8b21f66c 100644 --- a/frontend/src/components/PromptTemplateSelector.vue +++ b/frontend/src/components/PromptTemplateSelector.vue @@ -15,7 +15,7 @@
- {{ $t('promptTemplate.noTemplates') || '暂无模板' }} + {{ $t('promptTemplate.noTemplates') }}
props.details?.chunkLoading, (val) => { const hasError = Boolean(props.details?.chunkLoadError); if (hasError && currentLength <= pendingChunksBeforeLoad) { page = Math.max(1, pendingRequestedPage - 1); - MessagePlugin.warning(props.details?.chunkLoadError || '分块加载失败,请继续下滑重试'); + MessagePlugin.warning(props.details?.chunkLoadError); } } pendingRequestedPage = null; @@ -407,11 +407,11 @@ const getDisplayTitle = () => { const getTypeLabel = () => { switch (props.details.type) { case 'url': - return t('knowledgeBase.typeURL') || '网页'; + return t('knowledgeBase.typeURL'); case 'manual': - return t('knowledgeBase.typeManual') || '手动创建'; + return t('knowledgeBase.typeManual'); case 'file': - return props.details.file_type ? props.details.file_type.toUpperCase() : t('knowledgeBase.typeFile') || '文件'; + return props.details.file_type ? props.details.file_type.toUpperCase() : t('knowledgeBase.typeFile'); default: return ''; } @@ -435,12 +435,12 @@ const getTypeTheme = () => { const getContentLabel = () => { switch (props.details.type) { case 'url': - return t('knowledgeBase.webContent') || '网页内容'; + return t('knowledgeBase.webContent'); case 'manual': - return t('knowledgeBase.documentContent') || '文档内容'; + return t('knowledgeBase.documentContent'); case 'file': default: - return t('knowledgeBase.fileContent') || '文件内容'; + return t('knowledgeBase.fileContent'); } }; @@ -448,12 +448,12 @@ const getContentLabel = () => { const getTimeLabel = () => { switch (props.details.type) { case 'url': - return t('knowledgeBase.importTime') || '导入时间'; + return t('knowledgeBase.importTime'); case 'manual': - return t('knowledgeBase.createTime') || '创建时间'; + return t('knowledgeBase.createTime'); case 'file': default: - return t('knowledgeBase.uploadTime') || '上传时间'; + return t('knowledgeBase.uploadTime'); } }; @@ -467,7 +467,7 @@ const getChunkMeta = (item: any) => { if (!item) return ''; const parts = []; if (item.char_count) { - parts.push(`${item.char_count} ${t('knowledgeBase.characters') || '字符'}`); + parts.push(`${item.char_count} ${t('knowledgeBase.characters')}`); } if (item.token_count) { parts.push(`${item.token_count} tokens`); @@ -521,27 +521,27 @@ const deletingQuestion = ref<{ chunkIndex: number; questionId: string } | null>( // 删除生成的问题 const handleDeleteQuestion = async (item: any, chunkIndex: number, question: GeneratedQuestion) => { if (!item || !item.id) { - MessagePlugin.error(t('common.error') || '操作失败'); + MessagePlugin.error(t('common.error')); return; } // 检查是否是旧格式数据(无法删除) if (question.id.startsWith('legacy-')) { - MessagePlugin.warning(t('knowledgeBase.legacyQuestionCannotDelete') || '旧格式问题无法删除,请重新生成问题'); + MessagePlugin.warning(t('knowledgeBase.legacyQuestionCannotDelete')); return; } const confirmDialog = DialogPlugin.confirm({ - header: t('common.confirmDelete') || '确认删除', - body: t('knowledgeBase.confirmDeleteQuestion') || '确定要删除这个问题吗?删除后将同时移除对应的向量索引。', - confirmBtn: t('common.confirm') || '确认', - cancelBtn: t('common.cancel') || '取消', + header: t('common.confirmDelete'), + body: t('knowledgeBase.confirmDeleteQuestion'), + confirmBtn: t('common.confirm'), + cancelBtn: t('common.cancel'), onConfirm: async () => { confirmDialog.hide(); deletingQuestion.value = { chunkIndex, questionId: question.id }; try { await deleteGeneratedQuestion(item.id, question.id); - MessagePlugin.success(t('common.deleteSuccess') || '删除成功'); + MessagePlugin.success(t('common.deleteSuccess')); // 更新本地数据 const metadata = typeof item.metadata === 'string' ? JSON.parse(item.metadata) : item.metadata; @@ -556,7 +556,7 @@ const handleDeleteQuestion = async (item: any, chunkIndex: number, question: Gen // 通知父组件刷新数据 emit('questionDeleted', { chunkId: item.id, questionId: question.id }); } catch (error: any) { - MessagePlugin.error(error?.message || t('common.deleteFailed') || '删除失败'); + MessagePlugin.error(error?.message || t('common.deleteFailed')); } finally { deletingQuestion.value = null; } @@ -599,7 +599,7 @@ const toggleParentContext = async (item: any, index: number) => { parentContextCache.value = new Map(parentContextCache.value); } } catch (err) { - MessagePlugin.error(t('knowledgeBase.parentContextLoadFailed') || '加载父上下文失败'); + MessagePlugin.error(t('knowledgeBase.parentContextLoadFailed')); return; } finally { parentContextLoading.value.delete(index); @@ -681,7 +681,7 @@ const handleDetailsScroll = () => {
- {{ $t('knowledgeBase.urlSource') || '来源网址' }} + {{ $t('knowledgeBase.urlSource') }}