diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 32c7eeff..4ef8e158 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -3535,8 +3535,6 @@ export default { sourceFilterSelected: '{count} documents selected', sourceFilterClear: 'Clear selection', sourceFilterTooMany: 'At most 1000 documents can be selected', - sourceFilterColName: 'File name', - sourceFilterColTime: 'Uploaded', sourceFilterSelectAll: 'Select all / none (across every hit)', sourceFilterOverflowRecent: 'Many documents: showing only the most recent {cap}. Refine with a keyword.', sourceFilterOverflowHits: '{total} documents hit; showing the first {cap}. Narrow the keyword before selecting all.', diff --git a/frontend/src/i18n/locales/ja-JP.ts b/frontend/src/i18n/locales/ja-JP.ts index abc559f5..b2837e56 100644 --- a/frontend/src/i18n/locales/ja-JP.ts +++ b/frontend/src/i18n/locales/ja-JP.ts @@ -3535,8 +3535,6 @@ export default { sourceFilterSelected: '{count} 件のドキュメントを選択中', sourceFilterClear: '選択をクリア', sourceFilterTooMany: '選択できるのは最大 1000 件です', - sourceFilterColName: 'ファイル名', - sourceFilterColTime: 'アップロード日時', sourceFilterSelectAll: 'すべて選択 / 選択解除(全ヒット対象)', sourceFilterOverflowRecent: 'ドキュメントが多いため、最新 {cap} 件のみ表示しています。キーワードで絞り込んでください', sourceFilterOverflowHits: '{total} 件がヒットしました。先頭 {cap} 件のみ表示中です。全選択前にキーワードを絞り込んでください', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index d5b1c49a..3339563c 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -4566,8 +4566,6 @@ export default { sourceFilterSelected: '{count}개 문서 선택됨', sourceFilterClear: '선택 지우기', sourceFilterTooMany: '최대 1000개 문서까지 선택할 수 있습니다', - sourceFilterColName: '파일 이름', - sourceFilterColTime: '업로드 시간', sourceFilterSelectAll: '전체 선택 / 해제 (모든 검색 결과 대상)', sourceFilterOverflowRecent: '문서가 많아 최근 {cap}개만 표시합니다. 키워드로 좁혀 주세요', sourceFilterOverflowHits: '{total}개 문서가 일치했습니다. 처음 {cap}개만 표시 중입니다. 전체 선택 전 키워드를 좁혀 주세요', diff --git a/frontend/src/i18n/locales/ru-RU.ts b/frontend/src/i18n/locales/ru-RU.ts index 7c5ca99d..5376346c 100755 --- a/frontend/src/i18n/locales/ru-RU.ts +++ b/frontend/src/i18n/locales/ru-RU.ts @@ -4566,8 +4566,6 @@ export default { sourceFilterSelected: 'Выбрано документов: {count}', sourceFilterClear: 'Сбросить выбор', sourceFilterTooMany: 'Можно выбрать не более 1000 документов', - sourceFilterColName: 'Имя файла', - sourceFilterColTime: 'Время загрузки', sourceFilterSelectAll: 'Выбрать все / снять выделение (по всем совпадениям)', sourceFilterOverflowRecent: 'Документов много: показаны только последние {cap}. Уточните запрос ключевым словом', sourceFilterOverflowHits: 'Найдено {total} документов; показаны первые {cap}. Сузьте ключевое слово перед выбором всех', diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index dd4f51b2..7a6c9c41 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -4568,8 +4568,6 @@ export default { sourceFilterSelected: '已选 {count} 个文档', sourceFilterClear: '清空已选', sourceFilterTooMany: '最多只能选择 1000 个文档', - sourceFilterColName: '文件名', - sourceFilterColTime: '上传时间', sourceFilterSelectAll: '全选 / 全不选(含全部命中结果)', sourceFilterOverflowRecent: '文档较多,仅显示最近 {cap} 条,请输入关键字精确定位', sourceFilterOverflowHits: '命中 {total} 个文档,仅显示前 {cap} 条,请细化关键字后再全选', diff --git a/frontend/src/i18n/locales/zh-TW.ts b/frontend/src/i18n/locales/zh-TW.ts index c36159b4..655a9147 100644 --- a/frontend/src/i18n/locales/zh-TW.ts +++ b/frontend/src/i18n/locales/zh-TW.ts @@ -4568,8 +4568,6 @@ export default { sourceFilterSelected: '已選 {count} 個文件', sourceFilterClear: '清空已選', sourceFilterTooMany: '最多只能選擇 1000 個文件', - sourceFilterColName: '文件名稱', - sourceFilterColTime: '上傳時間', sourceFilterSelectAll: '全選 / 全不選(含全部命中結果)', sourceFilterOverflowRecent: '文件較多,僅顯示最近 {cap} 條,請輸入關鍵字精確定位', sourceFilterOverflowHits: '命中 {total} 個文件,僅顯示前 {cap} 條,請細化關鍵字後再全選', diff --git a/frontend/src/views/knowledge/gallery/GallerySourcePicker.vue b/frontend/src/views/knowledge/gallery/GallerySourcePicker.vue index 25125e04..5505e8b9 100644 --- a/frontend/src/views/knowledge/gallery/GallerySourcePicker.vue +++ b/frontend/src/views/knowledge/gallery/GallerySourcePicker.vue @@ -4,16 +4,16 @@ import { useI18n } from 'vue-i18n' import { MessagePlugin } from 'tdesign-vue-next' import { listKnowledgeFiles } from '@/api/knowledge-base' -// GallerySourcePicker is the "filter by source document" dialog of the image -// gallery: a paginated, keyword-searchable, sortable checkbox list of the -// knowledge base's documents. Confirming hands the selected ids to the -// gallery (an empty selection clears the restriction); the selection starts -// from what is already active so reopening shows the state the user last -// committed. +// GallerySourcePicker is the "filter by source document" panel of the image +// gallery, rendered inside the toolbar popup next to the filter and sort +// panels: a keyword-searchable checkbox list of the knowledge base's +// documents, newest uploads first, loaded page by page as it scrolls. Like the +// filter panel, every tick applies at once (an empty selection clears the +// restriction). // // Overflow guards: a KB with a huge document count must neither flood the -// dialog nor produce an unbounded gallery query. Without a keyword only the -// most recent RECENT_WINDOW documents are shown; a keyword hit list beyond +// panel nor produce an unbounded gallery query. Without a keyword only the +// most recent RECENT_WINDOW documents are listed; a keyword hit list beyond // SAFE_HITS cannot be select-all-ed (the user is asked to narrow the // keyword), which also keeps one select-all fetch within the backend's // page_size ceiling — the same 1000 the POST /images body cap enforces. @@ -24,33 +24,28 @@ const props = defineProps<{ }>() const emit = defineEmits<{ - (e: 'update:visible', value: boolean): void - (e: 'confirm', knowledgeIds: string[]): void + (e: 'update:selected', knowledgeIds: string[]): void }>() const NS = 'knowledgeEditor.wikiBrowser.gallery' const { t } = useI18n() -const PAGE_SIZE = 20 +const PAGE_SIZE = 30 const RECENT_WINDOW = 500 const SAFE_HITS = 1000 const SEARCH_DEBOUNCE_MS = 300 +const LOAD_AHEAD_PX = 80 const keyword = ref('') -const page = ref(1) +const page = ref(0) const total = ref(0) const loading = ref(false) const bulkLoading = ref(false) -// Sort of the document list; newest uploads first by default so recently -// added documents are at hand. -const sortBy = ref<'created_at' | 'file_name'>('created_at') -const sortDesc = ref(true) -// Documents of the current page. +// Documents loaded so far for the current keyword. const docs = ref>([]) -// Draft selection while the dialog is open; committed on confirm. Search, -// sort and paging only re-render the list and never touch the draft, so a -// keyword-A select-all survives a later keyword-B one (union, not replace). -const draft = ref>(new Set()) +const listEl = ref(null) + +const selectedSet = computed(() => new Set(props.selected)) // How many documents the listing actually offers: the raw total, capped to // the window the overflow guards allow for the current search state. @@ -59,51 +54,62 @@ const shownTotal = computed(() => { return Math.min(total.value, RECENT_WINDOW) }) const overflown = computed(() => total.value > shownTotal.value) +const hasMore = computed(() => docs.value.length < shownTotal.value) // Select-all needs the full hit list in one fetch, so it is only offered // while the current listing is fully enumerable. const canSelectAll = computed(() => !overflown.value && shownTotal.value > 0) -const pageAllSelected = computed( - () => docs.value.length > 0 && docs.value.every((d) => draft.value.has(d.id)), +const loadedAllSelected = computed( + () => docs.value.length > 0 && docs.value.every((d) => selectedSet.value.has(d.id)), ) -const pageSomeSelected = computed(() => docs.value.some((d) => draft.value.has(d.id))) +const loadedSomeSelected = computed(() => docs.value.some((d) => selectedSet.value.has(d.id))) -// Confirming is a no-op only when nothing was committed and nothing is picked. -const canConfirm = computed(() => draft.value.size > 0 || props.selected.length > 0) - -// Bumped by every listing change, so a response for an older search state +// Bumped by every keyword change, so a response for an older search state // (page fetch or select-all) is dropped. let fetchToken = 0 -async function loadDocs() { +async function loadPage(reset: boolean) { if (!props.kbId) return - const token = ++fetchToken + if (reset) { + fetchToken++ + page.value = 0 + docs.value = [] + total.value = 0 + listEl.value?.scrollTo({ top: 0 }) + } + const token = fetchToken + const nextPage = page.value + 1 loading.value = true try { const res: any = await listKnowledgeFiles(props.kbId, { - page: page.value, + page: nextPage, page_size: PAGE_SIZE, keyword: keyword.value.trim() || undefined, - sort_by: sortBy.value, - sort_order: sortDesc.value ? 'desc' : 'asc', + sort_by: 'created_at', + sort_order: 'desc', }) if (token !== fetchToken) return + const known = new Set(docs.value.map((d) => d.id)) const items: any[] = res?.data ?? [] - docs.value = items.map((it) => ({ - id: String(it.id), - file_name: it.file_name || it.title || it.id, - created_at: it.created_at || '', - })) - total.value = Number(res?.total) || 0 - } catch (_) { - if (token === fetchToken) { - docs.value = [] - total.value = 0 + for (const it of items) { + const id = String(it.id) + if (known.has(id)) continue + docs.value.push({ id, file_name: it.file_name || it.title || id, created_at: it.created_at || '' }) } + page.value = nextPage + total.value = items.length ? Number(res?.total) || 0 : docs.value.length + } catch (_) { + if (token === fetchToken && reset) total.value = 0 } finally { if (token === fetchToken) loading.value = false } } +function onListScroll() { + const el = listEl.value + if (!el || loading.value || !hasMore.value) return + if (el.scrollTop + el.clientHeight >= el.scrollHeight - LOAD_AHEAD_PX) void loadPage(false) +} + let searchTimer: ReturnType | undefined function cancelSearch() { if (searchTimer) clearTimeout(searchTimer) @@ -115,53 +121,38 @@ watch( (open) => { cancelSearch() if (!open) return - draft.value = new Set(props.selected) keyword.value = '' - page.value = 1 - sortBy.value = 'created_at' - sortDesc.value = true - void loadDocs() + void loadPage(true) }, + { immediate: true }, ) function onKeywordChange(value: string) { keyword.value = value cancelSearch() - searchTimer = setTimeout(() => { - page.value = 1 - void loadDocs() - }, SEARCH_DEBOUNCE_MS) + searchTimer = setTimeout(() => void loadPage(true), SEARCH_DEBOUNCE_MS) } -// TDesign's pagination change event hands over an info object, not a number. -function onPageChange(info: { current: number; previous: number; pageSize: number }) { - page.value = info.current - void loadDocs() -} - -function toggleSort(field: 'created_at' | 'file_name') { - if (sortBy.value === field) { - sortDesc.value = !sortDesc.value - } else { - sortBy.value = field - // Newest first for upload time, A→Z for names. - sortDesc.value = field === 'created_at' +function commit(next: Set): boolean { + if (next.size > SAFE_HITS) { + MessagePlugin.warning(t(`${NS}.sourceFilterTooMany`)) + return false } - page.value = 1 - void loadDocs() + emit('update:selected', Array.from(next)) + return true } function toggle(id: string, checked: boolean) { - const next = new Set(draft.value) + const next = new Set(props.selected) if (checked) next.add(id) else next.delete(id) - draft.value = next + commit(next) } // Header checkbox, across every hit of the current search (the guards above // keep one fetch within the backend's page_size ceiling): drops the hits when // all of them are already selected, adds them otherwise. Merged into the -// draft so earlier keywords survive. +// selection so earlier keywords survive. async function onToggleAll() { if (!canSelectAll.value || bulkLoading.value) return const token = fetchToken @@ -171,256 +162,162 @@ async function onToggleAll() { page: 1, page_size: SAFE_HITS, keyword: keyword.value.trim() || undefined, - sort_by: sortBy.value, - sort_order: sortDesc.value ? 'desc' : 'asc', + sort_by: 'created_at', + sort_order: 'desc', }) if (token !== fetchToken) return const ids: string[] = (res?.data ?? []).map((it: any) => String(it.id)) if (!ids.length) return - const next = new Set(draft.value) + const next = new Set(props.selected) if (ids.every((id) => next.has(id))) { for (const id of ids) next.delete(id) } else { for (const id of ids) next.add(id) } - draft.value = next + commit(next) } catch (_) { - // keep the draft untouched on failure + // keep the selection untouched on failure } finally { bulkLoading.value = false } } -function close() { - emit('update:visible', false) +function onClear() { + emit('update:selected', []) } -function onConfirm() { - if (draft.value.size > SAFE_HITS) { - MessagePlugin.warning(t(`${NS}.sourceFilterTooMany`)) - return - } - emit('confirm', Array.from(draft.value)) - close() -} +const pad = (n: number) => String(n).padStart(2, '0') -function onClearDraft() { - draft.value = new Set() +function formatDate(raw: string): string { + if (!raw) return '' + const d = new Date(raw) + if (Number.isNaN(d.getTime())) return raw + return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}` } function formatTime(raw: string): string { - if (!raw) return '—' + if (!raw) return '' const d = new Date(raw) if (Number.isNaN(d.getTime())) return raw - const p = (n: number) => String(n).padStart(2, '0') - return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}` + return `${formatDate(raw)} ${pad(d.getHours())}:${pad(d.getMinutes())}` } - - diff --git a/frontend/src/views/knowledge/gallery/ImageGallery.vue b/frontend/src/views/knowledge/gallery/ImageGallery.vue index 28472d8f..14a696dc 100644 --- a/frontend/src/views/knowledge/gallery/ImageGallery.vue +++ b/frontend/src/views/knowledge/gallery/ImageGallery.vue @@ -53,7 +53,7 @@ let scrollObserver: ResizeObserver | undefined // Source-document restriction (the "filter by document" picker). An empty // array means every document of the KB; otherwise only images whose owning -// document is listed are fetched. Committed by the picker dialog. +// document is listed are fetched. Edited from the toolbar's source panel. const sourceDocIds = ref([]) const sourcePickerVisible = ref(false) @@ -365,15 +365,18 @@ function clearFilters(): void { /** The empty state's way back: forget the keyword and source documents as well. */ function clearAll(): void { + if (sourceTimer) clearTimeout(sourceTimer) keyword.value = '' sourceDocIds.value = [] clearFilters() } -/** Committed by the source picker: restrict the listing to these documents. */ -function onSourceDocsConfirm(ids: string[]): void { +/** Ticked in the source panel: restrict the listing to these documents. */ +let sourceTimer: ReturnType | undefined +function onSourceDocsChange(ids: string[]): void { sourceDocIds.value = ids - reload() + if (sourceTimer) clearTimeout(sourceTimer) + sourceTimer = setTimeout(() => reload(), 300) } // --------------------------------------------------------------------------- @@ -576,6 +579,7 @@ function sourceLabel(img: ImageAsset): string { // --------------------------------------------------------------------------- onBeforeUnmount(() => { if (searchTimer) clearTimeout(searchTimer) + if (sourceTimer) clearTimeout(sourceTimer) // Orphan any in-flight listing so it cannot map new blobs after unmount. listToken++ initToken++ @@ -597,6 +601,7 @@ async function initGallery() { const token = ++initToken resetResults() if (searchTimer) clearTimeout(searchTimer) + if (sourceTimer) clearTimeout(sourceTimer) error.value = '' keyword.value = '' sortBy.value = '' @@ -674,16 +679,32 @@ watch( - + + +
- + {{ sourceLabel(img) }}
@@ -922,14 +943,6 @@ watch( @close="closeViewer" @open-source="onOpenSource" /> - - @@ -1385,6 +1398,8 @@ watch( color: var(--td-text-color-placeholder); font-size: var(--app-text-sm); + .t-icon { flex-shrink: 0; } + span { min-width: 0; overflow: hidden;