refactor(gallery): turn source document filter into a toolbar popover (#4190)
Replace the modal dialog with a dropdown panel matching the filter and sort popovers: ticks apply immediately, the list loads on scroll, and the overflow guards (recent window, select-all cap, 1000-doc limit) are kept. Also enlarge the source file icon on gallery cards.main
parent
98362dd296
commit
1c54beb551
|
|
@ -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.',
|
||||
|
|
|
|||
|
|
@ -3535,8 +3535,6 @@ export default {
|
|||
sourceFilterSelected: '{count} 件のドキュメントを選択中',
|
||||
sourceFilterClear: '選択をクリア',
|
||||
sourceFilterTooMany: '選択できるのは最大 1000 件です',
|
||||
sourceFilterColName: 'ファイル名',
|
||||
sourceFilterColTime: 'アップロード日時',
|
||||
sourceFilterSelectAll: 'すべて選択 / 選択解除(全ヒット対象)',
|
||||
sourceFilterOverflowRecent: 'ドキュメントが多いため、最新 {cap} 件のみ表示しています。キーワードで絞り込んでください',
|
||||
sourceFilterOverflowHits: '{total} 件がヒットしました。先頭 {cap} 件のみ表示中です。全選択前にキーワードを絞り込んでください',
|
||||
|
|
|
|||
|
|
@ -4566,8 +4566,6 @@ export default {
|
|||
sourceFilterSelected: '{count}개 문서 선택됨',
|
||||
sourceFilterClear: '선택 지우기',
|
||||
sourceFilterTooMany: '최대 1000개 문서까지 선택할 수 있습니다',
|
||||
sourceFilterColName: '파일 이름',
|
||||
sourceFilterColTime: '업로드 시간',
|
||||
sourceFilterSelectAll: '전체 선택 / 해제 (모든 검색 결과 대상)',
|
||||
sourceFilterOverflowRecent: '문서가 많아 최근 {cap}개만 표시합니다. 키워드로 좁혀 주세요',
|
||||
sourceFilterOverflowHits: '{total}개 문서가 일치했습니다. 처음 {cap}개만 표시 중입니다. 전체 선택 전 키워드를 좁혀 주세요',
|
||||
|
|
|
|||
|
|
@ -4566,8 +4566,6 @@ export default {
|
|||
sourceFilterSelected: 'Выбрано документов: {count}',
|
||||
sourceFilterClear: 'Сбросить выбор',
|
||||
sourceFilterTooMany: 'Можно выбрать не более 1000 документов',
|
||||
sourceFilterColName: 'Имя файла',
|
||||
sourceFilterColTime: 'Время загрузки',
|
||||
sourceFilterSelectAll: 'Выбрать все / снять выделение (по всем совпадениям)',
|
||||
sourceFilterOverflowRecent: 'Документов много: показаны только последние {cap}. Уточните запрос ключевым словом',
|
||||
sourceFilterOverflowHits: 'Найдено {total} документов; показаны первые {cap}. Сузьте ключевое слово перед выбором всех',
|
||||
|
|
|
|||
|
|
@ -4568,8 +4568,6 @@ export default {
|
|||
sourceFilterSelected: '已选 {count} 个文档',
|
||||
sourceFilterClear: '清空已选',
|
||||
sourceFilterTooMany: '最多只能选择 1000 个文档',
|
||||
sourceFilterColName: '文件名',
|
||||
sourceFilterColTime: '上传时间',
|
||||
sourceFilterSelectAll: '全选 / 全不选(含全部命中结果)',
|
||||
sourceFilterOverflowRecent: '文档较多,仅显示最近 {cap} 条,请输入关键字精确定位',
|
||||
sourceFilterOverflowHits: '命中 {total} 个文档,仅显示前 {cap} 条,请细化关键字后再全选',
|
||||
|
|
|
|||
|
|
@ -4568,8 +4568,6 @@ export default {
|
|||
sourceFilterSelected: '已選 {count} 個文件',
|
||||
sourceFilterClear: '清空已選',
|
||||
sourceFilterTooMany: '最多只能選擇 1000 個文件',
|
||||
sourceFilterColName: '文件名稱',
|
||||
sourceFilterColTime: '上傳時間',
|
||||
sourceFilterSelectAll: '全選 / 全不選(含全部命中結果)',
|
||||
sourceFilterOverflowRecent: '文件較多,僅顯示最近 {cap} 條,請輸入關鍵字精確定位',
|
||||
sourceFilterOverflowHits: '命中 {total} 個文件,僅顯示前 {cap} 條,請細化關鍵字後再全選',
|
||||
|
|
|
|||
|
|
@ -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<Array<{ id: string; file_name: string; created_at: string }>>([])
|
||||
// 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<Set<string>>(new Set())
|
||||
const listEl = ref<HTMLElement | null>(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<typeof setTimeout> | 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<string>): 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())}`
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<t-dialog
|
||||
:visible="props.visible"
|
||||
:footer="false"
|
||||
width="640px"
|
||||
dialog-class-name="gallery-source-dialog"
|
||||
:close-on-overlay-click="false"
|
||||
@close="close"
|
||||
>
|
||||
<template #header>
|
||||
<div class="gsp-heading">
|
||||
<div class="gsp-heading__row">
|
||||
<t-icon name="file" size="16px" class="gsp-heading__icon" aria-hidden="true" />
|
||||
<span class="gsp-heading__title">{{ t(`${NS}.sourceFilterTitle`) }}</span>
|
||||
</div>
|
||||
<p class="gsp-heading__subtitle">{{ t(`${NS}.sourceFilterSubtitle`) }}</p>
|
||||
</div>
|
||||
</template>
|
||||
<section class="gsp-panel" :aria-label="t(`${NS}.sourceFilterTitle`)">
|
||||
<header class="gsp-panel__header">
|
||||
<strong>{{ t(`${NS}.sourceFilterTitle`) }}</strong>
|
||||
<button type="button" :disabled="!props.selected.length" @click="onClear">
|
||||
{{ t(`${NS}.sourceFilterClear`) }}
|
||||
</button>
|
||||
</header>
|
||||
<div class="gsp-panel__hint">{{ t(`${NS}.sourceFilterSubtitle`) }}</div>
|
||||
|
||||
<div class="gsp-body">
|
||||
<t-input
|
||||
:value="keyword"
|
||||
clearable
|
||||
:placeholder="t(`${NS}.sourceFilterSearch`)"
|
||||
:aria-label="t(`${NS}.sourceFilterSearch`)"
|
||||
class="gsp-search"
|
||||
@change="(v: string) => onKeywordChange(String(v ?? ''))"
|
||||
<t-input
|
||||
:value="keyword"
|
||||
clearable
|
||||
:placeholder="t(`${NS}.sourceFilterSearch`)"
|
||||
:aria-label="t(`${NS}.sourceFilterSearch`)"
|
||||
class="gsp-search"
|
||||
@change="(v: string) => onKeywordChange(String(v ?? ''))"
|
||||
>
|
||||
<template #prefix-icon><t-icon name="search" size="16px" /></template>
|
||||
</t-input>
|
||||
|
||||
<div v-if="overflown" class="gsp-overflow-hint" role="status">
|
||||
<t-icon name="info-circle" size="14px" />
|
||||
<span>
|
||||
{{
|
||||
keyword.trim()
|
||||
? t(`${NS}.sourceFilterOverflowHits`, { total: total, cap: shownTotal })
|
||||
: t(`${NS}.sourceFilterOverflowRecent`, { cap: shownTotal })
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="gsp-bar">
|
||||
<t-checkbox
|
||||
:checked="loadedAllSelected"
|
||||
:indeterminate="loadedSomeSelected && !loadedAllSelected"
|
||||
:disabled="!canSelectAll || bulkLoading"
|
||||
:title="canSelectAll ? t(`${NS}.sourceFilterSelectAll`) : undefined"
|
||||
@change="onToggleAll"
|
||||
>
|
||||
<template #prefix-icon><t-icon name="search" size="16px" /></template>
|
||||
</t-input>
|
||||
{{ t('common.selectAll') }}
|
||||
</t-checkbox>
|
||||
<span class="gsp-bar__count">{{ t(`${NS}.sourceFilterSelected`, { count: props.selected.length }) }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="overflown" class="gsp-overflow-hint" role="status">
|
||||
<t-icon name="info-circle" size="14px" />
|
||||
<span>
|
||||
{{
|
||||
keyword.trim()
|
||||
? t(`${NS}.sourceFilterOverflowHits`, { total: total, cap: shownTotal })
|
||||
: t(`${NS}.sourceFilterOverflowRecent`, { cap: shownTotal })
|
||||
}}
|
||||
<div ref="listEl" class="gsp-list" @scroll.passive="onListScroll">
|
||||
<div
|
||||
v-for="d in docs"
|
||||
:key="d.id"
|
||||
class="gsp-item"
|
||||
:class="{ 'is-selected': selectedSet.has(d.id) }"
|
||||
:title="`${d.file_name}${d.created_at ? ' · ' + formatTime(d.created_at) : ''}`"
|
||||
@click="toggle(d.id, !selectedSet.has(d.id))"
|
||||
>
|
||||
<span class="gsp-item__check" @click.stop>
|
||||
<t-checkbox
|
||||
:checked="selectedSet.has(d.id)"
|
||||
@change="(checked: boolean) => toggle(d.id, checked)"
|
||||
/>
|
||||
</span>
|
||||
<span class="gsp-item__name">{{ d.file_name }}</span>
|
||||
<span class="gsp-item__time">{{ formatDate(d.created_at) }}</span>
|
||||
</div>
|
||||
|
||||
<t-loading :loading="loading || bulkLoading" size="small" show-overlay>
|
||||
<div class="gsp-table">
|
||||
<div class="gsp-row gsp-head">
|
||||
<div class="gsp-col-check">
|
||||
<t-checkbox
|
||||
:checked="pageAllSelected"
|
||||
:indeterminate="pageSomeSelected && !pageAllSelected"
|
||||
:disabled="!canSelectAll"
|
||||
:title="canSelectAll ? t(`${NS}.sourceFilterSelectAll`) : undefined"
|
||||
@change="onToggleAll"
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="gsp-head-cell"
|
||||
:class="{ 'is-active': sortBy === 'file_name' }"
|
||||
@click="toggleSort('file_name')"
|
||||
>
|
||||
<span>{{ t(`${NS}.sourceFilterColName`) }}</span>
|
||||
<t-icon v-if="sortBy === 'file_name'" :name="sortDesc ? 'arrow-down' : 'arrow-up'" size="14px" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="gsp-head-cell"
|
||||
:class="{ 'is-active': sortBy === 'created_at' }"
|
||||
@click="toggleSort('created_at')"
|
||||
>
|
||||
<span>{{ t(`${NS}.sourceFilterColTime`) }}</span>
|
||||
<t-icon v-if="sortBy === 'created_at'" :name="sortDesc ? 'arrow-down' : 'arrow-up'" size="14px" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="gsp-list">
|
||||
<div
|
||||
v-for="d in docs"
|
||||
:key="d.id"
|
||||
class="gsp-row gsp-item"
|
||||
:class="{ 'is-selected': draft.has(d.id) }"
|
||||
@click="toggle(d.id, !draft.has(d.id))"
|
||||
>
|
||||
<div class="gsp-col-check" @click.stop>
|
||||
<t-checkbox :checked="draft.has(d.id)" @change="(checked: boolean) => toggle(d.id, checked)" />
|
||||
</div>
|
||||
<div class="gsp-col-name" :title="d.file_name">{{ d.file_name }}</div>
|
||||
<div class="gsp-col-time">{{ formatTime(d.created_at) }}</div>
|
||||
</div>
|
||||
<div v-if="!docs.length && !loading" class="gsp-empty">
|
||||
{{ t(`${NS}.sourceFilterEmpty`) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t-loading>
|
||||
|
||||
<t-pagination
|
||||
v-if="shownTotal > PAGE_SIZE"
|
||||
class="gsp-pagination"
|
||||
size="small"
|
||||
:current="page"
|
||||
:total="shownTotal"
|
||||
:page-size="PAGE_SIZE"
|
||||
:show-page-size="false"
|
||||
:show-jumper="false"
|
||||
@change="onPageChange"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="gsp-footer">
|
||||
<div class="gsp-footer__left">
|
||||
<span class="gsp-footer__count">{{ t(`${NS}.sourceFilterSelected`, { count: draft.size }) }}</span>
|
||||
<button v-if="draft.size" type="button" class="gsp-footer__clear" @click="onClearDraft">
|
||||
{{ t(`${NS}.sourceFilterClear`) }}
|
||||
</button>
|
||||
<div v-if="loading || bulkLoading" class="gsp-list__status">
|
||||
<t-loading size="small" />
|
||||
</div>
|
||||
<div class="gsp-footer__right">
|
||||
<t-button variant="outline" size="small" @click="close">{{ t('common.cancel') }}</t-button>
|
||||
<t-button theme="primary" size="small" :disabled="!canConfirm || bulkLoading" @click="onConfirm">
|
||||
{{ t('common.confirm') }}
|
||||
</t-button>
|
||||
<div v-else-if="!docs.length" class="gsp-list__status">
|
||||
{{ t(`${NS}.sourceFilterEmpty`) }}
|
||||
</div>
|
||||
</div>
|
||||
</t-dialog>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
/* The dialog renders outside the component; same shell as BatchTagDialog. */
|
||||
.gallery-source-dialog {
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
border-radius: var(--app-radius-xs);
|
||||
}
|
||||
|
||||
.gallery-source-dialog .t-dialog__header {
|
||||
min-height: auto;
|
||||
padding: 20px 20px 0;
|
||||
}
|
||||
|
||||
.gallery-source-dialog .t-dialog__body {
|
||||
padding: 16px 20px 20px;
|
||||
}
|
||||
|
||||
.gallery-source-dialog .t-dialog__close {
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
border-radius: var(--app-radius-xs);
|
||||
color: var(--td-text-color-secondary);
|
||||
transition: background var(--app-motion-fast) ease;
|
||||
}
|
||||
|
||||
.gallery-source-dialog .t-dialog__close:hover {
|
||||
<style scoped lang="less">
|
||||
// Same frame and type scale as the gallery's filter panel.
|
||||
.gsp-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 360px;
|
||||
max-width: calc(100vw - 32px);
|
||||
padding: 16px;
|
||||
box-sizing: border-box;
|
||||
color: var(--td-text-color-primary);
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
font-size: var(--app-text-md);
|
||||
|
||||
@media (max-width: 680px) {
|
||||
.gallery-source-dialog {
|
||||
width: calc(100vw - 24px) !important;
|
||||
&__header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
strong {
|
||||
font-size: var(--app-text-base);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
button {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary);
|
||||
font: inherit;
|
||||
font-size: var(--app-text-sm);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover:not(:disabled) { color: var(--td-brand-color); }
|
||||
&:disabled { color: var(--td-text-color-disabled); cursor: default; }
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style scoped>
|
||||
.gsp-heading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
padding-right: 28px;
|
||||
}
|
||||
|
||||
.gsp-heading__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.gsp-heading__icon {
|
||||
flex-shrink: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
|
||||
.gsp-heading__title {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-lg);
|
||||
font-weight: 600;
|
||||
line-height: 22px;
|
||||
}
|
||||
|
||||
.gsp-heading__subtitle {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
font-weight: 400;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
.gsp-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
&__hint {
|
||||
margin: 2px 0 12px;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-xs);
|
||||
line-height: 17px;
|
||||
}
|
||||
}
|
||||
|
||||
.gsp-search :deep(.t-input) {
|
||||
|
|
@ -433,167 +330,82 @@ function formatTime(raw: string): string {
|
|||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
padding: 8px 10px;
|
||||
border-radius: var(--app-radius-md);
|
||||
background: var(--td-warning-color-1);
|
||||
color: var(--td-warning-color-7);
|
||||
font-size: var(--app-text-sm);
|
||||
line-height: 18px;
|
||||
margin-top: 8px;
|
||||
color: var(--td-warning-color);
|
||||
font-size: var(--app-text-xs);
|
||||
line-height: 17px;
|
||||
|
||||
.t-icon {
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.gsp-overflow-hint .t-icon {
|
||||
flex-shrink: 0;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.gsp-table {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 240px;
|
||||
border: 1px solid var(--td-component-stroke);
|
||||
border-radius: var(--app-radius-md);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.gsp-row {
|
||||
display: grid;
|
||||
grid-template-columns: 32px minmax(0, 1fr) 136px;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.gsp-head {
|
||||
height: 36px;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.gsp-head-cell {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: none;
|
||||
font: inherit;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
justify-self: start;
|
||||
}
|
||||
|
||||
.gsp-head-cell:hover {
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.gsp-head-cell.is-active {
|
||||
color: var(--td-text-color-primary);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.gsp-head-cell:focus-visible {
|
||||
outline: 2px solid var(--app-focus-border);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.gsp-list {
|
||||
max-height: 324px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.gsp-item {
|
||||
height: 36px;
|
||||
cursor: pointer;
|
||||
transition: background-color var(--app-motion-fast) ease;
|
||||
}
|
||||
|
||||
.gsp-item + .gsp-item {
|
||||
border-top: 1px solid var(--td-component-stroke);
|
||||
}
|
||||
|
||||
.gsp-item:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
.gsp-item.is-selected {
|
||||
background: var(--td-brand-color-light);
|
||||
}
|
||||
|
||||
.gsp-col-check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.gsp-col-name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: var(--app-text-md);
|
||||
}
|
||||
|
||||
.gsp-col-time {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.gsp-empty {
|
||||
padding: 48px 0;
|
||||
text-align: center;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
|
||||
.gsp-pagination {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.gsp-footer {
|
||||
.gsp-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-top: 14px;
|
||||
padding-top: 14px;
|
||||
border-top: 1px solid var(--td-component-stroke);
|
||||
margin-top: 12px;
|
||||
padding: 0 8px 8px;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
&__count {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.gsp-footer__left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
min-width: 0;
|
||||
.gsp-list {
|
||||
max-height: 288px;
|
||||
min-height: 96px;
|
||||
margin: 4px -8px 0;
|
||||
padding: 0 8px;
|
||||
overflow-y: auto;
|
||||
|
||||
&__status {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 16px 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
}
|
||||
}
|
||||
|
||||
.gsp-footer__count {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-sm);
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.gsp-footer__clear {
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--td-text-color-secondary);
|
||||
font: inherit;
|
||||
font-size: var(--app-text-sm);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.gsp-footer__clear:hover {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
|
||||
.gsp-footer__right {
|
||||
.gsp-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
height: 32px;
|
||||
padding: 0 8px;
|
||||
border-radius: var(--app-radius-sm);
|
||||
cursor: pointer;
|
||||
transition: background-color var(--app-motion-fast) ease;
|
||||
|
||||
&:hover { background: var(--td-bg-color-secondarycontainer); }
|
||||
|
||||
&__check {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
&__name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&__time {
|
||||
flex-shrink: 0;
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-size: var(--app-text-xs);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
&.is-selected .gsp-item__name { color: var(--td-brand-color); }
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -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<string[]>([])
|
||||
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<typeof setTimeout> | 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(
|
|||
<template #prefix-icon><t-icon name="search" size="16px" /></template>
|
||||
</t-input>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="ig-tool-btn"
|
||||
:class="{ active: sourcePickerVisible || sourceDocIds.length > 0 }"
|
||||
@click="sourcePickerVisible = true"
|
||||
<t-popup
|
||||
v-model:visible="sourcePickerVisible"
|
||||
trigger="click"
|
||||
placement="bottom-right"
|
||||
overlay-class-name="gallery-toolbar-popup"
|
||||
:overlay-inner-style="{ padding: 0 }"
|
||||
>
|
||||
<t-icon name="file" size="16px" />
|
||||
{{ t(`${NS}.sourceFilter`) }}
|
||||
<span v-if="sourceDocIds.length" class="ig-tool-btn__count">{{ sourceDocIds.length }}</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="ig-tool-btn"
|
||||
:class="{ active: sourcePickerVisible || sourceDocIds.length > 0 }"
|
||||
:aria-expanded="sourcePickerVisible"
|
||||
>
|
||||
<t-icon name="file" size="16px" />
|
||||
{{ t(`${NS}.sourceFilter`) }}
|
||||
<span v-if="sourceDocIds.length" class="ig-tool-btn__count">{{ sourceDocIds.length }}</span>
|
||||
</button>
|
||||
<template #content>
|
||||
<GallerySourcePicker
|
||||
:kb-id="props.knowledgeBaseId"
|
||||
:visible="sourcePickerVisible"
|
||||
:selected="sourceDocIds"
|
||||
@update:selected="onSourceDocsChange"
|
||||
/>
|
||||
</template>
|
||||
</t-popup>
|
||||
|
||||
<t-popup
|
||||
v-model:visible="filterPanelVisible"
|
||||
|
|
@ -890,7 +911,7 @@ watch(
|
|||
{{ img.caption || t(`${NS}.noCaption`) }}
|
||||
</div>
|
||||
<div class="ig-card__source" :title="sourceLabel(img)">
|
||||
<t-icon name="file" size="12px" />
|
||||
<t-icon name="file" size="14px" />
|
||||
<span>{{ sourceLabel(img) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -922,14 +943,6 @@ watch(
|
|||
@close="closeViewer"
|
||||
@open-source="onOpenSource"
|
||||
/>
|
||||
|
||||
<GallerySourcePicker
|
||||
:kb-id="props.knowledgeBaseId"
|
||||
:visible="sourcePickerVisible"
|
||||
:selected="sourceDocIds"
|
||||
@update:visible="(v: boolean) => (sourcePickerVisible = v)"
|
||||
@confirm="onSourceDocsConfirm"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue