simplify
This commit is contained in:
@@ -11,6 +11,7 @@ import { useTemplateCatalog } from '@/composables/template/useTemplateCatalog';
|
||||
import { usePageBoot } from '@/composables/shell/usePageBoot';
|
||||
import { useApiAction } from '@/composables/actions/useApiAction';
|
||||
import { DEFAULT_DOCUMENT_TYPE, normalizeDocumentType } from '@/utils/documentType';
|
||||
import { formatDate as _formatDate } from '@/utils/formatDate';
|
||||
|
||||
export function useKnowledgeBaseDetailPage({ t, router, route, userStore, locale }) {
|
||||
const { runWithLoading, createApiErrorHandler } = useApiAction({ t });
|
||||
@@ -73,11 +74,7 @@ export function useKnowledgeBaseDetailPage({ t, router, route, userStore, locale
|
||||
{ value: 'type', label: t('knowledgeBase.sortByType') }
|
||||
]);
|
||||
|
||||
const formatDate = (dateString) => {
|
||||
if (!dateString) return t('common.unknown');
|
||||
const date = new Date(dateString);
|
||||
return date.toLocaleDateString();
|
||||
};
|
||||
const formatDate = (value) => _formatDate(value, { fallback: t('common.unknown') });
|
||||
|
||||
const knowledgeBaseStats = computed(() => [
|
||||
{ key: 'documents', icon: Document, label: t('knowledgeBase.documentsCount'), value: totalDocuments.value },
|
||||
@@ -88,16 +85,19 @@ export function useKnowledgeBaseDetailPage({ t, router, route, userStore, locale
|
||||
const directoryTreeData = computed(() => {
|
||||
if (!knowledgeBaseData.value?.documents) return [];
|
||||
|
||||
const mapDoc = (doc, parentId = null) => ({
|
||||
id: doc.external_id,
|
||||
label: doc.title,
|
||||
type: doc.type,
|
||||
isFolder: doc.hasChildren || (doc.children && doc.children.length > 0),
|
||||
isLeaf: !(doc.hasChildren || (doc.children && doc.children.length > 0)),
|
||||
tags: doc.tags || [],
|
||||
parentId,
|
||||
children: doc.children ? doc.children.map((child) => mapDoc(child, doc.external_id)) : []
|
||||
});
|
||||
const mapDoc = (doc, parentId = null) => {
|
||||
const isFolder = doc.hasChildren || (doc.children && doc.children.length > 0);
|
||||
return {
|
||||
id: doc.external_id,
|
||||
label: doc.title,
|
||||
type: doc.type,
|
||||
isFolder,
|
||||
isLeaf: !isFolder,
|
||||
tags: doc.tags || [],
|
||||
parentId,
|
||||
children: doc.children ? doc.children.map((child) => mapDoc(child, doc.external_id)) : []
|
||||
};
|
||||
};
|
||||
|
||||
return knowledgeBaseData.value.documents.map((doc) => mapDoc(doc));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user