From 5ad61332529ab8b5123be0a2624cec164abf7363 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Tue, 11 Nov 2025 16:55:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=96=87=E6=A1=A3=E8=B5=84?= =?UTF-8?q?=E6=96=99=E9=A1=B5=E7=9A=84API=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/composables/directus/useDocumentList.ts | 63 ++------------------- app/graphql/documentList.graphql | 31 ++++++++++ app/pages/support/documents.vue | 4 +- 3 files changed, 40 insertions(+), 58 deletions(-) create mode 100644 app/graphql/documentList.graphql diff --git a/app/composables/directus/useDocumentList.ts b/app/composables/directus/useDocumentList.ts index fc21823..11b0978 100644 --- a/app/composables/directus/useDocumentList.ts +++ b/app/composables/directus/useDocumentList.ts @@ -1,4 +1,4 @@ -import { readItems } from '@directus/sdk'; +import GetDocumentList from '@/graphql/documentList.graphql?raw'; export const useDocumentList = () => { const { $directus } = useNuxtApp(); @@ -6,62 +6,11 @@ export const useDocumentList = () => { const locale = getDirectusLocale(); return useAsyncData(`document-list-${locale}`, async () => { - return await $directus.request( - readItems('product_documents', { - fields: [ - 'id', - { - file: ['id', 'filesize', 'filename_download'], - }, - { - translations: ['id', 'title'], - }, - { - products: [ - 'id', - { - products_id: [ - 'id', - { - translations: ['id', 'name'], - }, - { - product_type: [ - 'id', - { - translations: ['id', 'name'], - }, - ], - }, - ], - }, - ], - }, - ], - deep: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - products: { - products_id: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - product_type: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - }, - }, - }, - }, - }) + return await $directus.query<{ product_documents: ProductDocument[] }>( + GetDocumentList, + { + locale: locale, + } ); }); }; diff --git a/app/graphql/documentList.graphql b/app/graphql/documentList.graphql new file mode 100644 index 0000000..e133dcd --- /dev/null +++ b/app/graphql/documentList.graphql @@ -0,0 +1,31 @@ +query GetDocumentList($locale: String!) { + product_documents { + id + file { + id + filesize + filename_download + } + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + title + } + products { + id + products_id { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + name + } + product_type { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + name + } + } + } + } + } +} diff --git a/app/pages/support/documents.vue b/app/pages/support/documents.vue index 3320a67..454caaf 100644 --- a/app/pages/support/documents.vue +++ b/app/pages/support/documents.vue @@ -38,7 +38,9 @@ const { data, pending, error } = await useDocumentList(); const documents = computed( - () => data?.value.map((item) => toDocumentListView(item)) ?? [] + () => + data?.value.product_documents.map((item) => toDocumentListView(item)) ?? + [] ); const productTypeOptions = computed(() => {