fix(knowledgeBase): improve tag loading logic and ensure consistent behavior
- Updated the loadTags function to prevent unnecessary calls when tags are already loading, enhancing performance and user experience. - Modified tag loading calls in various tag-related functions to ensure the reset parameter is consistently set to true, ensuring the tag list is refreshed correctly after operations like create, edit, and delete. - Improved the FAQEntryManager component to handle tag loading more efficiently during scrolling and batch operations.
This commit is contained in:
@@ -593,6 +593,8 @@ const loadTags = async (kbIdValue: string, reset = false) => {
|
||||
tagList.value = [];
|
||||
tagTotal.value = 0;
|
||||
tagHasMore.value = false;
|
||||
} else if (tagLoading.value || tagLoadingMore.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentPage = tagPage.value || 1;
|
||||
@@ -699,7 +701,7 @@ const submitCreateTag = async () => {
|
||||
await createKnowledgeBaseTag(kbId.value, { name });
|
||||
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'));
|
||||
cancelCreateTag();
|
||||
await loadTags(kbId.value);
|
||||
await loadTags(kbId.value, true);
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('common.operationFailed'));
|
||||
} finally {
|
||||
@@ -742,7 +744,7 @@ const submitEditTag = async () => {
|
||||
await updateKnowledgeBaseTag(kbId.value, editingTagId.value, { name });
|
||||
MessagePlugin.success(t('knowledgeBase.tagEditSuccess'));
|
||||
cancelEditTag();
|
||||
await loadTags(kbId.value);
|
||||
await loadTags(kbId.value, true);
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('common.operationFailed'));
|
||||
} finally {
|
||||
@@ -774,7 +776,7 @@ const confirmDeleteTag = (tag: any) => {
|
||||
selectedTagId.value = '';
|
||||
handleTagFilterChange('');
|
||||
}
|
||||
loadTags(kbId.value);
|
||||
loadTags(kbId.value, true);
|
||||
// 由于后端是异步删除文档,延迟刷新以确保看到最新数据
|
||||
setTimeout(() => {
|
||||
resetPage(); // Reset page counter when reloading files after tag deletion
|
||||
@@ -794,7 +796,7 @@ const handleKnowledgeTagChange = async (knowledgeId: string, tagValue: string) =
|
||||
MessagePlugin.success(t('knowledgeBase.tagUpdateSuccess'));
|
||||
resetPage(); // Reset page counter to 1 when reloading files after tag change
|
||||
loadKnowledgeFiles(kbId.value);
|
||||
loadTags(kbId.value);
|
||||
loadTags(kbId.value, true);
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('common.operationFailed'));
|
||||
}
|
||||
@@ -1861,7 +1863,7 @@ const delCardConfirm = () => {
|
||||
if (!stillPresent) break;
|
||||
await new Promise<void>((r) => setTimeout(r, delayMs));
|
||||
}
|
||||
loadTags(kbId.value);
|
||||
loadTags(kbId.value, true);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1964,7 +1966,7 @@ const confirmBatchDelete = async () => {
|
||||
if (!stillPresent) break;
|
||||
await new Promise<void>((r) => setTimeout(r, delayMs));
|
||||
}
|
||||
loadTags(kbId.value);
|
||||
loadTags(kbId.value, true);
|
||||
} else {
|
||||
MessagePlugin.error(res?.message || t('knowledgeBase.batchDeleteFailed'));
|
||||
}
|
||||
|
||||
@@ -1272,7 +1272,7 @@ const searchForm = reactive({
|
||||
const handleTagListScroll = () => {
|
||||
const container = tagListRef.value
|
||||
if (!container) return
|
||||
if (tagLoadingMore.value || !tagHasMore.value) return
|
||||
if (tagLoading.value || tagLoadingMore.value || !tagHasMore.value) return
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = container
|
||||
// 距离底部 50px 时触发加载
|
||||
@@ -1295,6 +1295,8 @@ const loadTags = async (reset = false) => {
|
||||
tagList.value = []
|
||||
tagTotal.value = 0
|
||||
tagHasMore.value = false
|
||||
} else if (tagLoading.value || tagLoadingMore.value) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentPage = tagPage.value || 1
|
||||
@@ -1394,7 +1396,7 @@ const submitCreateTag = async () => {
|
||||
await createKnowledgeBaseTag(props.kbId, { name })
|
||||
MessagePlugin.success(t('knowledgeBase.tagCreateSuccess'))
|
||||
cancelCreateTag()
|
||||
await loadTags()
|
||||
await loadTags(true)
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
@@ -1436,7 +1438,7 @@ const submitEditTag = async () => {
|
||||
await updateKnowledgeBaseTag(props.kbId, editingTagId.value, { name })
|
||||
MessagePlugin.success(t('knowledgeBase.tagEditSuccess'))
|
||||
cancelEditTag()
|
||||
await loadTags()
|
||||
await loadTags(true)
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('common.operationFailed'))
|
||||
} finally {
|
||||
@@ -1469,7 +1471,7 @@ const confirmDeleteTag = (tag: any) => {
|
||||
selectedTagId.value = 0
|
||||
handleTagFilterChange(0)
|
||||
}
|
||||
await loadTags()
|
||||
await loadTags(true)
|
||||
await loadEntries()
|
||||
confirmDialog.hide()
|
||||
} catch (error: any) {
|
||||
@@ -1491,7 +1493,7 @@ const handleEntryTagChange = async (entryId: number, value?: string) => {
|
||||
await updateFAQEntryTagBatch(props.kbId, { updates: { [entryId]: normalizedValue } })
|
||||
MessagePlugin.success(t('knowledgeEditor.messages.updateSuccess'))
|
||||
await loadEntries()
|
||||
await loadTags()
|
||||
await loadTags(true)
|
||||
} catch (error: any) {
|
||||
if (targetEntry) {
|
||||
targetEntry.tag_id = previousTagId
|
||||
@@ -1885,7 +1887,7 @@ const handleBatchTag = async () => {
|
||||
batchTagDialogVisible.value = false
|
||||
selectedRowKeys.value = []
|
||||
await loadEntries()
|
||||
await loadTags()
|
||||
await loadTags(true)
|
||||
} catch (error: any) {
|
||||
MessagePlugin.error(error?.message || t('common.operationFailed'))
|
||||
}
|
||||
@@ -2176,7 +2178,7 @@ const startPolling = (taskId: string) => {
|
||||
if (processed > lastProcessed) {
|
||||
lastProcessed = processed
|
||||
await loadEntries()
|
||||
await loadTags()
|
||||
await loadTags(true)
|
||||
}
|
||||
|
||||
// 任务完成或失败,停止轮询(但不自动关闭进度条,让用户手动关闭)
|
||||
@@ -2193,7 +2195,7 @@ const startPolling = (taskId: string) => {
|
||||
entrySearchKeyword.value = ''
|
||||
overallFAQTotal.value = 0 // Reset to trigger re-fetch
|
||||
await loadEntries()
|
||||
await loadTags()
|
||||
await loadTags(true)
|
||||
await loadImportResult() // 加载最新的导入结果统计
|
||||
// 任务完成后,3秒后自动关闭进度条
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -124,7 +124,8 @@ func (r *knowledgeTagRepository) ListByKB(
|
||||
|
||||
var tags []*types.KnowledgeTag
|
||||
if err := dataQuery.
|
||||
Order("sort_order ASC, created_at DESC").
|
||||
// seq_id tie-breaker keeps OFFSET pagination stable when sort_order and created_at collide.
|
||||
Order("sort_order ASC, created_at DESC, seq_id DESC").
|
||||
Offset(page.Offset()).
|
||||
Limit(page.Limit()).
|
||||
Find(&tags).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user