fix(knowledge): pre-select common tags in batch tag dialog

This commit is contained in:
Binks Riverton
2026-07-30 12:04:38 +08:00
committed by lyingbug
parent 0f667e0fd8
commit de262ba6dd
2 changed files with 20 additions and 2 deletions
+18 -1
View File
@@ -423,6 +423,22 @@ const batchDeleting = ref(false);
const batchReparsing = ref(false);
const batchTagging = ref(false);
const batchTagDialogVisible = ref(false);
const batchTagPreSelectedIds = computed(() => {
const ids = Array.from(selectedIds.value);
if (ids.length === 0) return [];
const cards = ids
.map((id) => cardList.value.find((c) => c.id === id))
.filter((c): c is KnowledgeCard => Boolean(c));
if (cards.length === 0) return [];
const firstTagIds = new Set((cards[0].tags || []).map((t) => t.id));
for (let i = 1; i < cards.length; i++) {
const cur = new Set((cards[i].tags || []).map((t) => t.id));
for (const tid of firstTagIds) {
if (!cur.has(tid)) firstTagIds.delete(tid);
}
}
return Array.from(firstTagIds);
});
// IDs submitted for async batch reparse; hold optimistic pending until the worker updates DB.
const pendingReparseAck = ref<Set<string>>(new Set());
@@ -2409,7 +2425,8 @@ async function createNewSession(value: string): Promise<void> {
<!-- 批量打标签弹窗 -->
<BatchTagDialog :visible="batchTagDialogVisible"
:count="selectedIds.size" :kb-id="kbId" :tag-list="tagList" :can-manage="canEdit"
:count="selectedIds.size" :kb-id="kbId" :tag-list="tagList"
:pre-selected-tag-ids="batchTagPreSelectedIds" :can-manage="canEdit"
@update:visible="batchTagDialogVisible = $event" @confirm="onBatchTagConfirm"
@tag-created="loadTags(kbId, true)" @open-manage="openTagManageFromBatchDialog" />
@@ -104,6 +104,7 @@ const props = defineProps<{
count: number;
kbId: string;
tagList: Tag[];
preSelectedTagIds?: string[];
canManage?: boolean;
}>();
@@ -126,7 +127,7 @@ watch(
() => props.visible,
(val) => {
if (val) {
selectedSet.value = new Set();
selectedSet.value = new Set(props.preSelectedTagIds ?? []);
searchQuery.value = '';
newTagName.value = '';
}