feat(knowledge-base): add document batch delete and list view
Add a list-view alongside the existing card grid (issue #957) and multi-select batch delete (issue #1045) for documents inside a knowledge base. The two views are toggled from the toolbar and the preference is persisted in localStorage. Selection state is shared between views with shift-range support and a sticky batch-action bar. Backend - POST /api/v1/knowledge/batch-delete: validates KB scope and editor permission, then delegates to the existing DeleteKnowledgeList service which already cascades vector/file/graph cleanup. Caps batch size at 200 and uses a single GetKnowledgeBatch call for membership validation. Frontend - DocumentListView: table layout with sticky header, checkbox column (with indeterminate select-all), file-type icons, status badges, per-row action menu. - DocumentBatchBar: floating pill bar with selected count and delete action; appears when items are selected. - KnowledgeBase.vue: view-mode toggle, selection state, batch-delete confirmation dialog, hover/active checkbox overlay on existing cards. - Extracted formatFileSize and getFileIcon to utils/files.ts to share with the new list view and avoid further drift from the existing inline copies. - i18n keys added for zh-CN, en-US, ko-KR, ru-RU. Closes #1045 Closes #957
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Format a byte count as a human-readable string (B / KB / MB).
|
||||
* Returns '' for null/undefined/non-positive values so callers can use it as a v-if guard.
|
||||
*/
|
||||
export function formatFileSize(bytes?: number | string | null): string {
|
||||
if (bytes == null || bytes === '') return '';
|
||||
const n = typeof bytes === 'string' ? parseInt(bytes, 10) : bytes;
|
||||
if (Number.isNaN(n) || n <= 0) return '';
|
||||
if (n < 1024) return `${n} B`;
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
||||
return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a knowledge item or filename to a TDesign icon name.
|
||||
* Accepts either a string (filename) or a knowledge-like object with `type`/`file_type`/`file_name`.
|
||||
*/
|
||||
export function getFileIcon(input: string | { type?: string; file_type?: string; file_name?: string }): string {
|
||||
let type: string | undefined;
|
||||
let ext: string | undefined;
|
||||
if (typeof input === 'string') {
|
||||
ext = input.split('.').pop()?.toLowerCase();
|
||||
} else {
|
||||
type = input.type;
|
||||
if (type === 'manual') return 'edit';
|
||||
if (type === 'url') return 'link';
|
||||
ext = (input.file_type || input.file_name?.split('.').pop() || '').toLowerCase();
|
||||
}
|
||||
if (!ext) return 'file';
|
||||
if (['pdf'].includes(ext)) return 'file-pdf';
|
||||
if (['doc', 'docx'].includes(ext)) return 'file-word';
|
||||
if (['xls', 'xlsx', 'csv'].includes(ext)) return 'file-excel';
|
||||
if (['ppt', 'pptx'].includes(ext)) return 'file-powerpoint';
|
||||
if (['txt', 'md', 'markdown'].includes(ext)) return 'file-text';
|
||||
if (['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp'].includes(ext)) return 'image';
|
||||
if (['mp3', 'wav', 'm4a', 'flac', 'ogg', 'aac'].includes(ext)) return 'sound';
|
||||
return 'file';
|
||||
}
|
||||
Reference in New Issue
Block a user