From 3e7b19500229af346c03a087fac2bad3d4a568c8 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Tue, 11 Nov 2025 16:43:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=A7=A3=E5=86=B3=E6=96=B9?= =?UTF-8?q?=E6=A1=88=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/useSolution.ts | 24 ++++--------------- app/graphql/solution.graphql | 12 ++++++++++ .../solutions/{[...slug].vue => [slug].vue} | 8 +++---- 3 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 app/graphql/solution.graphql rename app/pages/solutions/{[...slug].vue => [slug].vue} (90%) diff --git a/app/composables/directus/useSolution.ts b/app/composables/directus/useSolution.ts index 78b77de..1ab8f55 100644 --- a/app/composables/directus/useSolution.ts +++ b/app/composables/directus/useSolution.ts @@ -1,4 +1,4 @@ -import { readItem } from '@directus/sdk'; +import GetSolution from '@/graphql/solution.graphql?raw'; export const useSolution = (id: string) => { const { $directus } = useNuxtApp(); @@ -6,23 +6,9 @@ export const useSolution = (id: string) => { const locale = getDirectusLocale(); return useAsyncData(`solution-${id}-${locale}`, async () => { - return await $directus.request( - readItem('solutions', id, { - fields: [ - 'id', - { - translations: ['*'], - }, - 'create_at', - ], - deep: { - translations: { - _filter: { - languages_code: { _eq: locale }, - }, - }, - }, - }) - ); + return await $directus.query<{ solutions_by_id: Solution }>(GetSolution, { + id: id, + locale: locale, + }); }); }; diff --git a/app/graphql/solution.graphql b/app/graphql/solution.graphql new file mode 100644 index 0000000..ae2f590 --- /dev/null +++ b/app/graphql/solution.graphql @@ -0,0 +1,12 @@ +query GetSolution($id: ID!, $locale: String!) { + solutions_by_id(id: $id) { + id + translations(filter: { languages_code: { code: { _eq: $locale } } }) { + id + title + summary + content + } + create_at + } +} diff --git a/app/pages/solutions/[...slug].vue b/app/pages/solutions/[slug].vue similarity index 90% rename from app/pages/solutions/[...slug].vue rename to app/pages/solutions/[slug].vue index e3ec505..06a7ec8 100644 --- a/app/pages/solutions/[...slug].vue +++ b/app/pages/solutions/[slug].vue @@ -26,16 +26,16 @@ const route = useRoute(); const localePath = useLocalePath(); - // 获取路由参数(documentId) - const id = computed(() => route.params.slug as string); + // 获取路由参数 + const id = route.params.slug as string; - const { data, pending, error } = await useSolution(id.value); + const { data, pending, error } = await useSolution(id); const solution = computed(() => { if (!data.value) { return null; } - return toSolutionView(data.value); + return toSolutionView(data.value.solutions_by_id); }); const breadcrumbItems = computed(() => [