feat: Integrate vue-i18n for multilingual support across components
- Added vue-i18n integration to various components for dynamic text translation. - Updated text placeholders, button labels, and error messages to utilize translation functions. - Enhanced user experience by providing localized content in the Knowledge Base, chat components, and settings. - Removed hardcoded strings and replaced them with translation keys for better maintainability and scalability.
This commit is contained in:
@@ -10,6 +10,7 @@ import { stopSession } from '@/api/chat';
|
||||
import KnowledgeBaseSelector from './KnowledgeBaseSelector.vue';
|
||||
import { getModel, type ModelConfig } from '@/api/model';
|
||||
import { getTenantWebSearchConfig } from '@/api/web-search';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
@@ -56,6 +57,8 @@ const showModelSelector = ref(false);
|
||||
const modelButtonRef = ref<HTMLElement>();
|
||||
const modelDropdownStyle = ref<Record<string, string>>({});
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
// 显示的知识库标签(最多显示2个)
|
||||
const displayedKbs = computed(() => selectedKbs.value.slice(0, 2));
|
||||
const remainingCount = computed(() => Math.max(0, selectedKbs.value.length - 2));
|
||||
@@ -299,15 +302,15 @@ const emit = defineEmits(['send-msg', 'stop-generation']);
|
||||
|
||||
const createSession = (val: string) => {
|
||||
if (!val.trim()) {
|
||||
MessagePlugin.info("请先输入内容!");
|
||||
MessagePlugin.info(t('input.messages.enterContent'));
|
||||
return;
|
||||
}
|
||||
if (selectedKbIds.value.length === 0) {
|
||||
MessagePlugin.warning("请先选择知识库!");
|
||||
MessagePlugin.warning(t('input.messages.selectKnowledge'));
|
||||
return;
|
||||
}
|
||||
if (props.isReplying) {
|
||||
return MessagePlugin.error("正在回复中,请稍后再试!");
|
||||
return MessagePlugin.error(t('input.messages.replying'));
|
||||
}
|
||||
emit('send-msg', val, selectedModelId.value);
|
||||
clearvalue();
|
||||
@@ -438,7 +441,7 @@ const selectAgentMode = (mode: 'normal' | 'agent') => {
|
||||
const shouldEnableAgent = mode === 'agent';
|
||||
if (shouldEnableAgent !== isAgentEnabled.value) {
|
||||
settingsStore.toggleAgent(shouldEnableAgent);
|
||||
MessagePlugin.success(shouldEnableAgent ? '已切换到 Agent 模式' : '已切换到普通模式');
|
||||
MessagePlugin.success(shouldEnableAgent ? t('input.messages.agentSwitchedOn') : t('input.messages.agentSwitchedOff'));
|
||||
}
|
||||
showAgentModeSelector.value = false;
|
||||
}
|
||||
@@ -482,7 +485,7 @@ const toggleAgentMode = () => {
|
||||
if (!agentReady) {
|
||||
// 创建带跳转链接的自定义消息
|
||||
const messageContent = h('div', { style: 'display: flex; align-items: center; gap: 8px; flex-wrap: wrap;' }, [
|
||||
h('span', { style: 'flex: 1; min-width: 0;' }, 'Agent 未就绪,请先在设置中完成 Agent 配置(思考模型、Rerank 模型和允许的工具)'),
|
||||
h('span', { style: 'flex: 1; min-width: 0;' }, t('input.messages.agentNotReadyDetail')),
|
||||
h('a', {
|
||||
href: '#',
|
||||
onClick: (e: Event) => {
|
||||
@@ -496,7 +499,7 @@ const toggleAgentMode = () => {
|
||||
onMouseleave: (e: Event) => {
|
||||
(e.target as HTMLElement).style.textDecoration = 'none';
|
||||
}
|
||||
}, '去设置 →')
|
||||
}, t('input.goToSettings'))
|
||||
]);
|
||||
|
||||
MessagePlugin.warning({
|
||||
@@ -509,14 +512,14 @@ const toggleAgentMode = () => {
|
||||
|
||||
// 正常切换 Agent 状态
|
||||
settingsStore.toggleAgent(!isAgentEnabled.value);
|
||||
const message = isAgentEnabled.value ? 'Agent 模式已启用' : 'Agent 模式已禁用';
|
||||
const message = isAgentEnabled.value ? t('input.messages.agentEnabled') : t('input.messages.agentDisabled');
|
||||
MessagePlugin.success(message);
|
||||
}
|
||||
|
||||
const toggleWebSearch = () => {
|
||||
if (!isWebSearchConfigured.value) {
|
||||
const messageContent = h('div', { style: 'display: flex; flex-direction: column; gap: 6px; max-width: 280px;' }, [
|
||||
h('span', { style: 'color: #333; line-height: 1.5;' }, '未配置网络搜索引擎,请先在设置中完成搜索引擎选择与接口配置。'),
|
||||
h('span', { style: 'color: #333; line-height: 1.5;' }, t('input.messages.webSearchNotConfigured')),
|
||||
h('a', {
|
||||
href: '#',
|
||||
onClick: (e: Event) => {
|
||||
@@ -530,7 +533,7 @@ const toggleWebSearch = () => {
|
||||
onMouseleave: (e: Event) => {
|
||||
(e.target as HTMLElement).style.textDecoration = 'none';
|
||||
}
|
||||
}, '去设置 →')
|
||||
}, t('input.goToSettings'))
|
||||
]);
|
||||
MessagePlugin.warning({
|
||||
content: () => messageContent,
|
||||
@@ -542,7 +545,7 @@ const toggleWebSearch = () => {
|
||||
const currentValue = settingsStore.isWebSearchEnabled;
|
||||
const newValue = !currentValue;
|
||||
settingsStore.toggleWebSearch(newValue);
|
||||
MessagePlugin.success(newValue ? '网络搜索已开启' : '网络搜索已关闭');
|
||||
MessagePlugin.success(newValue ? t('input.messages.webSearchEnabled') : t('input.messages.webSearchDisabled'));
|
||||
};
|
||||
|
||||
const toggleKbSelector = () => {
|
||||
@@ -555,13 +558,13 @@ const removeKb = (kbId: string) => {
|
||||
|
||||
const handleStop = async () => {
|
||||
if (!props.sessionId) {
|
||||
MessagePlugin.warning('会话 ID 不存在');
|
||||
MessagePlugin.warning(t('input.messages.sessionMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!props.assistantMessageId) {
|
||||
console.error('[Stop] Assistant message ID is empty');
|
||||
MessagePlugin.warning('无法获取消息 ID,请刷新页面后重试');
|
||||
MessagePlugin.warning(t('input.messages.messageMissing'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -572,10 +575,10 @@ const handleStop = async () => {
|
||||
|
||||
try {
|
||||
await stopSession(props.sessionId, props.assistantMessageId);
|
||||
MessagePlugin.success('已停止生成');
|
||||
MessagePlugin.success(t('input.messages.stopSuccess'));
|
||||
} catch (error) {
|
||||
console.error('Failed to stop session:', error);
|
||||
MessagePlugin.error('停止失败,请重试');
|
||||
MessagePlugin.error(t('input.messages.stopFailed'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -587,7 +590,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
</script>
|
||||
<template>
|
||||
<div class="answers-input">
|
||||
<t-textarea v-model="query" placeholder="基于知识库提问" name="description" :autosize="true" @keydown="onKeydown" />
|
||||
<t-textarea v-model="query" :placeholder="$t('input.placeholder')" name="description" :autosize="true" @keydown="onKeydown" />
|
||||
|
||||
<!-- 控制栏 -->
|
||||
<div class="control-bar">
|
||||
@@ -606,7 +609,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
<img
|
||||
v-if="isAgentEnabled"
|
||||
:src="getImgSrc('agent-active.svg')"
|
||||
alt="Agent模式"
|
||||
:alt="$t('input.agentMode')"
|
||||
class="control-icon agent-icon"
|
||||
/>
|
||||
<svg
|
||||
@@ -621,7 +624,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
<path d="M8 4.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7zM6 8a2 2 0 1 1 4 0 2 2 0 0 1-4 0z"/>
|
||||
</svg>
|
||||
<span class="agent-mode-text">
|
||||
{{ isAgentEnabled ? 'Agent 模式' : '普通模式' }}
|
||||
{{ isAgentEnabled ? $t('input.agentMode') : $t('input.normalMode') }}
|
||||
</span>
|
||||
<svg
|
||||
width="12"
|
||||
@@ -649,8 +652,8 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
@click="selectAgentMode('normal')"
|
||||
>
|
||||
<div class="agent-mode-option-main">
|
||||
<span class="agent-mode-option-name">普通模式</span>
|
||||
<span class="agent-mode-option-desc">基于知识库的 RAG 问答</span>
|
||||
<span class="agent-mode-option-name">{{ $t('input.normalMode') }}</span>
|
||||
<span class="agent-mode-option-desc">{{ $t('input.normalModeDesc') }}</span>
|
||||
</div>
|
||||
<svg
|
||||
v-if="!isAgentEnabled"
|
||||
@@ -672,8 +675,8 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
@click="selectAgentMode('agent')"
|
||||
>
|
||||
<div class="agent-mode-option-main">
|
||||
<span class="agent-mode-option-name">Agent 模式</span>
|
||||
<span class="agent-mode-option-desc">ReAct 推理框架,多步思考</span>
|
||||
<span class="agent-mode-option-name">{{ $t('input.agentMode') }}</span>
|
||||
<span class="agent-mode-option-desc">{{ $t('input.agentModeDesc') }}</span>
|
||||
</div>
|
||||
<svg
|
||||
v-if="isAgentEnabled"
|
||||
@@ -686,7 +689,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
<path d="M13.5 4.5L6 12L2.5 8.5L3.5 7.5L6 10L12.5 3.5L13.5 4.5Z"/>
|
||||
</svg>
|
||||
<div v-if="!settingsStore.isAgentReady && !isAgentEnabled" class="agent-mode-warning">
|
||||
<t-tooltip content="Agent 未就绪,请先在设置中完成配置" placement="left">
|
||||
<t-tooltip :content="$t('input.agentNotReadyTooltip')" placement="left">
|
||||
<t-icon name="error-circle" class="warning-icon" />
|
||||
</t-tooltip>
|
||||
</div>
|
||||
@@ -697,7 +700,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
@click.prevent="handleGoToAgentSettings"
|
||||
class="agent-mode-link"
|
||||
>
|
||||
前往设置 →
|
||||
{{ $t('input.goToSettings') }}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -707,10 +710,10 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
<!-- WebSearch 开关按钮 -->
|
||||
<t-tooltip placement="top">
|
||||
<template #content>
|
||||
<span v-if="isWebSearchConfigured">{{ isWebSearchEnabled ? '关闭网络搜索' : '开启网络搜索' }}</span>
|
||||
<span v-if="isWebSearchConfigured">{{ isWebSearchEnabled ? $t('input.webSearch.toggleOff') : $t('input.webSearch.toggleOn') }}</span>
|
||||
<div v-else class="websearch-tooltip-disabled">
|
||||
<span>未配置网络搜索引擎</span>
|
||||
<a href="#" @click.prevent="handleGoToWebSearchSettings">前往设置 →</a>
|
||||
<span>{{ $t('input.webSearch.notConfigured') }}</span>
|
||||
<a href="#" @click.prevent="handleGoToWebSearchSettings">{{ $t('input.goToSettings') }}</a>
|
||||
</div>
|
||||
</template>
|
||||
<div
|
||||
@@ -745,7 +748,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
>
|
||||
<img :src="getImgSrc('at-icon.svg')" alt="@" class="control-icon" />
|
||||
<span class="kb-btn-text">
|
||||
{{ selectedKbIds.length > 0 ? `知识库(${selectedKbIds.length})` : '知识库' }}
|
||||
{{ selectedKbIds.length > 0 ? $t('input.knowledgeBaseWithCount', { count: selectedKbIds.length }) : $t('input.knowledgeBase') }}
|
||||
</span>
|
||||
<svg
|
||||
width="12"
|
||||
@@ -778,8 +781,8 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
<div v-if="selectedKbIds.length > 0" class="model-display">
|
||||
<!-- Agent 模式:只读显示 Thinking 模型 -->
|
||||
<div v-if="isAgentEnabled" class="model-badge">
|
||||
<span class="model-label">Thinking:</span>
|
||||
<span class="model-name">{{ thinkingModelName || '未配置' }}</span>
|
||||
<span class="model-label">{{ $t('input.thinkingLabel') }}</span>
|
||||
<span class="model-name">{{ thinkingModelName || $t('input.notConfigured') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 非 Agent 模式:可选择的模型下拉 -->
|
||||
@@ -791,7 +794,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
@click.stop="toggleModelSelector"
|
||||
>
|
||||
<span class="model-btn-text">
|
||||
{{ selectedModel ? selectedModel.name : '模型' }}
|
||||
{{ selectedModel ? selectedModel.name : $t('input.model') }}
|
||||
</span>
|
||||
<svg
|
||||
width="12"
|
||||
@@ -823,7 +826,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
>
|
||||
<div class="model-option-main">
|
||||
<span class="model-option-name">{{ model.name }}</span>
|
||||
<span v-if="model.source === 'remote'" class="model-badge-remote">远程</span>
|
||||
<span v-if="model.source === 'remote'" class="model-badge-remote">{{ $t('input.remote') }}</span>
|
||||
<span v-else-if="model.parameters?.parameter_size" class="model-badge-local">
|
||||
{{ model.parameters.parameter_size }}
|
||||
</span>
|
||||
@@ -833,7 +836,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="availableModels.length === 0" class="model-option empty">
|
||||
暂无可用模型
|
||||
{{ $t('input.noModel') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -847,7 +850,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
<!-- 停止按钮(仅在回复中时显示) -->
|
||||
<t-tooltip
|
||||
v-if="isReplying"
|
||||
content="停止生成"
|
||||
:content="$t('input.stopGeneration')"
|
||||
placement="top"
|
||||
>
|
||||
<div
|
||||
@@ -867,7 +870,7 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
class="control-btn send-btn"
|
||||
:class="{ 'disabled': !query.length || selectedKbIds.length === 0 }"
|
||||
>
|
||||
<img src="../assets/img/sending-aircraft.svg" alt="发送" />
|
||||
<img src="../assets/img/sending-aircraft.svg" :alt="$t('input.send')" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
ref="searchInput"
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
placeholder="搜索知识库..."
|
||||
:placeholder="$t('knowledgeBase.searchPlaceholder')"
|
||||
class="kb-search-input"
|
||||
@keydown.down.prevent="moveSelection(1)"
|
||||
@keydown.up.prevent="moveSelection(-1)"
|
||||
@@ -33,20 +33,20 @@
|
||||
</div>
|
||||
<div class="kb-name-wrap">
|
||||
<span class="kb-name">{{ kb.name }}</span>
|
||||
<span class="kb-docs" v-if="kb.docsCount !== undefined">{{ kb.docsCount }} docs</span>
|
||||
<span class="kb-docs" v-if="kb.docsCount !== undefined">{{ kb.docsCount }} {{ $t('knowledgeBase.documents') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="filteredKnowledgeBases.length === 0" class="kb-empty">
|
||||
{{ searchQuery ? '未找到匹配的知识库' : '暂无可用知识库' }}
|
||||
{{ searchQuery ? $t('knowledgeBase.noMatch') : $t('knowledgeBase.noKnowledge') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部操作 -->
|
||||
<div class="kb-actions">
|
||||
<button @click="selectAll" class="kb-btn">全选</button>
|
||||
<button @click="clearAll" class="kb-btn">清空</button>
|
||||
<button @click="selectAll" class="kb-btn">{{ $t('common.selectAll') }}</button>
|
||||
<button @click="clearAll" class="kb-btn">{{ $t('common.clear') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -56,6 +56,7 @@
|
||||
import { ref, computed, watch, nextTick } from 'vue'
|
||||
import { useSettingsStore } from '@/stores/settings'
|
||||
import { listKnowledgeBases } from '@/api/knowledge-base'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
interface KnowledgeBase {
|
||||
id: string
|
||||
@@ -65,6 +66,8 @@ interface KnowledgeBase {
|
||||
summary_model_id?: string
|
||||
}
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
anchorEl?: any | null // 支持 DOM 节点、ref、组件实例
|
||||
@@ -151,7 +154,7 @@ const loadKnowledgeBases = async () => {
|
||||
const res: any = await listKnowledgeBases()
|
||||
if (res?.data && Array.isArray(res.data)) knowledgeBases.value = res.data
|
||||
} catch (e) {
|
||||
console.error('加载知识库失败', e)
|
||||
console.error(t('knowledgeBase.loadingFailed'), e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<div v-if="dialogVisible" class="model-editor-overlay" @click.self="handleCancel">
|
||||
<div class="model-editor-modal">
|
||||
<!-- 关闭按钮 -->
|
||||
<button class="close-btn" @click="handleCancel" aria-label="关闭">
|
||||
<button class="close-btn" @click="handleCancel" :aria-label="$t('common.close')">
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M15 5L5 15M5 5L15 15" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
|
||||
</svg>
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<!-- 标题区域 -->
|
||||
<div class="modal-header">
|
||||
<h2 class="modal-title">{{ isEdit ? '编辑模型' : '添加模型' }}</h2>
|
||||
<h2 class="modal-title">{{ isEdit ? $t('model.editor.editTitle') : $t('model.editor.addTitle') }}</h2>
|
||||
<p class="modal-desc">{{ getModalDescription() }}</p>
|
||||
</div>
|
||||
|
||||
@@ -21,16 +21,16 @@
|
||||
<t-form ref="formRef" :data="formData" :rules="rules" layout="vertical">
|
||||
<!-- 模型来源 -->
|
||||
<div class="form-item">
|
||||
<label class="form-label required">模型来源</label>
|
||||
<label class="form-label required">{{ $t('model.editor.sourceLabel') }}</label>
|
||||
<t-radio-group v-model="formData.source">
|
||||
<t-radio value="local">Ollama (本地)</t-radio>
|
||||
<t-radio value="remote">Remote API (远程)</t-radio>
|
||||
<t-radio value="local">{{ $t('model.editor.sourceLocal') }}</t-radio>
|
||||
<t-radio value="remote">{{ $t('model.editor.sourceRemote') }}</t-radio>
|
||||
</t-radio-group>
|
||||
</div>
|
||||
|
||||
<!-- Ollama 本地模型选择器 -->
|
||||
<div v-if="formData.source === 'local'" class="form-item">
|
||||
<label class="form-label required">模型名称</label>
|
||||
<label class="form-label required">{{ $t('model.modelName') }}</label>
|
||||
<div class="model-select-row">
|
||||
<t-select
|
||||
v-model="formData.modelName"
|
||||
@@ -39,7 +39,7 @@
|
||||
:style="downloading ? `--progress: ${downloadProgress}%` : ''"
|
||||
filterable
|
||||
:filter="handleModelFilter"
|
||||
placeholder="搜索模型..."
|
||||
:placeholder="$t('model.searchPlaceholder')"
|
||||
@focus="loadOllamaModels"
|
||||
@visible-change="handleDropdownVisibleChange"
|
||||
>
|
||||
@@ -61,12 +61,12 @@
|
||||
<t-option
|
||||
v-if="showDownloadOption"
|
||||
:value="`__download__${searchKeyword}`"
|
||||
:label="`下载: ${searchKeyword}`"
|
||||
:label="$t('model.editor.downloadLabel', { keyword: searchKeyword })"
|
||||
class="download-option"
|
||||
>
|
||||
<div class="model-option download">
|
||||
<t-icon name="download" class="download-icon" />
|
||||
<span class="model-name">下载: {{ searchKeyword }}</span>
|
||||
<span class="model-name">{{ $t('model.editor.downloadLabel', { keyword: searchKeyword }) }}</span>
|
||||
</div>
|
||||
</t-option>
|
||||
|
||||
@@ -88,14 +88,14 @@
|
||||
class="refresh-btn"
|
||||
>
|
||||
<t-icon name="refresh" />
|
||||
刷新列表
|
||||
{{ $t('model.editor.refreshList') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Remote API 和 VLLM 保持原有的 input -->
|
||||
<div v-else class="form-item">
|
||||
<label class="form-label required">模型名称</label>
|
||||
<label class="form-label required">{{ $t('model.modelName') }}</label>
|
||||
<t-input
|
||||
v-model="formData.modelName"
|
||||
:placeholder="getModelNamePlaceholder()"
|
||||
@@ -105,25 +105,25 @@
|
||||
<!-- Remote API 配置 -->
|
||||
<template v-if="formData.source === 'remote'">
|
||||
<div class="form-item">
|
||||
<label class="form-label required">Base URL</label>
|
||||
<label class="form-label required">{{ $t('model.editor.baseUrlLabel') }}</label>
|
||||
<t-input
|
||||
v-model="formData.baseUrl"
|
||||
:placeholder="modelType === 'vllm' ? '如:http://localhost:11434/v1' : '如:https://api.openai.com/v1'"
|
||||
:placeholder="getBaseUrlPlaceholder()"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-item">
|
||||
<label class="form-label">API Key (可选)</label>
|
||||
<label class="form-label">{{ $t('model.editor.apiKeyOptional') }}</label>
|
||||
<t-input
|
||||
v-model="formData.apiKey"
|
||||
type="password"
|
||||
placeholder="输入 API Key"
|
||||
:placeholder="$t('model.editor.apiKeyPlaceholder')"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Remote API 校验 -->
|
||||
<div class="form-item">
|
||||
<label class="form-label">连接测试</label>
|
||||
<label class="form-label">{{ $t('model.editor.connectionTest') }}</label>
|
||||
<div class="api-test-section">
|
||||
<t-button
|
||||
variant="outline"
|
||||
@@ -143,7 +143,7 @@
|
||||
class="status-icon unavailable"
|
||||
/>
|
||||
</template>
|
||||
{{ checking ? '测试中...' : '测试连接' }}
|
||||
{{ checking ? $t('model.editor.testing') : $t('model.editor.testConnection') }}
|
||||
</t-button>
|
||||
<span v-if="remoteChecked" :class="['test-message', remoteAvailable ? 'success' : 'error']">
|
||||
{{ remoteMessage }}
|
||||
@@ -154,14 +154,14 @@
|
||||
|
||||
<!-- Embedding 专用:维度 -->
|
||||
<div v-if="modelType === 'embedding'" class="form-item">
|
||||
<label class="form-label">向量维度</label>
|
||||
<label class="form-label">{{ $t('model.editor.dimensionLabel') }}</label>
|
||||
<div class="dimension-control">
|
||||
<t-input
|
||||
v-model.number="formData.dimension"
|
||||
type="number"
|
||||
:min="128"
|
||||
:max="4096"
|
||||
placeholder="如:1536"
|
||||
:placeholder="$t('model.editor.dimensionPlaceholder')"
|
||||
:disabled="formData.source === 'local' && checking"
|
||||
/>
|
||||
<!-- Ollama 本地模型:自动检测维度按钮 -->
|
||||
@@ -174,7 +174,7 @@
|
||||
class="dimension-check-btn"
|
||||
>
|
||||
<t-icon name="refresh" />
|
||||
检测维度
|
||||
{{ $t('model.editor.checkDimension') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<p v-if="dimensionChecked && dimensionMessage" class="dimension-hint" :class="{ success: dimensionSuccess }">
|
||||
@@ -184,7 +184,7 @@
|
||||
|
||||
<!-- 设为默认 -->
|
||||
<div class="form-item">
|
||||
<t-checkbox v-model="formData.isDefault">设为默认模型</t-checkbox>
|
||||
<t-checkbox v-model="formData.isDefault">{{ $t('model.editor.setAsDefault') }}</t-checkbox>
|
||||
</div>
|
||||
</t-form>
|
||||
</div>
|
||||
@@ -192,10 +192,10 @@
|
||||
<!-- 底部按钮区域 -->
|
||||
<div class="modal-footer">
|
||||
<t-button theme="default" variant="outline" @click="handleCancel">
|
||||
取消
|
||||
{{ $t('common.cancel') }}
|
||||
</t-button>
|
||||
<t-button theme="primary" @click="handleConfirm" :loading="saving">
|
||||
保存
|
||||
{{ $t('common.save') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -208,6 +208,7 @@
|
||||
import { ref, watch, computed, onUnmounted } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { checkOllamaModels, checkRemoteModel, testEmbeddingModel, checkRerankModel, listOllamaModels, downloadOllamaModel, getDownloadProgress, type OllamaModelInfo } from '@/api/initialization'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
interface ModelFormData {
|
||||
id: string
|
||||
@@ -227,6 +228,8 @@ interface Props {
|
||||
modelData?: ModelFormData | null
|
||||
}
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
visible: false,
|
||||
modelData: null
|
||||
@@ -277,16 +280,16 @@ const formData = ref<ModelFormData>({
|
||||
isDefault: false
|
||||
})
|
||||
|
||||
const rules = {
|
||||
const rules = computed(() => ({
|
||||
modelName: [
|
||||
{ required: true, message: '请输入模型名称' },
|
||||
{ required: true, message: t('model.editor.validation.modelNameRequired') },
|
||||
{
|
||||
validator: (val: string) => {
|
||||
if (!val || !val.trim()) {
|
||||
return { result: false, message: '模型名称不能为空' }
|
||||
return { result: false, message: t('model.editor.validation.modelNameEmpty') }
|
||||
}
|
||||
if (val.trim().length > 100) {
|
||||
return { result: false, message: '模型名称不能超过100个字符' }
|
||||
return { result: false, message: t('model.editor.validation.modelNameMax') }
|
||||
}
|
||||
return { result: true }
|
||||
},
|
||||
@@ -296,44 +299,49 @@ const rules = {
|
||||
baseUrl: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入 Base URL',
|
||||
message: t('model.editor.validation.baseUrlRequired'),
|
||||
trigger: 'blur'
|
||||
},
|
||||
{
|
||||
validator: (val: string) => {
|
||||
if (!val || !val.trim()) {
|
||||
return { result: false, message: 'Base URL 不能为空' }
|
||||
return { result: false, message: t('model.editor.validation.baseUrlEmpty') }
|
||||
}
|
||||
// 简单的 URL 格式校验
|
||||
try {
|
||||
new URL(val.trim())
|
||||
return { result: true }
|
||||
} catch {
|
||||
return { result: false, message: 'Base URL 格式不正确,请输入有效的 URL' }
|
||||
return { result: false, message: t('model.editor.validation.baseUrlInvalid') }
|
||||
}
|
||||
},
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
}))
|
||||
|
||||
// 获取弹窗描述文字
|
||||
const getModalDescription = () => {
|
||||
const typeDesc = {
|
||||
chat: '配置用于对话的大语言模型',
|
||||
embedding: '配置用于文本向量化的嵌入模型',
|
||||
rerank: '配置用于结果重排序的模型',
|
||||
vllm: '配置用于视觉理解和多模态的视觉语言模型'
|
||||
}
|
||||
return typeDesc[props.modelType] || '配置模型信息'
|
||||
const key = `model.editor.description.${props.modelType}` as const
|
||||
return t(key) || t('model.editor.description.default')
|
||||
}
|
||||
|
||||
// 获取模型名称占位符
|
||||
const getModelNamePlaceholder = () => {
|
||||
if (props.modelType === 'vllm') {
|
||||
return formData.value.source === 'local' ? '如:llava:latest' : '如:gpt-4-vision-preview'
|
||||
return formData.value.source === 'local'
|
||||
? t('model.editor.modelNamePlaceholder.localVllm')
|
||||
: t('model.editor.modelNamePlaceholder.remoteVllm')
|
||||
}
|
||||
return formData.value.source === 'local' ? '如:llama2:latest' : '如:gpt-4, claude-3-opus'
|
||||
return formData.value.source === 'local'
|
||||
? t('model.editor.modelNamePlaceholder.local')
|
||||
: t('model.editor.modelNamePlaceholder.remote')
|
||||
}
|
||||
|
||||
const getBaseUrlPlaceholder = () => {
|
||||
return props.modelType === 'vllm'
|
||||
? t('model.editor.baseUrlPlaceholderVllm')
|
||||
: t('model.editor.baseUrlPlaceholder')
|
||||
}
|
||||
|
||||
// 监听 visible 变化,初始化表单
|
||||
@@ -417,8 +425,8 @@ const loadOllamaModels = async () => {
|
||||
const models = await listOllamaModels()
|
||||
ollamaModelList.value = models
|
||||
} catch (error) {
|
||||
console.error('加载 Ollama 模型列表失败:', error)
|
||||
MessagePlugin.error('加载模型列表失败')
|
||||
console.error(t('model.editor.loadModelListFailed'), error)
|
||||
MessagePlugin.error(t('model.editor.loadModelListFailed'))
|
||||
} finally {
|
||||
loadingOllamaModels.value = false
|
||||
}
|
||||
@@ -428,7 +436,7 @@ const loadOllamaModels = async () => {
|
||||
const refreshOllamaModels = async () => {
|
||||
ollamaModelList.value = [] // 清空以强制重新加载
|
||||
await loadOllamaModels()
|
||||
MessagePlugin.success('列表已刷新')
|
||||
MessagePlugin.success(t('model.editor.listRefreshed'))
|
||||
}
|
||||
|
||||
// 监听下拉框可见性变化
|
||||
@@ -485,17 +493,17 @@ const checkOllamaDimension = async () => {
|
||||
|
||||
if (result.available && result.dimension) {
|
||||
formData.value.dimension = result.dimension
|
||||
dimensionMessage.value = `检测成功,向量维度:${result.dimension}`
|
||||
dimensionMessage.value = t('model.editor.dimensionDetected', { value: result.dimension })
|
||||
MessagePlugin.success(dimensionMessage.value)
|
||||
} else {
|
||||
dimensionMessage.value = result.message || '检测失败,请手动输入维度'
|
||||
dimensionMessage.value = result.message || t('model.editor.dimensionFailed')
|
||||
MessagePlugin.warning(dimensionMessage.value)
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.error('检测 Ollama 模型维度失败:', error)
|
||||
dimensionChecked.value = true
|
||||
dimensionSuccess.value = false
|
||||
dimensionMessage.value = error.message || '检测失败,请手动输入维度'
|
||||
dimensionMessage.value = error.message || t('model.editor.dimensionFailed')
|
||||
MessagePlugin.error(dimensionMessage.value)
|
||||
} finally {
|
||||
checking.value = false
|
||||
@@ -505,7 +513,7 @@ const checkOllamaDimension = async () => {
|
||||
// 检查 Remote API 连接(根据模型类型调用不同的接口)
|
||||
const checkRemoteAPI = async () => {
|
||||
if (!formData.value.modelName || !formData.value.baseUrl) {
|
||||
MessagePlugin.warning('请先填写模型标识和 Base URL')
|
||||
MessagePlugin.warning(t('model.editor.fillModelAndUrl'))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -539,7 +547,7 @@ const checkRemoteAPI = async () => {
|
||||
// 如果测试成功且返回了维度,自动填充
|
||||
if (result.available && result.dimension) {
|
||||
formData.value.dimension = result.dimension
|
||||
MessagePlugin.info(`检测到向量维度:${result.dimension}`)
|
||||
MessagePlugin.info(t('model.editor.remoteDimensionDetected', { value: result.dimension }))
|
||||
}
|
||||
break
|
||||
|
||||
@@ -563,13 +571,13 @@ const checkRemoteAPI = async () => {
|
||||
break
|
||||
|
||||
default:
|
||||
MessagePlugin.error('不支持的模型类型')
|
||||
MessagePlugin.error(t('model.editor.unsupportedModelType'))
|
||||
return
|
||||
}
|
||||
|
||||
remoteChecked.value = true
|
||||
remoteAvailable.value = result.available || false
|
||||
remoteMessage.value = result.message || (result.available ? '连接成功' : '连接失败')
|
||||
remoteMessage.value = result.message || (result.available ? t('model.editor.connectionSuccess') : t('model.editor.connectionFailed'))
|
||||
|
||||
if (result.available) {
|
||||
MessagePlugin.success(remoteMessage.value)
|
||||
@@ -580,7 +588,7 @@ const checkRemoteAPI = async () => {
|
||||
console.error('Remote API 校验失败:', error)
|
||||
remoteChecked.value = true
|
||||
remoteAvailable.value = false
|
||||
remoteMessage.value = error.message || '连接失败,请检查配置'
|
||||
remoteMessage.value = error.message || t('model.editor.connectionConfigError')
|
||||
MessagePlugin.error(remoteMessage.value)
|
||||
} finally {
|
||||
checking.value = false
|
||||
@@ -592,19 +600,19 @@ const handleConfirm = async () => {
|
||||
try {
|
||||
// 手动校验必填字段
|
||||
if (!formData.value.modelName || !formData.value.modelName.trim()) {
|
||||
MessagePlugin.warning('请输入模型名称')
|
||||
MessagePlugin.warning(t('model.editor.validation.modelNameRequired'))
|
||||
return
|
||||
}
|
||||
|
||||
if (formData.value.modelName.trim().length > 100) {
|
||||
MessagePlugin.warning('模型名称不能超过100个字符')
|
||||
MessagePlugin.warning(t('model.editor.validation.modelNameMax'))
|
||||
return
|
||||
}
|
||||
|
||||
// 如果是 remote 类型,必须填写 baseUrl
|
||||
if (formData.value.source === 'remote') {
|
||||
if (!formData.value.baseUrl || !formData.value.baseUrl.trim()) {
|
||||
MessagePlugin.warning('Remote API 类型必须填写 Base URL')
|
||||
MessagePlugin.warning(t('model.editor.remoteBaseUrlRequired'))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -612,7 +620,7 @@ const handleConfirm = async () => {
|
||||
try {
|
||||
new URL(formData.value.baseUrl.trim())
|
||||
} catch {
|
||||
MessagePlugin.warning('Base URL 格式不正确,请输入有效的 URL')
|
||||
MessagePlugin.warning(t('model.editor.validation.baseUrlInvalid'))
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -659,7 +667,7 @@ watch(() => formData.value.modelName, async (newValue, oldValue) => {
|
||||
newValue !== oldValue &&
|
||||
oldValue !== '') {
|
||||
// 提示用户可以检测维度
|
||||
MessagePlugin.info('模型已选择,点击"检测维度"按钮自动获取向量维度')
|
||||
MessagePlugin.info(t('model.editor.dimensionHint'))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -674,7 +682,7 @@ const startDownload = async (modelName: string) => {
|
||||
const result = await downloadOllamaModel(modelName)
|
||||
const taskId = result.taskId
|
||||
|
||||
MessagePlugin.success(`开始下载 ${modelName}`)
|
||||
MessagePlugin.success(t('model.editor.downloadStarted', { name: modelName }))
|
||||
|
||||
// 轮询下载进度
|
||||
downloadInterval = setInterval(async () => {
|
||||
@@ -688,7 +696,7 @@ const startDownload = async (modelName: string) => {
|
||||
downloadInterval = null
|
||||
downloading.value = false
|
||||
|
||||
MessagePlugin.success(`${modelName} 下载完成`)
|
||||
MessagePlugin.success(t('model.editor.downloadCompleted', { name: modelName }))
|
||||
|
||||
// 刷新模型列表
|
||||
await loadOllamaModels()
|
||||
@@ -705,7 +713,7 @@ const startDownload = async (modelName: string) => {
|
||||
clearInterval(downloadInterval)
|
||||
downloadInterval = null
|
||||
downloading.value = false
|
||||
MessagePlugin.error(progress.message || `${modelName} 下载失败`)
|
||||
MessagePlugin.error(progress.message || t('model.editor.downloadFailed', { name: modelName }))
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = ''
|
||||
}
|
||||
@@ -718,7 +726,7 @@ const startDownload = async (modelName: string) => {
|
||||
downloading.value = false
|
||||
downloadProgress.value = 0
|
||||
currentDownloadModel.value = ''
|
||||
MessagePlugin.error(error.message || '启动下载失败')
|
||||
MessagePlugin.error(error.message || t('model.editor.downloadStartFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<t-select
|
||||
:value="selectedModelId"
|
||||
@change="handleModelChange"
|
||||
:placeholder="placeholder"
|
||||
:placeholder="placeholderText"
|
||||
:disabled="disabled"
|
||||
:loading="loading"
|
||||
filterable
|
||||
@@ -19,7 +19,7 @@
|
||||
<div class="model-option">
|
||||
<t-icon name="check-circle-filled" class="model-icon" />
|
||||
<span class="model-name">{{ model.name }}</span>
|
||||
<t-tag v-if="model.is_default" size="small" theme="success">默认</t-tag>
|
||||
<t-tag v-if="model.is_default" size="small" theme="success">{{ $t('model.defaultTag') }}</t-tag>
|
||||
</div>
|
||||
</t-option>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
>
|
||||
<div class="model-option add">
|
||||
<t-icon name="add" class="add-icon" />
|
||||
<span class="model-name">前往全局设置添加模型</span>
|
||||
<span class="model-name">{{ $t('model.addModelInSettings') }}</span>
|
||||
</div>
|
||||
</t-option>
|
||||
</t-select>
|
||||
@@ -42,6 +42,7 @@
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { listModels, type ModelConfig } from '@/api/model'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
interface Props {
|
||||
modelType: 'KnowledgeQA' | 'Embedding' | 'Rerank' | 'VLLM'
|
||||
@@ -54,7 +55,7 @@ interface Props {
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
disabled: false,
|
||||
placeholder: '请选择模型'
|
||||
placeholder: ''
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -64,6 +65,11 @@ const emit = defineEmits<{
|
||||
|
||||
const models = ref<ModelConfig[]>([])
|
||||
const loading = ref(false)
|
||||
const { t } = useI18n()
|
||||
|
||||
const placeholderText = computed(() => {
|
||||
return props.placeholder || t('model.selectModelPlaceholder')
|
||||
})
|
||||
|
||||
// 监听 allModels 变化,自动过滤当前类型的模型
|
||||
watch(() => props.allModels, (newModels) => {
|
||||
@@ -94,8 +100,8 @@ const loadModels = async () => {
|
||||
models.value = []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载模型列表失败:', error)
|
||||
MessagePlugin.error('加载模型列表失败')
|
||||
console.error(t('model.loadFailed'), error)
|
||||
MessagePlugin.error(t('model.loadFailed'))
|
||||
models.value = []
|
||||
} finally {
|
||||
loading.value = false
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<!-- 用户按钮 -->
|
||||
<div class="user-button" @click="toggleMenu">
|
||||
<div class="user-avatar">
|
||||
<img v-if="userAvatar" :src="userAvatar" alt="用户头像" />
|
||||
<img v-if="userAvatar" :src="userAvatar" :alt="$t('common.avatar')" />
|
||||
<span v-else class="avatar-placeholder">{{ userInitial }}</span>
|
||||
</div>
|
||||
<div class="user-info">
|
||||
@@ -18,7 +18,7 @@
|
||||
<div v-if="menuVisible" class="user-dropdown" @click.stop>
|
||||
<div class="menu-item" @click="handleQuickNav('models')">
|
||||
<t-icon name="control-platform" class="menu-icon" />
|
||||
<span>模型配置</span>
|
||||
<span>{{ $t('settings.modelConfig') }}</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('ollama')">
|
||||
<t-icon name="server" class="menu-icon" />
|
||||
@@ -27,25 +27,49 @@
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item" @click="handleSettings">
|
||||
<t-icon name="setting" class="menu-icon" />
|
||||
<span>全部设置</span>
|
||||
<span>{{ $t('general.allSettings') }}</span>
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item" @click="openApiDoc">
|
||||
<t-icon name="book" class="menu-icon" />
|
||||
<span>API 文档</span>
|
||||
<span class="menu-text-with-icon">
|
||||
<span>{{ $t('tenant.apiDocument') }}</span>
|
||||
<svg class="menu-external-icon" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M12.667 8a.667.667 0 0 1 .666.667v4a2.667 2.667 0 0 1-2.666 2.666H4.667a2.667 2.667 0 0 1-2.667-2.666V5.333a2.667 2.667 0 0 1 2.667-2.666h4a.667.667 0 1 1 0 1.333h-4a1.333 1.333 0 0 0-1.333 1.333v7.334A1.333 1.333 0 0 0 4.667 13.333h6a1.333 1.333 0 0 0 1.333-1.333v-4A.667.667 0 0 1 12.667 8Zm2.666-6.667v4a.667.667 0 0 1-1.333 0V3.276l-5.195 5.195a.667.667 0 0 1-.943-.943l5.195-5.195h-2.057a.667.667 0 0 1 0-1.333h4a.667.667 0 0 1 .666.666Z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="openWebsite">
|
||||
<t-icon name="home" class="menu-icon" />
|
||||
<span>官网</span>
|
||||
<span class="menu-text-with-icon">
|
||||
<span>{{ $t('common.website') }}</span>
|
||||
<svg class="menu-external-icon" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M12.667 8a.667.667 0 0 1 .666.667v4a2.667 2.667 0 0 1-2.666 2.666H4.667a2.667 2.667 0 0 1-2.667-2.666V5.333a2.667 2.667 0 0 1 2.667-2.666h4a.667.667 0 1 1 0 1.333h-4a1.333 1.333 0 0 0-1.333 1.333v7.334A1.333 1.333 0 0 0 4.667 13.333h6a1.333 1.333 0 0 0 1.333-1.333v-4A.667.667 0 0 1 12.667 8Zm2.666-6.667v4a.667.667 0 0 1-1.333 0V3.276l-5.195 5.195a.667.667 0 0 1-.943-.943l5.195-5.195h-2.057a.667.667 0 0 1 0-1.333h4a.667.667 0 0 1 .666.666Z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="openGithub">
|
||||
<t-icon name="logo-github" class="menu-icon" />
|
||||
<span>GitHub</span>
|
||||
<span class="menu-text-with-icon">
|
||||
<span>GitHub</span>
|
||||
<svg class="menu-external-icon" viewBox="0 0 16 16" aria-hidden="true">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M12.667 8a.667.667 0 0 1 .666.667v4a2.667 2.667 0 0 1-2.666 2.666H4.667a2.667 2.667 0 0 1-2.667-2.666V5.333a2.667 2.667 0 0 1 2.667-2.666h4a.667.667 0 1 1 0 1.333h-4a1.333 1.333 0 0 0-1.333 1.333v7.334A1.333 1.333 0 0 0 4.667 13.333h6a1.333 1.333 0 0 0 1.333-1.333v-4A.667.667 0 0 1 12.667 8Zm2.666-6.667v4a.667.667 0 0 1-1.333 0V3.276l-5.195 5.195a.667.667 0 0 1-.943-.943l5.195-5.195h-2.057a.667.667 0 0 1 0-1.333h4a.667.667 0 0 1 .666.666Z"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item danger" @click="handleLogout">
|
||||
<t-icon name="logout" class="menu-icon" />
|
||||
<span>注销</span>
|
||||
<span>{{ $t('auth.logout') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
@@ -59,6 +83,9 @@ import { useUIStore } from '@/stores/ui'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { getCurrentUser, logout as logoutApi } from '@/api/auth'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
const router = useRouter()
|
||||
const uiStore = useUIStore()
|
||||
@@ -142,7 +169,7 @@ const handleLogout = async () => {
|
||||
// 清理所有状态和本地存储
|
||||
authStore.logout()
|
||||
|
||||
MessagePlugin.success('已退出登录')
|
||||
MessagePlugin.success(t('auth.logout'))
|
||||
|
||||
// 跳转到登录页
|
||||
router.push('/login')
|
||||
@@ -154,7 +181,7 @@ const loadUserInfo = async () => {
|
||||
const response = await getCurrentUser()
|
||||
if (response.success && response.data && response.data.user) {
|
||||
userInfo.value = {
|
||||
username: response.data.user.username || '用户',
|
||||
username: response.data.user.username || t('common.info'),
|
||||
email: response.data.user.email || 'user@example.com',
|
||||
avatar: response.data.user.avatar || ''
|
||||
}
|
||||
@@ -304,6 +331,34 @@ onUnmounted(() => {
|
||||
font-size: 16px;
|
||||
color: #666666;
|
||||
}
|
||||
|
||||
.menu-text-with-icon {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: inherit;
|
||||
min-width: 0;
|
||||
|
||||
span {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-external-icon {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
color: #9ca3af;
|
||||
flex-shrink: 0;
|
||||
transition: color 0.2s ease;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&:hover .menu-external-icon {
|
||||
color: #07c05f;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-divider {
|
||||
|
||||
@@ -5,6 +5,9 @@ import { downKnowledgeDetails } from "@/api/knowledge-base/index";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import picturePreview from '@/components/picture-preview.vue';
|
||||
import { sanitizeHTML, safeMarkdownToHTML, createSafeImage, isValidImageURL } from '@/utils/security';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
marked.use({
|
||||
mangle: false,
|
||||
@@ -41,7 +44,7 @@ const checkImage = (url) => {
|
||||
renderer.image = function (href, title, text) {
|
||||
// 安全地处理图片链接
|
||||
if (!isValidImageURL(href)) {
|
||||
return `<p>无效的图片链接</p>`;
|
||||
return `<p>${t('error.invalidImageLink')}</p>`;
|
||||
}
|
||||
|
||||
// 使用安全的图片创建函数
|
||||
@@ -120,7 +123,7 @@ const downloadFile = () => {
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
MessagePlugin.error("获取文件失败!");
|
||||
MessagePlugin.error(t('file.downloadFailed'));
|
||||
});
|
||||
};
|
||||
const handleDetailsScroll = () => {
|
||||
@@ -144,7 +147,7 @@ const handleDetailsScroll = () => {
|
||||
}}</template>
|
||||
<div class="doc_box">
|
||||
<a :href="url" style="display: none" ref="down" :download="details.title"></a>
|
||||
<span class="label">文档标题</span>
|
||||
<span class="label">{{ $t('knowledgeBase.fileName') }}</span>
|
||||
<div class="download_box">
|
||||
<span class="doc_t">{{ details.title }}</span>
|
||||
<div class="icon_box" @click="downloadFile()">
|
||||
@@ -153,10 +156,10 @@ const handleDetailsScroll = () => {
|
||||
</div>
|
||||
</div>
|
||||
<div class="content_header">
|
||||
<span class="label">文档内容</span>
|
||||
<span class="time"> 更新时间:{{ details.time }} </span>
|
||||
<span class="label">{{ $t('knowledgeBase.fileContent') }}</span>
|
||||
<span class="time"> {{ $t('knowledgeBase.uploadTime') }}:{{ details.time }} </span>
|
||||
</div>
|
||||
<div v-if="details.md.length == 0" class="no_content">暂无数据</div>
|
||||
<div v-if="details.md.length == 0" class="no_content">{{ $t('common.noData') }}</div>
|
||||
<div v-else class="content" v-for="(item, index) in details.md" :key="index" :style="index % 2 !== 0
|
||||
? 'background: #07c05f26;'
|
||||
: 'background: #3032360f;'
|
||||
@@ -164,8 +167,8 @@ const handleDetailsScroll = () => {
|
||||
<div class="md-content" v-html="processMarkdown(item.content)"></div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<t-button @click="handleClose">确定</t-button>
|
||||
<t-button theme="default" @click="handleClose">取消</t-button>
|
||||
<t-button @click="handleClose">{{ $t('common.confirm') }}</t-button>
|
||||
<t-button theme="default" @click="handleClose">{{ $t('common.cancel') }}</t-button>
|
||||
</template>
|
||||
</t-drawer>
|
||||
<picturePreview :reviewImg="reviewImg" :reviewUrl="reviewUrl" @closePreImg="closePreImg"></picturePreview>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n'
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
<template>
|
||||
<div class="empty">
|
||||
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
||||
<span class="empty-txt">知识为空,拖放上传</span>
|
||||
<span class="empty-type-txt">pdf、doc 格式文件,不超过10M</span>
|
||||
<span class="empty-type-txt">text、markdown格式文件,不超过200K</span>
|
||||
<span class="empty-txt">{{ $t('knowledgeBase.emptyKnowledgeDragDrop') }}</span>
|
||||
<span class="empty-type-txt">{{ $t('knowledgeBase.pdfDocFormat') }}</span>
|
||||
<span class="empty-type-txt">{{ $t('knowledgeBase.textMarkdownFormat') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped lang="less">
|
||||
|
||||
@@ -5,6 +5,7 @@ import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import { listKnowledgeBases, getKnowledgeDetails, createManualKnowledge, updateManualKnowledge } from '@/api/knowledge-base'
|
||||
import { sanitizeHTML, safeMarkdownToHTML } from '@/utils/security'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
interface KnowledgeBaseOption {
|
||||
label: string
|
||||
@@ -23,6 +24,7 @@ interface KnowledgeDetailResponse {
|
||||
type ManualStatus = 'draft' | 'publish'
|
||||
|
||||
const uiStore = useUIStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
const visible = computed({
|
||||
get: () => uiStore.manualEditorVisible,
|
||||
@@ -205,7 +207,7 @@ const applyHeading = (level: number) => {
|
||||
const hashes = '#'.repeat(level)
|
||||
transformSelectedLines((line) => {
|
||||
const trimmed = line.replace(/^#+\s*/, '').trim()
|
||||
const content = trimmed || `标题${level}`
|
||||
const content = trimmed || t('manualEditor.placeholders.heading', { level })
|
||||
return `${hashes} ${content}`
|
||||
})
|
||||
}
|
||||
@@ -217,7 +219,7 @@ const applyBulletList = () => {
|
||||
transformSelectedLines((line) => {
|
||||
const trimmed = line.trim()
|
||||
const content = trimmed.replace(listPrefixPattern, '').trim()
|
||||
return `- ${content || '列表项'}`
|
||||
return `- ${content || t('manualEditor.placeholders.listItem')}`
|
||||
})
|
||||
}
|
||||
|
||||
@@ -225,7 +227,7 @@ const applyOrderedList = () => {
|
||||
transformSelectedLines((line, index) => {
|
||||
const trimmed = line.trim()
|
||||
const content = trimmed.replace(listPrefixPattern, '').trim()
|
||||
return `${index + 1}. ${content || '列表项'}`
|
||||
return `${index + 1}. ${content || t('manualEditor.placeholders.listItem')}`
|
||||
})
|
||||
}
|
||||
|
||||
@@ -233,19 +235,19 @@ const applyTaskList = () => {
|
||||
transformSelectedLines((line) => {
|
||||
const trimmed = line.trim()
|
||||
const content = trimmed.replace(listPrefixPattern, '').trim()
|
||||
return `- [ ] ${content || '任务项'}`
|
||||
return `- [ ] ${content || t('manualEditor.placeholders.taskItem')}`
|
||||
})
|
||||
}
|
||||
|
||||
const applyBlockquote = () => {
|
||||
transformSelectedLines((line) => {
|
||||
const trimmed = line.trim().replace(/^>\s?/, '').trim()
|
||||
return `> ${trimmed || '引用内容'}`
|
||||
return `> ${trimmed || t('manualEditor.placeholders.quote')}`
|
||||
})
|
||||
}
|
||||
|
||||
const insertCodeBlock = () => {
|
||||
const placeholder = '代码内容'
|
||||
const placeholder = t('manualEditor.placeholders.code')
|
||||
const block = `\n\`\`\`\n${placeholder}\n\`\`\`\n`
|
||||
const startOffset = block.indexOf(placeholder)
|
||||
insertBlock(block, startOffset, startOffset + placeholder.length)
|
||||
@@ -256,9 +258,10 @@ const insertHorizontalRule = () => {
|
||||
}
|
||||
|
||||
const insertTable = () => {
|
||||
const template = '\n| 列1 | 列2 |\n| --- | --- |\n| 内容 | 内容 |\n'
|
||||
const placeholderIndex = template.indexOf('内容')
|
||||
insertBlock(template, placeholderIndex, placeholderIndex + 2)
|
||||
const cell = t('manualEditor.table.cell')
|
||||
const template = `\n| ${t('manualEditor.table.column1')} | ${t('manualEditor.table.column2')} |\n| --- | --- |\n| ${cell} | ${cell} |\n`
|
||||
const placeholderIndex = template.indexOf(cell)
|
||||
insertBlock(template, placeholderIndex, placeholderIndex + cell.length)
|
||||
}
|
||||
|
||||
const insertLink = () => {
|
||||
@@ -266,7 +269,7 @@ const insertLink = () => {
|
||||
const { start, end } = getSelectionRange()
|
||||
const { safeStart, safeEnd } = clampRange(start, end, value.length)
|
||||
const selectedText =
|
||||
safeEnd > safeStart ? value.slice(safeStart, safeEnd) : '链接文本'
|
||||
safeEnd > safeStart ? value.slice(safeStart, safeEnd) : t('manualEditor.placeholders.linkText')
|
||||
const urlPlaceholder = 'https://'
|
||||
const result =
|
||||
value.slice(0, safeStart) +
|
||||
@@ -281,7 +284,7 @@ const insertImage = () => {
|
||||
const value = form.content ?? ''
|
||||
const { start, end } = getSelectionRange()
|
||||
const { safeStart, safeEnd } = clampRange(start, end, value.length)
|
||||
const altText = safeEnd > safeStart ? value.slice(safeStart, safeEnd) : '描述'
|
||||
const altText = safeEnd > safeStart ? value.slice(safeStart, safeEnd) : t('manualEditor.placeholders.imageAlt')
|
||||
const urlPlaceholder = 'https://'
|
||||
const result =
|
||||
value.slice(0, safeStart) +
|
||||
@@ -304,49 +307,55 @@ type ToolbarGroup = {
|
||||
buttons: ToolbarButton[]
|
||||
}
|
||||
|
||||
const toolbarGroups: ToolbarGroup[] = [
|
||||
const toolbarGroups = computed<ToolbarGroup[]>(() => [
|
||||
{
|
||||
key: 'format',
|
||||
buttons: [
|
||||
{ key: 'bold', icon: 'textformat-bold', tooltip: '加粗', action: () => wrapSelection('**', '**', '加粗文本') },
|
||||
{ key: 'italic', icon: 'textformat-italic', tooltip: '斜体', action: () => wrapSelection('*', '*', '斜体文本') },
|
||||
{ key: 'strike', icon: 'textformat-strikethrough', tooltip: '删除线', action: () => wrapSelection('~~', '~~', '删除线') },
|
||||
{ key: 'inline-code', icon: 'code', tooltip: '行内代码', action: () => wrapSelection('`', '`', 'code') },
|
||||
{ key: 'bold', icon: 'textformat-bold', tooltip: t('manualEditor.toolbar.bold'), action: () => wrapSelection('**', '**', t('manualEditor.placeholders.bold')) },
|
||||
{ key: 'italic', icon: 'textformat-italic', tooltip: t('manualEditor.toolbar.italic'), action: () => wrapSelection('*', '*', t('manualEditor.placeholders.italic')) },
|
||||
{ key: 'strike', icon: 'textformat-strikethrough', tooltip: t('manualEditor.toolbar.strike'), action: () => wrapSelection('~~', '~~', t('manualEditor.placeholders.strike')) },
|
||||
{ key: 'inline-code', icon: 'code', tooltip: t('manualEditor.toolbar.inlineCode'), action: () => wrapSelection('`', '`', t('manualEditor.placeholders.inlineCode')) },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'heading',
|
||||
buttons: [
|
||||
{ key: 'h1', icon: 'numbers-1', tooltip: '一级标题', action: () => applyHeading(1) },
|
||||
{ key: 'h2', icon: 'numbers-2', tooltip: '二级标题', action: () => applyHeading(2) },
|
||||
{ key: 'h3', icon: 'numbers-3', tooltip: '三级标题', action: () => applyHeading(3) },
|
||||
{ key: 'h1', icon: 'numbers-1', tooltip: t('manualEditor.toolbar.heading1'), action: () => applyHeading(1) },
|
||||
{ key: 'h2', icon: 'numbers-2', tooltip: t('manualEditor.toolbar.heading2'), action: () => applyHeading(2) },
|
||||
{ key: 'h3', icon: 'numbers-3', tooltip: t('manualEditor.toolbar.heading3'), action: () => applyHeading(3) },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'list',
|
||||
buttons: [
|
||||
{ key: 'ul', icon: 'view-list', tooltip: '无序列表', action: applyBulletList },
|
||||
{ key: 'ol', icon: 'list-numbered', tooltip: '有序列表', action: applyOrderedList },
|
||||
{ key: 'task', icon: 'check-rectangle', tooltip: '任务列表', action: applyTaskList },
|
||||
{ key: 'quote', icon: 'quote', tooltip: '引用', action: applyBlockquote },
|
||||
{ key: 'ul', icon: 'view-list', tooltip: t('manualEditor.toolbar.bulletList'), action: applyBulletList },
|
||||
{ key: 'ol', icon: 'list-numbered', tooltip: t('manualEditor.toolbar.orderedList'), action: applyOrderedList },
|
||||
{ key: 'task', icon: 'check-rectangle', tooltip: t('manualEditor.toolbar.taskList'), action: applyTaskList },
|
||||
{ key: 'quote', icon: 'quote', tooltip: t('manualEditor.toolbar.blockquote'), action: applyBlockquote },
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'insert',
|
||||
buttons: [
|
||||
{ key: 'codeblock', icon: 'code-1', tooltip: '代码块', action: insertCodeBlock },
|
||||
{ key: 'link', icon: 'link', tooltip: '插入链接', action: insertLink },
|
||||
{ key: 'image', icon: 'image', tooltip: '插入图片', action: insertImage },
|
||||
{ key: 'table', icon: 'table', tooltip: '插入表格', action: insertTable },
|
||||
{ key: 'hr', icon: 'component-divider-horizontal', tooltip: '分割线', action: insertHorizontalRule },
|
||||
{ key: 'codeblock', icon: 'code-1', tooltip: t('manualEditor.toolbar.codeBlock'), action: insertCodeBlock },
|
||||
{ key: 'link', icon: 'link', tooltip: t('manualEditor.toolbar.link'), action: insertLink },
|
||||
{ key: 'image', icon: 'image', tooltip: t('manualEditor.toolbar.image'), action: insertImage },
|
||||
{ key: 'table', icon: 'table', tooltip: t('manualEditor.toolbar.table'), action: insertTable },
|
||||
{ key: 'hr', icon: 'component-divider-horizontal', tooltip: t('manualEditor.toolbar.horizontalRule'), action: insertHorizontalRule },
|
||||
],
|
||||
},
|
||||
]
|
||||
])
|
||||
|
||||
const isPreviewMode = computed(() => activeTab.value === 'preview')
|
||||
const viewToggleIcon = computed(() => (isPreviewMode.value ? 'edit' : 'view-module'))
|
||||
const viewToggleTooltip = computed(() => (isPreviewMode.value ? '切换到编辑视图' : '切换到预览视图'))
|
||||
const viewToggleLabel = computed(() => (isPreviewMode.value ? '返回编辑' : '预览内容'))
|
||||
const viewToggleTooltip = computed(() =>
|
||||
isPreviewMode.value
|
||||
? t('manualEditor.view.toggleToEdit')
|
||||
: t('manualEditor.view.toggleToPreview'),
|
||||
)
|
||||
const viewToggleLabel = computed(() =>
|
||||
isPreviewMode.value ? t('manualEditor.view.editLabel') : t('manualEditor.view.previewLabel'),
|
||||
)
|
||||
|
||||
const handleToolbarAction = (action: ToolbarAction) => {
|
||||
if (saving.value) {
|
||||
@@ -374,7 +383,9 @@ marked.use({
|
||||
})
|
||||
|
||||
const previewHTML = computed(() => {
|
||||
if (!form.content) return '<p class="empty-preview">暂无内容</p>'
|
||||
if (!form.content) {
|
||||
return `<p class="empty-preview">${t('manualEditor.preview.empty')}</p>`
|
||||
}
|
||||
const safeMarkdown = safeMarkdownToHTML(form.content)
|
||||
const html = marked.parse(safeMarkdown)
|
||||
return sanitizeHTML(html)
|
||||
@@ -382,12 +393,13 @@ const previewHTML = computed(() => {
|
||||
|
||||
const kbDisabled = computed(() => mode.value === 'edit' && !!form.kbId)
|
||||
|
||||
const dialogTitle = computed(() => {
|
||||
if (mode.value === 'edit') {
|
||||
return '编辑 Markdown 知识'
|
||||
}
|
||||
return '在线编辑 Markdown 知识'
|
||||
})
|
||||
const dialogTitle = computed(() =>
|
||||
mode.value === 'edit' ? t('manualEditor.title.edit') : t('manualEditor.title.create'),
|
||||
)
|
||||
|
||||
const lastUpdatedText = computed(() =>
|
||||
lastUpdatedAt.value ? t('manualEditor.status.lastUpdated', { time: lastUpdatedAt.value }) : '',
|
||||
)
|
||||
|
||||
const loadKnowledgeBases = async () => {
|
||||
kbLoading.value = true
|
||||
@@ -403,7 +415,10 @@ const loadKnowledgeBases = async () => {
|
||||
if (presetKbId) {
|
||||
const exists = list.find((item) => item.value === presetKbId)
|
||||
if (!exists) {
|
||||
kbOptions.value.unshift({ label: '当前知识库', value: presetKbId })
|
||||
kbOptions.value.unshift({
|
||||
label: t('manualEditor.labels.currentKnowledgeBase'),
|
||||
value: presetKbId,
|
||||
})
|
||||
}
|
||||
form.kbId = presetKbId
|
||||
} else {
|
||||
@@ -411,7 +426,7 @@ const loadKnowledgeBases = async () => {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载知识库列表失败:', error)
|
||||
console.error('[ManualEditor] Failed to load knowledge base list:', error)
|
||||
kbOptions.value = []
|
||||
} finally {
|
||||
kbLoading.value = false
|
||||
@@ -438,7 +453,7 @@ const parseManualMetadata = (
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('解析手工知识元数据失败:', error)
|
||||
console.warn('[ManualEditor] Failed to parse manual metadata:', error)
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -452,7 +467,7 @@ const loadKnowledgeContent = async () => {
|
||||
const res: any = await getKnowledgeDetails(knowledgeId.value)
|
||||
const data: KnowledgeDetailResponse | undefined = res?.data
|
||||
if (!data) {
|
||||
MessagePlugin.error('获取知识详情失败')
|
||||
MessagePlugin.error(t('manualEditor.error.fetchDetailFailed'))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -470,11 +485,14 @@ const loadKnowledgeContent = async () => {
|
||||
}
|
||||
|
||||
if (form.kbId && !kbOptions.value.find((item) => item.value === form.kbId)) {
|
||||
kbOptions.value.unshift({ label: '当前知识库', value: form.kbId })
|
||||
kbOptions.value.unshift({
|
||||
label: t('manualEditor.labels.currentKnowledgeBase'),
|
||||
value: form.kbId,
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载手工知识失败:', error)
|
||||
MessagePlugin.error('获取知识详情失败')
|
||||
console.error('[ManualEditor] Failed to load manual knowledge:', error)
|
||||
MessagePlugin.error(t('manualEditor.error.fetchDetailFailed'))
|
||||
} finally {
|
||||
contentLoading.value = false
|
||||
}
|
||||
@@ -496,7 +514,7 @@ const generateDefaultTitle = () => {
|
||||
if (uiStore.manualEditorInitialTitle) {
|
||||
return uiStore.manualEditorInitialTitle
|
||||
}
|
||||
return `新建文档-${new Date().toLocaleString()}`
|
||||
return `${t('manualEditor.defaultTitlePrefix')}-${new Date().toLocaleString()}`
|
||||
}
|
||||
|
||||
const initialize = async () => {
|
||||
@@ -521,19 +539,19 @@ const initialize = async () => {
|
||||
|
||||
const validateForm = (targetStatus: ManualStatus): boolean => {
|
||||
if (!form.kbId) {
|
||||
MessagePlugin.warning('请选择目标知识库')
|
||||
MessagePlugin.warning(t('manualEditor.warning.selectKnowledgeBase'))
|
||||
return false
|
||||
}
|
||||
if (!form.title || !form.title.trim()) {
|
||||
MessagePlugin.warning('请输入知识标题')
|
||||
MessagePlugin.warning(t('manualEditor.warning.enterTitle'))
|
||||
return false
|
||||
}
|
||||
if (!form.content || !form.content.trim()) {
|
||||
MessagePlugin.warning('请输入知识内容')
|
||||
MessagePlugin.warning(t('manualEditor.warning.enterContent'))
|
||||
return false
|
||||
}
|
||||
if (targetStatus === 'publish' && form.content.trim().length < 10) {
|
||||
MessagePlugin.warning('内容过短,建议补充更多信息后再发布')
|
||||
MessagePlugin.warning(t('manualEditor.warning.contentTooShort'))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -564,7 +582,11 @@ const handleSave = async (targetStatus: ManualStatus) => {
|
||||
}
|
||||
|
||||
if (response?.success) {
|
||||
MessagePlugin.success(targetStatus === 'draft' ? '草稿已保存' : '知识已发布并开始索引')
|
||||
MessagePlugin.success(
|
||||
targetStatus === 'draft'
|
||||
? t('manualEditor.success.draftSaved')
|
||||
: t('manualEditor.success.published'),
|
||||
)
|
||||
if (knowledgeID) {
|
||||
uiStore.notifyManualEditorSuccess({
|
||||
kbId,
|
||||
@@ -574,11 +596,11 @@ const handleSave = async (targetStatus: ManualStatus) => {
|
||||
}
|
||||
uiStore.closeManualEditor()
|
||||
} else {
|
||||
const message = response?.message || '保存失败,请稍后重试'
|
||||
const message = response?.message || t('manualEditor.error.saveFailed')
|
||||
MessagePlugin.error(message)
|
||||
}
|
||||
} catch (error: any) {
|
||||
const message = error?.error?.message || error?.message || '保存失败,请稍后重试'
|
||||
const message = error?.error?.message || error?.message || t('manualEditor.error.saveFailed')
|
||||
MessagePlugin.error(message)
|
||||
} finally {
|
||||
saving.value = false
|
||||
@@ -630,31 +652,31 @@ onBeforeUnmount(() => {
|
||||
>
|
||||
<div class="editor-body" v-if="initialLoaded">
|
||||
<div class="form-row">
|
||||
<label class="form-label">目标知识库</label>
|
||||
<label class="form-label">{{ $t('manualEditor.form.knowledgeBaseLabel') }}</label>
|
||||
<t-select
|
||||
v-model="form.kbId"
|
||||
:disabled="kbDisabled"
|
||||
:loading="kbLoading"
|
||||
:options="kbOptions"
|
||||
placeholder="请选择知识库"
|
||||
:placeholder="$t('manualEditor.form.knowledgeBasePlaceholder')"
|
||||
:popup-props="{ overlayStyle: { zIndex: 2200 } }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label class="form-label">知识标题</label>
|
||||
<label class="form-label">{{ $t('manualEditor.form.titleLabel') }}</label>
|
||||
<t-input
|
||||
v-model="form.title"
|
||||
maxlength="100"
|
||||
placeholder="请输入标题"
|
||||
:placeholder="$t('manualEditor.form.titlePlaceholder')"
|
||||
showLimitNumber
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="status-row" v-if="mode === 'edit'">
|
||||
<t-tag theme="warning" v-if="form.status === 'draft'">当前状态:草稿</t-tag>
|
||||
<t-tag theme="success" v-else>当前状态:已发布</t-tag>
|
||||
<span v-if="lastUpdatedAt" class="status-timestamp">最近更新:{{ lastUpdatedAt }}</span>
|
||||
<t-tag theme="warning" v-if="form.status === 'draft'">{{ $t('manualEditor.status.draftTag') }}</t-tag>
|
||||
<t-tag theme="success" v-else>{{ $t('manualEditor.status.publishedTag') }}</t-tag>
|
||||
<span v-if="lastUpdatedText" class="status-timestamp">{{ lastUpdatedText }}</span>
|
||||
</div>
|
||||
|
||||
<div class="editor-toolbar">
|
||||
@@ -687,11 +709,11 @@ onBeforeUnmount(() => {
|
||||
ref="textareaComponent"
|
||||
v-if="!contentLoading"
|
||||
v-model="form.content"
|
||||
placeholder="支持 Markdown 语法,可使用 # 标题、列表、代码块等"
|
||||
:placeholder="$t('manualEditor.form.contentPlaceholder')"
|
||||
:autosize="{ minRows: 16, maxRows: 24 }"
|
||||
/>
|
||||
<div v-else class="loading-placeholder">
|
||||
<t-loading size="small" text="正在加载内容" />
|
||||
<t-loading size="small" :text="$t('manualEditor.loading.content')" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="editor-pane" v-show="activeTab === 'preview'">
|
||||
@@ -701,7 +723,9 @@ onBeforeUnmount(() => {
|
||||
|
||||
<div class="dialog-footer">
|
||||
<div class="footer-left">
|
||||
<t-button variant="outline" theme="default" @click="handleClose">取消</t-button>
|
||||
<t-button variant="outline" theme="default" @click="handleClose">
|
||||
{{ $t('manualEditor.actions.cancel') }}
|
||||
</t-button>
|
||||
</div>
|
||||
<div class="footer-right">
|
||||
<t-tooltip :content="viewToggleTooltip" placement="top">
|
||||
@@ -722,20 +746,20 @@ onBeforeUnmount(() => {
|
||||
@click="handleSave('draft')"
|
||||
:loading="saving && savingAction === 'draft'"
|
||||
>
|
||||
暂存草稿
|
||||
{{ $t('manualEditor.actions.saveDraft') }}
|
||||
</t-button>
|
||||
<t-button
|
||||
theme="primary"
|
||||
@click="handleSave('publish')"
|
||||
:loading="saving && savingAction === 'publish'"
|
||||
>
|
||||
发布入库
|
||||
{{ $t('manualEditor.actions.publish') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="loading-wrapper">
|
||||
<t-loading size="medium" text="正在准备编辑器" />
|
||||
<t-loading size="medium" :text="$t('manualEditor.loading.preparing')" />
|
||||
</div>
|
||||
</t-dialog>
|
||||
</template>
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
{{ subitem.title }}
|
||||
</span>
|
||||
<t-dropdown
|
||||
:options="[{ content: '删除记录', value: 'delete' }]"
|
||||
:options="[{ content: t('upload.deleteRecord'), value: 'delete' }]"
|
||||
@click="(data) => data.value === 'delete' && delCard(subitem.originalIndex, subitem)"
|
||||
placement="bottom-right"
|
||||
trigger="click">
|
||||
@@ -104,6 +104,9 @@ import { useAuthStore } from '@/stores/auth';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import UserMenu from '@/components/UserMenu.vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const { t } = useI18n();
|
||||
let uploadInput = ref();
|
||||
const usemenuStore = useMenuStore();
|
||||
const authStore = useAuthStore();
|
||||
@@ -195,7 +198,7 @@ const initializedKnowledgeBases = computed(() => {
|
||||
|
||||
// 时间分组函数
|
||||
const getTimeCategory = (dateStr: string): string => {
|
||||
if (!dateStr) return '更早';
|
||||
if (!dateStr) return t('time.earlier');
|
||||
|
||||
const date = new Date(dateStr);
|
||||
const now = new Date();
|
||||
@@ -208,17 +211,17 @@ const getTimeCategory = (dateStr: string): string => {
|
||||
const sessionDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||
|
||||
if (sessionDate.getTime() >= today.getTime()) {
|
||||
return '今天';
|
||||
return t('time.today');
|
||||
} else if (sessionDate.getTime() >= yesterday.getTime()) {
|
||||
return '昨天';
|
||||
return t('time.yesterday');
|
||||
} else if (date.getTime() >= sevenDaysAgo.getTime()) {
|
||||
return '近7天';
|
||||
return t('time.last7Days');
|
||||
} else if (date.getTime() >= thirtyDaysAgo.getTime()) {
|
||||
return '近30天';
|
||||
return t('time.last30Days');
|
||||
} else if (date.getTime() >= oneYearAgo.getTime()) {
|
||||
return '近1年';
|
||||
return t('time.lastYear');
|
||||
} else {
|
||||
return '更早';
|
||||
return t('time.earlier');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -230,12 +233,12 @@ const groupedSessions = computed(() => {
|
||||
}
|
||||
|
||||
const groups: { [key: string]: any[] } = {
|
||||
'今天': [],
|
||||
'昨天': [],
|
||||
'近7天': [],
|
||||
'近30天': [],
|
||||
'近1年': [],
|
||||
'更早': []
|
||||
[t('time.today')]: [],
|
||||
[t('time.yesterday')]: [],
|
||||
[t('time.last7Days')]: [],
|
||||
[t('time.last30Days')]: [],
|
||||
[t('time.lastYear')]: [],
|
||||
[t('time.earlier')]: []
|
||||
};
|
||||
|
||||
// 将sessions按时间分组
|
||||
@@ -248,7 +251,7 @@ const groupedSessions = computed(() => {
|
||||
});
|
||||
|
||||
// 按顺序返回非空分组
|
||||
const orderedLabels = ['今天', '昨天', '近7天', '近30天', '近1年', '更早'];
|
||||
const orderedLabels = [t('time.today'), t('time.yesterday'), t('time.last7Days'), t('time.last30Days'), t('time.lastYear'), t('time.earlier')];
|
||||
return orderedLabels
|
||||
.filter(label => groups[label].length > 0)
|
||||
.map(label => ({
|
||||
@@ -267,10 +270,10 @@ const kbMenuItem = computed(() => {
|
||||
})
|
||||
|
||||
const loading = ref(false)
|
||||
const uploadActionOptions = [
|
||||
{ content: '上传文档', value: 'upload' },
|
||||
{ content: '在线编辑', value: 'manual' },
|
||||
]
|
||||
const uploadActionOptions = computed(() => [
|
||||
{ content: t('upload.uploadDocument'), value: 'upload' },
|
||||
{ content: t('upload.onlineEdit'), value: 'manual' },
|
||||
])
|
||||
const uploadFile = async () => {
|
||||
// 获取当前知识库ID
|
||||
const currentKbId = await getCurrentKbId();
|
||||
@@ -284,12 +287,12 @@ const uploadFile = async () => {
|
||||
// 检查知识库是否已初始化(有 EmbeddingModelID 和 SummaryModelID)
|
||||
if (!kb.embedding_model_id || kb.embedding_model_id === '' ||
|
||||
!kb.summary_model_id || kb.summary_model_id === '') {
|
||||
MessagePlugin.warning("该知识库尚未完成初始化配置,请先前往设置页面配置模型信息后再上传文件");
|
||||
MessagePlugin.warning(t('knowledgeBase.notInitialized'));
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取知识库信息失败:', error);
|
||||
MessagePlugin.error("获取知识库信息失败,无法上传文件");
|
||||
MessagePlugin.error(t('knowledgeBase.getInfoFailed'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n'
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
<template>
|
||||
<div class="mask">
|
||||
<img class="upload-mask-img" src="@/assets/img/upload-mask.svg" alt="">
|
||||
<span class="drag-txt">将文件拖放到此处</span>
|
||||
<span class="drag-type-txt">pdf、doc 格式文件,不超过30M</span>
|
||||
<span class="drag-type-txt">text、markdown格式文件,不超过30M</span>
|
||||
<span class="drag-txt">{{ $t('file.upload') }}</span>
|
||||
<span class="drag-type-txt">{{ $t('knowledgeBase.pdfDocFormat') }}</span>
|
||||
<span class="drag-type-txt">{{ $t('knowledgeBase.textMarkdownFormat') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<style scoped lang="less">
|
||||
|
||||
Reference in New Issue
Block a user