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:
@@ -19,8 +19,17 @@ export async function knowledgeChat(data: { session_id: string; query: string; }
|
||||
}
|
||||
|
||||
// Agent chat with streaming support
|
||||
export async function agentChat(data: { session_id: string; query: string; }) {
|
||||
return postChat(`/api/v1/agent-chat/${data.session_id}`, { query: data.query });
|
||||
export async function agentChat(data: {
|
||||
session_id: string;
|
||||
query: string;
|
||||
knowledge_base_ids?: string[];
|
||||
agent_enabled: boolean;
|
||||
}) {
|
||||
return postChat(`/api/v1/agent-chat/${data.session_id}`, {
|
||||
query: data.query,
|
||||
knowledge_base_ids: data.knowledge_base_ids,
|
||||
agent_enabled: data.agent_enabled
|
||||
});
|
||||
}
|
||||
|
||||
export async function getMessageList(data: { session_id: string; limit: number, created_at: string }) {
|
||||
@@ -33,4 +42,8 @@ export async function getMessageList(data: { session_id: string; limit: number,
|
||||
|
||||
export async function delSession(session_id: string) {
|
||||
return del(`/api/v1/sessions/${session_id}`);
|
||||
}
|
||||
|
||||
export async function getSession(session_id: string) {
|
||||
return get(`/api/v1/sessions/${session_id}`);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export function useStream() {
|
||||
let renderTimer: number | null = null
|
||||
|
||||
// 启动流式请求
|
||||
const startStream = async (params: { session_id: any; query: any; method: string; url: string }) => {
|
||||
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; agent_enabled?: boolean; method: string; url: string }) => {
|
||||
// 重置状态
|
||||
output.value = '';
|
||||
error.value = null;
|
||||
@@ -46,11 +46,33 @@ export function useStream() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Validate knowledge_base_ids for agent-chat requests
|
||||
const isAgentChat = params.url === '/api/v1/agent-chat';
|
||||
if (isAgentChat && params.method === 'POST') {
|
||||
if (!params.knowledge_base_ids || params.knowledge_base_ids.length === 0) {
|
||||
error.value = "请至少选择一个知识库";
|
||||
stopStream();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
let url =
|
||||
params.method == "POST"
|
||||
? `${apiUrl}${params.url}/${params.session_id}`
|
||||
: `${apiUrl}${params.url}/${params.session_id}?message_id=${params.query}`;
|
||||
|
||||
// Prepare POST body with required fields for agent-chat
|
||||
// knowledge_base_ids array and agent_enabled can update Session's SessionAgentConfig
|
||||
const postBody: any = {
|
||||
query: params.query,
|
||||
agent_enabled: params.agent_enabled !== undefined ? params.agent_enabled : true
|
||||
};
|
||||
// Always include knowledge_base_ids for agent-chat (already validated above)
|
||||
if (params.knowledge_base_ids !== undefined && params.knowledge_base_ids.length > 0) {
|
||||
postBody.knowledge_base_ids = params.knowledge_base_ids;
|
||||
}
|
||||
|
||||
await fetchEventSource(url, {
|
||||
method: params.method,
|
||||
headers: {
|
||||
@@ -60,7 +82,7 @@ export function useStream() {
|
||||
},
|
||||
body:
|
||||
params.method == "POST"
|
||||
? JSON.stringify({ query: params.query })
|
||||
? JSON.stringify(postBody)
|
||||
: null,
|
||||
signal: controller.signal,
|
||||
openWhenHidden: true,
|
||||
|
||||
@@ -5,7 +5,18 @@ export function listKnowledgeBases() {
|
||||
return get(`/api/v1/knowledge-bases`);
|
||||
}
|
||||
|
||||
export function createKnowledgeBase(data: { name: string; description?: string; chunking_config?: any }) {
|
||||
export function createKnowledgeBase(data: {
|
||||
name: string;
|
||||
description?: string;
|
||||
chunking_config?: any;
|
||||
embedding_model_id?: string;
|
||||
summary_model_id?: string;
|
||||
rerank_model_id?: string;
|
||||
vlm_model_id?: string;
|
||||
vlm_config?: any;
|
||||
cos_config?: any;
|
||||
extract_config?: any;
|
||||
}) {
|
||||
return post(`/api/v1/knowledge-bases`, data);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,32 +49,34 @@
|
||||
</t-popup>
|
||||
</div>
|
||||
<div ref="submenuscrollContainer" @scroll="handleScroll" class="submenu" v-if="item.children">
|
||||
<div class="submenu_item_p" v-for="(subitem, subindex) in item.children" :key="subindex"
|
||||
@click="gotopage(subitem.path)">
|
||||
<div :class="['submenu_item', currentSecondpath == subitem.path ? 'submenu_item_active' : '']"
|
||||
@mouseenter="mouseenteBotDownr(subindex)" @mouseleave="mouseleaveBotDown">
|
||||
<i v-if="currentSecondpath == subitem.path" class="dot"></i>
|
||||
<span class="submenu_title"
|
||||
:style="currentSecondpath == subitem.path ? 'margin-left:14px;max-width:160px;' : 'margin-left:18px;max-width:173px;'">
|
||||
{{ subitem.title }}
|
||||
</span>
|
||||
<t-popup v-model:visible="subitem.isMore" @overlay-click="delCard(subindex, subitem)"
|
||||
@visible-change="onVisibleChange" overlayClassName="del-menu-popup" trigger="click"
|
||||
destroy-on-close placement="top-left">
|
||||
<div v-if="(activeSubmenu == subindex) || (currentSecondpath == subitem.path) || subitem.isMore"
|
||||
@click.stop="openMore(subindex)" variant="outline" class="menu-more-wrap">
|
||||
<t-icon name="ellipsis" class="menu-more" />
|
||||
</div>
|
||||
<template #content>
|
||||
<span class="del_submenu">删除记录</span>
|
||||
</template>
|
||||
</t-popup>
|
||||
<template v-for="(group, groupIndex) in groupedSessions" :key="groupIndex">
|
||||
<div class="timeline_header">{{ group.label }}</div>
|
||||
<div class="submenu_item_p" v-for="(subitem, subindex) in group.items" :key="subitem.id">
|
||||
<div :class="['submenu_item', currentSecondpath == subitem.path ? 'submenu_item_active' : '']"
|
||||
@mouseenter="mouseenteBotDownr(subitem.id)" @mouseleave="mouseleaveBotDown"
|
||||
@click="gotopage(subitem.path)">
|
||||
<i v-if="currentSecondpath == subitem.path" class="dot"></i>
|
||||
<span class="submenu_title"
|
||||
:style="currentSecondpath == subitem.path ? 'margin-left:14px;max-width:160px;' : 'margin-left:18px;max-width:173px;'">
|
||||
{{ subitem.title }}
|
||||
</span>
|
||||
<t-dropdown
|
||||
:options="[{ content: '删除记录', value: 'delete' }]"
|
||||
@click="(data) => data.value === 'delete' && delCard(subitem.originalIndex, subitem)"
|
||||
placement="bottom-right"
|
||||
trigger="click">
|
||||
<div @click.stop class="menu-more-wrap">
|
||||
<t-icon name="ellipsis" class="menu-more" />
|
||||
</div>
|
||||
</t-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- 下半部分:用户菜单 -->
|
||||
<div class="menu_bottom">
|
||||
<UserMenu />
|
||||
@@ -114,13 +116,12 @@ const totalPages = computed(() => Math.ceil(total.value / page_size.value));
|
||||
const hasMore = computed(() => currentPage.value < totalPages.value);
|
||||
type MenuItem = { title: string; icon: string; path: string; childrenPath?: string; children?: any[] };
|
||||
const { menuArr } = storeToRefs(usemenuStore);
|
||||
let activeSubmenu = ref<number>(-1);
|
||||
let activeSubmenu = ref<string>('');
|
||||
|
||||
// 是否处于知识库详情页
|
||||
// 是否处于知识库详情页(不包括全局聊天)
|
||||
const isInKnowledgeBase = computed<boolean>(() => {
|
||||
return route.name === 'knowledgeBaseDetail' ||
|
||||
route.name === 'kbCreatChat' ||
|
||||
route.name === 'chat' ||
|
||||
route.name === 'knowledgeBaseSettings';
|
||||
});
|
||||
|
||||
@@ -187,6 +188,70 @@ const initializedKnowledgeBases = computed(() => {
|
||||
)
|
||||
})
|
||||
|
||||
// 时间分组函数
|
||||
const getTimeCategory = (dateStr: string): string => {
|
||||
if (!dateStr) return '更早';
|
||||
|
||||
const date = new Date(dateStr);
|
||||
const now = new Date();
|
||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
||||
const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000);
|
||||
const sevenDaysAgo = new Date(today.getTime() - 7 * 24 * 60 * 60 * 1000);
|
||||
const thirtyDaysAgo = new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000);
|
||||
const oneYearAgo = new Date(today.getTime() - 365 * 24 * 60 * 60 * 1000);
|
||||
|
||||
const sessionDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||
|
||||
if (sessionDate.getTime() >= today.getTime()) {
|
||||
return '今天';
|
||||
} else if (sessionDate.getTime() >= yesterday.getTime()) {
|
||||
return '昨天';
|
||||
} else if (date.getTime() >= sevenDaysAgo.getTime()) {
|
||||
return '近7天';
|
||||
} else if (date.getTime() >= thirtyDaysAgo.getTime()) {
|
||||
return '近30天';
|
||||
} else if (date.getTime() >= oneYearAgo.getTime()) {
|
||||
return '近1年';
|
||||
} else {
|
||||
return '更早';
|
||||
}
|
||||
};
|
||||
|
||||
// 按时间分组Session列表
|
||||
const groupedSessions = computed(() => {
|
||||
const chatMenu = (menuArr.value as unknown as MenuItem[]).find((item: MenuItem) => item.path === 'creatChat');
|
||||
if (!chatMenu || !chatMenu.children || chatMenu.children.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const groups: { [key: string]: any[] } = {
|
||||
'今天': [],
|
||||
'昨天': [],
|
||||
'近7天': [],
|
||||
'近30天': [],
|
||||
'近1年': [],
|
||||
'更早': []
|
||||
};
|
||||
|
||||
// 将sessions按时间分组
|
||||
(chatMenu.children as any[]).forEach((session: any, index: number) => {
|
||||
const category = getTimeCategory(session.updated_at || session.created_at);
|
||||
groups[category].push({
|
||||
...session,
|
||||
originalIndex: index
|
||||
});
|
||||
});
|
||||
|
||||
// 按顺序返回非空分组
|
||||
const orderedLabels = ['今天', '昨天', '近7天', '近30天', '近1年', '更早'];
|
||||
return orderedLabels
|
||||
.filter(label => groups[label].length > 0)
|
||||
.map(label => ({
|
||||
label,
|
||||
items: groups[label]
|
||||
}));
|
||||
});
|
||||
|
||||
// 动态更新知识库菜单项标题
|
||||
const kbMenuItem = computed(() => {
|
||||
const kbItem = topMenuItems.value.find(item => item.path === 'knowledge-bases')
|
||||
@@ -282,27 +347,27 @@ const upload = async (e: any) => {
|
||||
uploadInput.value.value = "";
|
||||
}
|
||||
}
|
||||
const mouseenteBotDownr = (val: number) => {
|
||||
const mouseenteBotDownr = (val: string) => {
|
||||
activeSubmenu.value = val;
|
||||
}
|
||||
const mouseleaveBotDown = () => {
|
||||
activeSubmenu.value = -1;
|
||||
}
|
||||
const onVisibleChange = (_e: any) => {
|
||||
activeSubmenu.value = '';
|
||||
}
|
||||
|
||||
const delCard = (index: number, item: any) => {
|
||||
delSession(item.id).then((res: any) => {
|
||||
if (res && (res as any).success) {
|
||||
(menuArr.value as any[])[1]?.children?.splice(index, 1);
|
||||
// 使用 originalIndex 找到正确的位置进行删除
|
||||
const actualIndex = index !== undefined ? index :
|
||||
(menuArr.value as any[])[1]?.children?.findIndex((s: any) => s.id === item.id);
|
||||
|
||||
if (actualIndex !== -1) {
|
||||
(menuArr.value as any[])[1]?.children?.splice(actualIndex, 1);
|
||||
}
|
||||
|
||||
if (item.id == route.params.chatid) {
|
||||
// 删除当前会话后,跳转到当前知识库的创建聊天页面
|
||||
const kbId = route.params.kbId;
|
||||
if (kbId) {
|
||||
router.push(`/platform/knowledge-bases/${kbId}/creatChat`);
|
||||
} else {
|
||||
router.push('/platform/knowledge-bases');
|
||||
}
|
||||
// 删除当前会话后,跳转到全局创建聊天页面
|
||||
router.push('/platform/creatChat');
|
||||
}
|
||||
} else {
|
||||
MessagePlugin.error("删除失败,请稍后再试!");
|
||||
@@ -319,70 +384,89 @@ const debounce = (fn: (...args: any[]) => void, delay: number) => {
|
||||
// 滚动处理
|
||||
const checkScrollBottom = () => {
|
||||
const container = submenuscrollContainer.value
|
||||
if (!container) return
|
||||
if (!container || !container[0]) return
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = container[0]
|
||||
const isBottom = scrollHeight - (scrollTop + clientHeight) < 100 // 触底阈值
|
||||
if (isBottom && hasMore.value) {
|
||||
|
||||
if (isBottom && hasMore.value && !loading.value) {
|
||||
currentPage.value++;
|
||||
getMessageList();
|
||||
getMessageList(true);
|
||||
}
|
||||
}
|
||||
const handleScroll = debounce(checkScrollBottom, 200)
|
||||
const getMessageList = async () => {
|
||||
// 仅在知识库内部显示对话列表
|
||||
if (!isInKnowledgeBase.value) {
|
||||
usemenuStore.clearMenuArr();
|
||||
currentKbName.value = '';
|
||||
return;
|
||||
}
|
||||
const getMessageList = async (isLoadMore = false) => {
|
||||
// 全局显示对话列表(所有有"对话"入口的地方都显示)
|
||||
let kbId = (route.params as any)?.kbId as string
|
||||
// 新的路由格式:/platform/chat/:kbId/:chatid,直接从路由参数获取知识库ID
|
||||
if (!kbId) {
|
||||
usemenuStore.clearMenuArr();
|
||||
|
||||
// 如果在知识库内部,获取知识库名称和所有知识库列表
|
||||
if (kbId && isInKnowledgeBase.value) {
|
||||
try {
|
||||
const [kbRes, allKbRes]: any[] = await Promise.all([
|
||||
getKnowledgeBaseById(kbId),
|
||||
listKnowledgeBases()
|
||||
])
|
||||
if (kbRes?.data?.name) {
|
||||
currentKbName.value = kbRes.data.name
|
||||
}
|
||||
if (allKbRes?.data) {
|
||||
allKnowledgeBases.value = allKbRes.data
|
||||
}
|
||||
} catch {}
|
||||
} else {
|
||||
// 不在知识库内部时,清空知识库名称
|
||||
currentKbName.value = '';
|
||||
return;
|
||||
// 不在知识库列表页时才调用API(避免与页面组件KnowledgeBaseList.vue重复调用)
|
||||
// 知识库列表页会自己调用listKnowledgeBases来显示列表
|
||||
if (route.name !== 'knowledgeBaseList') {
|
||||
try {
|
||||
const allKbRes: any = await listKnowledgeBases()
|
||||
if (allKbRes?.data) {
|
||||
allKnowledgeBases.value = allKbRes.data
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取知识库名称和所有知识库列表
|
||||
try {
|
||||
const [kbRes, allKbRes]: any[] = await Promise.all([
|
||||
getKnowledgeBaseById(kbId),
|
||||
listKnowledgeBases()
|
||||
])
|
||||
if (kbRes?.data?.name) {
|
||||
currentKbName.value = kbRes.data.name
|
||||
}
|
||||
if (allKbRes?.data) {
|
||||
allKnowledgeBases.value = allKbRes.data
|
||||
}
|
||||
} catch {}
|
||||
|
||||
if (loading.value) return;
|
||||
if (loading.value) return Promise.resolve();
|
||||
loading.value = true;
|
||||
usemenuStore.clearMenuArr();
|
||||
getSessionsList(currentPage.value, page_size.value).then((res: any) => {
|
||||
|
||||
// 只有在首次加载或路由变化时才清空数组,滚动加载时不清空
|
||||
if (!isLoadMore) {
|
||||
currentPage.value = 1; // 重置页码
|
||||
usemenuStore.clearMenuArr();
|
||||
}
|
||||
|
||||
return getSessionsList(currentPage.value, page_size.value).then((res: any) => {
|
||||
if (res.data && res.data.length) {
|
||||
// 过滤出当前知识库的会话
|
||||
const filtered = res.data.filter((s: any) => s.knowledge_base_id === kbId)
|
||||
filtered.forEach((item: any) => {
|
||||
let obj = { title: item.title ? item.title : "新会话", path: `chat/${kbId}/${item.id}`, id: item.id, isMore: false, isNoTitle: item.title ? false : true }
|
||||
// Display all sessions globally without filtering
|
||||
res.data.forEach((item: any) => {
|
||||
let obj = {
|
||||
title: item.title ? item.title : "新会话",
|
||||
path: `chat/${item.id}`,
|
||||
id: item.id,
|
||||
isMore: false,
|
||||
isNoTitle: item.title ? false : true,
|
||||
created_at: item.created_at,
|
||||
updated_at: item.updated_at
|
||||
}
|
||||
usemenuStore.updatemenuArr(obj)
|
||||
});
|
||||
loading.value = false;
|
||||
}
|
||||
if ((res as any).total) {
|
||||
total.value = (res as any).total;
|
||||
}
|
||||
loading.value = false;
|
||||
}).catch(() => {
|
||||
loading.value = false;
|
||||
})
|
||||
}
|
||||
|
||||
const openMore = (_e: any) => { }
|
||||
onMounted(() => {
|
||||
const routeName = typeof route.name === 'string' ? route.name : (route.name ? String(route.name) : '')
|
||||
currentpath.value = routeName;
|
||||
if (route.params.chatid && route.params.kbId) {
|
||||
currentSecondpath.value = `chat/${route.params.kbId}/${route.params.chatid}`;
|
||||
if (route.params.chatid) {
|
||||
currentSecondpath.value = `chat/${route.params.chatid}`;
|
||||
}
|
||||
getMessageList();
|
||||
});
|
||||
@@ -390,12 +474,12 @@ onMounted(() => {
|
||||
watch([() => route.name, () => route.params], (newvalue) => {
|
||||
const nameStr = typeof newvalue[0] === 'string' ? (newvalue[0] as string) : (newvalue[0] ? String(newvalue[0]) : '')
|
||||
currentpath.value = nameStr;
|
||||
if (newvalue[1].chatid && newvalue[1].kbId) {
|
||||
currentSecondpath.value = `chat/${newvalue[1].kbId}/${newvalue[1].chatid}`;
|
||||
if (newvalue[1].chatid) {
|
||||
currentSecondpath.value = `chat/${newvalue[1].chatid}`;
|
||||
} else {
|
||||
currentSecondpath.value = "";
|
||||
}
|
||||
// 路由变化时刷新对话列表(仅在知识库内部)
|
||||
// 路由变化时刷新对话列表
|
||||
getMessageList();
|
||||
// 路由变化时更新图标状态
|
||||
getIcon(nameStr);
|
||||
@@ -553,11 +637,6 @@ watch(() => route.params.kbId, () => {
|
||||
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.del_submenu {
|
||||
color: #fa5151;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.aside_box {
|
||||
min-width: 260px;
|
||||
padding: 8px;
|
||||
@@ -733,10 +812,25 @@ watch(() => route.params.kbId, () => {
|
||||
min-height: 0;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.timeline_header {
|
||||
font-family: "PingFang SC";
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: #00000066;
|
||||
padding: 12px 18px 6px 18px;
|
||||
margin-top: 8px;
|
||||
line-height: 20px;
|
||||
user-select: none;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.submenu_item_p {
|
||||
height: 44px;
|
||||
padding: 4px 8px 4px 12px;
|
||||
padding: 4px 8px 4px 0px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
@@ -749,7 +843,7 @@ watch(() => route.params.kbId, () => {
|
||||
font-weight: 400;
|
||||
line-height: 22px;
|
||||
height: 36px;
|
||||
padding-left: 18px;
|
||||
padding-left: 0px;
|
||||
padding-right: 14px;
|
||||
position: relative;
|
||||
|
||||
@@ -761,6 +855,8 @@ watch(() => route.params.kbId, () => {
|
||||
|
||||
.menu-more-wrap {
|
||||
margin-left: auto;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
}
|
||||
|
||||
.menu-more {
|
||||
@@ -789,6 +885,10 @@ watch(() => route.params.kbId, () => {
|
||||
color: #00000099;
|
||||
}
|
||||
|
||||
.menu-more-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.submenu_title {
|
||||
max-width: 160px !important;
|
||||
|
||||
@@ -804,6 +904,14 @@ watch(() => route.params.kbId, () => {
|
||||
.menu-more {
|
||||
color: #07c05f !important;
|
||||
}
|
||||
|
||||
.menu-more-wrap {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.submenu_title {
|
||||
max-width: 160px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -908,19 +1016,6 @@ watch(() => route.params.kbId, () => {
|
||||
}
|
||||
}
|
||||
|
||||
.del-menu-popup {
|
||||
z-index: 99 !important;
|
||||
|
||||
.t-popup__content {
|
||||
width: 100px;
|
||||
height: 40px;
|
||||
line-height: 30px;
|
||||
padding-left: 14px;
|
||||
cursor: pointer;
|
||||
margin-top: 4px !important;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 退出登录确认框样式
|
||||
:deep(.t-popconfirm) {
|
||||
|
||||
@@ -71,7 +71,7 @@ const router = createRouter({
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: "chat/:kbId/:chatid",
|
||||
path: "chat/:chatid",
|
||||
name: "chat",
|
||||
component: () => import("../views/chat/index.vue"),
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
|
||||
@@ -25,7 +25,11 @@ export const useMenuStore = defineStore('menuStore', {
|
||||
this.menuArr[1].children = reactive<object[]>([]);
|
||||
},
|
||||
updatemenuArr(obj: any) {
|
||||
this.menuArr[1].children?.push(obj);
|
||||
// 检查是否已存在相同 ID 的 session,避免重复添加
|
||||
const exists = this.menuArr[1].children?.some((item: any) => item.id === obj.id);
|
||||
if (!exists) {
|
||||
this.menuArr[1].children?.push(obj);
|
||||
}
|
||||
},
|
||||
updataMenuChildren(item: object) {
|
||||
this.menuArr[1].children?.unshift(item)
|
||||
|
||||
@@ -3,7 +3,8 @@ import { defineStore } from 'pinia'
|
||||
export const useUIStore = defineStore('ui', {
|
||||
state: () => ({
|
||||
showSettingsModal: false,
|
||||
showKBSettingsModal: false,
|
||||
showKBEditorModal: false,
|
||||
kbEditorMode: 'create' as 'create' | 'edit',
|
||||
currentKBId: null as string | null,
|
||||
settingsInitialSection: null as string | null,
|
||||
settingsInitialSubSection: null as string | null
|
||||
@@ -28,11 +29,18 @@ export const useUIStore = defineStore('ui', {
|
||||
|
||||
openKBSettings(kbId: string) {
|
||||
this.currentKBId = kbId
|
||||
this.showKBSettingsModal = true
|
||||
this.kbEditorMode = 'edit'
|
||||
this.showKBEditorModal = true
|
||||
},
|
||||
|
||||
closeKBSettings() {
|
||||
this.showKBSettingsModal = false
|
||||
openCreateKB() {
|
||||
this.currentKBId = null
|
||||
this.kbEditorMode = 'create'
|
||||
this.showKBEditorModal = true
|
||||
},
|
||||
|
||||
closeKBEditor() {
|
||||
this.showKBEditorModal = false
|
||||
this.currentKBId = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
<div v-if="event.type === 'thinking'" class="thinking-event">
|
||||
<div
|
||||
class="thinking-phase"
|
||||
:class="{ 'thinking-active': event.thinking }"
|
||||
:class="{
|
||||
'thinking-active': event.thinking,
|
||||
'thinking-last': isLastThinking(event.event_id)
|
||||
}"
|
||||
>
|
||||
<div v-if="event.content"
|
||||
class="thinking-content markdown-content"
|
||||
@@ -136,6 +139,26 @@ const expandedEvents = ref<Set<string>>(new Set());
|
||||
// State for intermediate steps collapse
|
||||
const showIntermediateSteps = ref(false);
|
||||
|
||||
// Find the last thinking event in the current message's event stream
|
||||
// Only the last thinking should have the green border-left
|
||||
const lastThinkingEventId = computed(() => {
|
||||
const stream = eventStream.value;
|
||||
if (!stream || stream.length === 0) return null;
|
||||
|
||||
// Find all thinking events
|
||||
const thinkingEvents = stream.filter((e: any) => e.type === 'thinking');
|
||||
if (thinkingEvents.length === 0) return null;
|
||||
|
||||
// Return the event_id of the last thinking event
|
||||
const lastThinking = thinkingEvents[thinkingEvents.length - 1];
|
||||
return lastThinking.event_id;
|
||||
});
|
||||
|
||||
// Check if a thinking event is the last one (should have green border)
|
||||
const isLastThinking = (eventId: string): boolean => {
|
||||
return eventId === lastThinkingEventId.value;
|
||||
};
|
||||
|
||||
// Check if conversation is done (based on answer event with done=true)
|
||||
const isConversationDone = computed(() => {
|
||||
const stream = eventStream.value;
|
||||
@@ -498,10 +521,18 @@ const formatJSON = (obj: any): string => {
|
||||
background: #ffffff;
|
||||
border-radius: 8px;
|
||||
padding: 1px 14px;
|
||||
border-left: 3px solid #d1d5db;
|
||||
// 默认不显示 border-left
|
||||
border-left: 3px solid transparent;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
// 只有最后一个 thinking 显示绿色 border-left
|
||||
&.thinking-last {
|
||||
border-left-color: #07c05f;
|
||||
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
|
||||
}
|
||||
|
||||
// 进行中的 thinking(实时对话)显示绿色 border-left 和动画
|
||||
&.thinking-active {
|
||||
border-left-color: #07c05f;
|
||||
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<AgentStreamDisplay :session="session" v-if="session.isAgentMode"></AgentStreamDisplay>
|
||||
<deepThink :deepSession="session" v-if="session.showThink && !session.isAgentMode"></deepThink>
|
||||
</div>
|
||||
<div ref="parentMd">
|
||||
<div ref="parentMd" v-if="!session.hideContent">
|
||||
<!-- 消息正在总结中则渲染加载gif -->
|
||||
<img v-if="session.thinking" class="botanswer_laoding_gif" src="@/assets/img/botanswer_loading.gif"
|
||||
alt="正在总结答案……">
|
||||
@@ -212,11 +212,11 @@ onMounted(async () => {
|
||||
}
|
||||
|
||||
.bot_msg {
|
||||
background: #fff;
|
||||
// background: #fff;
|
||||
border-radius: 4px;
|
||||
color: rgba(0, 0, 0, 0.9);
|
||||
font-size: 16px;
|
||||
padding: 10px 12px;
|
||||
// padding: 10px 12px;
|
||||
margin-right: auto;
|
||||
max-width: 100%;
|
||||
box-sizing: border-box;
|
||||
|
||||
@@ -29,10 +29,11 @@ import { useRoute, useRouter, onBeforeRouteLeave, onBeforeRouteUpdate } from 'vu
|
||||
import InputField from '../../components/Input-field.vue';
|
||||
import botmsg from './components/botmsg.vue';
|
||||
import usermsg from './components/usermsg.vue';
|
||||
import { getMessageList, generateSessionsTitle } from "@/api/chat/index";
|
||||
import { getMessageList, generateSessionsTitle, getSession } from "@/api/chat/index";
|
||||
import { useStream } from '../../api/chat/streame'
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { MessagePlugin } from 'tdesign-vue-next';
|
||||
const usemenuStore = useMenuStore();
|
||||
const useSettingsStoreInstance = useSettingsStore();
|
||||
const { menuArr, isFirstSession, firstQuery } = storeToRefs(usemenuStore);
|
||||
@@ -40,7 +41,7 @@ const { output, onChunk, isStreaming, isLoading, error, startStream, stopStream
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const session_id = ref(route.params.chatid);
|
||||
const knowledge_base_id = ref(route.params.kbId);
|
||||
const sessionData = ref(null);
|
||||
const created_at = ref('');
|
||||
const limit = ref(20);
|
||||
const messagesList = reactive([]);
|
||||
@@ -60,7 +61,6 @@ watch([() => route.params], (newvalue) => {
|
||||
}
|
||||
messagesList.splice(0);
|
||||
session_id.value = newvalue[0].chatid;
|
||||
knowledge_base_id.value = newvalue[0].kbId;
|
||||
checkmenuTitle(session_id.value)
|
||||
let data = {
|
||||
session_id: session_id.value,
|
||||
@@ -107,6 +107,59 @@ const getmsgList = (data, isScrollType = false, scrollHeight) => {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Reconstruct agentEventStream from agent_steps stored in database
|
||||
// This allows the frontend to restore the exact conversation state including all agent reasoning steps
|
||||
const reconstructEventStreamFromSteps = (agentSteps) => {
|
||||
if (!agentSteps || !Array.isArray(agentSteps) || agentSteps.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const events = [];
|
||||
|
||||
agentSteps.forEach((step) => {
|
||||
// Add thinking event if thought content exists
|
||||
if (step.thought && step.thought.trim()) {
|
||||
events.push({
|
||||
type: 'thinking',
|
||||
event_id: `step-${step.iteration}-thought`,
|
||||
content: step.thought,
|
||||
done: true,
|
||||
thinking: false,
|
||||
});
|
||||
}
|
||||
|
||||
// Add tool call and result events
|
||||
if (step.tool_calls && Array.isArray(step.tool_calls)) {
|
||||
step.tool_calls.forEach((toolCall) => {
|
||||
events.push({
|
||||
type: 'tool_call',
|
||||
tool_call_id: toolCall.id,
|
||||
tool_name: toolCall.name,
|
||||
arguments: toolCall.args,
|
||||
pending: false,
|
||||
success: toolCall.result?.success !== false,
|
||||
output: toolCall.result?.output || '',
|
||||
error: toolCall.result?.error || undefined,
|
||||
duration: toolCall.duration,
|
||||
display_type: toolCall.result?.data?.display_type,
|
||||
tool_data: toolCall.result?.data,
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// 添加一个完成标记的 answer 事件,触发折叠逻辑
|
||||
if (events.length > 0) {
|
||||
events.push({
|
||||
type: 'answer',
|
||||
content: '', // 空内容,因为最终答案会在 message.content 中
|
||||
done: true
|
||||
});
|
||||
}
|
||||
|
||||
return events;
|
||||
};
|
||||
const handleMsgList = async (data, isScrollType = false, newScrollHeight) => {
|
||||
let chatlist = data.reverse()
|
||||
for (let i = 0, len = chatlist.length; i < len; i++) {
|
||||
@@ -116,6 +169,17 @@ const handleMsgList = async (data, isScrollType = false, newScrollHeight) => {
|
||||
item._eventMap = new Map();
|
||||
item._pendingToolCalls = new Map();
|
||||
|
||||
// Check if this message has agent_steps from database (historical agent conversation)
|
||||
// If so, reconstruct the agentEventStream to restore the exact conversation state
|
||||
if (item.agent_steps && Array.isArray(item.agent_steps) && item.agent_steps.length > 0) {
|
||||
console.log('[Message Load] Reconstructing agent steps for message:', item.id, 'steps:', item.agent_steps.length);
|
||||
item.isAgentMode = true;
|
||||
item.agentEventStream = reconstructEventStreamFromSteps(item.agent_steps);
|
||||
// 隐藏最终答案内容,用户可以通过展开步骤查看完整过程
|
||||
item.hideContent = true;
|
||||
console.log('[Message Load] Reconstructed', item.agentEventStream.length, 'events from agent steps');
|
||||
}
|
||||
|
||||
if (item.content) {
|
||||
if (!item.content.includes('<think>') && !item.content.includes('<\/think>')) {
|
||||
item.thinkContent = "";
|
||||
@@ -163,19 +227,42 @@ const sendMsg = async (value) => {
|
||||
messagesList.push({ content: value, role: 'user' });
|
||||
scrollToBottom();
|
||||
|
||||
// 判断是否使用 Agent 模式
|
||||
const isAgentMode = useSettingsStoreInstance.isAgentEnabled;
|
||||
const chatUrl = isAgentMode ? '/api/v1/agent-chat' : '/api/v1/knowledge-chat';
|
||||
// Always use agent mode with unified architecture
|
||||
// Get knowledge_base_ids from session's agent_config.knowledge_bases to update SessionAgentConfig
|
||||
let kbIds = [];
|
||||
if (sessionData.value?.agent_config?.knowledge_bases?.length > 0) {
|
||||
kbIds = sessionData.value.agent_config.knowledge_bases;
|
||||
}
|
||||
|
||||
// Validate knowledge_base_ids before sending
|
||||
if (kbIds.length === 0) {
|
||||
MessagePlugin.warning('请至少选择一个知识库');
|
||||
isReplying.value = false;
|
||||
loading.value = false;
|
||||
// Remove the user message that was just added
|
||||
messagesList.pop();
|
||||
return;
|
||||
}
|
||||
|
||||
await startStream({
|
||||
session_id: session_id.value,
|
||||
knowledge_base_id: knowledge_base_id.value,
|
||||
knowledge_base_ids: kbIds,
|
||||
agent_enabled: true,
|
||||
query: value,
|
||||
method: 'POST',
|
||||
url: chatUrl
|
||||
url: '/api/v1/agent-chat'
|
||||
});
|
||||
}
|
||||
|
||||
// Watch for stream errors and show message
|
||||
watch(error, (newError) => {
|
||||
if (newError) {
|
||||
MessagePlugin.error(newError);
|
||||
isReplying.value = false;
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 处理流式数据
|
||||
onChunk((data) => {
|
||||
loading.value = false;
|
||||
@@ -190,6 +277,33 @@ onChunk((data) => {
|
||||
data: data.data
|
||||
});
|
||||
|
||||
// 处理 agent query 事件 - 确保显示 loading 状态
|
||||
if (data.response_type === 'agent_query') {
|
||||
console.log('[Agent Query Event]', {
|
||||
session_id: data.data?.session_id,
|
||||
query: data.data?.query,
|
||||
request_id: data.data?.request_id
|
||||
});
|
||||
// Loading state is already set in sendMsg, but ensure it's true
|
||||
loading.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 处理会话标题更新事件
|
||||
if (data.response_type === 'session_title') {
|
||||
const title = data.content || data.data?.title;
|
||||
if (title && data.data?.session_id) {
|
||||
console.log('[Session Title Update]', {
|
||||
session_id: data.data.session_id,
|
||||
title: title
|
||||
});
|
||||
usemenuStore.updatasessionTitle(data.data.session_id, title);
|
||||
usemenuStore.changeIsFirstSession(false);
|
||||
isNeedTitle.value = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断是否是 Agent 模式的响应
|
||||
const isAgentResponse = data.response_type === 'thinking' ||
|
||||
data.response_type === 'tool_call' ||
|
||||
@@ -220,17 +334,8 @@ onChunk((data) => {
|
||||
obj.content = fullContent.value;
|
||||
}
|
||||
if (data.done) {
|
||||
if (isFirstSession.value || isNeedTitle.value) {
|
||||
generateSessionsTitle(session_id.value, {
|
||||
messages: [{ role: "user", content: userquery.value }]
|
||||
}).then(res => {
|
||||
if (res.data) {
|
||||
usemenuStore.changeIsFirstSession(false);
|
||||
usemenuStore.updatasessionTitle(session_id.value, res.data);
|
||||
isNeedTitle.value = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
// 标题生成已改为异步事件推送,不再需要在这里手动调用
|
||||
// 如果标题还未生成,前端会通过 SSE 事件接收
|
||||
isReplying.value = false;
|
||||
fullContent.value = "";
|
||||
}
|
||||
@@ -444,18 +549,8 @@ const handleAgentChunk = (data) => {
|
||||
isReplying.value = false;
|
||||
fullContent.value = '';
|
||||
|
||||
// 生成标题
|
||||
if (isFirstSession.value || isNeedTitle.value) {
|
||||
generateSessionsTitle(session_id.value, {
|
||||
messages: [{ role: "user", content: userquery.value }]
|
||||
}).then(res => {
|
||||
if (res.data) {
|
||||
usemenuStore.changeIsFirstSession(false);
|
||||
usemenuStore.updatasessionTitle(session_id.value, res.data);
|
||||
isNeedTitle.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
// 标题生成已改为异步事件推送,不再需要在这里手动调用
|
||||
// 如果标题还未生成,前端会通过 SSE 事件接收
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -481,13 +576,19 @@ const updateAssistantSession = (payload) => {
|
||||
}
|
||||
scrollToBottom();
|
||||
}
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
messagesList.splice(0);
|
||||
// scrollContainer.value.addEventListener("scroll", () => {
|
||||
// if (scrollContainer.value.scrollTop == 0) {
|
||||
// onChatScrollTop();
|
||||
// }
|
||||
// });
|
||||
|
||||
// Load session data to get agent_config
|
||||
try {
|
||||
const sessionRes = await getSession(session_id.value);
|
||||
if (sessionRes?.data) {
|
||||
sessionData.value = sessionRes.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load session data:', error);
|
||||
}
|
||||
|
||||
checkmenuTitle(session_id.value)
|
||||
if (firstQuery.value) {
|
||||
scrollLock.value = true;
|
||||
@@ -546,7 +647,6 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
max-width: 800px;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 0;
|
||||
@@ -586,6 +686,8 @@ onBeforeRouteUpdate((to, from, next) => {
|
||||
gap: 16px;
|
||||
max-width: 800px;
|
||||
flex: 1;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
|
||||
.botanswer_laoding_gif {
|
||||
width: 24px;
|
||||
|
||||
@@ -50,7 +50,7 @@ async function createNewSession(value: string) {
|
||||
try {
|
||||
const res = await createSessions(sessionData);
|
||||
if (res.data && res.data.id) {
|
||||
await navigateToSession(res.data.id, value, selectedKbs[0]);
|
||||
await navigateToSession(res.data.id, value);
|
||||
} else {
|
||||
console.error("创建会话失败");
|
||||
MessagePlugin.error("创建会话失败");
|
||||
@@ -61,18 +61,21 @@ async function createNewSession(value: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const navigateToSession = async (sessionId: string, value: string, kbId: string) => {
|
||||
const navigateToSession = async (sessionId: string, value: string) => {
|
||||
const now = new Date().toISOString();
|
||||
let obj = {
|
||||
title: '新会话',
|
||||
path: `chat/${kbId}/${sessionId}`,
|
||||
path: `chat/${sessionId}`,
|
||||
id: sessionId,
|
||||
isMore: false,
|
||||
isNoTitle: true
|
||||
isNoTitle: true,
|
||||
created_at: now,
|
||||
updated_at: now
|
||||
};
|
||||
usemenuStore.updataMenuChildren(obj);
|
||||
usemenuStore.changeIsFirstSession(true);
|
||||
usemenuStore.changeFirstQuery(value);
|
||||
router.push(`/platform/chat/${kbId}/${sessionId}`);
|
||||
router.push(`/platform/chat/${sessionId}`);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -243,11 +243,12 @@ onUnmounted(() => {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1000;
|
||||
background: transparent;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 20px;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
/* 弹窗容器 */
|
||||
|
||||
Reference in New Issue
Block a user