feat: 将/support/faq界面迁移至Directus
- 路由界面脚本修改 - 视图模型相关定义
This commit is contained in:
@ -28,22 +28,22 @@
|
||||
<div class="question-category">
|
||||
<el-select v-model="selectedType" placeholder="选择产品类型" clearable>
|
||||
<el-option
|
||||
v-for="type in productionTypeOptions"
|
||||
:key="type.documentId"
|
||||
:label="type.type"
|
||||
:value="type.documentId"
|
||||
v-for="type in productTypeOptions"
|
||||
:key="type.id"
|
||||
:label="type.name"
|
||||
:value="type.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select
|
||||
v-model="selectedProduction"
|
||||
v-model="selectedProduct"
|
||||
placeholder="选择系列产品"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="production in productionOptions"
|
||||
:key="production.documentId"
|
||||
:label="production.title"
|
||||
:value="production.documentId"
|
||||
v-for="production in productOptions"
|
||||
:key="production.id"
|
||||
:label="production.name"
|
||||
:value="production.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input
|
||||
@ -62,68 +62,58 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Search } from '@element-plus/icons-vue';
|
||||
const { find } = useStrapi();
|
||||
const { getStrapiLocale } = useLocalizations();
|
||||
const strapiLocale = getStrapiLocale();
|
||||
|
||||
const { data, pending, error } = useAsyncData('questions', () =>
|
||||
find<Question>('questions', {
|
||||
populate: {
|
||||
related_productions: {
|
||||
populate: ['production_type'],
|
||||
},
|
||||
},
|
||||
locale: strapiLocale,
|
||||
})
|
||||
const { data, pending, error } = await useQuestionList();
|
||||
|
||||
const questions = computed(
|
||||
() => data.value.map((item) => toQuestionListView(item)) ?? null
|
||||
);
|
||||
|
||||
const questions = computed(() => data.value?.data ?? null);
|
||||
|
||||
const keyword = ref('');
|
||||
|
||||
const selectedType = ref<string | null>(null);
|
||||
const selectedProduction = ref<string | null>(null);
|
||||
const selectedType = ref<number | null>(null);
|
||||
const selectedProduct = ref<number | null>(null);
|
||||
|
||||
const productionTypeOptions = computed(() => {
|
||||
const types: ProductionType[] = [];
|
||||
questions.value.forEach((q: Question) => {
|
||||
q.related_productions?.forEach((production: Production) => {
|
||||
const productionType = production?.production_type;
|
||||
if (!types.some((p) => p.documentId === productionType.documentId)) {
|
||||
types.push(productionType);
|
||||
const productTypeOptions = computed(() => {
|
||||
const types: QuestionListProductType[] = [];
|
||||
questions.value.forEach((q: QuestionListView) => {
|
||||
q.products.forEach((product: QuestionListProduct) => {
|
||||
const productType = product.type;
|
||||
if (!types.some((p) => p.id === productType.id)) {
|
||||
types.push(productType);
|
||||
}
|
||||
});
|
||||
});
|
||||
return types;
|
||||
});
|
||||
|
||||
const productionOptions = computed(() => {
|
||||
const productOptions = computed(() => {
|
||||
if (!selectedType.value) return [];
|
||||
const productions: Production[] = [];
|
||||
questions.value.forEach((question: Question) => {
|
||||
question.related_productions.forEach((production: Production) => {
|
||||
const products: QuestionListProduct[] = [];
|
||||
questions.value.forEach((q: QuestionListView) => {
|
||||
q.products.forEach((product: QuestionListProduct) => {
|
||||
if (
|
||||
production.production_type?.documentId === selectedType.value &&
|
||||
!productions.some((p) => p.documentId === production.documentId)
|
||||
product.type.id === selectedType.value &&
|
||||
!products.some((p) => p.id === product.id)
|
||||
) {
|
||||
productions.push(production);
|
||||
products.push(product);
|
||||
}
|
||||
});
|
||||
});
|
||||
return productions;
|
||||
return products;
|
||||
});
|
||||
|
||||
const filteredQuestions = computed(() => {
|
||||
return questions.value.filter((question: Question) => {
|
||||
const matchProduction = selectedProduction.value
|
||||
? question.related_productions?.some(
|
||||
(production: Production) =>
|
||||
production.documentId === selectedProduction.value
|
||||
return questions.value.filter((question: QuestionListView) => {
|
||||
const matchProduction = selectedProduct.value
|
||||
? question.products?.some(
|
||||
(product: QuestionListProduct) =>
|
||||
product.id === selectedProduct.value
|
||||
)
|
||||
: selectedType.value
|
||||
? question.related_productions?.some(
|
||||
(production: Production) =>
|
||||
production.production_type?.documentId === selectedType.value
|
||||
? question.products?.some(
|
||||
(product: QuestionListProduct) =>
|
||||
product.type.id === selectedType.value
|
||||
)
|
||||
: true;
|
||||
|
||||
@ -137,7 +127,7 @@
|
||||
});
|
||||
|
||||
watch(selectedType, () => {
|
||||
selectedProduction.value = null;
|
||||
selectedProduct.value = null;
|
||||
});
|
||||
|
||||
watch(data, (newVal) => {
|
||||
|
||||
Reference in New Issue
Block a user