refactor: 关于我们页的API重构
Some checks failed
deploy to server / build-and-deploy (push) Has been cancelled
Some checks failed
deploy to server / build-and-deploy (push) Has been cancelled
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { readSingleton } from '@directus/sdk';
|
import GetCompanyProfile from '@/graphql/companyProfile.graphql?raw';
|
||||||
|
|
||||||
export const useCompanyProfile = () => {
|
export const useCompanyProfile = () => {
|
||||||
const { $directus } = useNuxtApp();
|
const { $directus } = useNuxtApp();
|
||||||
@ -6,24 +6,11 @@ export const useCompanyProfile = () => {
|
|||||||
const locale = getDirectusLocale();
|
const locale = getDirectusLocale();
|
||||||
|
|
||||||
return useAsyncData(`company-profile-${locale}`, async () => {
|
return useAsyncData(`company-profile-${locale}`, async () => {
|
||||||
return await $directus.request(
|
return await $directus.query<{ company_profile: CompanyProfile }>(
|
||||||
readSingleton('company_profile', {
|
GetCompanyProfile,
|
||||||
fields: [
|
{
|
||||||
'id',
|
locale: locale,
|
||||||
{
|
}
|
||||||
translations: ['id', 'content'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
deep: {
|
|
||||||
translations: {
|
|
||||||
_filter: {
|
|
||||||
languages_code: {
|
|
||||||
_eq: locale,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
9
app/graphql/companyProfile.graphql
Normal file
9
app/graphql/companyProfile.graphql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
query GetCompanyProfile($locale: String!) {
|
||||||
|
company_profile {
|
||||||
|
id
|
||||||
|
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||||
|
id
|
||||||
|
content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -34,7 +34,9 @@
|
|||||||
];
|
];
|
||||||
const { data, pending, error } = await useCompanyProfile();
|
const { data, pending, error } = await useCompanyProfile();
|
||||||
|
|
||||||
const content = computed(() => toCompanyProfileView(data.value));
|
const content = computed(() =>
|
||||||
|
toCompanyProfileView(data.value.company_profile)
|
||||||
|
);
|
||||||
|
|
||||||
watch(error, (value) => {
|
watch(error, (value) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user