feat: 新增URL导入功能并优化知识库文档展示样式
This commit is contained in:
Generated
+1
-1
@@ -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": {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ renderer.image = function (href, title, text) {
|
||||
<figcaption style="text-align: left;">${text || ''}</figcaption>
|
||||
</figure>`;
|
||||
};
|
||||
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 = () => {
|
||||
<template>
|
||||
<div class="doc_content" ref="mdContentWrap">
|
||||
<t-drawer :visible="visible" :zIndex="2000" :closeBtn="true" @close="handleClose">
|
||||
<template #header>{{
|
||||
details.title.substring(0, details.title.lastIndexOf("."))
|
||||
}}</template>
|
||||
<div class="doc_box">
|
||||
<template #header>
|
||||
<div class="drawer-header">
|
||||
<span class="header-title">{{ getDisplayTitle() }}</span>
|
||||
<t-tag v-if="details.type" size="small" :theme="getTypeTheme()" variant="light">
|
||||
{{ getTypeLabel() }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 文件类型专属区域 -->
|
||||
<div v-if="details.type === 'file'" class="doc_box">
|
||||
<a :href="url" style="display: none" ref="down" :download="details.title"></a>
|
||||
<span class="label">{{ $t('knowledgeBase.fileName') }}</span>
|
||||
<div class="download_box">
|
||||
@@ -152,17 +244,48 @@ const handleDetailsScroll = () => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- URL类型专属区域 -->
|
||||
<div v-else-if="details.type === 'url'" class="url_box">
|
||||
<span class="label">{{ $t('knowledgeBase.urlSource') || '来源网址' }}</span>
|
||||
<div class="url_link_box">
|
||||
<a :href="details.source" target="_blank" class="url_link">
|
||||
<t-icon name="link" size="14px" />
|
||||
<span class="url_text">{{ details.source }}</span>
|
||||
<t-icon name="jump" size="14px" class="jump-icon" />
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 手动创建类型专属区域 -->
|
||||
<div v-else-if="details.type === 'manual'" class="manual_box">
|
||||
<span class="label">{{ $t('knowledgeBase.documentTitle') || '文档标题' }}</span>
|
||||
<div class="manual_title_box">
|
||||
<span class="manual_title">{{ details.title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content_header">
|
||||
<span class="label">{{ $t('knowledgeBase.fileContent') }}</span>
|
||||
<span class="time"> {{ $t('knowledgeBase.uploadTime') }}:{{ details.time }} </span>
|
||||
<span class="label">{{ getContentLabel() }}</span>
|
||||
<span class="time"> {{ getTimeLabel() }}:{{ details.time }} </span>
|
||||
</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;'
|
||||
">
|
||||
<div class="md-content" v-html="processMarkdown(item.content)"></div>
|
||||
<div v-else class="chunk-list">
|
||||
<div
|
||||
class="chunk-item"
|
||||
v-for="(item, index) in details.md"
|
||||
:key="index"
|
||||
:class="getChunkClass(index)"
|
||||
>
|
||||
<div class="chunk-header">
|
||||
<span class="chunk-index">{{ $t('knowledgeBase.segment') || '片段' }} {{ index + 1 }}</span>
|
||||
<span class="chunk-meta">{{ getChunkMeta(item) }}</span>
|
||||
</div>
|
||||
<div class="md-content" v-html="processMarkdown(item.content)"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<t-button @click="handleClose">{{ $t('common.confirm') }}</t-button>
|
||||
<t-button theme="default" @click="handleClose">{{ $t('common.cancel') }}</t-button>
|
||||
@@ -185,16 +308,24 @@ const handleDetailsScroll = () => {
|
||||
padding: 16px 24px;
|
||||
}
|
||||
|
||||
.content {
|
||||
word-break: break-word;
|
||||
padding: 4px;
|
||||
gap: 4px;
|
||||
margin-top: 12px;
|
||||
.drawer-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
|
||||
.header-title {
|
||||
flex: 1;
|
||||
font-weight: 600;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.doc_box {
|
||||
.doc_box, .url_box, .manual_box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.label {
|
||||
@@ -206,6 +337,7 @@ const handleDetailsScroll = () => {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
// 文件下载区域
|
||||
.download_box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -238,13 +370,71 @@ const handleDetailsScroll = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// URL链接区域
|
||||
.url_link_box {
|
||||
border-radius: 4px;
|
||||
border: 1px solid #d0e8dc;
|
||||
background: #f0fdf4;
|
||||
padding: 8px 12px;
|
||||
|
||||
.url_link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #059669;
|
||||
text-decoration: none;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
color: #07c05f;
|
||||
background: #e6f7ed;
|
||||
border-radius: 3px;
|
||||
padding: 4px 6px;
|
||||
margin: -4px -6px;
|
||||
|
||||
.jump-icon {
|
||||
transform: translateX(2px);
|
||||
}
|
||||
}
|
||||
|
||||
.url_text {
|
||||
flex: 1;
|
||||
font-size: 13px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.jump-icon {
|
||||
transition: transform 0.2s ease;
|
||||
flex-shrink: 0;
|
||||
color: #059669;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 手动创建标题区域
|
||||
.manual_title_box {
|
||||
border-radius: 4px;
|
||||
border: 1px solid #dcdcdc;
|
||||
background: #f0fdf4;
|
||||
padding: 8px 12px;
|
||||
|
||||
.manual_title {
|
||||
color: #1d2129;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
word-break: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
.content_header {
|
||||
margin-top: 22px;
|
||||
margin-bottom: 24px;
|
||||
margin-bottom: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.time {
|
||||
margin-left: 12px;
|
||||
color: #00000066;
|
||||
font-size: 12px;
|
||||
font-style: normal;
|
||||
@@ -258,5 +448,68 @@ const handleDetailsScroll = () => {
|
||||
font-size: 12px;
|
||||
padding: 16px;
|
||||
background: #fbfbfb;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
// Chunk列表样式
|
||||
.chunk-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.chunk-item {
|
||||
border-radius: 6px;
|
||||
padding: 12px;
|
||||
transition: all 0.2s ease;
|
||||
border: 1px solid transparent;
|
||||
|
||||
&.chunk-even {
|
||||
background: #3032360f;
|
||||
}
|
||||
|
||||
&.chunk-odd {
|
||||
background: #07c05f0d;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: #07c05f;
|
||||
box-shadow: 0 2px 8px rgba(7, 192, 95, 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
.chunk-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 8px;
|
||||
padding-bottom: 6px;
|
||||
border-bottom: 1px solid #e7e7e7;
|
||||
|
||||
.chunk-index {
|
||||
color: #00000099;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.chunk-meta {
|
||||
color: #00000066;
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
|
||||
.md-content {
|
||||
word-break: break-word;
|
||||
line-height: 1.6;
|
||||
color: #1d2129;
|
||||
}
|
||||
|
||||
// 保留旧样式作为兼容(已被chunk-item替代)
|
||||
.content {
|
||||
word-break: break-word;
|
||||
padding: 4px;
|
||||
gap: 4px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -32,6 +32,16 @@
|
||||
<span class="kb-action-title">{{ t('upload.uploadDocument') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="menu_item kb-action-item" @click.stop="handleDocURLImport">
|
||||
<div class="kb-action-icon-wrapper">
|
||||
<svg class="kb-action-icon" width="18" height="18" viewBox="0 0 18 18" fill="none">
|
||||
<path d="M7.5 10.5L10.5 7.5M7.875 5.625L6.9375 4.6875C6.15326 3.90326 5.09511 3.46585 3.99 3.46585C2.88489 3.46585 1.82674 3.90326 1.0425 4.6875C0.258257 5.47174 -0.179153 6.52989 -0.179153 7.635C-0.179153 8.74011 0.258257 9.79826 1.0425 10.5825L2.25 11.7975M10.125 12.375L11.0625 13.3125C11.8467 14.0967 12.9049 14.5341 14.01 14.5341C15.1151 14.5341 16.1733 14.0967 16.9575 13.3125C17.7417 12.5283 18.1791 11.4701 18.1791 10.365C18.1791 9.25989 17.7417 8.20174 16.9575 7.4175L15.75 6.2025M5.625 12.375L12.375 5.625" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="kb-action-content">
|
||||
<span class="kb-action-title">{{ t('knowledgeBase.importURL') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="menu_item kb-action-item" @click.stop="handleDocManualCreate">
|
||||
<div class="kb-action-icon-wrapper">
|
||||
<svg class="kb-action-icon" width="18" height="18" viewBox="0 0 18 18" fill="none">
|
||||
@@ -127,7 +137,7 @@ import { storeToRefs } from 'pinia';
|
||||
import { onMounted, watch, computed, ref, reactive } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getSessionsList, delSession } from "@/api/chat/index";
|
||||
import { getKnowledgeBaseById, uploadKnowledgeFile } from '@/api/knowledge-base';
|
||||
import { getKnowledgeBaseById, uploadKnowledgeFile, createKnowledgeFromURL } from '@/api/knowledge-base';
|
||||
import { logout as logoutApi } from '@/api/auth';
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
@@ -636,6 +646,15 @@ const handleDocManualCreate = async () => {
|
||||
})
|
||||
}
|
||||
|
||||
const handleDocURLImport = async () => {
|
||||
const kbId = await ensureDocKnowledgeBaseReady()
|
||||
if (!kbId) return
|
||||
|
||||
window.dispatchEvent(new CustomEvent('openURLImportDialog', {
|
||||
detail: { kbId }
|
||||
}))
|
||||
}
|
||||
|
||||
const dispatchFaqMenuAction = (action: 'create' | 'import', kbId: string) => {
|
||||
window.dispatchEvent(new CustomEvent('faqMenuAction', {
|
||||
detail: { action, kbId }
|
||||
|
||||
@@ -22,7 +22,10 @@ export default function (knowledgeBaseId?: string) {
|
||||
time: "",
|
||||
md: [] as any[],
|
||||
id: "",
|
||||
total: 0
|
||||
total: 0,
|
||||
type: "",
|
||||
source: "",
|
||||
file_type: ""
|
||||
});
|
||||
const getKnowled = (
|
||||
query: { page: number; page_size: number; tag_id?: string } = { page: 1, page_size: 35 },
|
||||
@@ -130,15 +133,21 @@ export default function (knowledgeBaseId?: string) {
|
||||
time: "",
|
||||
md: [],
|
||||
id: "",
|
||||
type: "",
|
||||
source: "",
|
||||
file_type: ""
|
||||
});
|
||||
getKnowledgeDetails(item.id)
|
||||
.then((result: any) => {
|
||||
if (result.success && result.data) {
|
||||
const { data } = result;
|
||||
Object.assign(details, {
|
||||
title: data.file_name,
|
||||
title: data.file_name || data.title || data.source || '未命名文档',
|
||||
time: formatStringDate(new Date(data.updated_at)),
|
||||
id: data.id,
|
||||
type: data.type || 'file',
|
||||
source: data.source || '',
|
||||
file_type: data.file_type || ''
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
@@ -50,6 +50,32 @@ export default {
|
||||
uploadFailed: 'File upload failed!',
|
||||
docActionUnsupported: 'This knowledge base type does not support this action',
|
||||
fileExists: 'File already exists',
|
||||
uploadFile: 'Upload File',
|
||||
uploadFileDesc: 'Supports PDF, Word, TXT, etc.',
|
||||
importURL: 'Import from URL',
|
||||
importURLDesc: 'Import via URL link',
|
||||
importURLTitle: 'Import from URL',
|
||||
manualCreate: 'Manual Create',
|
||||
manualCreateDesc: 'Write document content directly',
|
||||
urlRequired: 'Please enter a URL',
|
||||
invalidURL: 'Please enter a valid URL',
|
||||
urlImportSuccess: 'URL imported successfully!',
|
||||
urlImportFailed: 'URL import failed!',
|
||||
urlExists: 'This URL already exists',
|
||||
urlLabel: 'URL Address',
|
||||
urlPlaceholder: 'Enter webpage URL, e.g., https://example.com',
|
||||
urlTip: 'Supports importing various webpage contents. The system will automatically extract and parse text content from the webpage',
|
||||
typeURL: 'URL',
|
||||
typeManual: 'Manual',
|
||||
typeFile: 'File',
|
||||
urlSource: 'Source URL',
|
||||
documentTitle: 'Document Title',
|
||||
webContent: 'Web Content',
|
||||
documentContent: 'Document Content',
|
||||
importTime: 'Import Time',
|
||||
createTime: 'Create Time',
|
||||
characters: 'chars',
|
||||
segment: 'Segment',
|
||||
notInitialized: 'Knowledge base is not initialized. Please configure models in settings before uploading files',
|
||||
getInfoFailed: 'Failed to get knowledge base information, file upload is not possible',
|
||||
missingId: 'Knowledge base ID is missing',
|
||||
|
||||
@@ -50,6 +50,32 @@ export default {
|
||||
uploadFailed: 'Ошибка загрузки файла!',
|
||||
docActionUnsupported: 'Этот тип базы знаний не поддерживает данную операцию',
|
||||
fileExists: 'Файл уже существует',
|
||||
uploadFile: 'Загрузить файл',
|
||||
uploadFileDesc: 'Поддерживает PDF, Word, TXT и т.д.',
|
||||
importURL: 'Импорт из URL',
|
||||
importURLDesc: 'Импорт по ссылке URL',
|
||||
importURLTitle: 'Импорт из URL',
|
||||
manualCreate: 'Создать вручную',
|
||||
manualCreateDesc: 'Написать содержимое документа напрямую',
|
||||
urlRequired: 'Пожалуйста, введите URL',
|
||||
invalidURL: 'Пожалуйста, введите корректный URL',
|
||||
urlImportSuccess: 'URL успешно импортирован!',
|
||||
urlImportFailed: 'Ошибка импорта URL!',
|
||||
urlExists: 'Этот URL уже существует',
|
||||
urlLabel: 'Адрес URL',
|
||||
urlPlaceholder: 'Введите URL веб-страницы, например: https://example.com',
|
||||
urlTip: 'Поддерживает импорт различного веб-содержимого. Система автоматически извлечет и проанализирует текстовое содержимое с веб-страницы',
|
||||
typeURL: 'URL',
|
||||
typeManual: 'Вручную',
|
||||
typeFile: 'Файл',
|
||||
urlSource: 'Исходный URL',
|
||||
documentTitle: 'Название документа',
|
||||
webContent: 'Веб-содержимое',
|
||||
documentContent: 'Содержимое документа',
|
||||
importTime: 'Время импорта',
|
||||
createTime: 'Время создания',
|
||||
characters: 'символов',
|
||||
segment: 'Фрагмент',
|
||||
notInitialized: 'База знаний не инициализирована. Пожалуйста, настройте модели в разделе настроек перед загрузкой файлов',
|
||||
getInfoFailed: 'Не удалось получить информацию о базе знаний, загрузка файла невозможна',
|
||||
missingId: 'Отсутствует ID базы знаний',
|
||||
|
||||
@@ -49,6 +49,32 @@ export default {
|
||||
uploadSuccess: "文件上传成功!",
|
||||
uploadFailed: "文件上传失败!",
|
||||
fileExists: "文件已存在",
|
||||
uploadFile: "上传文件",
|
||||
uploadFileDesc: "支持 PDF、Word、TXT 等",
|
||||
importURL: "导入网页",
|
||||
importURLDesc: "通过URL链接导入",
|
||||
importURLTitle: "导入网页",
|
||||
manualCreate: "手动创建",
|
||||
manualCreateDesc: "直接编写文档内容",
|
||||
urlRequired: "请输入URL",
|
||||
invalidURL: "请输入有效的URL",
|
||||
urlImportSuccess: "URL导入成功!",
|
||||
urlImportFailed: "URL导入失败!",
|
||||
urlExists: "该URL已存在",
|
||||
urlLabel: "URL地址",
|
||||
urlPlaceholder: "请输入网页URL,例如:https://example.com",
|
||||
urlTip: "支持导入各类网页内容,系统会自动提取和解析网页中的文本内容",
|
||||
typeURL: "网页",
|
||||
typeManual: "手动创建",
|
||||
typeFile: "文件",
|
||||
urlSource: "来源网址",
|
||||
documentTitle: "文档标题",
|
||||
webContent: "网页内容",
|
||||
documentContent: "文档内容",
|
||||
importTime: "导入时间",
|
||||
createTime: "创建时间",
|
||||
characters: "字符",
|
||||
segment: "片段",
|
||||
docActionUnsupported: "当前知识库类型不支持该操作",
|
||||
notInitialized:
|
||||
"该知识库尚未完成初始化配置,请先前往设置页面配置模型信息后再上传文件",
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
updateKnowledgeBaseTag,
|
||||
deleteKnowledgeBaseTag,
|
||||
uploadKnowledgeFile,
|
||||
createKnowledgeFromURL,
|
||||
listKnowledgeBases,
|
||||
} from "@/api/knowledge-base/index";
|
||||
import FAQEntryManager from './components/FAQEntryManager.vue';
|
||||
@@ -118,6 +119,20 @@ const formatDocTime = (time?: string) => {
|
||||
return formatted.slice(2, 16) // "YY-MM-DD HH:mm"
|
||||
}
|
||||
|
||||
// 获取知识条目的显示类型
|
||||
const getKnowledgeType = (item: any) => {
|
||||
if (item.type === 'url') {
|
||||
return t('knowledgeBase.typeURL') || 'URL';
|
||||
}
|
||||
if (item.type === 'manual') {
|
||||
return t('knowledgeBase.typeManual') || '手动创建';
|
||||
}
|
||||
if (item.file_type) {
|
||||
return item.file_type.toUpperCase();
|
||||
}
|
||||
return '--';
|
||||
}
|
||||
|
||||
const loadKnowledgeFiles = (kbIdValue: string) => {
|
||||
if (!kbIdValue) return;
|
||||
getKnowled(
|
||||
@@ -384,16 +399,28 @@ const handleFileUploaded = (event: CustomEvent) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 监听从菜单触发的URL导入事件
|
||||
const handleOpenURLImportDialog = (event: CustomEvent) => {
|
||||
const eventKbId = event.detail.kbId;
|
||||
console.log('接收到URL导入对话框打开事件,知识库ID:', eventKbId, '当前知识库ID:', kbId.value);
|
||||
if (eventKbId && eventKbId === kbId.value && !isFAQ.value) {
|
||||
urlDialogVisible.value = true;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
loadKnowledgeBaseInfo(kbId.value);
|
||||
loadKnowledgeList();
|
||||
|
||||
// 监听文件上传事件
|
||||
window.addEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
|
||||
// 监听URL导入对话框打开事件
|
||||
window.addEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
|
||||
window.removeEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
|
||||
});
|
||||
watch(() => cardList.value, (newValue) => {
|
||||
if (isFAQ.value) return;
|
||||
@@ -560,6 +587,76 @@ const handleManualCreate = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// URL 导入相关
|
||||
const urlDialogVisible = ref(false);
|
||||
const urlInputValue = ref('');
|
||||
const urlImporting = ref(false);
|
||||
|
||||
const handleURLImportClick = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
urlInputValue.value = '';
|
||||
urlDialogVisible.value = true;
|
||||
};
|
||||
|
||||
const handleURLImportCancel = () => {
|
||||
urlDialogVisible.value = false;
|
||||
urlInputValue.value = '';
|
||||
};
|
||||
|
||||
const handleURLImportConfirm = async () => {
|
||||
const url = urlInputValue.value.trim();
|
||||
if (!url) {
|
||||
MessagePlugin.warning(t('knowledgeBase.urlRequired') || '请输入URL');
|
||||
return;
|
||||
}
|
||||
|
||||
// 简单的URL格式验证
|
||||
try {
|
||||
new URL(url);
|
||||
} catch (error) {
|
||||
MessagePlugin.warning(t('knowledgeBase.invalidURL') || '请输入有效的URL');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!kbId.value) {
|
||||
MessagePlugin.error("缺少知识库ID");
|
||||
return;
|
||||
}
|
||||
|
||||
urlImporting.value = true;
|
||||
try {
|
||||
const responseData: any = await createKnowledgeFromURL(kbId.value, { url });
|
||||
window.dispatchEvent(new CustomEvent('knowledgeFileUploaded', {
|
||||
detail: { kbId: kbId.value }
|
||||
}));
|
||||
const isSuccess = responseData?.success || responseData?.code === 200 || responseData?.status === 'success' || (!responseData?.error && responseData);
|
||||
if (isSuccess) {
|
||||
MessagePlugin.success(t('knowledgeBase.urlImportSuccess') || 'URL导入成功!');
|
||||
urlDialogVisible.value = false;
|
||||
urlInputValue.value = '';
|
||||
} else {
|
||||
let errorMessage = t('knowledgeBase.urlImportFailed') || "URL导入失败!";
|
||||
if (responseData?.error?.message) {
|
||||
errorMessage = responseData.error.message;
|
||||
} else if (responseData?.message) {
|
||||
errorMessage = responseData.message;
|
||||
}
|
||||
if (responseData?.code === 'duplicate_url' || responseData?.error?.code === 'duplicate_url') {
|
||||
errorMessage = t('knowledgeBase.urlExists') || "该URL已存在";
|
||||
}
|
||||
MessagePlugin.error(errorMessage);
|
||||
}
|
||||
} catch (error: any) {
|
||||
let errorMessage = error?.error?.message || error?.message || t('knowledgeBase.urlImportFailed') || "URL导入失败!";
|
||||
if (error?.code === 'duplicate_url') {
|
||||
errorMessage = t('knowledgeBase.urlExists') || "该URL已存在";
|
||||
}
|
||||
MessagePlugin.error(errorMessage);
|
||||
} finally {
|
||||
urlImporting.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleOpenKBSettings = () => {
|
||||
if (!kbId.value) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.missingId'));
|
||||
@@ -898,6 +995,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
>
|
||||
<template v-if="cardList.length">
|
||||
<div class="doc-card-list">
|
||||
<!-- 现有文档卡片 -->
|
||||
<div
|
||||
class="knowledge-card"
|
||||
v-for="(item, index) in cardList"
|
||||
@@ -975,7 +1073,7 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</t-dropdown>
|
||||
</div>
|
||||
<div class="card-type">
|
||||
<span>{{ item.file_type }}</span>
|
||||
<span>{{ getKnowledgeType(item) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1012,6 +1110,34 @@ async function createNewSession(value: string): Promise<void> {
|
||||
</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<!-- URL 导入对话框 -->
|
||||
<t-dialog
|
||||
v-model:visible="urlDialogVisible"
|
||||
:header="$t('knowledgeBase.importURLTitle') || '导入网页'"
|
||||
:confirm-btn="{
|
||||
content: $t('common.confirm') || '确认',
|
||||
theme: 'primary',
|
||||
loading: urlImporting,
|
||||
}"
|
||||
:cancel-btn="{ content: $t('common.cancel') || '取消' }"
|
||||
@confirm="handleURLImportConfirm"
|
||||
@cancel="handleURLImportCancel"
|
||||
width="500px"
|
||||
>
|
||||
<div class="url-import-form">
|
||||
<div class="url-input-label">{{ $t('knowledgeBase.urlLabel') || 'URL地址' }}</div>
|
||||
<t-input
|
||||
v-model="urlInputValue"
|
||||
:placeholder="$t('knowledgeBase.urlPlaceholder') || '请输入网页URL,例如:https://example.com'"
|
||||
clearable
|
||||
autofocus
|
||||
@keydown.enter="handleURLImportConfirm"
|
||||
/>
|
||||
<div class="url-input-tip">{{ $t('knowledgeBase.urlTip') || '支持导入各类网页内容,系统会自动提取和解析网页中的文本内容' }}</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<DocContent :visible="isCardDetails" :details="details" @closeDoc="closeDoc" @getDoc="getDoc"></DocContent>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1989,6 +2115,24 @@ async function createNewSession(value: string): Promise<void> {
|
||||
border: 2px solid #07c05f;
|
||||
}
|
||||
|
||||
.url-import-form {
|
||||
padding: 8px 0;
|
||||
|
||||
.url-input-label {
|
||||
color: #1d2129;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.url-input-tip {
|
||||
color: #86909c;
|
||||
font-size: 12px;
|
||||
margin-top: 8px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.knowledge-card-upload {
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
|
||||
Reference in New Issue
Block a user