feat: Enhance FAQ import functionality and UI improvements
- Added support for tracking the status of FAQ import tasks, including progress indicators for ongoing imports. - Introduced new localization strings for processing tasks and batch operations in multiple languages. - Updated the FAQ entry manager to display import progress and improved user feedback during the import process. - Enhanced the KnowledgeBase component to reflect the processing state of knowledge items, improving user experience during document uploads. - Implemented batch deletion functionality for chunks, streamlining the management of knowledge base content.
This commit is contained in:
@@ -85,6 +85,37 @@
|
||||
<span class="kb-action-title">{{ t('knowledgeEditor.faqImport.importButton') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="menu_item kb-action-item" @click.stop="handleFaqSearchTestFromMenu">
|
||||
<div class="kb-action-icon-wrapper">
|
||||
<svg class="kb-action-icon" width="18" height="18" viewBox="0 0 18 18" fill="none">
|
||||
<path d="M8.25 15C11.9779 15 15 11.9779 15 8.25C15 4.52208 11.9779 1.5 8.25 1.5C4.52208 1.5 1.5 4.52208 1.5 8.25C1.5 11.9779 4.52208 15 8.25 15Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M16.5 16.5L12.4875 12.4875" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="kb-action-content">
|
||||
<span class="kb-action-title">{{ t('knowledgeEditor.faq.searchTest') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<t-dropdown
|
||||
v-if="selectedFaqCount > 0"
|
||||
:options="faqBatchActionOptions"
|
||||
trigger="hover"
|
||||
placement="right"
|
||||
@click="handleFaqBatchActionFromMenu"
|
||||
>
|
||||
<div class="menu_item kb-action-item">
|
||||
<div class="kb-action-icon-wrapper">
|
||||
<svg class="kb-action-icon" width="18" height="18" viewBox="0 0 18 18" fill="none">
|
||||
<path d="M3.75 9H14.25M9 3.75V14.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M3.75 3.75H14.25V14.25H3.75V3.75Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="kb-action-content">
|
||||
<span class="kb-action-title">{{ t('knowledgeEditor.faq.batchOperations') }}</span>
|
||||
<span class="kb-action-count">({{ selectedFaqCount }})</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-dropdown>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
@@ -153,7 +184,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { onMounted, watch, computed, ref, reactive } from 'vue';
|
||||
import { onMounted, onUnmounted, watch, computed, ref, reactive } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getSessionsList, delSession } from "@/api/chat/index";
|
||||
import { getKnowledgeBaseById, uploadKnowledgeFile, createKnowledgeFromURL } from '@/api/knowledge-base';
|
||||
@@ -197,6 +228,11 @@ const isInKnowledgeBaseList = computed<boolean>(() => {
|
||||
return route.name === 'knowledgeBaseList';
|
||||
});
|
||||
|
||||
// 是否在创建聊天页面
|
||||
const isInCreatChat = computed<boolean>(() => {
|
||||
return route.name === 'globalCreatChat' || route.name === 'kbCreatChat';
|
||||
});
|
||||
|
||||
// 统一的菜单项激活状态判断
|
||||
const isMenuItemActive = (itemPath: string): boolean => {
|
||||
const currentRoute = route.name;
|
||||
@@ -234,7 +270,7 @@ const getIconActiveState = (itemPath: string) => {
|
||||
// 分离上下两部分菜单
|
||||
const topMenuItems = computed<MenuItem[]>(() => {
|
||||
return (menuArr.value as unknown as MenuItem[]).filter((item: MenuItem) =>
|
||||
item.path === 'creatChat'
|
||||
item.path === 'knowledge-bases' || item.path === 'creatChat'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -253,12 +289,23 @@ const currentKbInfo = ref<any>(null)
|
||||
const docUploadInput = ref<HTMLInputElement | null>(null)
|
||||
const docFolderInput = ref<HTMLInputElement | null>(null)
|
||||
const pendingUploadKbId = ref<string | null>(null)
|
||||
const selectedFaqCount = ref<number>(0)
|
||||
const selectedFaqEnabledCount = ref<number>(0)
|
||||
const selectedFaqDisabledCount = ref<number>(0)
|
||||
|
||||
const showKbActions = computed(() => (isInKnowledgeBase.value && !!currentKbInfo.value) || isInKnowledgeBaseList.value)
|
||||
// 监听FAQ选中数量变化
|
||||
const handleFaqSelectionChanged = ((event: CustomEvent<{ count: number; enabledCount?: number; disabledCount?: number }>) => {
|
||||
const count = event.detail?.count || 0
|
||||
selectedFaqCount.value = count
|
||||
selectedFaqEnabledCount.value = event.detail?.enabledCount || 0
|
||||
selectedFaqDisabledCount.value = event.detail?.disabledCount || 0
|
||||
}) as EventListener
|
||||
|
||||
const showKbActions = computed(() => (isInKnowledgeBase.value && !!currentKbInfo.value) || isInKnowledgeBaseList.value || isInCreatChat.value)
|
||||
const currentKbType = computed(() => currentKbInfo.value?.type || 'document')
|
||||
const showDocActions = computed(() => showKbActions.value && isInKnowledgeBase.value && currentKbType.value !== 'faq')
|
||||
const showFaqActions = computed(() => showKbActions.value && isInKnowledgeBase.value && currentKbType.value === 'faq')
|
||||
const showCreateKbAction = computed(() => showKbActions.value && isInKnowledgeBaseList.value)
|
||||
const showCreateKbAction = computed(() => showKbActions.value && (isInKnowledgeBaseList.value || isInCreatChat.value))
|
||||
|
||||
// 时间分组函数
|
||||
const getTimeCategory = (dateStr: string): string => {
|
||||
@@ -438,9 +485,20 @@ onMounted(async () => {
|
||||
|
||||
// 加载对话列表
|
||||
getMessageList();
|
||||
|
||||
// 监听FAQ选中数量变化
|
||||
window.addEventListener('faqSelectionChanged', handleFaqSelectionChanged)
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('faqSelectionChanged', handleFaqSelectionChanged)
|
||||
})
|
||||
|
||||
watch([() => route.name, () => route.params], (newvalue, oldvalue) => {
|
||||
// 切换知识库时重置选中数量
|
||||
if (newvalue[1].kbId !== oldvalue?.[1]?.kbId) {
|
||||
selectedFaqCount.value = 0
|
||||
}
|
||||
const nameStr = typeof newvalue[0] === 'string' ? (newvalue[0] as string) : (newvalue[0] ? String(newvalue[0]) : '')
|
||||
currentpath.value = nameStr;
|
||||
if (newvalue[1].chatid) {
|
||||
@@ -558,13 +616,11 @@ const gotopage = async (path: string) => {
|
||||
return;
|
||||
} else {
|
||||
if (path === 'creatChat') {
|
||||
// 尝试获取当前知识库ID
|
||||
const kbId = await getCurrentKbId()
|
||||
if (kbId) {
|
||||
// 如果在知识库内部,进入该知识库的对话页
|
||||
router.push(`/platform/knowledge-bases/${kbId}/creatChat`)
|
||||
// 如果在知识库详情页,跳转到全局对话创建页
|
||||
if (isInKnowledgeBase.value) {
|
||||
router.push('/platform/creatChat')
|
||||
} else {
|
||||
// 如果不在知识库内,也进入对话创建页,让用户通过 @ 按钮选择知识库
|
||||
// 如果不在知识库内,进入对话创建页
|
||||
router.push(`/platform/creatChat`)
|
||||
}
|
||||
} else {
|
||||
@@ -938,7 +994,7 @@ const handleDocURLImport = async () => {
|
||||
}))
|
||||
}
|
||||
|
||||
const dispatchFaqMenuAction = (action: 'create' | 'import', kbId: string) => {
|
||||
const dispatchFaqMenuAction = (action: 'create' | 'import' | 'search' | 'batch' | 'batchTag' | 'batchEnable' | 'batchDisable' | 'batchDelete', kbId: string) => {
|
||||
window.dispatchEvent(new CustomEvent('faqMenuAction', {
|
||||
detail: { action, kbId }
|
||||
}))
|
||||
@@ -962,6 +1018,65 @@ const handleFaqImportFromMenu = async () => {
|
||||
dispatchFaqMenuAction('import', kbId)
|
||||
}
|
||||
|
||||
const handleFaqSearchTestFromMenu = async () => {
|
||||
const kbId = await getCurrentKbId()
|
||||
if (!kbId) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.missingId'))
|
||||
return
|
||||
}
|
||||
dispatchFaqMenuAction('search', kbId)
|
||||
}
|
||||
|
||||
const faqBatchActionOptions = computed(() => {
|
||||
if (selectedFaqCount.value === 0) {
|
||||
return []
|
||||
}
|
||||
const options = [
|
||||
{
|
||||
content: `${t('knowledgeEditor.faq.batchUpdateTag')} (${selectedFaqCount.value})`,
|
||||
value: 'batchTag',
|
||||
icon: 'folder'
|
||||
}
|
||||
]
|
||||
|
||||
// 根据选中条目的状态显示批量启用或禁用
|
||||
if (selectedFaqDisabledCount.value > 0) {
|
||||
options.push({
|
||||
content: `${t('knowledgeEditor.faq.batchEnable')} (${selectedFaqDisabledCount.value})`,
|
||||
value: 'batchEnable',
|
||||
icon: 'check-circle',
|
||||
})
|
||||
}
|
||||
if (selectedFaqEnabledCount.value > 0) {
|
||||
options.push({
|
||||
content: `${t('knowledgeEditor.faq.batchDisable')} (${selectedFaqEnabledCount.value})`,
|
||||
value: 'batchDisable',
|
||||
icon: 'close-circle',
|
||||
})
|
||||
}
|
||||
|
||||
options.push({
|
||||
content: `${t('knowledgeEditor.faqImport.deleteSelected')} (${selectedFaqCount.value})`,
|
||||
value: 'batchDelete',
|
||||
icon: 'delete',
|
||||
})
|
||||
|
||||
return options
|
||||
})
|
||||
|
||||
const handleFaqBatchActionFromMenu = async (data: { value: string }) => {
|
||||
const kbId = await getCurrentKbId()
|
||||
if (!kbId) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.messages.missingId'))
|
||||
return
|
||||
}
|
||||
if (selectedFaqCount.value === 0) {
|
||||
MessagePlugin.warning(t('knowledgeEditor.faq.selectEntriesFirst') || '请先选中要操作的FAQ条目')
|
||||
return
|
||||
}
|
||||
dispatchFaqMenuAction(data.value as 'batchTag' | 'batchEnable' | 'batchDisable' | 'batchDelete', kbId)
|
||||
}
|
||||
|
||||
const handleCreateKnowledgeBase = () => {
|
||||
uiStore.openCreateKB()
|
||||
}
|
||||
@@ -1097,6 +1212,9 @@ const handleCreateKnowledgeBase = () => {
|
||||
.kb-action-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.kb-action-title {
|
||||
@@ -1104,10 +1222,21 @@ const handleCreateKnowledgeBase = () => {
|
||||
font-weight: 500;
|
||||
color: #0f172a;
|
||||
transition: color 0.08s ease;
|
||||
display: block;
|
||||
display: inline;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.kb-action-count {
|
||||
font-size: 12px;
|
||||
color: #10b981;
|
||||
font-weight: 600;
|
||||
margin-left: 4px;
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.menu_box {
|
||||
|
||||
@@ -754,6 +754,8 @@ export default {
|
||||
knowledgeGraph: 'Knowledge Graph Enabled',
|
||||
multimodal: 'Multimodal Enabled'
|
||||
},
|
||||
processing: 'Processing import task',
|
||||
processingDocuments: 'Processing {count} documents',
|
||||
stats: {
|
||||
documents: 'Document Count',
|
||||
faqEntries: 'FAQ Entries',
|
||||
@@ -863,6 +865,7 @@ export default {
|
||||
statusEnableSuccess: 'FAQ entry enabled',
|
||||
statusDisableSuccess: 'FAQ entry disabled',
|
||||
statusUpdateFailed: 'Failed to update status',
|
||||
batchOperations: 'Batch Operations',
|
||||
batchUpdateTag: 'Batch Update Category',
|
||||
batchUpdateTagTip: 'Set category for {count} selected entries',
|
||||
batchEnable: 'Batch Enable',
|
||||
@@ -874,7 +877,7 @@ export default {
|
||||
appendMode: 'Append',
|
||||
replaceMode: 'Replace existing entries',
|
||||
fileLabel: 'Select File',
|
||||
fileTip: 'Supports JSON / CSV / Excel with fields standard_question, answers, similar_questions, negative_questions',
|
||||
fileTip: 'Supports JSON / CSV / Excel. CSV/Excel headers: 分类(必填), 问题(必填), 相似问题(选填-多个用##分隔), 反例问题(选填-多个用##分隔), 机器人回答(必填-多个用##分隔), 是否全部回复(选填-默认FALSE), 是否停用(选填-默认FALSE), 是否禁止被推荐(选填-默认False 可被推荐). Also supports old format: standard_question, answers, similar_questions, negative_questions',
|
||||
clickToUpload: 'Click to upload file',
|
||||
dragDropTip: 'or drag and drop file here',
|
||||
importButton: 'Import FAQ',
|
||||
|
||||
@@ -842,6 +842,8 @@ export default {
|
||||
knowledgeGraph: 'Граф знаний включен',
|
||||
multimodal: 'Мультимодальность включена'
|
||||
},
|
||||
processing: 'Обработка задачи импорта',
|
||||
processingDocuments: 'Обработка {count} документов',
|
||||
stats: {
|
||||
documents: 'Количество документов',
|
||||
faqEntries: 'FAQ записи',
|
||||
@@ -951,6 +953,7 @@ export default {
|
||||
statusEnableSuccess: 'Запись FAQ включена',
|
||||
statusDisableSuccess: 'Запись FAQ отключена',
|
||||
statusUpdateFailed: 'Не удалось обновить статус',
|
||||
batchOperations: 'Пакетные операции',
|
||||
batchUpdateTag: 'Пакетное обновление категории',
|
||||
batchUpdateTagTip: 'Установить категорию для {count} выбранных записей',
|
||||
batchEnable: 'Пакетное включение',
|
||||
@@ -962,7 +965,7 @@ export default {
|
||||
appendMode: 'Добавить',
|
||||
replaceMode: 'Заменить существующие записи',
|
||||
fileLabel: 'Выберите файл',
|
||||
fileTip: 'Поддерживаются JSON / CSV / Excel. Поля: standard_question, answers, similar_questions, negative_questions',
|
||||
fileTip: 'Поддерживаются JSON / CSV / Excel. Заголовки CSV/Excel: 分类(必填), 问题(必填), 相似问题(选填-多个用##分隔), 反例问题(选填-多个用##分隔), 机器人回答(必填-多个用##分隔), 是否全部回复(选填-默认FALSE), 是否停用(选填-默认FALSE), 是否禁止被推荐(选填-默认False 可被推荐). Также поддерживается старый формат: standard_question, answers, similar_questions, negative_questions',
|
||||
clickToUpload: 'Нажмите для загрузки файла',
|
||||
dragDropTip: 'или перетащите файл сюда',
|
||||
importButton: 'Импортировать FAQ',
|
||||
|
||||
@@ -1077,6 +1077,8 @@ export default {
|
||||
knowledgeGraph: "已启用知识图谱",
|
||||
multimodal: "已启用多模态",
|
||||
},
|
||||
processing: "正在处理导入任务",
|
||||
processingDocuments: "正在处理 {count} 个文档",
|
||||
stats: {
|
||||
documents: "文档数量",
|
||||
faqEntries: "问答条目",
|
||||
@@ -1190,6 +1192,7 @@ export default {
|
||||
statusEnableSuccess: "FAQ 条目已启用",
|
||||
statusDisableSuccess: "FAQ 条目已禁用",
|
||||
statusUpdateFailed: "更新状态失败",
|
||||
batchOperations: "批量操作",
|
||||
batchUpdateTag: "批量分类",
|
||||
batchUpdateTagTip: "将为 {count} 个选中的条目设置分类",
|
||||
batchEnable: "批量启用",
|
||||
@@ -1201,7 +1204,7 @@ export default {
|
||||
appendMode: "追加导入",
|
||||
replaceMode: "替换现有条目",
|
||||
fileLabel: "选择文件",
|
||||
fileTip: "支持 JSON / CSV / Excel,字段包含 standard_question、answers、similar_questions、negative_questions",
|
||||
fileTip: "支持 JSON / CSV / Excel。CSV/Excel 表头:分类(必填)、问题(必填)、相似问题(选填-多个用##分隔)、反例问题(选填-多个用##分隔)、机器人回答(必填-多个用##分隔)、是否全部回复(选填-默认FALSE)、是否停用(选填-默认FALSE)、是否禁止被推荐(选填-默认False 可被推荐)。也支持旧格式:standard_question、answers、similar_questions、negative_questions",
|
||||
clickToUpload: "点击上传文件",
|
||||
dragDropTip: "或拖拽文件到此处",
|
||||
importButton: "导入 FAQ",
|
||||
|
||||
@@ -207,7 +207,7 @@ export interface GrepChunkItem {
|
||||
// Grep results data
|
||||
export interface GrepResultsData {
|
||||
display_type: 'grep_results';
|
||||
pattern: string;
|
||||
patterns: string[];
|
||||
case_sensitive: boolean;
|
||||
use_regex: boolean;
|
||||
results: GrepChunkItem[];
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
'action-error': event.success === false
|
||||
}"
|
||||
>
|
||||
<div class="action-header" @click="toggleEvent(event.tool_call_id)">
|
||||
<div class="action-header" @click="handleActionHeaderClick(event)" :class="{ 'no-results': !hasResults(event) }">
|
||||
<div class="action-title">
|
||||
<img v-if="event.tool_name && !isBookIcon(event.tool_name)" class="action-title-icon" :src="getToolIcon(event.tool_name)" alt="" />
|
||||
<t-icon v-if="event.tool_name && isBookIcon(event.tool_name)" class="action-title-icon" name="book" />
|
||||
@@ -91,7 +91,7 @@
|
||||
<span class="action-name">{{ getToolTitle(event) }}</span>
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<div v-if="!event.pending" class="action-show-icon">
|
||||
<div v-if="!event.pending && hasResults(event)" class="action-show-icon">
|
||||
<t-icon :name="isEventExpanded(event.tool_call_id) ? 'chevron-up' : 'chevron-down'" />
|
||||
</div>
|
||||
</div>
|
||||
@@ -109,7 +109,7 @@
|
||||
|
||||
<!-- Search Results Summary (Fixed, always visible, outside action-details) -->
|
||||
<div v-if="!event.pending && (event.tool_name === 'search_knowledge' || event.tool_name === 'knowledge_search') && event.tool_data" class="search-results-summary-fixed">
|
||||
<div class="results-summary-text" v-html="getSearchResultsSummary(event.tool_data)"></div>
|
||||
<div class="results-summary-text" v-html="getSearchResultsSummary(event)"></div>
|
||||
</div>
|
||||
|
||||
<!-- Web Search Results Summary (Fixed, always visible, outside action-details) -->
|
||||
@@ -122,7 +122,7 @@
|
||||
<div class="results-summary-text" v-html="getGrepResultsSummary(event.tool_data)"></div>
|
||||
</div>
|
||||
|
||||
<div v-if="isEventExpanded(event.tool_call_id) && !event.pending" class="action-details">
|
||||
<div v-if="isEventExpanded(event.tool_call_id) && !event.pending && hasResults(event)" class="action-details">
|
||||
<!-- Thinking tool: only render markdown thought content -->
|
||||
<template v-if="event.tool_name === 'thinking' && event.tool_data?.thought">
|
||||
<div class="thinking-thought-content">
|
||||
@@ -676,10 +676,45 @@ const toggleEvent = (eventId: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleActionHeaderClick = (event: any) => {
|
||||
if (hasResults(event) && event.tool_call_id) {
|
||||
toggleEvent(event.tool_call_id);
|
||||
}
|
||||
};
|
||||
|
||||
const isEventExpanded = (eventId: string): boolean => {
|
||||
return expandedEvents.value.has(eventId);
|
||||
};
|
||||
|
||||
// Check if search/grep tools have results
|
||||
const hasResults = (event: any): boolean => {
|
||||
if (!event || !event.tool_data) return true; // Default to true for other tools
|
||||
|
||||
const toolName = event.tool_name;
|
||||
|
||||
// For knowledge search tools
|
||||
if (toolName === 'search_knowledge' || toolName === 'knowledge_search') {
|
||||
const count = event.tool_data.results?.length || event.tool_data.count || 0;
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
// For web search tools
|
||||
if (toolName === 'web_search') {
|
||||
const count = event.tool_data.results?.length || event.tool_data.count || 0;
|
||||
return count > 0;
|
||||
}
|
||||
|
||||
// For grep tools
|
||||
if (toolName === 'grep_chunks') {
|
||||
const totalMatches = event.tool_data.total_matches || 0;
|
||||
const resultCount = event.tool_data.result_count || 0;
|
||||
return totalMatches > 0 || resultCount > 0;
|
||||
}
|
||||
|
||||
// For other tools, always allow expansion
|
||||
return true;
|
||||
};
|
||||
|
||||
// Delegated handlers for span-based citation clicks/keyboard
|
||||
const handleCitationActivate = (el: HTMLElement) => {
|
||||
const url = el.getAttribute('data-url');
|
||||
@@ -1215,17 +1250,22 @@ const getToolIcon = (toolName: string): string => {
|
||||
};
|
||||
|
||||
// Get search results summary text (returns HTML with colored numbers)
|
||||
const getSearchResultsSummary = (toolData: any): string => {
|
||||
if (!toolData) return '';
|
||||
const getSearchResultsSummary = (event: any): string => {
|
||||
if (!event || !event.tool_data) return '';
|
||||
|
||||
const toolData = event.tool_data;
|
||||
const count = toolData.results?.length || toolData.count || 0;
|
||||
if (count === 0) return '';
|
||||
if (count === 0) return `未找到匹配的内容`;
|
||||
|
||||
// Build summary text
|
||||
let summary = '';
|
||||
const kbCount = toolData.kb_counts ? Object.keys(toolData.kb_counts).length : 0;
|
||||
if (kbCount > 0) {
|
||||
return `找到 <strong>${count}</strong> 个结果,来自 <strong>${kbCount}</strong> 个知识库`;
|
||||
summary = `找到 <strong>${count}</strong> 个结果,来自 <strong>${kbCount}</strong> 个文件`;
|
||||
} else {
|
||||
summary = `找到 <strong>${count}</strong> 个结果`;
|
||||
}
|
||||
return `找到 <strong>${count}</strong> 个结果`;
|
||||
return summary;
|
||||
};
|
||||
|
||||
// Get web search results summary text
|
||||
@@ -1248,12 +1288,11 @@ const getResultsCount = (toolData: any): number => {
|
||||
const getGrepResultsSummary = (toolData: any): string => {
|
||||
if (!toolData) return '';
|
||||
|
||||
const pattern = toolData.pattern || '';
|
||||
const totalMatches = toolData.total_matches || 0;
|
||||
const resultCount = toolData.result_count || 0;
|
||||
|
||||
if (totalMatches === 0) {
|
||||
return `未找到匹配 <code>${pattern}</code> 的内容`;
|
||||
return '未找到匹配的内容';
|
||||
}
|
||||
|
||||
let summary = `找到 <strong>${totalMatches}</strong> 处匹配`;
|
||||
@@ -1288,28 +1327,15 @@ const getQueryText = (args: any): string => {
|
||||
}
|
||||
|
||||
// Add vector_queries if exists
|
||||
if (Array.isArray(parsedArgs.vector_queries) && parsedArgs.vector_queries.length > 0) {
|
||||
const vectorQueries = parsedArgs.vector_queries
|
||||
if (Array.isArray(parsedArgs.queries) && parsedArgs.queries.length > 0) {
|
||||
queries.push(...parsedArgs.queries
|
||||
.filter((q: any) => q && typeof q === 'string')
|
||||
.join(' ');
|
||||
if (vectorQueries) {
|
||||
queries.push(vectorQueries);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Add keyword_queries if exists
|
||||
if (Array.isArray(parsedArgs.keyword_queries) && parsedArgs.keyword_queries.length > 0) {
|
||||
const keywordQueries = parsedArgs.keyword_queries
|
||||
.filter((q: any) => q && typeof q === 'string')
|
||||
.join(' ');
|
||||
if (keywordQueries) {
|
||||
queries.push(keywordQueries);
|
||||
}
|
||||
}
|
||||
|
||||
// Join all queries with space and remove duplicates
|
||||
// Join all queries with comma and remove duplicates
|
||||
const uniqueQueries = Array.from(new Set(queries));
|
||||
return uniqueQueries.join(' ');
|
||||
return uniqueQueries.join(',');
|
||||
};
|
||||
|
||||
// Get tool title - prefer summary over description, add query for search tools
|
||||
@@ -1322,6 +1348,7 @@ const getToolTitle = (event: any): string => {
|
||||
const toolName = event.tool_name;
|
||||
const isSearchTool = toolName === 'search_knowledge' || toolName === 'knowledge_search';
|
||||
const isWebSearchTool = toolName === 'web_search';
|
||||
const isGrepTool = toolName === 'grep_chunks';
|
||||
|
||||
// For search tools, use description with query text
|
||||
if (isSearchTool) {
|
||||
@@ -1341,9 +1368,21 @@ const getToolTitle = (event: any): string => {
|
||||
// Try to get query from arguments or tool_data
|
||||
let queryText = '';
|
||||
if (event.arguments && typeof event.arguments === 'object' && event.arguments.query) {
|
||||
queryText = event.arguments.query;
|
||||
const query = event.arguments.query;
|
||||
// Handle both string and array formats
|
||||
if (Array.isArray(query)) {
|
||||
queryText = query.filter((q: any) => q && typeof q === 'string').join(',');
|
||||
} else if (typeof query === 'string') {
|
||||
queryText = query;
|
||||
}
|
||||
} else if (event.tool_data && event.tool_data.query) {
|
||||
queryText = event.tool_data.query;
|
||||
const query = event.tool_data.query;
|
||||
// Handle both string and array formats
|
||||
if (Array.isArray(query)) {
|
||||
queryText = query.filter((q: any) => q && typeof q === 'string').join(',');
|
||||
} else if (typeof query === 'string') {
|
||||
queryText = query;
|
||||
}
|
||||
}
|
||||
if (queryText) {
|
||||
return `${baseTitle}:「${queryText}」`;
|
||||
@@ -1351,6 +1390,34 @@ const getToolTitle = (event: any): string => {
|
||||
return baseTitle;
|
||||
}
|
||||
|
||||
// For grep tools, use description with patterns
|
||||
if (isGrepTool) {
|
||||
const baseTitle = getToolDescription(event);
|
||||
// Try to get patterns from arguments or tool_data
|
||||
let patterns: string[] = [];
|
||||
if (event.arguments && typeof event.arguments === 'object') {
|
||||
if (Array.isArray(event.arguments.patterns)) {
|
||||
patterns = event.arguments.patterns;
|
||||
} else if (event.arguments.pattern) {
|
||||
patterns = [event.arguments.pattern];
|
||||
}
|
||||
} else if (event.tool_data) {
|
||||
if (Array.isArray(event.tool_data.patterns)) {
|
||||
patterns = event.tool_data.patterns;
|
||||
} else if (event.tool_data.pattern) {
|
||||
patterns = [event.tool_data.pattern];
|
||||
}
|
||||
}
|
||||
if (patterns.length > 0) {
|
||||
// Show up to 2 patterns in title
|
||||
const displayPatterns = patterns.slice(0, 2);
|
||||
const patternText = displayPatterns.join('、');
|
||||
const moreText = patterns.length > 2 ? ` +${patterns.length - 2}` : '';
|
||||
return `${baseTitle}:「${patternText}${moreText}」`;
|
||||
}
|
||||
return baseTitle;
|
||||
}
|
||||
|
||||
// Use tool summary if available
|
||||
const summary = getToolSummary(event);
|
||||
return summary || getToolDescription(event);
|
||||
@@ -1514,80 +1581,93 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
// 时间轴连线容器
|
||||
.event-item {
|
||||
position: relative;
|
||||
padding-left: 28px;
|
||||
padding-left: 32px;
|
||||
margin-bottom: 12px;
|
||||
|
||||
// 时间轴垂直线
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 8px;
|
||||
left: 10px;
|
||||
top: 0;
|
||||
bottom: -12px;
|
||||
width: 2px;
|
||||
background: linear-gradient(to bottom, #e5e7eb 0%, #e5e7eb 100%);
|
||||
width: 1.5px;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
rgba(7, 192, 95, 0.1) 0%,
|
||||
rgba(7, 192, 95, 0.15) 50%,
|
||||
rgba(7, 192, 95, 0.1) 100%
|
||||
);
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
// 第一个事件的连线从节点开始
|
||||
&:first-child::before {
|
||||
top: 12px;
|
||||
top: 14px;
|
||||
}
|
||||
|
||||
// 最后一个事件不显示底部连线
|
||||
&.event-last::before {
|
||||
bottom: auto;
|
||||
height: 20px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
// 时间轴节点(圆点)
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 4px;
|
||||
top: 12px;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
left: 6.25px; // 线条中心 10.75px - 圆点半径 4.5px = 6.25px (box-sizing: border-box)
|
||||
top: 14px;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 50%;
|
||||
background: #ffffff;
|
||||
border: 2px solid #e5e7eb;
|
||||
border: 2px solid rgba(7, 192, 95, 0.3);
|
||||
z-index: 1;
|
||||
transition: all 0.2s ease;
|
||||
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
box-sizing: border-box; // 确保 border 包含在尺寸内
|
||||
}
|
||||
|
||||
// 不同事件类型的节点颜色
|
||||
&:has(.thinking-event)::after {
|
||||
border-color: #9ca3af;
|
||||
border-color: rgba(156, 163, 175, 0.4);
|
||||
background: #f9fafb;
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
&:has(.answer-event)::after {
|
||||
border-color: #07c05f;
|
||||
background: #07c05f;
|
||||
box-shadow: 0 0 0 3px rgba(7, 192, 95, 0.15);
|
||||
box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.12), 0 2px 4px rgba(7, 192, 95, 0.2);
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
&:has(.tool-event)::after {
|
||||
border-color: #07c05f;
|
||||
background: #ffffff;
|
||||
box-shadow: 0 1px 3px rgba(7, 192, 95, 0.15);
|
||||
}
|
||||
|
||||
&:has(.tool-event .action-pending)::after {
|
||||
border-color: #07c05f;
|
||||
background: rgba(7, 192, 95, 0.2);
|
||||
background: rgba(7, 192, 95, 0.15);
|
||||
box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.1);
|
||||
animation: pulseNode 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
&:has(.tool-event .action-error)::after {
|
||||
border-color: #e34d59;
|
||||
background: #e34d59;
|
||||
box-shadow: 0 0 0 2px rgba(227, 77, 89, 0.15), 0 2px 4px rgba(227, 77, 89, 0.2);
|
||||
}
|
||||
|
||||
&:has(.plan-task-change-event)::after {
|
||||
border-color: #07c05f;
|
||||
background: #07c05f;
|
||||
transform: rotate(45deg);
|
||||
transform: rotate(45deg) scale(0.9);
|
||||
border-radius: 2px;
|
||||
box-shadow: 0 1px 3px rgba(7, 192, 95, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1606,21 +1686,6 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
margin-bottom: 16px;
|
||||
position: relative;
|
||||
|
||||
// 添加时间轴起点标记
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: -20px;
|
||||
top: 12px;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
background: #07c05f;
|
||||
border: 2px solid #ffffff;
|
||||
box-shadow: 0 0 0 2px #07c05f, 0 0 0 4px rgba(7, 192, 95, 0.1);
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.intermediate-steps-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
@@ -1630,6 +1695,10 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
background: linear-gradient(to right, rgba(7, 192, 95, 0.03), transparent);
|
||||
|
||||
&:hover {
|
||||
background: linear-gradient(to right, rgba(7, 192, 95, 0.05), rgba(7, 192, 95, 0.01));
|
||||
}
|
||||
}
|
||||
|
||||
.intermediate-steps-title {
|
||||
@@ -1658,10 +1727,6 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
padding: 0 2px 1px 2px;
|
||||
color: #07c05f;
|
||||
}
|
||||
|
||||
.intermediate-steps-header:hover {
|
||||
background: linear-gradient(to right, rgba(7, 192, 95, 0.05), rgba(7, 192, 95, 0.01));
|
||||
}
|
||||
}
|
||||
|
||||
// Thinking Event
|
||||
@@ -1700,7 +1765,7 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
|
||||
&.markdown-content {
|
||||
:deep(p) {
|
||||
margin: 6px 0;
|
||||
margin: 0 0;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@@ -2079,6 +2144,14 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
&:hover {
|
||||
background-color: rgba(7, 192, 95, 0.03);
|
||||
}
|
||||
|
||||
&.no-results {
|
||||
cursor: default;
|
||||
|
||||
&:hover {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-title {
|
||||
@@ -2151,11 +2224,15 @@ const handleAddToKnowledge = (answerEvent: any) => {
|
||||
@keyframes pulseNode {
|
||||
0%, 100% {
|
||||
border-color: #07c05f;
|
||||
box-shadow: 0 0 0 0 rgba(7, 192, 95, 0.4);
|
||||
background: rgba(7, 192, 95, 0.15);
|
||||
box-shadow: 0 0 0 2px rgba(7, 192, 95, 0.1);
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
border-color: #0ae06f;
|
||||
box-shadow: 0 0 0 4px rgba(7, 192, 95, 0.1);
|
||||
background: rgba(7, 192, 95, 0.25);
|
||||
box-shadow: 0 0 0 3px rgba(7, 192, 95, 0.15);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
<template>
|
||||
<div class="grep-results">
|
||||
<!-- Results List -->
|
||||
<div v-if="results && results.length > 0" class="results-list">
|
||||
<div
|
||||
v-for="(result, index) in results"
|
||||
:key="result.id"
|
||||
class="result-item"
|
||||
>
|
||||
<t-popup
|
||||
:overlayClassName="`grep-popup-${result.id}`"
|
||||
placement="bottom-left"
|
||||
width="400"
|
||||
:showArrow="false"
|
||||
trigger="click"
|
||||
destroy-on-close
|
||||
>
|
||||
<template #content>
|
||||
<ContentPopup
|
||||
:content="result.content"
|
||||
:chunk-id="result.id"
|
||||
:knowledge-id="result.knowledge_id"
|
||||
/>
|
||||
</template>
|
||||
<div class="result-header">
|
||||
<div class="result-title">
|
||||
<span class="result-index">#{{ index + 1 }}</span>
|
||||
<span class="knowledge-title">{{ result.knowledge_title || 'Untitled' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-popup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else class="empty-state">
|
||||
未找到匹配的内容
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import type { GrepResultsData } from '@/types/tool-results';
|
||||
import ContentPopup from './ContentPopup.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
data: GrepResultsData;
|
||||
}>();
|
||||
|
||||
const maxDisplayPatterns = 2;
|
||||
|
||||
const displayPatterns = computed(() => {
|
||||
if (!props.data.patterns || props.data.patterns.length === 0) {
|
||||
return [];
|
||||
}
|
||||
return props.data.patterns.slice(0, maxDisplayPatterns);
|
||||
});
|
||||
|
||||
const results = computed(() => props.data.results || []);
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
@import './tool-results.less';
|
||||
|
||||
.grep-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
padding: 0 0 0 12px;
|
||||
}
|
||||
|
||||
.results-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.result-header {
|
||||
padding: 2px 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
transition: color 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
color: #07c05f;
|
||||
}
|
||||
}
|
||||
|
||||
.result-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.result-index {
|
||||
font-size: 11px;
|
||||
color: #9ca3af;
|
||||
font-weight: 600;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.pattern-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.pattern-text {
|
||||
font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
|
||||
font-size: 10px;
|
||||
background: #f3f4f6;
|
||||
color: #6b7280;
|
||||
padding: 2px 5px;
|
||||
border-radius: 3px;
|
||||
white-space: nowrap;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.more-patterns {
|
||||
font-size: 10px;
|
||||
color: #9ca3af;
|
||||
padding: 2px 4px;
|
||||
background: #f3f4f6;
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.knowledge-title {
|
||||
font-size: 12px;
|
||||
color: #374151;
|
||||
flex: 1;
|
||||
font-weight: 500;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.chunk-info {
|
||||
font-size: 10px;
|
||||
color: #9ca3af;
|
||||
background: #f3f4f6;
|
||||
padding: 2px 5px;
|
||||
border-radius: 3px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
font-size: 12px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
// Popup overlay styles
|
||||
:deep([class*="grep-popup-"]) {
|
||||
.t-popup__content {
|
||||
max-height: 400px;
|
||||
max-width: 500px;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding: 0;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
|
||||
word-wrap: break-word;
|
||||
word-break: break-word;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -25,9 +25,6 @@
|
||||
<div class="result-header">
|
||||
<div class="result-title">
|
||||
<span class="result-index">#{{ result.result_index }}</span>
|
||||
<span class="relevance-badge" :class="getRelevanceClass(result.relevance_level)">
|
||||
{{ getRelevanceLabel(result.relevance_level) }}
|
||||
</span>
|
||||
<span class="knowledge-title">{{ result.knowledge_title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,16 @@
|
||||
<InputField @send-msg="sendMsg"></InputField>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 知识库编辑器(创建/编辑统一组件) -->
|
||||
<KnowledgeBaseEditorModal
|
||||
:visible="uiStore.showKBEditorModal"
|
||||
:mode="uiStore.kbEditorMode"
|
||||
:kb-id="uiStore.currentKBId || undefined"
|
||||
:initial-type="uiStore.kbEditorType"
|
||||
@update:visible="(val) => val ? null : uiStore.closeKBEditor()"
|
||||
@success="handleKBEditorSuccess"
|
||||
/>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
@@ -14,14 +24,17 @@ import InputField from '@/components/Input-field.vue';
|
||||
import { createSessions } from "@/api/chat/index";
|
||||
import { useMenuStore } from '@/stores/menu';
|
||||
import { useSettingsStore } from '@/stores/settings';
|
||||
import { useUIStore } from '@/stores/ui';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { MessagePlugin } from 'tdesign-vue-next';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import KnowledgeBaseEditorModal from '@/views/knowledge/KnowledgeBaseEditorModal.vue';
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const usemenuStore = useMenuStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const uiStore = useUIStore();
|
||||
const { t } = useI18n();
|
||||
|
||||
const sendMsg = (value: string) => {
|
||||
@@ -79,6 +92,15 @@ const navigateToSession = async (sessionId: string, value: string) => {
|
||||
router.push(`/platform/chat/${sessionId}`);
|
||||
}
|
||||
|
||||
const handleKBEditorSuccess = (kbId: string) => {
|
||||
console.log('[creatChat] knowledge base created successfully:', kbId)
|
||||
// 创建成功后跳转到知识库列表页面,并高亮新创建的知识库
|
||||
router.push({
|
||||
path: '/platform/knowledge-bases',
|
||||
query: { highlightKbId: kbId }
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.dialogue-wrap {
|
||||
|
||||
@@ -45,6 +45,15 @@ let knowledgeIndex = ref(-1)
|
||||
let knowledgeScroll = ref()
|
||||
let page = 1;
|
||||
let pageSize = 35;
|
||||
|
||||
// 文档处理进度条状态
|
||||
const documentProcessingState = reactive({
|
||||
processingIds: [] as string[],
|
||||
total: 0,
|
||||
completed: 0,
|
||||
failed: 0,
|
||||
pollingInterval: null as ReturnType<typeof setInterval> | null,
|
||||
})
|
||||
const selectedTagId = ref<string>("");
|
||||
const tagList = ref<any[]>([]);
|
||||
const tagLoading = ref(false);
|
||||
@@ -396,6 +405,15 @@ const handleFileUploaded = (event: CustomEvent) => {
|
||||
// 如果上传的文件属于当前知识库,使用 loadKnowledgeFiles 刷新文件列表
|
||||
loadKnowledgeFiles(uploadedKbId);
|
||||
loadTags(uploadedKbId);
|
||||
// 延迟一下,等待文件列表加载完成后再检查处理状态
|
||||
setTimeout(() => {
|
||||
const processingList = cardList.value.filter(item =>
|
||||
item.parse_status === 'pending' || item.parse_status === 'processing'
|
||||
)
|
||||
if (processingList.length > 0) {
|
||||
updateDocumentProcessingState(processingList)
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -416,11 +434,17 @@ onMounted(() => {
|
||||
window.addEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
|
||||
// 监听URL导入对话框打开事件
|
||||
window.addEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
|
||||
|
||||
// 恢复文档处理状态
|
||||
if (!isFAQ.value) {
|
||||
restoreDocumentProcessingState()
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('knowledgeFileUploaded', handleFileUploaded as EventListener);
|
||||
window.removeEventListener('openURLImportDialog', handleOpenURLImportDialog as EventListener);
|
||||
stopDocumentProcessingPolling()
|
||||
});
|
||||
watch(() => cardList.value, (newValue) => {
|
||||
if (isFAQ.value) return;
|
||||
@@ -435,6 +459,9 @@ watch(() => cardList.value, (newValue) => {
|
||||
if (analyzeList.length) {
|
||||
updateStatus(analyzeList)
|
||||
}
|
||||
|
||||
// 更新文档处理进度条状态
|
||||
updateDocumentProcessingState(analyzeList)
|
||||
}, { deep: true })
|
||||
type KnowledgeCard = {
|
||||
id: string;
|
||||
@@ -477,6 +504,168 @@ const updateStatus = (analyzeList: KnowledgeCard[]) => {
|
||||
}, 1500);
|
||||
};
|
||||
|
||||
// 更新文档处理进度条状态
|
||||
const updateDocumentProcessingState = (processingList: KnowledgeCard[]) => {
|
||||
const processingIds = processingList.map(item => item.id)
|
||||
const hasChanged = JSON.stringify(processingIds.sort()) !== JSON.stringify(documentProcessingState.processingIds.sort())
|
||||
|
||||
if (hasChanged) {
|
||||
documentProcessingState.processingIds = processingIds
|
||||
documentProcessingState.total = processingIds.length
|
||||
documentProcessingState.completed = 0
|
||||
documentProcessingState.failed = 0
|
||||
|
||||
// 保存到 localStorage
|
||||
saveProcessingIdsToStorage(processingIds)
|
||||
|
||||
// 开始轮询
|
||||
if (processingIds.length > 0) {
|
||||
startDocumentProcessingPolling()
|
||||
} else {
|
||||
stopDocumentProcessingPolling()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 开始轮询文档处理状态
|
||||
const startDocumentProcessingPolling = () => {
|
||||
stopDocumentProcessingPolling()
|
||||
|
||||
if (documentProcessingState.processingIds.length === 0) return
|
||||
|
||||
documentProcessingState.pollingInterval = setInterval(() => {
|
||||
if (documentProcessingState.processingIds.length === 0) {
|
||||
stopDocumentProcessingPolling()
|
||||
return
|
||||
}
|
||||
|
||||
let query = ``
|
||||
documentProcessingState.processingIds.forEach(id => {
|
||||
query += `ids=${id}&`
|
||||
})
|
||||
|
||||
batchQueryKnowledge(query).then((result: any) => {
|
||||
if (result.success && result.data) {
|
||||
const completedIds: string[] = []
|
||||
const failedIds: string[] = []
|
||||
|
||||
;(result.data as KnowledgeCard[]).forEach((item: KnowledgeCard) => {
|
||||
if (item.parse_status === 'completed') {
|
||||
completedIds.push(item.id)
|
||||
documentProcessingState.completed++
|
||||
} else if (item.parse_status === 'failed') {
|
||||
failedIds.push(item.id)
|
||||
documentProcessingState.failed++
|
||||
}
|
||||
})
|
||||
|
||||
// 从处理列表中移除已完成的文档
|
||||
documentProcessingState.processingIds = documentProcessingState.processingIds.filter(
|
||||
id => !completedIds.includes(id) && !failedIds.includes(id)
|
||||
)
|
||||
|
||||
// 如果所有文档都处理完成,停止轮询
|
||||
if (documentProcessingState.processingIds.length === 0) {
|
||||
stopDocumentProcessingPolling()
|
||||
clearProcessingIdsFromStorage()
|
||||
|
||||
// 刷新文件列表
|
||||
if (kbId.value) {
|
||||
loadKnowledgeFiles(kbId.value)
|
||||
}
|
||||
} else {
|
||||
// 更新 localStorage
|
||||
saveProcessingIdsToStorage(documentProcessingState.processingIds)
|
||||
}
|
||||
}
|
||||
}).catch((_err) => {
|
||||
// 错误处理
|
||||
})
|
||||
}, 2000)
|
||||
}
|
||||
|
||||
// 停止轮询文档处理状态
|
||||
const stopDocumentProcessingPolling = () => {
|
||||
if (documentProcessingState.pollingInterval) {
|
||||
clearInterval(documentProcessingState.pollingInterval)
|
||||
documentProcessingState.pollingInterval = null
|
||||
}
|
||||
}
|
||||
|
||||
// localStorage 相关函数
|
||||
const getProcessingIdsStorageKey = () => {
|
||||
return `document_processing_ids_${kbId.value}`
|
||||
}
|
||||
|
||||
const saveProcessingIdsToStorage = (ids: string[]) => {
|
||||
if (!kbId.value) return
|
||||
try {
|
||||
localStorage.setItem(getProcessingIdsStorageKey(), JSON.stringify(ids))
|
||||
} catch (error) {
|
||||
console.error('Failed to save processing IDs to localStorage:', error)
|
||||
}
|
||||
}
|
||||
|
||||
const getProcessingIdsFromStorage = (): string[] => {
|
||||
if (!kbId.value) return []
|
||||
try {
|
||||
const data = localStorage.getItem(getProcessingIdsStorageKey())
|
||||
return data ? JSON.parse(data) : []
|
||||
} catch (error) {
|
||||
console.error('Failed to get processing IDs from localStorage:', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
const clearProcessingIdsFromStorage = () => {
|
||||
if (!kbId.value) return
|
||||
try {
|
||||
localStorage.removeItem(getProcessingIdsStorageKey())
|
||||
} catch (error) {
|
||||
console.error('Failed to clear processing IDs from localStorage:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复文档处理状态(用于刷新后恢复)
|
||||
const restoreDocumentProcessingState = async () => {
|
||||
if (!kbId.value || isFAQ.value) return
|
||||
|
||||
const savedIds = getProcessingIdsFromStorage()
|
||||
if (savedIds.length === 0) return
|
||||
|
||||
// 检查这些文档是否还在处理中
|
||||
let query = ``
|
||||
savedIds.forEach(id => {
|
||||
query += `ids=${id}&`
|
||||
})
|
||||
|
||||
try {
|
||||
const result: any = await batchQueryKnowledge(query)
|
||||
if (result.success && result.data) {
|
||||
const stillProcessing: string[] = []
|
||||
;(result.data as KnowledgeCard[]).forEach((item: KnowledgeCard) => {
|
||||
if (item.parse_status === 'pending' || item.parse_status === 'processing') {
|
||||
stillProcessing.push(item.id)
|
||||
}
|
||||
})
|
||||
|
||||
if (stillProcessing.length > 0) {
|
||||
documentProcessingState.processingIds = stillProcessing
|
||||
documentProcessingState.total = stillProcessing.length
|
||||
documentProcessingState.completed = 0
|
||||
documentProcessingState.failed = 0
|
||||
saveProcessingIdsToStorage(stillProcessing)
|
||||
startDocumentProcessingPolling()
|
||||
} else {
|
||||
clearProcessingIdsFromStorage()
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to restore document processing state:', error)
|
||||
clearProcessingIdsFromStorage()
|
||||
}
|
||||
}
|
||||
|
||||
const closeDoc = () => {
|
||||
isCardDetails.value = false;
|
||||
};
|
||||
@@ -520,6 +709,16 @@ const ensureDocumentKbReady = () => {
|
||||
return true;
|
||||
};
|
||||
|
||||
// 关闭文档处理进度条
|
||||
const handleCloseDocumentProgress = () => {
|
||||
stopDocumentProcessingPolling()
|
||||
documentProcessingState.processingIds = []
|
||||
documentProcessingState.total = 0
|
||||
documentProcessingState.completed = 0
|
||||
documentProcessingState.failed = 0
|
||||
clearProcessingIdsFromStorage()
|
||||
}
|
||||
|
||||
const handleDocumentUploadClick = () => {
|
||||
if (!ensureDocumentKbReady()) return;
|
||||
uploadInputRef.value?.click();
|
||||
@@ -818,6 +1017,41 @@ async function createNewSession(value: string): Promise<void> {
|
||||
<p class="document-subtitle">{{ $t('knowledgeEditor.document.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 文档处理进度条 -->
|
||||
<div v-if="!isFAQ && documentProcessingState.processingIds.length > 0" class="document-processing-progress-bar">
|
||||
<div class="progress-bar-content">
|
||||
<div class="progress-bar-header">
|
||||
<t-icon
|
||||
name="loading"
|
||||
size="16px"
|
||||
class="progress-icon icon-loading"
|
||||
/>
|
||||
<span class="progress-title">
|
||||
{{ $t('knowledgeList.processingDocuments', { count: documentProcessingState.processingIds.length }) }}
|
||||
</span>
|
||||
<span class="progress-count">
|
||||
{{ documentProcessingState.completed + documentProcessingState.failed }}/{{ documentProcessingState.total }}
|
||||
</span>
|
||||
<t-button
|
||||
variant="text"
|
||||
theme="default"
|
||||
size="small"
|
||||
class="progress-close-btn"
|
||||
@click="handleCloseDocumentProgress"
|
||||
>
|
||||
<t-icon name="close" size="14px" />
|
||||
</t-button>
|
||||
</div>
|
||||
<t-progress
|
||||
:percentage="Math.round(((documentProcessingState.completed + documentProcessingState.failed) / documentProcessingState.total) * 100)"
|
||||
:status="documentProcessingState.failed > 0 ? 'error' : 'active'"
|
||||
:label="false"
|
||||
class="progress-bar"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input
|
||||
ref="uploadInputRef"
|
||||
type="file"
|
||||
@@ -1872,6 +2106,76 @@ async function createNewSession(value: string): Promise<void> {
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
.document-processing-progress-bar {
|
||||
margin-bottom: 16px;
|
||||
background: #fff;
|
||||
border: 1px solid #e7ebf0;
|
||||
border-radius: 8px;
|
||||
padding: 12px 16px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
|
||||
|
||||
.progress-bar-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.progress-bar-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
color: #000000e6;
|
||||
|
||||
.progress-icon {
|
||||
flex-shrink: 0;
|
||||
|
||||
&.icon-loading {
|
||||
animation: rotate 1s linear infinite;
|
||||
color: #07c05f;
|
||||
}
|
||||
}
|
||||
|
||||
.progress-title {
|
||||
font-weight: 500;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.progress-count {
|
||||
color: #86909c;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.progress-close-btn {
|
||||
flex-shrink: 0;
|
||||
padding: 4px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
|
||||
:deep(.t-progress) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.t-progress__bar) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
:deep(.del-knowledge) {
|
||||
padding: 0px !important;
|
||||
border-radius: 6px !important;
|
||||
|
||||
@@ -24,8 +24,10 @@
|
||||
:class="{
|
||||
'uninitialized': !isInitialized(kb),
|
||||
'kb-type-document': (kb.type || 'document') === 'document',
|
||||
'kb-type-faq': kb.type === 'faq'
|
||||
'kb-type-faq': kb.type === 'faq',
|
||||
'highlight-flash': highlightedKbId !== null && highlightedKbId === kb.id
|
||||
}"
|
||||
:ref="el => { if (highlightedKbId !== null && highlightedKbId === kb.id && el) highlightedCardRef = el as HTMLElement }"
|
||||
@click="handleCardClick(kb)"
|
||||
>
|
||||
<!-- 卡片头部 -->
|
||||
@@ -78,6 +80,15 @@
|
||||
{{ kb.type === 'faq' ? $t('knowledgeEditor.basic.typeFAQ') : $t('knowledgeEditor.basic.typeDocument') }}
|
||||
({{ kb.type === 'faq' ? (kb.chunk_count || 0) : (kb.knowledge_count || 0) }})
|
||||
</span>
|
||||
<t-tooltip
|
||||
v-if="kb.isProcessing"
|
||||
:content="kb.type === 'document' && (kb.processing_count || 0) > 0
|
||||
? $t('knowledgeList.processingDocuments', { count: kb.processing_count || 0 })
|
||||
: $t('knowledgeList.processing')"
|
||||
placement="top"
|
||||
>
|
||||
<t-icon name="loading" size="14px" class="processing-icon" />
|
||||
</t-tooltip>
|
||||
</div>
|
||||
<div class="feature-badges">
|
||||
<t-tooltip v-if="kb.extract_config?.enabled" :content="$t('knowledgeList.features.knowledgeGraph')" placement="top">
|
||||
@@ -144,9 +155,9 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, computed, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { MessagePlugin } from 'tdesign-vue-next'
|
||||
import { onMounted, ref, computed, watch, nextTick } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { MessagePlugin, Icon as TIcon } from 'tdesign-vue-next'
|
||||
import { listKnowledgeBases, deleteKnowledgeBase } from '@/api/knowledge-base'
|
||||
import { formatStringDate } from '@/utils/index'
|
||||
import { useUIStore } from '@/stores/ui'
|
||||
@@ -155,6 +166,7 @@ import Settings from '@/views/settings/Settings.vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const uiStore = useUIStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -172,6 +184,8 @@ interface KB {
|
||||
cos_config?: { provider?: string; bucket_name?: string };
|
||||
knowledge_count?: number;
|
||||
chunk_count?: number;
|
||||
isProcessing?: boolean; // 是否有正在处理的导入任务
|
||||
processing_count?: number; // 正在处理的文档数量(仅文档类型)
|
||||
}
|
||||
|
||||
const kbs = ref<KB[]>([])
|
||||
@@ -179,22 +193,43 @@ const loading = ref(false)
|
||||
const deleteVisible = ref(false)
|
||||
const deletingKb = ref<KB | null>(null)
|
||||
const currentMoreIndex = ref<number>(-1)
|
||||
const highlightedKbId = ref<string | null>(null)
|
||||
const highlightedCardRef = ref<HTMLElement | null>(null)
|
||||
|
||||
const fetchList = () => {
|
||||
loading.value = true
|
||||
listKnowledgeBases().then((res: any) => {
|
||||
return listKnowledgeBases().then((res: any) => {
|
||||
const data = res.data || []
|
||||
// 格式化时间,并初始化 showMore 状态
|
||||
kbs.value = data.map((kb: KB) => ({
|
||||
// is_processing 字段由后端返回
|
||||
kbs.value = data.map((kb: any) => ({
|
||||
...kb,
|
||||
updated_at: kb.updated_at ? formatStringDate(new Date(kb.updated_at)) : '',
|
||||
showMore: false
|
||||
showMore: false,
|
||||
isProcessing: kb.is_processing || false,
|
||||
processing_count: kb.processing_count || 0
|
||||
}))
|
||||
}).finally(() => loading.value = false)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchList()
|
||||
fetchList().then(() => {
|
||||
// 检查路由参数中是否有需要高亮的知识库ID
|
||||
const highlightKbId = route.query.highlightKbId as string
|
||||
if (highlightKbId) {
|
||||
triggerHighlightFlash(highlightKbId)
|
||||
// 清除 URL 中的查询参数
|
||||
router.replace({ query: {} })
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// 监听路由变化,处理从其他页面跳转过来的高亮需求
|
||||
watch(() => route.query.highlightKbId, (newKbId) => {
|
||||
if (newKbId && typeof newKbId === 'string' && kbs.value.length > 0) {
|
||||
triggerHighlightFlash(newKbId)
|
||||
router.replace({ query: {} })
|
||||
}
|
||||
})
|
||||
|
||||
const openMore = (index: number) => {
|
||||
@@ -270,7 +305,32 @@ const goSettings = (id: string) => {
|
||||
// 知识库编辑器成功回调(创建或编辑成功)
|
||||
const handleKBEditorSuccess = (kbId: string) => {
|
||||
console.log('[KnowledgeBaseList] knowledge operation success:', kbId)
|
||||
fetchList()
|
||||
fetchList().then(() => {
|
||||
// 如果是从路由参数中获取的高亮ID,触发闪烁效果
|
||||
if (route.query.highlightKbId === kbId) {
|
||||
triggerHighlightFlash(kbId)
|
||||
// 清除 URL 中的查询参数
|
||||
router.replace({ query: {} })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 触发高亮闪烁效果
|
||||
const triggerHighlightFlash = (kbId: string) => {
|
||||
highlightedKbId.value = kbId
|
||||
nextTick(() => {
|
||||
if (highlightedCardRef.value) {
|
||||
// 滚动到高亮的卡片
|
||||
highlightedCardRef.value.scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'center'
|
||||
})
|
||||
}
|
||||
// 3秒后清除高亮
|
||||
setTimeout(() => {
|
||||
highlightedKbId.value = null
|
||||
}, 3000)
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -533,6 +593,19 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
color: #0052d9;
|
||||
border: 1px solid rgba(0, 82, 217, 0.2);
|
||||
}
|
||||
|
||||
.processing-icon {
|
||||
animation: spin 1s linear infinite;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
&.document .processing-icon {
|
||||
color: #059669;
|
||||
}
|
||||
|
||||
&.faq .processing-icon {
|
||||
color: #0052d9;
|
||||
}
|
||||
}
|
||||
|
||||
.feature-badges {
|
||||
@@ -569,6 +642,40 @@ const handleKBEditorSuccess = (kbId: string) => {
|
||||
background: rgba(255, 152, 0, 0.15);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes highlightFlash {
|
||||
0% {
|
||||
border-color: #07c05f;
|
||||
box-shadow: 0 0 0 0 rgba(7, 192, 95, 0.4);
|
||||
transform: scale(1);
|
||||
}
|
||||
50% {
|
||||
border-color: #07c05f;
|
||||
box-shadow: 0 0 0 8px rgba(7, 192, 95, 0);
|
||||
transform: scale(1.02);
|
||||
}
|
||||
100% {
|
||||
border-color: #07c05f;
|
||||
box-shadow: 0 0 0 0 rgba(7, 192, 95, 0);
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.kb-card.highlight-flash {
|
||||
animation: highlightFlash 0.6s ease-in-out 3;
|
||||
border-color: #07c05f !important;
|
||||
box-shadow: 0 0 12px rgba(7, 192, 95, 0.3) !important;
|
||||
}
|
||||
|
||||
.card-time {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user