From 8213eec21700dfca37e0a9147dccd6dba0e00641 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Tue, 11 Nov 2025 17:01:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=85=B3=E4=BA=8E=E6=88=91?= =?UTF-8?q?=E4=BB=AC=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/useCompanyProfile.ts | 25 +++++-------------- app/graphql/companyProfile.graphql | 9 +++++++ app/pages/about/index.vue | 4 ++- 3 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 app/graphql/companyProfile.graphql diff --git a/app/composables/directus/useCompanyProfile.ts b/app/composables/directus/useCompanyProfile.ts index 0b26039..af3954b 100644 --- a/app/composables/directus/useCompanyProfile.ts +++ b/app/composables/directus/useCompanyProfile.ts @@ -1,4 +1,4 @@ -import { readSingleton } from '@directus/sdk'; +import GetCompanyProfile from '@/graphql/companyProfile.graphql?raw'; export const useCompanyProfile = () => { const { $directus } = useNuxtApp(); @@ -6,24 +6,11 @@ export const useCompanyProfile = () => { const locale = getDirectusLocale(); return useAsyncData(`company-profile-${locale}`, async () => { - return await $directus.request( - readSingleton('company_profile', { - fields: [ - 'id', - { - translations: ['id', 'content'], - }, - ], - deep: { - translations: { - _filter: { - languages_code: { - _eq: locale, - }, - }, - }, - }, - }) + return await $directus.query<{ company_profile: CompanyProfile }>( + GetCompanyProfile, + { + locale: locale, + } ); }); }; diff --git a/app/graphql/companyProfile.graphql b/app/graphql/companyProfile.graphql new file mode 100644 index 0000000..97f362e --- /dev/null +++ b/app/graphql/companyProfile.graphql @@ -0,0 +1,9 @@ +query GetCompanyProfile($locale: String!) { + company_profile { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + content + } + } +} diff --git a/app/pages/about/index.vue b/app/pages/about/index.vue index 64dd05f..09a775c 100644 --- a/app/pages/about/index.vue +++ b/app/pages/about/index.vue @@ -34,7 +34,9 @@ ]; const { data, pending, error } = await useCompanyProfile(); - const content = computed(() => toCompanyProfileView(data.value)); + const content = computed(() => + toCompanyProfileView(data.value.company_profile) + ); watch(error, (value) => { if (value) {