From a07d77dde73468530cc8febf196e92db370460e8 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Tue, 11 Nov 2025 16:49:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=97=AE=E9=A2=98=E5=88=97?= =?UTF-8?q?=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/useQuestionList.ts | 57 ++------------------- app/graphql/questionList.graphql | 27 ++++++++++ app/pages/support/faq.vue | 2 +- 3 files changed, 32 insertions(+), 54 deletions(-) create mode 100644 app/graphql/questionList.graphql diff --git a/app/composables/directus/useQuestionList.ts b/app/composables/directus/useQuestionList.ts index 76e1350..d9c35b2 100644 --- a/app/composables/directus/useQuestionList.ts +++ b/app/composables/directus/useQuestionList.ts @@ -1,4 +1,4 @@ -import { readItems } from '@directus/sdk'; +import GetQuestionList from '@/graphql/questionList.graphql?raw'; export const useQuestionList = () => { const { $directus } = useNuxtApp(); @@ -7,57 +7,8 @@ export const useQuestionList = () => { const locale = getDirectusLocale(); return useAsyncData(`question-list-${locale}`, async () => { - return await $directus.request( - readItems('questions', { - fields: [ - 'id', - { - translations: ['*'], - }, - { - products: [ - 'id', - { - products_id: [ - 'id', - { - product_type: [ - 'id', - { - translations: ['id', 'name'], - }, - ], - }, - { translations: ['id', 'name'] }, - ], - }, - ], - }, - ], - deep: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - products: { - products_id: { - product_type: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - }, - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - }, - }, - }, - }) - ); + return await $directus.query<{ questions: Question[] }>(GetQuestionList, { + locale: locale, + }); }); }; diff --git a/app/graphql/questionList.graphql b/app/graphql/questionList.graphql new file mode 100644 index 0000000..39085c6 --- /dev/null +++ b/app/graphql/questionList.graphql @@ -0,0 +1,27 @@ +query GetQuestionList($locale: String!) { + questions { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + title + content + } + products { + id + products_id { + id + product_type { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + name + } + } + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + name + } + } + } + } +} diff --git a/app/pages/support/faq.vue b/app/pages/support/faq.vue index eb668f2..f9351d0 100644 --- a/app/pages/support/faq.vue +++ b/app/pages/support/faq.vue @@ -41,7 +41,7 @@ const { data, pending, error } = await useQuestionList(); const questions = computed( - () => data.value.map((item) => toQuestionListView(item)) ?? null + () => data.value.questions.map((item) => toQuestionListView(item)) ?? null ); const productTypeOptions = computed(() => {