feat: support multi-tag for document knowledge (#1790)
* feat: support multi-tag for document knowledge - Add knowledge_tag_relations join table for many-to-many tag-knowledge mapping - Migrate existing single tag_id data to the new table - Update Knowledge struct, filter, payload types (TagID -> Tags/TagIDs) - Rewrite repository layer: SetKnowledgeTags, GetKnowledgeTags, ListIDsByTagIDs - Update tag count references to query knowledge_tag_relations - Update service/handler layers for multi-tag create/list/batch-update - Frontend: multi-select tag sidebar, multi-tag chip display, tag toggle in popup - FAQ tags remain single-tag model (unchanged) * feat(knowledge): tag edit dialog with dynamic overflow and inline creation - Add TagEditDialog component with search, multi-select, and confirm - Replace inline t-popup tag selector with dialog-based editing - Tags overflow with +N badge, visible count adapts to container width via ResizeObserver - Date/card layout: fixed date width, tags flex to fill remaining space - Add persistent new-tag input bar in dialog (Enter to create, auto-select) - Tag creation emits callback to refresh parent tag list immediately - Apply same overflow + dialog trigger to both card view and list view - Add i18n keys: tagEditDialogTitle, tagEditSearch, tagSelectedCount, tagOverflowTip, tagNewPlaceholder * fix: exclude soft-deleted knowledge from tag reference counts CountReferences, BatchCountReferences, and DeleteUnusedTags now JOIN with knowledges table to filter out soft-deleted records when counting knowledge_tag_relations. Previously they queried knowledge_tag_relations directly without the deleted_at check, causing stale tag counts after knowledge deletion. * fix: refresh tag counts after async knowledge deletion completes Add a second delayed tag list refresh (2.5s) after tag deletion to capture updated reference counts for remaining tags. The original immediate refresh handles removing the deleted tag from the list, while this delayed refresh ensures other tags' counts are correct after the async deletion finishes. --------- Co-authored-by: lyingbug <xiayula2014@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import { computed, onBeforeUnmount, onMounted, reactive, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { formatFileSize, getFileIcon } from '@/utils/files';
|
||||
|
||||
@@ -15,7 +15,7 @@ interface KnowledgeItem {
|
||||
file_type?: string;
|
||||
file_size?: number | string;
|
||||
type?: string;
|
||||
tag_id?: string | number;
|
||||
tags?: Tag[];
|
||||
parse_status?: string;
|
||||
summary_status?: string;
|
||||
updated_at?: string;
|
||||
@@ -38,10 +38,63 @@ const emit = defineEmits<{
|
||||
(e: 'toggle-row', id: string, checked: boolean, shiftKey: boolean): void;
|
||||
(e: 'toggle-all', checked: boolean): void;
|
||||
(e: 'action', action: 'edit' | 'reparse' | 'cancel-parse' | 'move' | 'delete', item: KnowledgeItem): void;
|
||||
(e: 'tag-edit', item: KnowledgeItem): void;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
// 动态标签可见数量(根据列宽自适应)
|
||||
const TAG_EST_WIDTH = 82;
|
||||
const TAG_OVERFLOW_MIN = 32;
|
||||
const tagVisibleLimit = reactive<Record<string, number>>({});
|
||||
const tagItemTotalMap = new Map<string, number>();
|
||||
let tagChipsRO: ResizeObserver | null = null;
|
||||
|
||||
function setupTagChipsObserver(el: Element | null, itemId: string, totalCount: number) {
|
||||
if (!el) return;
|
||||
const htmlEl = el as HTMLElement;
|
||||
htmlEl.dataset.listTagItemId = itemId;
|
||||
tagItemTotalMap.set(itemId, totalCount);
|
||||
if (!tagChipsRO) {
|
||||
tagChipsRO = new ResizeObserver((entries) => {
|
||||
for (const entry of entries) {
|
||||
const target = entry.target as HTMLElement;
|
||||
const id = target.dataset.listTagItemId;
|
||||
if (!id) continue;
|
||||
const w = entry.contentRect.width;
|
||||
const total = tagItemTotalMap.get(id) ?? 0;
|
||||
if (total <= 0) { tagVisibleLimit[id] = 99; continue; }
|
||||
const maxFit = Math.floor((w - TAG_OVERFLOW_MIN) / TAG_EST_WIDTH);
|
||||
const limit = Math.max(1, Math.min(maxFit, total));
|
||||
tagVisibleLimit[id] = limit >= total ? 99 : limit;
|
||||
}
|
||||
});
|
||||
}
|
||||
tagChipsRO.observe(htmlEl);
|
||||
requestAnimationFrame(() => {
|
||||
const w = htmlEl.clientWidth;
|
||||
const total = totalCount;
|
||||
if (total <= 0) { tagVisibleLimit[itemId] = 99; return; }
|
||||
const maxFit = Math.floor((w - TAG_OVERFLOW_MIN) / TAG_EST_WIDTH);
|
||||
const limit = Math.max(1, Math.min(maxFit, total));
|
||||
tagVisibleLimit[itemId] = limit >= total ? 99 : limit;
|
||||
});
|
||||
}
|
||||
|
||||
function getTagLimit(itemId: string): number {
|
||||
return tagVisibleLimit[itemId] ?? 99;
|
||||
}
|
||||
|
||||
function hasTagOverflow(itemId: string, total: number): boolean {
|
||||
const limit = tagVisibleLimit[itemId] ?? 99;
|
||||
return total > limit;
|
||||
}
|
||||
|
||||
function getOverflowCount(itemId: string, total: number): number {
|
||||
const limit = tagVisibleLimit[itemId] ?? 99;
|
||||
return Math.max(0, total - limit);
|
||||
}
|
||||
|
||||
const tagMap = computed(() => {
|
||||
const map: Record<string, Tag> = {};
|
||||
for (const tag of props.tagList) map[String(tag.id)] = tag;
|
||||
@@ -248,10 +301,51 @@ const handleAction = (action: 'edit' | 'reparse' | 'cancel-parse' | 'move' | 'de
|
||||
|
||||
|
||||
<div class="cell cell-tag">
|
||||
<t-tag v-if="getTagName(item.tag_id)" size="small" variant="light-outline" class="row-tag">
|
||||
{{ getTagName(item.tag_id) }}
|
||||
</t-tag>
|
||||
<span v-else class="row-muted">--</span>
|
||||
<template v-if="item.tags && item.tags.length > 0">
|
||||
<t-tooltip
|
||||
v-if="hasTagOverflow(item.id, item.tags.length)"
|
||||
:content="item.tags.map((t: any) => t.name).join(', ')"
|
||||
placement="top"
|
||||
>
|
||||
<div
|
||||
class="row-tag-chips"
|
||||
:ref="(el: any) => setupTagChipsObserver(el, item.id, item.tags.length)"
|
||||
:class="{ 'is-clickable': canEdit }"
|
||||
@click.stop="canEdit && emit('tag-edit', item)"
|
||||
>
|
||||
<t-tag
|
||||
v-for="tag in item.tags.slice(0, getTagLimit(item.id))"
|
||||
:key="tag.id"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
class="row-tag"
|
||||
>
|
||||
{{ tag.name }}
|
||||
</t-tag>
|
||||
<span class="row-tag-overflow">+{{ getOverflowCount(item.id, item.tags.length) }}</span>
|
||||
</div>
|
||||
</t-tooltip>
|
||||
<div
|
||||
v-else
|
||||
class="row-tag-chips"
|
||||
:ref="(el: any) => setupTagChipsObserver(el, item.id, item.tags.length)"
|
||||
:class="{ 'is-clickable': canEdit }"
|
||||
@click.stop="canEdit && emit('tag-edit', item)"
|
||||
>
|
||||
<t-tag
|
||||
v-for="tag in item.tags.slice(0, getTagLimit(item.id))"
|
||||
:key="tag.id"
|
||||
size="small"
|
||||
variant="light-outline"
|
||||
class="row-tag"
|
||||
>
|
||||
{{ tag.name }}
|
||||
</t-tag>
|
||||
</div>
|
||||
</template>
|
||||
<span v-else class="row-tag-chips is-clickable" @click.stop="canEdit && emit('tag-edit', item)">
|
||||
<span class="row-tag-add">+ {{ t('knowledgeBase.tagLabel') }}</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="cell cell-source">
|
||||
@@ -597,6 +691,58 @@ const handleAction = (action: 'edit' | 'reparse' | 'cancel-parse' | 'move' | 'de
|
||||
}
|
||||
}
|
||||
|
||||
.row-tag-chips {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
flex-wrap: nowrap;
|
||||
|
||||
&.is-clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.row-tag-overflow {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 20px;
|
||||
min-width: 20px;
|
||||
padding: 0 4px;
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: 10px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
color: var(--td-brand-color);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
}
|
||||
}
|
||||
|
||||
.row-tag-add {
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
border: 1px dashed var(--td-component-stroke);
|
||||
border-radius: 999px;
|
||||
padding: 0 6px;
|
||||
height: 20px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover {
|
||||
border-color: var(--td-brand-color);
|
||||
color: var(--td-brand-color);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
border-style: solid;
|
||||
}
|
||||
}
|
||||
|
||||
.row-muted {
|
||||
color: var(--td-text-color-disabled, #bbb);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user