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

Manually merged
remilia merged 13 commits from refactor/graphql into master 2025-11-11 17:07:41 +08:00
37 changed files with 476 additions and 402 deletions
Showing only changes of commit 8213eec217 - Show all commits

View File

@ -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,
}
);
});
};

View File

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

View File

@ -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) {