refactor: 重构项目的数据获取方法 #72

Manually merged
remilia merged 13 commits from refactor/graphql into master 2025-11-11 17:07:41 +08:00
34 changed files with 458 additions and 382 deletions
Showing only changes of commit ac9e7b4436 - Show all commits

View File

@ -1,4 +1,4 @@
import { readSingleton } from '@directus/sdk';
import GetContactInfo from '@/graphql/contactInfo.graphql?raw';
export const useContactInfo = () => {
const { $directus } = useNuxtApp();
@ -6,24 +6,11 @@ export const useContactInfo = () => {
const locale = getDirectusLocale();
return useAsyncData(`contact-info-${locale}`, async () => {
return await $directus.request(
readSingleton('contact_info', {
fields: [
'id',
{
translations: ['id', 'content'],
},
],
deep: {
translations: {
_filter: {
languages_code: {
_eq: locale,
},
},
},
},
})
return await $directus.query<{ contact_info: ContactInfo }>(
GetContactInfo,
{
locale: locale,
}
);
});
};

View File

@ -0,0 +1,9 @@
query GetContactInfo($locale: String!) {
contact_info {
id
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
id
content
}
}
}

View File

@ -24,7 +24,7 @@
];
const { data, pending, error } = await useContactInfo();
const content = computed(() => toContactInfoView(data.value));
const content = computed(() => toContactInfoView(data.value.contact_info));
watch(error, (value) => {
if (value) {