From 21649b62c74593fd24a65ca0d723c1cb0fb7d0a5 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Thu, 20 Nov 2025 23:41:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9EURL=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98=E5=8C=96=E7=9F=A5=E8=AF=86?= =?UTF-8?q?=E5=BA=93=E6=96=87=E6=A1=A3=E5=B1=95=E7=A4=BA=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/package-lock.json | 2 +- frontend/src/api/knowledge-base/index.ts | 4 + frontend/src/components/doc-content.vue | 293 ++++++++++++++++-- frontend/src/components/menu.vue | 21 +- frontend/src/hooks/useKnowledgeBase.ts | 13 +- frontend/src/i18n/locales/en-US.ts | 26 ++ frontend/src/i18n/locales/ru-RU.ts | 26 ++ frontend/src/i18n/locales/zh-CN.ts | 26 ++ .../src/views/knowledge/KnowledgeBase.vue | 146 ++++++++- 9 files changed, 532 insertions(+), 25 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 4d7ae9c1..6d8675f1 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -3907,7 +3907,7 @@ }, "node_modules/xlsx": { "version": "0.20.2", - "resolved": "file:../packages/xlsx-0.20.2.tgz", + "resolved": "file:packages/xlsx-0.20.2.tgz", "integrity": "sha512-+nKZ39+nvK7Qq6i0PvWWRA4j/EkfWOtkP/YhMtupm+lJIiHxUrgTr1CcKv1nBk1rHtkRRQ3O2+Ih/q/sA+FXZA==", "license": "Apache-2.0", "bin": { diff --git a/frontend/src/api/knowledge-base/index.ts b/frontend/src/api/knowledge-base/index.ts index 4dbbc577..48cc52f8 100644 --- a/frontend/src/api/knowledge-base/index.ts +++ b/frontend/src/api/knowledge-base/index.ts @@ -44,6 +44,10 @@ export function uploadKnowledgeFile(kbId: string, data = {}) { return postUpload(`/api/v1/knowledge-bases/${kbId}/knowledge/file`, data); } +export function createKnowledgeFromURL(kbId: string, data: { url: string; enable_multimodel?: boolean }) { + return post(`/api/v1/knowledge-bases/${kbId}/knowledge/url`, data); +} + export function createManualKnowledge(kbId: string, data: { title: string; content: string; status: string }) { return post(`/api/v1/knowledge-bases/${kbId}/knowledge/manual`, data); } diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue index cfc82367..2e2cf282 100644 --- a/frontend/src/components/doc-content.vue +++ b/frontend/src/components/doc-content.vue @@ -51,7 +51,7 @@ renderer.image = function (href, title, text) {
${text || ''}
`; }; -const props = defineProps(["visible", "details"]); +const props = defineProps(["visible", "details", "knowledgeType", "sourceInfo"]); const emit = defineEmits(["closeDoc", "getDoc"]); watch(() => props.details.md, (newVal) => { nextTick(async () => { @@ -100,6 +100,91 @@ const handleClose = () => { emit("closeDoc", false); doc.scrollTop = 0; }; + +// 获取显示标题 +const getDisplayTitle = () => { + if (!props.details.title) return ''; + if (props.details.type === 'file') { + // 文件类型去掉扩展名 + const lastDotIndex = props.details.title.lastIndexOf("."); + return lastDotIndex > 0 ? props.details.title.substring(0, lastDotIndex) : props.details.title; + } + // URL和手动创建直接返回标题 + return props.details.title; +}; + +// 获取类型标签 +const getTypeLabel = () => { + switch (props.details.type) { + case 'url': + return t('knowledgeBase.typeURL') || '网页'; + case 'manual': + return t('knowledgeBase.typeManual') || '手动创建'; + case 'file': + return props.details.file_type ? props.details.file_type.toUpperCase() : t('knowledgeBase.typeFile') || '文件'; + default: + return ''; + } +}; + +// 获取类型主题色 +const getTypeTheme = () => { + switch (props.details.type) { + case 'url': + return 'primary'; + case 'manual': + return 'success'; + case 'file': + return 'default'; + default: + return 'default'; + } +}; + +// 获取内容标签 +const getContentLabel = () => { + switch (props.details.type) { + case 'url': + return t('knowledgeBase.webContent') || '网页内容'; + case 'manual': + return t('knowledgeBase.documentContent') || '文档内容'; + case 'file': + default: + return t('knowledgeBase.fileContent') || '文件内容'; + } +}; + +// 获取时间标签 +const getTimeLabel = () => { + switch (props.details.type) { + case 'url': + return t('knowledgeBase.importTime') || '导入时间'; + case 'manual': + return t('knowledgeBase.createTime') || '创建时间'; + case 'file': + default: + return t('knowledgeBase.uploadTime') || '上传时间'; + } +}; + +// 获取Chunk样式类 +const getChunkClass = (index: number) => { + return index % 2 !== 0 ? 'chunk-odd' : 'chunk-even'; +}; + +// 获取Chunk元数据 +const getChunkMeta = (item: any) => { + if (!item) return ''; + const parts = []; + if (item.char_count) { + parts.push(`${item.char_count} ${t('knowledgeBase.characters') || '字符'}`); + } + if (item.token_count) { + parts.push(`${item.token_count} tokens`); + } + return parts.join(' · '); +}; + const downloadFile = () => { downKnowledgeDetails(props.details.id) .then((result) => { @@ -139,10 +224,17 @@ const handleDetailsScroll = () => {