feat: Enhance chat and knowledge base functionalities with multi-KB support
- Updated agentChat API to accept optional knowledge_base_ids and agent_enabled parameters. - Introduced getSession API to retrieve session details. - Modified useStream to validate knowledge_base_ids for agent-chat requests and prepare POST body accordingly. - Enhanced createKnowledgeBase API to include additional configuration options. - Refactored chat routing to remove knowledge base ID from the chat path, allowing for dynamic knowledge base selection. - Improved session management by preventing duplicate session entries in the menu store. - Updated UI components for better session handling and display. - Added context management for agent conversations to improve state persistence across sessions.
This commit is contained in:
@@ -176,7 +176,16 @@ const sendMsg = (value: string) => {
|
||||
};
|
||||
|
||||
const getTitle = (session_id: string, value: string) => {
|
||||
let obj = { title: '新会话', path: `chat/${kbId.value}/${session_id}`, id: session_id, isMore: false, isNoTitle: true };
|
||||
const now = new Date().toISOString();
|
||||
let obj = {
|
||||
title: '新会话',
|
||||
path: `chat/${kbId.value}/${session_id}`,
|
||||
id: session_id,
|
||||
isMore: false,
|
||||
isNoTitle: true,
|
||||
created_at: now,
|
||||
updated_at: now
|
||||
};
|
||||
usemenuStore.updataMenuChildren(obj);
|
||||
usemenuStore.changeIsFirstSession(true);
|
||||
usemenuStore.changeFirstQuery(value);
|
||||
|
||||
@@ -0,0 +1,742 @@
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="modal">
|
||||
<div v-if="visible" class="settings-overlay" @click.self="handleClose">
|
||||
<div class="settings-modal">
|
||||
<!-- 关闭按钮 -->
|
||||
<button class="close-btn" @click="handleClose" aria-label="关闭">
|
||||
<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>
|
||||
</button>
|
||||
|
||||
<div class="settings-container">
|
||||
<!-- 左侧导航 -->
|
||||
<div class="settings-sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h2 class="sidebar-title">{{ mode === 'create' ? '新建知识库' : '知识库设置' }}</h2>
|
||||
</div>
|
||||
<div class="settings-nav">
|
||||
<div
|
||||
v-for="(item, index) in navItems"
|
||||
:key="index"
|
||||
:class="['nav-item', { 'active': currentSection === item.key }]"
|
||||
@click="currentSection = item.key"
|
||||
>
|
||||
<span class="nav-icon">{{ item.icon }}</span>
|
||||
<span class="nav-label">{{ item.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧内容区域 -->
|
||||
<div class="settings-content">
|
||||
<div class="content-wrapper">
|
||||
<!-- 基本信息 -->
|
||||
<div v-show="currentSection === 'basic'" class="section">
|
||||
<div v-if="formData" class="section-content">
|
||||
<div class="section-header">
|
||||
<h3 class="section-title">基本信息</h3>
|
||||
<p class="section-desc">设置知识库的名称和描述信息</p>
|
||||
</div>
|
||||
<div class="section-body">
|
||||
<div class="form-item">
|
||||
<label class="form-label required">知识库名称</label>
|
||||
<t-input
|
||||
v-model="formData.name"
|
||||
placeholder="请输入知识库名称"
|
||||
:maxlength="50"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<label class="form-label">知识库描述</label>
|
||||
<t-textarea
|
||||
v-model="formData.description"
|
||||
placeholder="请输入知识库描述(可选)"
|
||||
:maxlength="200"
|
||||
:autosize="{ minRows: 3, maxRows: 6 }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 模型配置 -->
|
||||
<div v-show="currentSection === 'models'" class="section">
|
||||
<KBModelConfig
|
||||
ref="modelConfigRef"
|
||||
v-if="formData"
|
||||
:config="formData.modelConfig"
|
||||
:has-files="hasFiles"
|
||||
:all-models="allModels"
|
||||
@update:config="handleModelConfigUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 分块设置 -->
|
||||
<div v-show="currentSection === 'chunking'" class="section">
|
||||
<KBChunkingSettings
|
||||
v-if="formData"
|
||||
:config="formData.chunkingConfig"
|
||||
@update:config="handleChunkingConfigUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 高级设置 -->
|
||||
<div v-show="currentSection === 'advanced'" class="section">
|
||||
<KBAdvancedSettings
|
||||
ref="advancedSettingsRef"
|
||||
v-if="formData"
|
||||
:multimodal="formData.multimodalConfig"
|
||||
:node-extract="formData.nodeExtractConfig"
|
||||
:all-models="allModels"
|
||||
@update:multimodal="handleMultimodalUpdate"
|
||||
@update:nodeExtract="handleNodeExtractUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 保存按钮 -->
|
||||
<div class="settings-footer">
|
||||
<t-button theme="default" variant="outline" @click="handleClose">
|
||||
取消
|
||||
</t-button>
|
||||
<t-button theme="primary" @click="handleSubmit" :loading="saving">
|
||||
{{ mode === 'create' ? '创建知识库' : '保存配置' }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { createKnowledgeBase, getKnowledgeBaseById, listKnowledgeFiles, updateKnowledgeBase } from '@/api/knowledge-base'
|
||||
import { updateKBConfig, type KBModelConfigRequest } from '@/api/initialization'
|
||||
import { listModels } from '@/api/model'
|
||||
import KBModelConfig from './settings/KBModelConfig.vue'
|
||||
import KBChunkingSettings from './settings/KBChunkingSettings.vue'
|
||||
import KBAdvancedSettings from './settings/KBAdvancedSettings.vue'
|
||||
|
||||
// Props
|
||||
const props = defineProps<{
|
||||
visible: boolean
|
||||
mode: 'create' | 'edit'
|
||||
kbId?: string
|
||||
}>()
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:visible', value: boolean): void
|
||||
(e: 'success', kbId: string): void
|
||||
}>()
|
||||
|
||||
const currentSection = ref<string>('basic')
|
||||
const saving = ref(false)
|
||||
const loading = ref(false)
|
||||
const allModels = ref<any[]>([])
|
||||
const hasFiles = ref(false)
|
||||
|
||||
const navItems = [
|
||||
{ key: 'basic', icon: 'ℹ️', label: '基本信息' },
|
||||
{ key: 'models', icon: '🤖', label: '模型配置' },
|
||||
{ key: 'chunking', icon: '📄', label: '分块设置' },
|
||||
{ key: 'advanced', icon: '⚙️', label: '高级设置' }
|
||||
]
|
||||
|
||||
// 模型配置引用
|
||||
const modelConfigRef = ref<InstanceType<typeof KBModelConfig>>()
|
||||
const advancedSettingsRef = ref<InstanceType<typeof KBAdvancedSettings>>()
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<any>(null)
|
||||
|
||||
// 初始化表单数据
|
||||
const initFormData = () => {
|
||||
return {
|
||||
name: '',
|
||||
description: '',
|
||||
modelConfig: {
|
||||
llmModelId: '',
|
||||
embeddingModelId: '',
|
||||
rerankModelId: ''
|
||||
},
|
||||
chunkingConfig: {
|
||||
chunkSize: 512,
|
||||
chunkOverlap: 100,
|
||||
separators: ['\n\n', '\n', '。', '!', '?', ';', ';']
|
||||
},
|
||||
multimodalConfig: {
|
||||
enabled: false,
|
||||
storageType: 'minio' as 'minio' | 'cos',
|
||||
vllmModelId: '',
|
||||
minio: {
|
||||
bucketName: '',
|
||||
useSSL: false,
|
||||
pathPrefix: ''
|
||||
},
|
||||
cos: {
|
||||
secretId: '',
|
||||
secretKey: '',
|
||||
region: '',
|
||||
bucketName: '',
|
||||
appId: '',
|
||||
pathPrefix: ''
|
||||
}
|
||||
},
|
||||
nodeExtractConfig: {
|
||||
enabled: false,
|
||||
text: '',
|
||||
tags: [] as string[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载所有模型
|
||||
const loadAllModels = async () => {
|
||||
try {
|
||||
const models = await listModels()
|
||||
allModels.value = models || []
|
||||
} catch (error) {
|
||||
console.error('加载模型列表失败:', error)
|
||||
MessagePlugin.error('加载模型列表失败')
|
||||
allModels.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载知识库数据(编辑模式)
|
||||
const loadKBData = async () => {
|
||||
if (props.mode !== 'edit' || !props.kbId) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const [kbInfo, models, filesResult] = await Promise.all([
|
||||
getKnowledgeBaseById(props.kbId),
|
||||
loadAllModels(),
|
||||
listKnowledgeFiles(props.kbId, { page: 1, page_size: 1 })
|
||||
])
|
||||
|
||||
if (!kbInfo || !kbInfo.data) {
|
||||
throw new Error('知识库不存在')
|
||||
}
|
||||
|
||||
const kb = kbInfo.data
|
||||
hasFiles.value = (filesResult as any)?.total > 0
|
||||
|
||||
// 设置表单数据
|
||||
formData.value = {
|
||||
name: kb.name || '',
|
||||
description: kb.description || '',
|
||||
modelConfig: {
|
||||
llmModelId: kb.summary_model_id || '',
|
||||
embeddingModelId: kb.embedding_model_id || '',
|
||||
rerankModelId: kb.rerank_model_id || ''
|
||||
},
|
||||
chunkingConfig: {
|
||||
chunkSize: kb.chunking_config?.chunk_size || 512,
|
||||
chunkOverlap: kb.chunking_config?.chunk_overlap || 100,
|
||||
separators: kb.chunking_config?.separators || ['\n\n', '\n', '。', '!', '?', ';', ';']
|
||||
},
|
||||
multimodalConfig: {
|
||||
enabled: !!(kb.vlm_model_id || (kb.cos_config?.provider && kb.cos_config?.bucket_name)),
|
||||
storageType: (kb.cos_config?.provider || 'minio') as 'minio' | 'cos',
|
||||
vllmModelId: kb.vlm_model_id || '',
|
||||
minio: {
|
||||
bucketName: kb.cos_config?.bucket_name || '',
|
||||
useSSL: kb.cos_config?.use_ssl || false,
|
||||
pathPrefix: kb.cos_config?.path_prefix || ''
|
||||
},
|
||||
cos: {
|
||||
secretId: kb.cos_config?.secret_id || '',
|
||||
secretKey: kb.cos_config?.secret_key || '',
|
||||
region: kb.cos_config?.region || '',
|
||||
bucketName: kb.cos_config?.bucket_name || '',
|
||||
appId: kb.cos_config?.app_id || '',
|
||||
pathPrefix: kb.cos_config?.path_prefix || ''
|
||||
}
|
||||
},
|
||||
nodeExtractConfig: {
|
||||
enabled: kb.extract_config?.enabled || false,
|
||||
text: kb.extract_config?.text || '',
|
||||
tags: kb.extract_config?.tags || []
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载知识库数据失败:', error)
|
||||
MessagePlugin.error('加载知识库数据失败')
|
||||
handleClose()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理配置更新
|
||||
const handleModelConfigUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.modelConfig = { ...config }
|
||||
}
|
||||
}
|
||||
|
||||
const handleChunkingConfigUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.chunkingConfig = { ...config }
|
||||
}
|
||||
}
|
||||
|
||||
const handleMultimodalUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.multimodalConfig = { ...config }
|
||||
}
|
||||
}
|
||||
|
||||
const handleNodeExtractUpdate = (config: any) => {
|
||||
if (formData.value) {
|
||||
formData.value.nodeExtractConfig = { ...config }
|
||||
}
|
||||
}
|
||||
|
||||
// 验证表单
|
||||
const validateForm = (): boolean => {
|
||||
if (!formData.value) return false
|
||||
|
||||
// 验证基本信息
|
||||
if (!formData.value.name || !formData.value.name.trim()) {
|
||||
MessagePlugin.warning('请输入知识库名称')
|
||||
currentSection.value = 'basic'
|
||||
return false
|
||||
}
|
||||
|
||||
// 验证模型配置 - 必须配置 embedding 和 summary 模型
|
||||
if (!formData.value.modelConfig.embeddingModelId) {
|
||||
MessagePlugin.warning('请选择 Embedding 模型')
|
||||
currentSection.value = 'models'
|
||||
return false
|
||||
}
|
||||
|
||||
if (!formData.value.modelConfig.llmModelId) {
|
||||
MessagePlugin.warning('请选择 Summary 模型')
|
||||
currentSection.value = 'models'
|
||||
return false
|
||||
}
|
||||
|
||||
// 验证多模态配置(如果启用)
|
||||
if (formData.value.multimodalConfig.enabled) {
|
||||
const validation = advancedSettingsRef.value?.validateMultimodal()
|
||||
if (validation && !validation.valid) {
|
||||
MessagePlugin.warning(validation.message || '多模态配置验证失败')
|
||||
currentSection.value = 'advanced'
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// 构建提交数据
|
||||
const buildSubmitData = () => {
|
||||
if (!formData.value) return null
|
||||
|
||||
const data: any = {
|
||||
name: formData.value.name,
|
||||
description: formData.value.description,
|
||||
chunking_config: {
|
||||
chunk_size: formData.value.chunkingConfig.chunkSize,
|
||||
chunk_overlap: formData.value.chunkingConfig.chunkOverlap,
|
||||
separators: formData.value.chunkingConfig.separators,
|
||||
enable_multimodal: formData.value.multimodalConfig.enabled
|
||||
},
|
||||
embedding_model_id: formData.value.modelConfig.embeddingModelId,
|
||||
summary_model_id: formData.value.modelConfig.llmModelId
|
||||
}
|
||||
|
||||
// 可选的 Rerank 模型
|
||||
if (formData.value.modelConfig.rerankModelId) {
|
||||
data.rerank_model_id = formData.value.modelConfig.rerankModelId
|
||||
}
|
||||
|
||||
// 添加多模态配置
|
||||
if (formData.value.multimodalConfig.enabled) {
|
||||
if (formData.value.multimodalConfig.vllmModelId) {
|
||||
data.vlm_model_id = formData.value.multimodalConfig.vllmModelId
|
||||
}
|
||||
|
||||
const storageType = formData.value.multimodalConfig.storageType
|
||||
if (storageType === 'minio') {
|
||||
data.cos_config = {
|
||||
provider: 'minio',
|
||||
bucket_name: formData.value.multimodalConfig.minio.bucketName,
|
||||
use_ssl: formData.value.multimodalConfig.minio.useSSL,
|
||||
path_prefix: formData.value.multimodalConfig.minio.pathPrefix || undefined
|
||||
}
|
||||
} else {
|
||||
data.cos_config = {
|
||||
provider: 'cos',
|
||||
secret_id: formData.value.multimodalConfig.cos.secretId,
|
||||
secret_key: formData.value.multimodalConfig.cos.secretKey,
|
||||
region: formData.value.multimodalConfig.cos.region,
|
||||
bucket_name: formData.value.multimodalConfig.cos.bucketName,
|
||||
app_id: formData.value.multimodalConfig.cos.appId,
|
||||
path_prefix: formData.value.multimodalConfig.cos.pathPrefix || undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加知识图谱配置
|
||||
if (formData.value.nodeExtractConfig.enabled) {
|
||||
data.extract_config = {
|
||||
enabled: true,
|
||||
text: formData.value.nodeExtractConfig.text,
|
||||
tags: formData.value.nodeExtractConfig.tags
|
||||
}
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const handleSubmit = async () => {
|
||||
if (!validateForm()) {
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
const data = buildSubmitData()
|
||||
if (!data) {
|
||||
throw new Error('数据构建失败')
|
||||
}
|
||||
|
||||
if (props.mode === 'create') {
|
||||
// 创建模式:一次性创建知识库及所有配置
|
||||
const result = await createKnowledgeBase(data)
|
||||
if (!result.success || !result.data?.id) {
|
||||
throw new Error(result.message || '创建知识库失败')
|
||||
}
|
||||
MessagePlugin.success('知识库创建成功')
|
||||
emit('success', result.data.id)
|
||||
} else {
|
||||
// 编辑模式:分别更新基本信息和配置
|
||||
if (!props.kbId) {
|
||||
throw new Error('缺少知识库ID')
|
||||
}
|
||||
|
||||
// 1. 更新基本信息(名称、描述)
|
||||
await updateKnowledgeBase(props.kbId, {
|
||||
name: data.name,
|
||||
description: data.description,
|
||||
config: {} // 空配置,只更新基本信息
|
||||
})
|
||||
|
||||
// 2. 更新完整配置(模型、分块、多模态、知识图谱等)
|
||||
const config: KBModelConfigRequest = {
|
||||
llmModelId: data.summary_model_id,
|
||||
embeddingModelId: data.embedding_model_id,
|
||||
rerankModelId: data.rerank_model_id || '',
|
||||
vllmModelId: data.vlm_model_id || '',
|
||||
documentSplitting: {
|
||||
chunkSize: data.chunking_config.chunk_size,
|
||||
chunkOverlap: data.chunking_config.chunk_overlap,
|
||||
separators: data.chunking_config.separators
|
||||
},
|
||||
multimodal: {
|
||||
enabled: !!data.cos_config,
|
||||
storageType: data.cos_config?.provider || 'minio',
|
||||
cos: data.cos_config?.provider === 'cos' ? {
|
||||
secretId: data.cos_config.secret_id,
|
||||
secretKey: data.cos_config.secret_key,
|
||||
region: data.cos_config.region,
|
||||
bucketName: data.cos_config.bucket_name,
|
||||
appId: data.cos_config.app_id,
|
||||
pathPrefix: data.cos_config.path_prefix || ''
|
||||
} : undefined,
|
||||
minio: data.cos_config?.provider === 'minio' ? {
|
||||
bucketName: data.cos_config.bucket_name,
|
||||
useSSL: data.cos_config.use_ssl || false,
|
||||
pathPrefix: data.cos_config.path_prefix || ''
|
||||
} : undefined
|
||||
},
|
||||
nodeExtract: {
|
||||
enabled: data.extract_config?.enabled || false,
|
||||
text: data.extract_config?.text || '',
|
||||
tags: data.extract_config?.tags || [],
|
||||
nodes: [],
|
||||
relations: []
|
||||
}
|
||||
}
|
||||
|
||||
await updateKBConfig(props.kbId, config)
|
||||
MessagePlugin.success('配置保存成功')
|
||||
emit('success', props.kbId)
|
||||
}
|
||||
|
||||
handleClose()
|
||||
} catch (error: any) {
|
||||
console.error('操作失败:', error)
|
||||
MessagePlugin.error(error.message || '操作失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 重置所有状态
|
||||
const resetState = () => {
|
||||
currentSection.value = 'basic'
|
||||
formData.value = null
|
||||
hasFiles.value = false
|
||||
saving.value = false
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
// 关闭弹窗
|
||||
const handleClose = () => {
|
||||
emit('update:visible', false)
|
||||
setTimeout(() => {
|
||||
resetState()
|
||||
}, 300)
|
||||
}
|
||||
|
||||
// 监听弹窗打开/关闭
|
||||
watch(() => props.visible, async (newVal) => {
|
||||
if (newVal) {
|
||||
// 打开弹窗时,先重置状态
|
||||
resetState()
|
||||
|
||||
// 加载模型列表
|
||||
await loadAllModels()
|
||||
|
||||
// 根据模式加载数据
|
||||
if (props.mode === 'edit' && props.kbId) {
|
||||
await loadKBData()
|
||||
} else {
|
||||
// 创建模式:初始化空表单
|
||||
formData.value = initFormData()
|
||||
hasFiles.value = false
|
||||
}
|
||||
} else {
|
||||
// 关闭弹窗时,延迟重置状态(等待动画结束)
|
||||
setTimeout(() => {
|
||||
resetState()
|
||||
}, 300)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
// 复用创建知识库的样式
|
||||
.settings-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.settings-modal {
|
||||
position: relative;
|
||||
width: 90vw;
|
||||
max-width: 1100px;
|
||||
height: 85vh;
|
||||
max-height: 750px;
|
||||
background: #fff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
background: #f5f5f5;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #666;
|
||||
transition: all 0.2s ease;
|
||||
z-index: 10;
|
||||
|
||||
&:hover {
|
||||
background: #e5e5e5;
|
||||
color: #000;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.settings-sidebar {
|
||||
width: 200px;
|
||||
background: #fafafa;
|
||||
border-right: 1px solid #e5e5e5;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 24px 20px;
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
margin: 0;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #000000e6;
|
||||
}
|
||||
|
||||
.settings-nav {
|
||||
flex: 1;
|
||||
padding: 12px 8px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
margin-bottom: 4px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
color: #00000099;
|
||||
|
||||
&:hover {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: #07c05f1a;
|
||||
color: #07c05f;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-icon {
|
||||
margin-right: 8px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 24px 32px;
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 32px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.section-content {
|
||||
.section-header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 0 0 8px 0;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #000000e6;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
margin: 0;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
color: #00000066;
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.section-body {
|
||||
background: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.form-item {
|
||||
margin-bottom: 20px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
|
||||
&.required::after {
|
||||
content: '*';
|
||||
color: #FA5151;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-footer {
|
||||
padding: 16px 32px;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
// 过渡动画
|
||||
.modal-enter-active,
|
||||
.modal-leave-active {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.modal-enter-from,
|
||||
.modal-leave-to {
|
||||
opacity: 0;
|
||||
|
||||
.settings-modal {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<template>
|
||||
<div class="kb-list-container">
|
||||
<!-- 头部 -->
|
||||
<div class="header">
|
||||
<h2>知识库</h2>
|
||||
<t-button theme="primary" @click="openCreate">新建知识库</t-button>
|
||||
<button class="create-btn" @click="openCreateModal">新建知识库</button>
|
||||
</div>
|
||||
|
||||
<!-- 未初始化知识库提示 -->
|
||||
@@ -10,66 +11,107 @@
|
||||
<t-icon name="info-circle" size="16px" />
|
||||
<span>部分知识库尚未初始化,需要先在设置中配置模型信息才能添加知识文档</span>
|
||||
</div>
|
||||
<t-table :data="kbs" :columns="columns" row-key="id" size="medium" hover>
|
||||
<template #status="{ row }">
|
||||
<div class="status-cell">
|
||||
<t-tag
|
||||
:theme="isInitialized(row) ? 'success' : 'warning'"
|
||||
size="small"
|
||||
>
|
||||
{{ isInitialized(row) ? '已初始化' : '未初始化' }}
|
||||
</t-tag>
|
||||
<t-tooltip
|
||||
v-if="!isInitialized(row)"
|
||||
content="需要先在设置中配置模型信息才能添加知识"
|
||||
placement="top"
|
||||
>
|
||||
<span class="warning-icon">⚠</span>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
</template>
|
||||
<template #description="{ row }">
|
||||
<div class="description-text">{{ row.description || '暂无描述' }}</div>
|
||||
</template>
|
||||
<template #op="{ row }">
|
||||
<t-space size="small">
|
||||
<t-button
|
||||
size="small"
|
||||
@click="goDetail(row.id)"
|
||||
:disabled="!isInitialized(row)"
|
||||
:theme="isInitialized(row) ? 'primary' : 'default'"
|
||||
:variant="isInitialized(row) ? 'base' : 'outline'"
|
||||
:title="!isInitialized(row) ? '请先在设置中配置模型信息' : ''"
|
||||
>
|
||||
文档
|
||||
</t-button>
|
||||
<t-button size="small" variant="outline" @click="goSettings(row.id)">设置</t-button>
|
||||
<t-popconfirm content="确认删除该知识库?" @confirm="remove(row.id)">
|
||||
<t-button size="small" theme="danger" variant="text">删除</t-button>
|
||||
</t-popconfirm>
|
||||
</t-space>
|
||||
</template>
|
||||
</t-table>
|
||||
|
||||
<t-dialog v-model:visible="createVisible" header="新建知识库" :footer="false">
|
||||
<t-form :data="createForm" @submit="create">
|
||||
<t-form-item label="名称" name="name" :rules="[{ required: true, message: '请输入名称' }]">
|
||||
<t-input v-model="createForm.name" />
|
||||
</t-form-item>
|
||||
<t-form-item label="描述" name="description">
|
||||
<t-textarea v-model="createForm.description" />
|
||||
</t-form-item>
|
||||
<t-form-item>
|
||||
<t-space>
|
||||
<t-button theme="primary" type="submit" :loading="creating">创建</t-button>
|
||||
<t-button variant="outline" @click="createVisible = false">取消</t-button>
|
||||
</t-space>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<!-- 卡片网格 -->
|
||||
<div v-if="kbs.length > 0" class="kb-card-wrap">
|
||||
<div
|
||||
v-for="(kb, index) in kbs"
|
||||
:key="kb.id"
|
||||
class="kb-card"
|
||||
:class="{ 'uninitialized': !isInitialized(kb) }"
|
||||
@click="handleCardClick(kb)"
|
||||
>
|
||||
<!-- 卡片头部 -->
|
||||
<div class="card-header">
|
||||
<span class="card-title" :title="kb.name">{{ kb.name }}</span>
|
||||
<t-popup
|
||||
v-model="kb.showMore"
|
||||
overlayClassName="card-more-popup"
|
||||
:on-visible-change="onVisibleChange"
|
||||
trigger="click"
|
||||
destroy-on-close
|
||||
placement="bottom-right"
|
||||
>
|
||||
<div
|
||||
variant="outline"
|
||||
class="more-wrap"
|
||||
@click.stop="openMore(index)"
|
||||
:class="{ 'active-more': currentMoreIndex === index }"
|
||||
>
|
||||
<img class="more-icon" src="@/assets/img/more.png" alt="" />
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="popup-menu" @click.stop>
|
||||
<div class="popup-menu-item" @click.stop="handleSettings(kb)">
|
||||
<t-icon class="menu-icon" name="setting" />
|
||||
<span>设置</span>
|
||||
</div>
|
||||
<div class="popup-menu-item delete" @click.stop="handleDelete(kb)">
|
||||
<t-icon class="menu-icon" name="delete" />
|
||||
<span>删除</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<!-- 卡片内容 -->
|
||||
<div class="card-content">
|
||||
<div class="card-description">
|
||||
{{ kb.description || '暂无描述' }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 卡片底部 -->
|
||||
<div class="card-bottom">
|
||||
<div class="status-badge" :class="{ 'initialized': isInitialized(kb), 'uninitialized': !isInitialized(kb) }">
|
||||
<span v-if="!isInitialized(kb)" class="warning-icon">⚠</span>
|
||||
<span>{{ isInitialized(kb) ? '已初始化' : '未初始化' }}</span>
|
||||
</div>
|
||||
<span class="card-time">{{ kb.updated_at }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div v-else-if="!loading" class="empty-state">
|
||||
<img class="empty-img" src="@/assets/img/upload.svg" alt="">
|
||||
<span class="empty-txt">暂无知识库</span>
|
||||
<span class="empty-desc">点击右上角"新建知识库"按钮创建第一个知识库</span>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 删除确认对话框 -->
|
||||
<t-dialog
|
||||
v-model:visible="deleteVisible"
|
||||
dialogClassName="del-knowledge-dialog"
|
||||
:closeBtn="false"
|
||||
:cancelBtn="null"
|
||||
:confirmBtn="null"
|
||||
>
|
||||
<div class="circle-wrap">
|
||||
<div class="dialog-header">
|
||||
<img class="circle-img" src="@/assets/img/circle.png" alt="">
|
||||
<span class="circle-title">删除确认</span>
|
||||
</div>
|
||||
<span class="del-circle-txt">
|
||||
{{ `确认要删除知识库"${deletingKb?.name}"?删除后不可恢复` }}
|
||||
</span>
|
||||
<div class="circle-btn">
|
||||
<span class="circle-btn-txt" @click="deleteVisible = false">取消</span>
|
||||
<span class="circle-btn-txt confirm" @click="confirmDelete">确认删除</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
|
||||
<!-- 知识库设置模态框 -->
|
||||
<KnowledgeBaseSettingsModal />
|
||||
<!-- 知识库编辑器(创建/编辑统一组件) -->
|
||||
<KnowledgeBaseEditorModal
|
||||
:visible="uiStore.showKBEditorModal"
|
||||
:mode="uiStore.kbEditorMode"
|
||||
:kb-id="uiStore.currentKBId || undefined"
|
||||
@update:visible="(val) => val ? null : uiStore.closeKBEditor()"
|
||||
@success="handleKBEditorSuccess"
|
||||
/>
|
||||
|
||||
<!-- 全局设置模态框 -->
|
||||
<Settings />
|
||||
@@ -77,13 +119,13 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref, computed, watch } from 'vue'
|
||||
import { onMounted, ref, computed, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { listKnowledgeBases, createKnowledgeBase, deleteKnowledgeBase } from '@/api/knowledge-base'
|
||||
import { listKnowledgeBases, deleteKnowledgeBase } from '@/api/knowledge-base'
|
||||
import { formatStringDate } from '@/utils/index'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import KnowledgeBaseSettingsModal from './KnowledgeBaseSettingsModal.vue'
|
||||
import KnowledgeBaseEditorModal from './KnowledgeBaseEditorModal.vue'
|
||||
import Settings from '@/views/settings/Settings.vue'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -96,71 +138,78 @@ interface KB {
|
||||
updated_at?: string;
|
||||
embedding_model_id?: string;
|
||||
summary_model_id?: string;
|
||||
showMore?: boolean;
|
||||
}
|
||||
|
||||
const kbs = ref<KB[]>([])
|
||||
const loading = ref(false)
|
||||
|
||||
const columns = [
|
||||
{ colKey: 'name', title: '名称' },
|
||||
{ colKey: 'description', title: '描述', cell: 'description', width: 300 },
|
||||
{ colKey: 'status', title: '状态', cell: 'status', width: 100 },
|
||||
{ colKey: 'updated_at', title: '更新时间' },
|
||||
{ colKey: 'op', title: '操作', cell: 'op', width: 220 },
|
||||
]
|
||||
const deleteVisible = ref(false)
|
||||
const deletingKb = ref<KB | null>(null)
|
||||
const currentMoreIndex = ref<number>(-1)
|
||||
|
||||
const fetchList = () => {
|
||||
loading.value = true
|
||||
listKnowledgeBases().then((res: any) => {
|
||||
const data = res.data || []
|
||||
// 格式化时间
|
||||
// 格式化时间,并初始化 showMore 状态
|
||||
kbs.value = data.map((kb: KB) => ({
|
||||
...kb,
|
||||
updated_at: kb.updated_at ? formatStringDate(new Date(kb.updated_at)) : ''
|
||||
updated_at: kb.updated_at ? formatStringDate(new Date(kb.updated_at)) : '',
|
||||
showMore: false
|
||||
}))
|
||||
}).finally(() => loading.value = false)
|
||||
}
|
||||
|
||||
onMounted(fetchList)
|
||||
onMounted(() => {
|
||||
fetchList()
|
||||
})
|
||||
|
||||
const createVisible = ref(false)
|
||||
const creating = ref(false)
|
||||
const createForm = reactive({ name: '', description: '' })
|
||||
const openCreate = () => {
|
||||
createForm.name = ''
|
||||
createForm.description = ''
|
||||
createVisible.value = true
|
||||
// 打开创建知识库弹窗
|
||||
const openCreateModal = () => {
|
||||
uiStore.openCreateKB()
|
||||
}
|
||||
const create = () => {
|
||||
if (!createForm.name) return
|
||||
creating.value = true
|
||||
const chunking_config = {
|
||||
chunk_size: 512,
|
||||
chunk_overlap: 100,
|
||||
separators: ['.', '?', '!', '。', '?', '!'],
|
||||
enable_multimodal: false
|
||||
|
||||
const openMore = (index: number) => {
|
||||
// 只记录当前打开的索引,用于显示激活样式
|
||||
// 弹窗的开关由 v-model 自动管理
|
||||
currentMoreIndex.value = index
|
||||
}
|
||||
|
||||
const onVisibleChange = (visible: boolean) => {
|
||||
// 弹窗关闭时重置索引
|
||||
if (!visible) {
|
||||
currentMoreIndex.value = -1
|
||||
}
|
||||
createKnowledgeBase({ name: createForm.name, description: createForm.description, chunking_config }).then((res: any) => {
|
||||
if (res.success) {
|
||||
MessagePlugin.success('创建成功')
|
||||
createVisible.value = false
|
||||
fetchList()
|
||||
} else {
|
||||
MessagePlugin.error(res.message || '创建失败')
|
||||
}
|
||||
}).catch((e: any) => {
|
||||
MessagePlugin.error(e?.message || '创建失败')
|
||||
}).finally(() => creating.value = false)
|
||||
}
|
||||
|
||||
const remove = (id: string) => {
|
||||
deleteKnowledgeBase(id).then((res: any) => {
|
||||
const handleSettings = (kb: KB) => {
|
||||
// 手动关闭弹窗
|
||||
kb.showMore = false
|
||||
goSettings(kb.id)
|
||||
}
|
||||
|
||||
const handleDelete = (kb: KB) => {
|
||||
// 手动关闭弹窗
|
||||
kb.showMore = false
|
||||
deletingKb.value = kb
|
||||
deleteVisible.value = true
|
||||
}
|
||||
|
||||
const confirmDelete = () => {
|
||||
if (!deletingKb.value) return
|
||||
|
||||
deleteKnowledgeBase(deletingKb.value.id).then((res: any) => {
|
||||
if (res.success) {
|
||||
MessagePlugin.success('已删除')
|
||||
deleteVisible.value = false
|
||||
deletingKb.value = null
|
||||
fetchList()
|
||||
} else {
|
||||
MessagePlugin.error(res.message || '删除失败')
|
||||
}
|
||||
}).catch((e: any) => MessagePlugin.error(e?.message || '删除失败'))
|
||||
}).catch((e: any) => {
|
||||
MessagePlugin.error(e?.message || '删除失败')
|
||||
})
|
||||
}
|
||||
|
||||
const isInitialized = (kb: KB) => {
|
||||
@@ -173,39 +222,77 @@ const hasUninitializedKbs = computed(() => {
|
||||
return kbs.value.some(kb => !isInitialized(kb))
|
||||
})
|
||||
|
||||
const handleCardClick = (kb: KB) => {
|
||||
if (isInitialized(kb)) {
|
||||
goDetail(kb.id)
|
||||
} else {
|
||||
goSettings(kb.id)
|
||||
}
|
||||
}
|
||||
|
||||
const goDetail = (id: string) => {
|
||||
router.push(`/platform/knowledge-bases/${id}`)
|
||||
}
|
||||
|
||||
const goSettings = (id: string) => {
|
||||
// 使用模态框打开设置,而不是路由导航
|
||||
// 使用模态框打开设置
|
||||
uiStore.openKBSettings(id)
|
||||
}
|
||||
|
||||
// 监听知识库设置模态框关闭,刷新列表
|
||||
watch(() => uiStore.showKBSettingsModal, (newVal, oldVal) => {
|
||||
// 当模态框从打开变为关闭时,刷新列表
|
||||
if (oldVal && !newVal) {
|
||||
fetchList()
|
||||
}
|
||||
})
|
||||
// 知识库编辑器成功回调(创建或编辑成功)
|
||||
const handleKBEditorSuccess = (kbId: string) => {
|
||||
console.log('知识库操作成功:', kbId)
|
||||
fetchList()
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.kb-list-container {
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
margin: 0 20px 0 20px;
|
||||
padding: 24px 44px;
|
||||
// background: #fff;
|
||||
margin: 0 20px;
|
||||
height: calc(100vh);
|
||||
overflow-y: auto;
|
||||
box-sizing: border-box;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
h2 { margin: 0; font-size: 20px; font-weight: 600; }
|
||||
margin-bottom: 20px;
|
||||
|
||||
h2 {
|
||||
margin: 0;
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
line-height: 32px;
|
||||
}
|
||||
}
|
||||
|
||||
.create-btn {
|
||||
padding: 8px 20px;
|
||||
height: 36px;
|
||||
background: #07c05f;
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
background: #05a04f;
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: #048f45;
|
||||
}
|
||||
}
|
||||
|
||||
.warning-banner {
|
||||
@@ -213,11 +300,12 @@ watch(() => uiStore.showKBSettingsModal, (newVal, oldVal) => {
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px 16px;
|
||||
margin-bottom: 16px;
|
||||
margin-bottom: 20px;
|
||||
background: #fff7e6;
|
||||
border: 1px solid #ffd591;
|
||||
border-radius: 6px;
|
||||
color: #d46b08;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
|
||||
.t-icon {
|
||||
@@ -226,28 +314,349 @@ watch(() => uiStore.showKBSettingsModal, (newVal, oldVal) => {
|
||||
}
|
||||
}
|
||||
|
||||
.status-cell {
|
||||
.kb-card-wrap {
|
||||
display: grid;
|
||||
gap: 20px;
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.kb-card {
|
||||
border: 2px solid #fbfbfb;
|
||||
border-radius: 6px;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 0 8px 0 #00000005;
|
||||
background: #fff;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
padding: 12px 16px 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
.warning-icon {
|
||||
color: #ff8800;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
transition: color 0.2s;
|
||||
|
||||
&:hover {
|
||||
color: #d46b08;
|
||||
}
|
||||
flex-direction: column;
|
||||
min-height: 150px;
|
||||
|
||||
&:hover {
|
||||
border-color: #07c05f;
|
||||
}
|
||||
|
||||
&.uninitialized {
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
.description-cell {
|
||||
.description-text {
|
||||
color: #000000e6;
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
line-height: 22px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex: 1;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.more-wrap {
|
||||
display: flex;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
background: #e7e7e7;
|
||||
}
|
||||
|
||||
&.active-more {
|
||||
background: #e7e7e7;
|
||||
}
|
||||
|
||||
.more-icon {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.card-content {
|
||||
flex: 1;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.card-description {
|
||||
display: -webkit-box;
|
||||
-webkit-box-orient: vertical;
|
||||
-webkit-line-clamp: 2;
|
||||
overflow: hidden;
|
||||
color: #00000066;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
line-height: 20px;
|
||||
min-height: 40px;
|
||||
}
|
||||
|
||||
.card-bottom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 0 0;
|
||||
border-top: 1px solid #f0f0f0;
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 3px;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
|
||||
&.initialized {
|
||||
background: #07c05f1a;
|
||||
color: #07c05f;
|
||||
}
|
||||
|
||||
&.uninitialized {
|
||||
background: #fff7e6;
|
||||
color: #d46b08;
|
||||
}
|
||||
|
||||
.warning-icon {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.card-time {
|
||||
color: #00000066;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
|
||||
.empty-state {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 60px 20px;
|
||||
|
||||
.empty-img {
|
||||
width: 162px;
|
||||
height: 162px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.empty-txt {
|
||||
color: #00000099;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 26px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.empty-desc {
|
||||
color: #00000066;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
}
|
||||
}
|
||||
|
||||
// 响应式布局
|
||||
@media (min-width: 900px) {
|
||||
.kb-card-wrap {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1250px) {
|
||||
.kb-card-wrap {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1600px) {
|
||||
.kb-card-wrap {
|
||||
grid-template-columns: repeat(4, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除确认对话框样式
|
||||
:deep(.del-knowledge-dialog) {
|
||||
padding: 0px !important;
|
||||
border-radius: 6px !important;
|
||||
|
||||
.t-dialog__header {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.t-dialog__body {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.t-dialog__footer {
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.t-dialog__position.t-dialog--top) {
|
||||
padding-top: 40vh !important;
|
||||
}
|
||||
|
||||
.circle-wrap {
|
||||
.dialog-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.circle-img {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.circle-title {
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
line-height: 24px;
|
||||
}
|
||||
|
||||
.del-circle-txt {
|
||||
color: #00000099;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
display: inline-block;
|
||||
margin-left: 29px;
|
||||
margin-bottom: 21px;
|
||||
}
|
||||
|
||||
.circle-btn {
|
||||
height: 22px;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.circle-btn-txt {
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
|
||||
.confirm {
|
||||
color: #FA5151;
|
||||
margin-left: 40px;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="less">
|
||||
// 更多操作弹窗样式
|
||||
.card-more-popup {
|
||||
z-index: 99 !important;
|
||||
|
||||
.t-popup__content {
|
||||
padding: 4px 0 !important;
|
||||
margin-top: 4px !important;
|
||||
min-width: 120px;
|
||||
}
|
||||
}
|
||||
|
||||
.popup-menu {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.popup-menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px 16px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
color: #000000e6;
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
|
||||
.menu-icon {
|
||||
margin-right: 8px;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
&.delete {
|
||||
color: #000000e6;
|
||||
|
||||
&:hover {
|
||||
background: #fff1f0;
|
||||
color: #FA5151;
|
||||
|
||||
.menu-icon {
|
||||
color: #FA5151;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 创建对话框样式优化
|
||||
.create-kb-dialog {
|
||||
.t-form-item__label {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #000000e6;
|
||||
}
|
||||
|
||||
.t-input,
|
||||
.t-textarea {
|
||||
font-family: "PingFang SC";
|
||||
}
|
||||
|
||||
.t-button--theme-primary {
|
||||
background-color: #07c05f;
|
||||
border-color: #07c05f;
|
||||
|
||||
&:hover {
|
||||
background-color: #05a04f;
|
||||
border-color: #05a04f;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,668 +0,0 @@
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="modal">
|
||||
<div v-if="visible" class="settings-overlay" @click.self="handleClose">
|
||||
<div class="settings-modal">
|
||||
<!-- 关闭按钮 -->
|
||||
<button class="close-btn" @click="handleClose" aria-label="关闭设置">
|
||||
<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>
|
||||
</button>
|
||||
|
||||
<div class="settings-container">
|
||||
<!-- 左侧导航 -->
|
||||
<div class="settings-sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h2 class="sidebar-title">知识库设置</h2>
|
||||
</div>
|
||||
<div class="settings-nav">
|
||||
<div
|
||||
v-for="(item, index) in navItems"
|
||||
:key="index"
|
||||
:class="['nav-item', { 'active': currentSection === item.key }]"
|
||||
@click="currentSection = item.key"
|
||||
>
|
||||
<span class="nav-icon">{{ item.icon }}</span>
|
||||
<span class="nav-label">{{ item.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧内容区域 -->
|
||||
<div class="settings-content">
|
||||
<div class="content-wrapper">
|
||||
<!-- 基本信息 -->
|
||||
<div v-show="currentSection === 'basic'" class="section">
|
||||
<KBBasicInfo
|
||||
v-if="kbData"
|
||||
:kb-id="kbId"
|
||||
:name="kbData.name"
|
||||
:description="kbData.description"
|
||||
@update:name="kbData.name = $event"
|
||||
@update:description="kbData.description = $event"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 模型配置 -->
|
||||
<div v-show="currentSection === 'models'" class="section">
|
||||
<KBModelConfig
|
||||
ref="modelConfigRef"
|
||||
v-if="configData"
|
||||
:config="modelConfig"
|
||||
:has-files="configData.hasFiles"
|
||||
:all-models="allModels"
|
||||
@update:config="handleModelConfigUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 分块设置 -->
|
||||
<div v-show="currentSection === 'chunking'" class="section">
|
||||
<KBChunkingSettings
|
||||
v-if="configData"
|
||||
:config="chunkingConfig"
|
||||
@update:config="handleChunkingConfigUpdate"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- 高级设置 -->
|
||||
<div v-show="currentSection === 'advanced'" class="section">
|
||||
<KBAdvancedSettings
|
||||
ref="advancedSettingsRef"
|
||||
v-if="configData"
|
||||
:multimodal="multimodalConfig"
|
||||
:node-extract="nodeExtractConfig"
|
||||
:all-models="allModels"
|
||||
@update:multimodal="handleMultimodalUpdate"
|
||||
@update:nodeExtract="handleNodeExtractUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 保存按钮 -->
|
||||
<div class="settings-footer">
|
||||
<t-button theme="default" variant="outline" @click="handleClose">
|
||||
取消
|
||||
</t-button>
|
||||
<t-button theme="primary" @click="handleSave" :loading="saving">
|
||||
保存配置
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted } from 'vue'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { getKnowledgeBaseById, listKnowledgeFiles } from '@/api/knowledge-base'
|
||||
import { updateKBConfig, type KBModelConfigRequest } from '@/api/initialization'
|
||||
import { listModels } from '@/api/model'
|
||||
import KBBasicInfo from './settings/KBBasicInfo.vue'
|
||||
import KBModelConfig from './settings/KBModelConfig.vue'
|
||||
import KBChunkingSettings from './settings/KBChunkingSettings.vue'
|
||||
import KBAdvancedSettings from './settings/KBAdvancedSettings.vue'
|
||||
|
||||
const uiStore = useUIStore()
|
||||
|
||||
const visible = computed(() => uiStore.showKBSettingsModal)
|
||||
const kbId = computed(() => uiStore.currentKBId || '')
|
||||
|
||||
const currentSection = ref<string>('basic')
|
||||
const saving = ref(false)
|
||||
const loading = ref(false)
|
||||
const allModels = ref<any[]>([])
|
||||
|
||||
const navItems = [
|
||||
{ key: 'basic', icon: 'ℹ️', label: '基本信息' },
|
||||
{ key: 'models', icon: '🤖', label: '模型配置' },
|
||||
{ key: 'chunking', icon: '📄', label: '分块设置' },
|
||||
{ key: 'advanced', icon: '⚙️', label: '高级设置' }
|
||||
]
|
||||
|
||||
// 知识库基本数据
|
||||
const kbData = ref<{
|
||||
name: string
|
||||
description?: string
|
||||
} | null>(null)
|
||||
|
||||
// 配置数据(简化为只需要 hasFiles 标记)
|
||||
const configData = ref<{ hasFiles: boolean } | null>(null)
|
||||
|
||||
// 模型配置引用
|
||||
const modelConfigRef = ref<InstanceType<typeof KBModelConfig>>()
|
||||
const advancedSettingsRef = ref<InstanceType<typeof KBAdvancedSettings>>()
|
||||
|
||||
// 模型配置
|
||||
const modelConfig = ref({
|
||||
llmModelId: '',
|
||||
embeddingModelId: '',
|
||||
rerankModelId: ''
|
||||
})
|
||||
|
||||
// 分块配置
|
||||
const chunkingConfig = ref({
|
||||
chunkSize: 512,
|
||||
chunkOverlap: 100,
|
||||
separators: ['\n\n', '\n', '。', '!', '?', ';', ';']
|
||||
})
|
||||
|
||||
// 多模态配置
|
||||
const multimodalConfig = ref({
|
||||
enabled: false,
|
||||
storageType: 'minio' as 'minio' | 'cos',
|
||||
vllmModelId: '',
|
||||
minio: {
|
||||
bucketName: '',
|
||||
useSSL: false,
|
||||
pathPrefix: ''
|
||||
},
|
||||
cos: {
|
||||
secretId: '',
|
||||
secretKey: '',
|
||||
region: '',
|
||||
bucketName: '',
|
||||
appId: '',
|
||||
pathPrefix: ''
|
||||
}
|
||||
})
|
||||
|
||||
// 知识图谱配置
|
||||
const nodeExtractConfig = ref({
|
||||
enabled: false,
|
||||
text: '',
|
||||
tags: [] as string[]
|
||||
})
|
||||
|
||||
// 加载所有模型(统一加载,避免重复调用)
|
||||
const loadAllModels = async () => {
|
||||
try {
|
||||
const models = await listModels()
|
||||
allModels.value = models || []
|
||||
return models || []
|
||||
} catch (error) {
|
||||
console.error('加载模型列表失败:', error)
|
||||
MessagePlugin.error('加载模型列表失败')
|
||||
allModels.value = []
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载知识库数据
|
||||
const loadKBData = async () => {
|
||||
if (!kbId.value) return
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
// 并行加载知识库信息和所有模型(只需要一个接口!)
|
||||
const [kbInfo, models] = await Promise.all([
|
||||
getKnowledgeBaseById(kbId.value),
|
||||
loadAllModels()
|
||||
])
|
||||
|
||||
if (!kbInfo || !kbInfo.data) {
|
||||
throw new Error('知识库不存在')
|
||||
}
|
||||
|
||||
const kb = kbInfo.data
|
||||
|
||||
// 设置基本信息
|
||||
kbData.value = {
|
||||
name: kb.name || '',
|
||||
description: kb.description || ''
|
||||
}
|
||||
|
||||
// 设置模型ID(直接从知识库数据中获取)
|
||||
modelConfig.value = {
|
||||
llmModelId: kb.summary_model_id || '',
|
||||
embeddingModelId: kb.embedding_model_id || '',
|
||||
rerankModelId: kb.rerank_model_id || ''
|
||||
}
|
||||
|
||||
// 设置分块配置
|
||||
chunkingConfig.value = {
|
||||
chunkSize: kb.chunking_config?.chunk_size || 512,
|
||||
chunkOverlap: kb.chunking_config?.chunk_overlap || 100,
|
||||
separators: kb.chunking_config?.separators || ['\n\n', '\n', '。', '!', '?', ';', ';']
|
||||
}
|
||||
|
||||
// 设置多模态配置
|
||||
// 判断是否真的有存储配置:provider 不为空且有实际的存储信息
|
||||
const hasStorage = kb.cos_config?.provider && (
|
||||
(kb.cos_config.provider === 'minio' && kb.cos_config.bucket_name) ||
|
||||
(kb.cos_config.provider === 'cos' && kb.cos_config.bucket_name)
|
||||
)
|
||||
const hasVLM = !!kb.vlm_model_id
|
||||
|
||||
multimodalConfig.value = {
|
||||
enabled: !!(hasStorage || hasVLM),
|
||||
storageType: (kb.cos_config?.provider || 'minio') as 'minio' | 'cos',
|
||||
vllmModelId: kb.vlm_model_id || '',
|
||||
minio: {
|
||||
bucketName: kb.cos_config?.bucket_name || '',
|
||||
useSSL: false,
|
||||
pathPrefix: kb.cos_config?.path_prefix || ''
|
||||
},
|
||||
cos: {
|
||||
secretId: kb.cos_config?.secret_id || '',
|
||||
secretKey: kb.cos_config?.secret_key || '',
|
||||
region: kb.cos_config?.region || '',
|
||||
bucketName: kb.cos_config?.bucket_name || '',
|
||||
appId: kb.cos_config?.app_id || '',
|
||||
pathPrefix: kb.cos_config?.path_prefix || ''
|
||||
}
|
||||
}
|
||||
|
||||
// 设置知识图谱配置
|
||||
if (kb.extract_config) {
|
||||
nodeExtractConfig.value = {
|
||||
enabled: true,
|
||||
text: kb.extract_config.text || '',
|
||||
tags: kb.extract_config.tags || []
|
||||
}
|
||||
} else {
|
||||
nodeExtractConfig.value = {
|
||||
enabled: false,
|
||||
text: '',
|
||||
tags: []
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否有文件(用于判断是否可以修改Embedding模型)
|
||||
const knowledgeList = await listKnowledgeFiles(kbId.value, { page: 1, page_size: 1 })
|
||||
const hasFiles = knowledgeList && knowledgeList.data && knowledgeList.data.items && knowledgeList.data.items.length > 0
|
||||
|
||||
// 设置 configData(用于传递 hasFiles 状态)
|
||||
configData.value = { hasFiles } as any
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载知识库数据失败:', error)
|
||||
MessagePlugin.error('加载知识库数据失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 不再需要 mapModelIds,直接使用知识库返回的模型ID
|
||||
|
||||
// 处理模型配置更新
|
||||
const handleModelConfigUpdate = (newConfig: typeof modelConfig.value) => {
|
||||
modelConfig.value = newConfig
|
||||
}
|
||||
|
||||
// 处理分块配置更新
|
||||
const handleChunkingConfigUpdate = (newConfig: typeof chunkingConfig.value) => {
|
||||
chunkingConfig.value = newConfig
|
||||
}
|
||||
|
||||
// 处理多模态配置更新
|
||||
const handleMultimodalUpdate = (newConfig: typeof multimodalConfig.value) => {
|
||||
multimodalConfig.value = newConfig
|
||||
}
|
||||
|
||||
// 处理知识图谱配置更新
|
||||
const handleNodeExtractUpdate = (newConfig: typeof nodeExtractConfig.value) => {
|
||||
nodeExtractConfig.value = newConfig
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
const handleSave = async () => {
|
||||
if (saving.value || !kbId.value) return
|
||||
|
||||
// 验证必填项 - 模型配置
|
||||
if (!modelConfig.value.llmModelId) {
|
||||
MessagePlugin.warning('请选择LLM模型')
|
||||
currentSection.value = 'models'
|
||||
return
|
||||
}
|
||||
|
||||
if (!modelConfig.value.embeddingModelId) {
|
||||
MessagePlugin.warning('请选择Embedding模型')
|
||||
currentSection.value = 'models'
|
||||
return
|
||||
}
|
||||
|
||||
// 验证多模态配置
|
||||
if (multimodalConfig.value.enabled) {
|
||||
// 验证VLLM模型(必选)
|
||||
if (!multimodalConfig.value.vllmModelId) {
|
||||
MessagePlugin.warning('多模态功能已启用,请选择VLLM视觉模型')
|
||||
currentSection.value = 'advanced'
|
||||
return
|
||||
}
|
||||
|
||||
// 验证存储配置
|
||||
if (multimodalConfig.value.storageType === 'minio') {
|
||||
if (!multimodalConfig.value.minio.bucketName) {
|
||||
MessagePlugin.warning('使用MinIO存储时,Bucket名称为必填项')
|
||||
currentSection.value = 'advanced'
|
||||
return
|
||||
}
|
||||
} else if (multimodalConfig.value.storageType === 'cos') {
|
||||
const cos = multimodalConfig.value.cos
|
||||
if (!cos.secretId) {
|
||||
MessagePlugin.warning('使用腾讯云COS时,SecretId为必填项')
|
||||
currentSection.value = 'advanced'
|
||||
return
|
||||
}
|
||||
if (!cos.secretKey) {
|
||||
MessagePlugin.warning('使用腾讯云COS时,SecretKey为必填项')
|
||||
currentSection.value = 'advanced'
|
||||
return
|
||||
}
|
||||
if (!cos.region) {
|
||||
MessagePlugin.warning('使用腾讯云COS时,地域为必填项')
|
||||
currentSection.value = 'advanced'
|
||||
return
|
||||
}
|
||||
if (!cos.bucketName) {
|
||||
MessagePlugin.warning('使用腾讯云COS时,Bucket名称为必填项')
|
||||
currentSection.value = 'advanced'
|
||||
return
|
||||
}
|
||||
if (!cos.appId) {
|
||||
MessagePlugin.warning('使用腾讯云COS时,AppId为必填项')
|
||||
currentSection.value = 'advanced'
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
// 构建配置对象(简化版,只传模型ID)
|
||||
const config: KBModelConfigRequest = {
|
||||
llmModelId: modelConfig.value.llmModelId,
|
||||
embeddingModelId: modelConfig.value.embeddingModelId,
|
||||
rerankModelId: modelConfig.value.rerankModelId || '',
|
||||
vllmModelId: multimodalConfig.value.vllmModelId || '',
|
||||
documentSplitting: {
|
||||
chunkSize: chunkingConfig.value.chunkSize,
|
||||
chunkOverlap: chunkingConfig.value.chunkOverlap,
|
||||
separators: chunkingConfig.value.separators
|
||||
},
|
||||
multimodal: {
|
||||
enabled: multimodalConfig.value.enabled,
|
||||
storageType: multimodalConfig.value.enabled ? multimodalConfig.value.storageType : 'minio',
|
||||
cos: multimodalConfig.value.enabled && multimodalConfig.value.storageType === 'cos' ? multimodalConfig.value.cos : undefined,
|
||||
minio: multimodalConfig.value.enabled && multimodalConfig.value.storageType === 'minio' ? multimodalConfig.value.minio : undefined
|
||||
},
|
||||
nodeExtract: {
|
||||
enabled: nodeExtractConfig.value.enabled,
|
||||
text: nodeExtractConfig.value.text,
|
||||
tags: nodeExtractConfig.value.tags,
|
||||
nodes: [],
|
||||
relations: []
|
||||
}
|
||||
}
|
||||
|
||||
// 保存配置
|
||||
await updateKBConfig(kbId.value, config)
|
||||
MessagePlugin.success('配置保存成功')
|
||||
handleClose()
|
||||
} catch (error) {
|
||||
console.error('保存配置失败:', error)
|
||||
MessagePlugin.error('保存配置失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理关闭
|
||||
const handleClose = () => {
|
||||
uiStore.closeKBSettings()
|
||||
// 重置当前选中的section
|
||||
setTimeout(() => {
|
||||
currentSection.value = 'basic'
|
||||
}, 300)
|
||||
}
|
||||
|
||||
// 监听visible变化,当打开时加载数据
|
||||
watch(visible, (newVal) => {
|
||||
if (newVal && kbId.value) {
|
||||
loadKBData()
|
||||
}
|
||||
})
|
||||
|
||||
// 监听全局设置关闭事件,刷新模型列表
|
||||
watch(() => uiStore.showSettingsModal, (newVal, oldVal) => {
|
||||
// 当全局设置从打开变为关闭,且知识库设置仍然打开时,刷新模型列表
|
||||
if (oldVal && !newVal && visible.value) {
|
||||
// 统一刷新所有模型列表(只调用一次API)
|
||||
loadAllModels()
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (visible.value && kbId.value) {
|
||||
loadKBData()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
/* 遮罩层 */
|
||||
.settings-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 999;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
/* 弹窗容器 */
|
||||
.settings-modal {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
max-width: 900px;
|
||||
height: 700px;
|
||||
background: #ffffff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 6px 28px rgba(15, 23, 42, 0.08);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
/* 关闭按钮 */
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: #666666;
|
||||
cursor: pointer;
|
||||
border-radius: 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s ease;
|
||||
z-index: 10;
|
||||
|
||||
&:hover {
|
||||
background: #f5f5f5;
|
||||
color: #333333;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* 左侧导航栏 */
|
||||
.settings-sidebar {
|
||||
width: 220px;
|
||||
background-color: #f8f9fa;
|
||||
border-right: 1px solid #e5e7eb;
|
||||
flex-shrink: 0;
|
||||
overflow-y: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 24px 16px 16px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.settings-nav {
|
||||
padding: 16px 8px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px 16px;
|
||||
margin-bottom: 4px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
color: #666666;
|
||||
font-size: 14px;
|
||||
transition: all 0.2s ease;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
background-color: #e8f5ed;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: rgba(7, 192, 95, 0.1);
|
||||
color: #07C05F;
|
||||
font-weight: 500;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-icon {
|
||||
margin-right: 12px;
|
||||
font-size: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
/* 右侧内容区域 */
|
||||
.settings-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
background-color: #ffffff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
flex: 1;
|
||||
max-width: 600px;
|
||||
padding: 40px 48px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.section {
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* 底部保存按钮 */
|
||||
.settings-footer {
|
||||
padding: 16px 48px;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
/* 弹窗动画 */
|
||||
.modal-enter-active,
|
||||
.modal-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.modal-enter-active .settings-modal,
|
||||
.modal-leave-active .settings-modal {
|
||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.modal-enter-from,
|
||||
.modal-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.modal-enter-from .settings-modal,
|
||||
.modal-leave-to .settings-modal {
|
||||
transform: scale(0.95);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
/* 滚动条样式 */
|
||||
.settings-sidebar::-webkit-scrollbar,
|
||||
.settings-content::-webkit-scrollbar,
|
||||
.content-wrapper::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.settings-sidebar::-webkit-scrollbar-track {
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
.settings-sidebar::-webkit-scrollbar-thumb {
|
||||
background: #d0d0d0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.settings-sidebar::-webkit-scrollbar-thumb:hover {
|
||||
background: #b0b0b0;
|
||||
}
|
||||
|
||||
.content-wrapper::-webkit-scrollbar-track {
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.content-wrapper::-webkit-scrollbar-thumb {
|
||||
background: #d0d0d0;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.content-wrapper::-webkit-scrollbar-thumb:hover {
|
||||
background: #b0b0b0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
<template>
|
||||
<div class="kb-basic-info">
|
||||
<div class="section-header">
|
||||
<h2>基本信息</h2>
|
||||
<p class="section-description">配置知识库的基本信息</p>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<!-- 知识库名称 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>知识库名称 <span class="required">*</span></label>
|
||||
<p class="desc">知识库的显示名称(最多50个字符)</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-input
|
||||
v-model="localName"
|
||||
placeholder="请输入知识库名称"
|
||||
maxlength="50"
|
||||
show-word-limit
|
||||
@blur="handleNameChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 知识库描述 -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>知识库描述</label>
|
||||
<p class="desc">知识库的详细描述信息(最多200个字符)</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<t-textarea
|
||||
v-model="localDescription"
|
||||
placeholder="请输入知识库描述"
|
||||
maxlength="200"
|
||||
show-word-limit
|
||||
:autosize="{ minRows: 3, maxRows: 6 }"
|
||||
@blur="handleDescriptionChange"
|
||||
style="width: 280px;"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { updateKnowledgeBase } from '@/api/knowledge-base'
|
||||
|
||||
interface Props {
|
||||
kbId: string
|
||||
name: string
|
||||
description?: string
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:name': [value: string]
|
||||
'update:description': [value: string]
|
||||
}>()
|
||||
|
||||
const localName = ref(props.name)
|
||||
const localDescription = ref(props.description || '')
|
||||
const saving = ref(false)
|
||||
|
||||
// 监听props变化
|
||||
watch(() => props.name, (newVal) => {
|
||||
localName.value = newVal
|
||||
})
|
||||
|
||||
watch(() => props.description, (newVal) => {
|
||||
localDescription.value = newVal || ''
|
||||
})
|
||||
|
||||
// 保存基本信息
|
||||
const saveBasicInfo = async () => {
|
||||
if (saving.value) return
|
||||
|
||||
if (!localName.value.trim()) {
|
||||
MessagePlugin.warning('知识库名称不能为空')
|
||||
return
|
||||
}
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
await updateKnowledgeBase(props.kbId, {
|
||||
name: localName.value,
|
||||
description: localDescription.value,
|
||||
config: {} // 这里只更新基本信息,不更新配置
|
||||
})
|
||||
|
||||
emit('update:name', localName.value)
|
||||
emit('update:description', localDescription.value)
|
||||
MessagePlugin.success('保存成功')
|
||||
} catch (error) {
|
||||
console.error('保存知识库基本信息失败:', error)
|
||||
MessagePlugin.error('保存失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 处理名称变化
|
||||
const handleNameChange = () => {
|
||||
if (localName.value !== props.name) {
|
||||
saveBasicInfo()
|
||||
}
|
||||
}
|
||||
|
||||
// 处理描述变化
|
||||
const handleDescriptionChange = () => {
|
||||
if (localDescription.value !== props.description) {
|
||||
saveBasicInfo()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.kb-basic-info {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 32px;
|
||||
|
||||
h2 {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #333333;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 14px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.setting-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
padding: 20px 0;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-info {
|
||||
flex: 1;
|
||||
max-width: 65%;
|
||||
padding-right: 24px;
|
||||
|
||||
label {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: #333333;
|
||||
display: block;
|
||||
margin-bottom: 4px;
|
||||
|
||||
.required {
|
||||
color: #fa5151;
|
||||
margin-left: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.desc {
|
||||
font-size: 13px;
|
||||
color: #666666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
.setting-control {
|
||||
flex-shrink: 0;
|
||||
min-width: 280px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user