refactor: 问题列表的API重构
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
import { readItems } from '@directus/sdk';
|
import GetQuestionList from '@/graphql/questionList.graphql?raw';
|
||||||
|
|
||||||
export const useQuestionList = () => {
|
export const useQuestionList = () => {
|
||||||
const { $directus } = useNuxtApp();
|
const { $directus } = useNuxtApp();
|
||||||
@ -7,57 +7,8 @@ export const useQuestionList = () => {
|
|||||||
const locale = getDirectusLocale();
|
const locale = getDirectusLocale();
|
||||||
|
|
||||||
return useAsyncData(`question-list-${locale}`, async () => {
|
return useAsyncData(`question-list-${locale}`, async () => {
|
||||||
return await $directus.request(
|
return await $directus.query<{ questions: Question[] }>(GetQuestionList, {
|
||||||
readItems('questions', {
|
locale: locale,
|
||||||
fields: [
|
});
|
||||||
'id',
|
|
||||||
{
|
|
||||||
translations: ['*'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
products: [
|
|
||||||
'id',
|
|
||||||
{
|
|
||||||
products_id: [
|
|
||||||
'id',
|
|
||||||
{
|
|
||||||
product_type: [
|
|
||||||
'id',
|
|
||||||
{
|
|
||||||
translations: ['id', 'name'],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ translations: ['id', 'name'] },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
deep: {
|
|
||||||
translations: {
|
|
||||||
_filter: {
|
|
||||||
languages_code: { _eq: locale },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
products: {
|
|
||||||
products_id: {
|
|
||||||
product_type: {
|
|
||||||
translations: {
|
|
||||||
_filter: {
|
|
||||||
languages_code: { _eq: locale },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
translations: {
|
|
||||||
_filter: {
|
|
||||||
languages_code: { _eq: locale },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
27
app/graphql/questionList.graphql
Normal file
27
app/graphql/questionList.graphql
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
query GetQuestionList($locale: String!) {
|
||||||
|
questions {
|
||||||
|
id
|
||||||
|
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
content
|
||||||
|
}
|
||||||
|
products {
|
||||||
|
id
|
||||||
|
products_id {
|
||||||
|
id
|
||||||
|
product_type {
|
||||||
|
id
|
||||||
|
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -41,7 +41,7 @@
|
|||||||
const { data, pending, error } = await useQuestionList();
|
const { data, pending, error } = await useQuestionList();
|
||||||
|
|
||||||
const questions = computed(
|
const questions = computed(
|
||||||
() => data.value.map((item) => toQuestionListView(item)) ?? null
|
() => data.value.questions.map((item) => toQuestionListView(item)) ?? null
|
||||||
);
|
);
|
||||||
|
|
||||||
const productTypeOptions = computed(() => {
|
const productTypeOptions = computed(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user