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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user