refactor: 解决方案列表的API重构
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { readItems } from '@directus/sdk';
|
import GetSolutionList from '@/graphql/solutionList.graphql?raw';
|
||||||
|
|
||||||
export const useSolutionList = () => {
|
export const useSolutionList = () => {
|
||||||
const { $directus } = useNuxtApp();
|
const { $directus } = useNuxtApp();
|
||||||
@ -6,33 +6,8 @@ export const useSolutionList = () => {
|
|||||||
const locale = getDirectusLocale();
|
const locale = getDirectusLocale();
|
||||||
|
|
||||||
return useAsyncData(`solution-list-${locale}`, async () => {
|
return useAsyncData(`solution-list-${locale}`, async () => {
|
||||||
return await $directus.request(
|
return await $directus.query<{ solutions: Solution[] }>(GetSolutionList, {
|
||||||
readItems('solutions', {
|
locale: locale,
|
||||||
fields: [
|
});
|
||||||
'id',
|
|
||||||
'cover',
|
|
||||||
{
|
|
||||||
type: ['id', { translations: ['id', 'name'] }, 'sort'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
translations: ['id', 'title', 'summary'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
deep: {
|
|
||||||
type: {
|
|
||||||
translations: {
|
|
||||||
_filter: {
|
|
||||||
languages_code: { _eq: locale },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
translations: {
|
|
||||||
_filter: {
|
|
||||||
languages_code: { _eq: locale },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
21
app/graphql/solutionList.graphql
Normal file
21
app/graphql/solutionList.graphql
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
query GetSolutionList($locale: String!) {
|
||||||
|
solutions {
|
||||||
|
id
|
||||||
|
cover {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
type {
|
||||||
|
id
|
||||||
|
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
sort
|
||||||
|
}
|
||||||
|
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
summary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
const { data, pending, error } = await useSolutionList();
|
const { data, pending, error } = await useSolutionList();
|
||||||
|
|
||||||
const solutionsRaw = computed(() => data.value ?? []);
|
const solutionsRaw = computed(() => data.value.solutions ?? []);
|
||||||
const solutions = computed(() =>
|
const solutions = computed(() =>
|
||||||
solutionsRaw.value.map((item) => toSolutionListView(item))
|
solutionsRaw.value.map((item) => toSolutionListView(item))
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user