refactor: 调整首页数据获取API
- 将首页的数据获取由REST重构为GraphQL
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { readSingleton } from '@directus/sdk';
|
||||
import GetHomepage from '@/graphql/homepage.graphql?raw';
|
||||
|
||||
export const useHomepage = () => {
|
||||
const { $directus } = useNuxtApp();
|
||||
@ -6,49 +6,8 @@ export const useHomepage = () => {
|
||||
const locale = getDirectusLocale();
|
||||
|
||||
return useAsyncData(`homepage-${locale}`, async () => {
|
||||
return await $directus.request(
|
||||
readSingleton('homepage', {
|
||||
fields: [
|
||||
'id',
|
||||
{
|
||||
carousel: ['id', 'directus_files_id'],
|
||||
},
|
||||
{
|
||||
recommend_products: [
|
||||
'id',
|
||||
{
|
||||
translations: ['id', 'name', 'summary'],
|
||||
},
|
||||
'cover',
|
||||
],
|
||||
},
|
||||
{
|
||||
recommend_solutions: [
|
||||
'id',
|
||||
{
|
||||
translations: ['id', 'title', 'summary'],
|
||||
},
|
||||
'cover',
|
||||
],
|
||||
},
|
||||
],
|
||||
deep: {
|
||||
recommend_products: {
|
||||
translations: {
|
||||
_filter: {
|
||||
languages_code: { _eq: locale },
|
||||
},
|
||||
},
|
||||
},
|
||||
recommend_solutions: {
|
||||
translations: {
|
||||
_filter: {
|
||||
languages_code: { _eq: locale },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
return await $directus.query<{ homepage: Homepage }>(GetHomepage, {
|
||||
locale: locale,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user