2025-11-06 19:47:22 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="knowledge-base-card">
|
|
|
|
|
|
<!-- 标题栏 -->
|
|
|
|
|
|
<div class="card-header">
|
|
|
|
|
|
<div class="header-left">
|
|
|
|
|
|
<a-button
|
|
|
|
|
|
@click="backToDatabase"
|
2025-12-10 19:42:58 +08:00
|
|
|
|
class="back-button"
|
2025-11-06 19:47:22 +08:00
|
|
|
|
shape="circle"
|
|
|
|
|
|
:icon="h(LeftOutlined)"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
></a-button>
|
|
|
|
|
|
<h3 class="card-title">{{ database.name || '数据库信息加载中' }}</h3>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="header-right">
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-button type="text" size="small" @click="copyDatabaseId" title="复制知识库ID">
|
2025-12-24 13:17:12 +08:00
|
|
|
|
<template #icon>
|
|
|
|
|
|
<Copy :size="14" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-button>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-button @click="showEditModal" type="text" size="small">
|
2025-12-24 13:17:12 +08:00
|
|
|
|
<template #icon>
|
|
|
|
|
|
<Pencil :size="14" />
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-button>
|
2025-11-06 19:47:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 卡片内容 -->
|
|
|
|
|
|
<div class="card-content">
|
|
|
|
|
|
<!-- 描述文本 -->
|
2025-12-10 19:42:58 +08:00
|
|
|
|
<div class="description">
|
|
|
|
|
|
<p class="description-text">{{ database.description || '暂无描述' }}</p>
|
2025-11-06 19:47:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Tags -->
|
|
|
|
|
|
<div class="tags-section">
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-tag :color="getKbTypeColor(database.kb_type || 'lightrag')" size="small">
|
2025-11-06 19:47:22 +08:00
|
|
|
|
{{ getKbTypeLabel(database.kb_type || 'lightrag') }}
|
|
|
|
|
|
</a-tag>
|
|
|
|
|
|
<a-tag color="blue" size="small">{{ database.embed_info?.name || 'N/A' }}</a-tag>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 编辑对话框 -->
|
|
|
|
|
|
<a-modal v-model:open="editModalVisible" title="编辑知识库信息">
|
|
|
|
|
|
<template #footer>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-button danger @click="deleteDatabase" style="margin-right: auto; margin-left: 0">
|
2025-12-24 13:17:12 +08:00
|
|
|
|
<template #icon>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<Trash2 :size="16" style="vertical-align: -3px; margin-right: 4px" />
|
2025-12-24 13:17:12 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
删除数据库
|
2025-11-06 19:47:22 +08:00
|
|
|
|
</a-button>
|
|
|
|
|
|
<a-button key="back" @click="editModalVisible = false">取消</a-button>
|
|
|
|
|
|
<a-button key="submit" type="primary" @click="handleEditSubmit">确定</a-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<a-form :model="editForm" :rules="rules" ref="editFormRef" layout="vertical">
|
|
|
|
|
|
<a-form-item label="知识库名称" name="name" required>
|
|
|
|
|
|
<a-input v-model:value="editForm.name" placeholder="请输入知识库名称" />
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<a-form-item label="知识库描述" name="description">
|
2025-12-18 21:01:25 +08:00
|
|
|
|
<AiTextarea
|
|
|
|
|
|
v-model="editForm.description"
|
|
|
|
|
|
:name="editForm.name"
|
2026-01-03 19:02:08 +08:00
|
|
|
|
:files="fileList"
|
2025-12-18 21:01:25 +08:00
|
|
|
|
placeholder="请输入知识库描述"
|
|
|
|
|
|
:rows="4"
|
|
|
|
|
|
/>
|
2025-11-06 19:47:22 +08:00
|
|
|
|
</a-form-item>
|
2025-12-10 19:42:58 +08:00
|
|
|
|
|
2025-11-30 18:48:33 +08:00
|
|
|
|
<a-form-item label="自动生成问题" name="auto_generate_questions">
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-switch
|
|
|
|
|
|
v-model:checked="editForm.auto_generate_questions"
|
|
|
|
|
|
checked-children="开启"
|
|
|
|
|
|
un-checked-children="关闭"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<span style="margin-left: 8px; font-size: 12px; color: var(--gray-500)"
|
|
|
|
|
|
>上传文件后自动生成测试问题</span
|
|
|
|
|
|
>
|
2025-11-30 18:48:33 +08:00
|
|
|
|
</a-form-item>
|
|
|
|
|
|
|
2025-11-06 19:47:22 +08:00
|
|
|
|
<!-- 仅对 LightRAG 类型显示 LLM 配置 -->
|
|
|
|
|
|
<a-form-item v-if="database.kb_type === 'lightrag'" label="语言模型 (LLM)" name="llm_info">
|
|
|
|
|
|
<ModelSelectorComponent
|
|
|
|
|
|
:model_spec="llmModelSpec"
|
|
|
|
|
|
placeholder="请选择模型"
|
|
|
|
|
|
@select-model="handleLLMSelect"
|
2026-01-15 06:01:34 +08:00
|
|
|
|
style="width: 100%"
|
2025-11-06 19:47:22 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
</a-form>
|
|
|
|
|
|
</a-modal>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
import { ref, reactive, computed, h } from 'vue'
|
|
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
|
import { useDatabaseStore } from '@/stores/database'
|
|
|
|
|
|
import { getKbTypeLabel, getKbTypeColor } from '@/utils/kb_utils'
|
|
|
|
|
|
import { message } from 'ant-design-vue'
|
|
|
|
|
|
import { LeftOutlined } from '@ant-design/icons-vue'
|
|
|
|
|
|
import { Pencil, Trash2, Copy } from 'lucide-vue-next'
|
|
|
|
|
|
import ModelSelectorComponent from '@/components/ModelSelectorComponent.vue'
|
|
|
|
|
|
import AiTextarea from '@/components/AiTextarea.vue'
|
|
|
|
|
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const store = useDatabaseStore()
|
|
|
|
|
|
|
|
|
|
|
|
const database = computed(() => store.database)
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
2026-01-03 19:02:08 +08:00
|
|
|
|
const fileList = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!database.value?.files) return []
|
|
|
|
|
|
return Object.values(database.value.files)
|
|
|
|
|
|
.map((f) => f.filename)
|
|
|
|
|
|
.filter(Boolean)
|
|
|
|
|
|
})
|
2026-01-03 19:02:08 +08:00
|
|
|
|
|
2025-11-06 19:47:22 +08:00
|
|
|
|
// 复制数据库ID
|
|
|
|
|
|
const copyDatabaseId = async () => {
|
|
|
|
|
|
if (!database.value.db_id) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
message.warning('知识库ID为空')
|
|
|
|
|
|
return
|
2025-11-06 19:47:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await navigator.clipboard.writeText(database.value.db_id)
|
|
|
|
|
|
message.success('知识库ID已复制到剪贴板')
|
2025-11-06 19:47:22 +08:00
|
|
|
|
} catch (err) {
|
|
|
|
|
|
// 降级方案
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const textArea = document.createElement('textarea')
|
|
|
|
|
|
textArea.value = database.value.db_id
|
|
|
|
|
|
document.body.appendChild(textArea)
|
|
|
|
|
|
textArea.select()
|
|
|
|
|
|
document.execCommand('copy')
|
|
|
|
|
|
document.body.removeChild(textArea)
|
|
|
|
|
|
message.success('知识库ID已复制到剪贴板')
|
2025-11-06 19:47:22 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 格式化日期
|
|
|
|
|
|
const formatDate = (dateStr) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!dateStr) return 'N/A'
|
|
|
|
|
|
const date = new Date(dateStr)
|
2025-11-06 19:47:22 +08:00
|
|
|
|
return date.toLocaleString('zh-CN', {
|
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
|
month: '2-digit',
|
|
|
|
|
|
day: '2-digit',
|
|
|
|
|
|
hour: '2-digit',
|
|
|
|
|
|
minute: '2-digit'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 返回数据库列表
|
|
|
|
|
|
const backToDatabase = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
router.push('/database')
|
|
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
// 编辑相关逻辑(复用自 DatabaseHeader)
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const editModalVisible = ref(false)
|
|
|
|
|
|
const editFormRef = ref(null)
|
2025-11-06 19:47:22 +08:00
|
|
|
|
const editForm = reactive({
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
description: '',
|
2025-11-30 18:48:33 +08:00
|
|
|
|
auto_generate_questions: false,
|
2025-11-06 19:47:22 +08:00
|
|
|
|
llm_info: {
|
|
|
|
|
|
provider: '',
|
|
|
|
|
|
model_name: ''
|
|
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
const rules = {
|
|
|
|
|
|
name: [{ required: true, message: '请输入知识库名称' }]
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
const showEditModal = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
editForm.name = database.value.name || ''
|
|
|
|
|
|
editForm.description = database.value.description || ''
|
|
|
|
|
|
editForm.auto_generate_questions =
|
|
|
|
|
|
database.value.additional_params?.auto_generate_questions || false
|
2025-12-10 19:42:58 +08:00
|
|
|
|
|
2025-11-06 19:47:22 +08:00
|
|
|
|
// 如果是 LightRAG 类型,加载当前的 LLM 配置
|
|
|
|
|
|
if (database.value.kb_type === 'lightrag') {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const llmInfo = database.value.llm_info || {}
|
|
|
|
|
|
editForm.llm_info.provider = llmInfo.provider || ''
|
|
|
|
|
|
editForm.llm_info.model_name = llmInfo.model_name || ''
|
2025-11-06 19:47:22 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
editModalVisible.value = true
|
|
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
const handleEditSubmit = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
editFormRef.value
|
|
|
|
|
|
.validate()
|
|
|
|
|
|
.then(async () => {
|
|
|
|
|
|
const updateData = {
|
|
|
|
|
|
name: editForm.name,
|
|
|
|
|
|
description: editForm.description,
|
|
|
|
|
|
additional_params: {
|
|
|
|
|
|
auto_generate_questions: editForm.auto_generate_questions
|
|
|
|
|
|
}
|
2025-11-30 18:48:33 +08:00
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
// 如果是 LightRAG 类型,包含 llm_info
|
|
|
|
|
|
if (database.value.kb_type === 'lightrag') {
|
|
|
|
|
|
updateData.llm_info = {
|
|
|
|
|
|
provider: editForm.llm_info.provider,
|
|
|
|
|
|
model_name: editForm.llm_info.model_name
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await store.updateDatabaseInfo(updateData)
|
|
|
|
|
|
editModalVisible.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
|
console.error('表单验证失败:', err)
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
// LLM 模型选择处理
|
|
|
|
|
|
const llmModelSpec = computed(() => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const provider = editForm.llm_info?.provider || ''
|
|
|
|
|
|
const modelName = editForm.llm_info?.model_name || ''
|
2025-11-06 19:47:22 +08:00
|
|
|
|
if (provider && modelName) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return `${provider}/${modelName}`
|
2025-11-06 19:47:22 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return ''
|
|
|
|
|
|
})
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
const handleLLMSelect = (spec) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.log('LLM选择:', spec)
|
|
|
|
|
|
if (typeof spec !== 'string' || !spec) return
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const index = spec.indexOf('/')
|
|
|
|
|
|
const provider = index !== -1 ? spec.slice(0, index) : ''
|
|
|
|
|
|
const modelName = index !== -1 ? spec.slice(index + 1) : ''
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
editForm.llm_info.provider = provider
|
|
|
|
|
|
editForm.llm_info.model_name = modelName
|
|
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
|
|
|
|
|
|
const deleteDatabase = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
store.deleteDatabase()
|
|
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
|
.knowledge-base-card {
|
2025-11-23 01:39:44 +08:00
|
|
|
|
background: linear-gradient(120deg, var(--main-30) 0%, var(--gray-0) 100%);
|
2025-11-06 19:47:22 +08:00
|
|
|
|
border-radius: 12px;
|
|
|
|
|
|
border: 1px solid var(--gray-200);
|
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-header {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
padding: 12px 16px;
|
|
|
|
|
|
|
|
|
|
|
|
.header-left {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2025-12-10 19:42:58 +08:00
|
|
|
|
gap: 4px;
|
2025-11-06 19:47:22 +08:00
|
|
|
|
flex: 1;
|
|
|
|
|
|
min-width: 0;
|
2025-12-10 19:42:58 +08:00
|
|
|
|
|
|
|
|
|
|
button.back-button {
|
|
|
|
|
|
margin-left: -5px;
|
|
|
|
|
|
font-size: 10px;
|
|
|
|
|
|
}
|
2025-11-06 19:47:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-title {
|
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
color: var(--gray-800);
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
// flex: 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.header-right {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 6px;
|
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
|
|
|
|
|
|
button {
|
2025-12-10 19:42:58 +08:00
|
|
|
|
color: var(--gray-500);
|
2025-11-06 19:47:22 +08:00
|
|
|
|
height: 100%;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
button:hover {
|
2025-12-10 19:42:58 +08:00
|
|
|
|
color: var(--gray-700);
|
2025-11-06 19:47:22 +08:00
|
|
|
|
background-color: var(--gray-100);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.card-content {
|
|
|
|
|
|
padding: 0 16px 16px 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.description {
|
|
|
|
|
|
margin-bottom: 12px;
|
|
|
|
|
|
|
|
|
|
|
|
.description-text {
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
color: var(--gray-700);
|
|
|
|
|
|
line-height: 1.5;
|
|
|
|
|
|
margin: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.tags-section {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 6px;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|