From 706b754905b430a80d8093d3b82d2e4984f8ac28 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Tue, 11 Nov 2025 16:35:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=A7=A3=E5=86=B3=E6=96=B9?= =?UTF-8?q?=E6=A1=88=E5=88=97=E8=A1=A8=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/useSolutionList.ts | 33 +++------------------ app/graphql/solutionList.graphql | 21 +++++++++++++ app/pages/solutions/index.vue | 2 +- 3 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 app/graphql/solutionList.graphql diff --git a/app/composables/directus/useSolutionList.ts b/app/composables/directus/useSolutionList.ts index 8fe659f..fcbd25d 100644 --- a/app/composables/directus/useSolutionList.ts +++ b/app/composables/directus/useSolutionList.ts @@ -1,4 +1,4 @@ -import { readItems } from '@directus/sdk'; +import GetSolutionList from '@/graphql/solutionList.graphql?raw'; export const useSolutionList = () => { const { $directus } = useNuxtApp(); @@ -6,33 +6,8 @@ export const useSolutionList = () => { const locale = getDirectusLocale(); return useAsyncData(`solution-list-${locale}`, async () => { - return await $directus.request( - readItems('solutions', { - fields: [ - 'id', - 'cover', - { - type: ['id', { translations: ['id', 'name'] }, 'sort'], - }, - { - translations: ['id', 'title', 'summary'], - }, - ], - deep: { - type: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - }, - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - }, - }) - ); + return await $directus.query<{ solutions: Solution[] }>(GetSolutionList, { + locale: locale, + }); }); }; diff --git a/app/graphql/solutionList.graphql b/app/graphql/solutionList.graphql new file mode 100644 index 0000000..8422275 --- /dev/null +++ b/app/graphql/solutionList.graphql @@ -0,0 +1,21 @@ +query GetSolutionList($locale: String!) { + solutions { + id + cover { + id + } + type { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + name + } + sort + } + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + title + summary + } + } +} diff --git a/app/pages/solutions/index.vue b/app/pages/solutions/index.vue index 33bf637..77442cd 100644 --- a/app/pages/solutions/index.vue +++ b/app/pages/solutions/index.vue @@ -54,7 +54,7 @@ const { data, pending, error } = await useSolutionList(); - const solutionsRaw = computed(() => data.value ?? []); + const solutionsRaw = computed(() => data.value.solutions ?? []); const solutions = computed(() => solutionsRaw.value.map((item) => toSolutionListView(item)) );