From de6ad2479ec21469bcac50ec091a1f1f676eb5c9 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 10 Feb 2025 22:05:33 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=B8=BADiscoverSource=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B7=BB=E5=8A=A0=E4=BE=9D=E8=B5=96=E5=85=B3=E7=B3=BB?= =?UTF-8?q?=E5=AD=97=E5=85=B8=EF=BC=8C=E4=BC=98=E5=8C=96=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=9A=84watch=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/types.ts | 2 ++ src/views/discover/ExtraSourceView.vue | 28 +++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/api/types.ts b/src/api/types.ts index 2cb740ab..e777a705 100644 --- a/src/api/types.ts +++ b/src/api/types.ts @@ -1243,6 +1243,8 @@ export interface DiscoverSource { filter_params: { [key: string]: any } // 过滤参数UI配置 filter_ui: RenderProps[] + // UI依赖关系字典 + depends?: { [key: string]: string[] } } // 推荐的数据源 diff --git a/src/views/discover/ExtraSourceView.vue b/src/views/discover/ExtraSourceView.vue index cda047cb..4fa9a8bc 100644 --- a/src/views/discover/ExtraSourceView.vue +++ b/src/views/discover/ExtraSourceView.vue @@ -2,7 +2,7 @@ import { DiscoverSource } from '@/api/types' import MediaCardListView from '@/views/discover/MediaCardListView.vue' import FormRender from '@/components/render/FormRender.vue' -import { cloneDeep } from 'lodash' +import { cloneDeep, isNull } from 'lodash' // 输入参数 const props = defineProps<{ @@ -15,17 +15,35 @@ const default_params = cloneDeep(props.source.filter_params) // 过滤参数 const filterParams = reactive(props.source.filter_params) +// 前一次的过滤参数 +let previousParams = cloneDeep(props.source.filter_params) + // 当前Key const currentKey = ref(0) // 类型和过滤参数变化后重新刷新列表 -watch([filterParams], () => { - // 检查每个值,如果没有值但有默认值时,设置为默认值 - for (const key in filterParams) { - if (!filterParams[key] && default_params[key]) { +watch(filterParams, newParams => { + // 检查每个值 + for (const key in newParams) { + // 如果没有值但有默认值时,设置为默认值 + if (!newParams[key] && default_params[key]) { filterParams[key] = default_params[key] } + // 检查依赖关系 + const depends = props.source?.depends + if (depends) { + if (newParams[key] !== previousParams[key]) { + for (const dependKey in depends) { + if (key != dependKey && depends[dependKey] && depends[dependKey].includes(key)) { + filterParams[dependKey] = null + } + } + } + } } + // 更新 previousParams + previousParams = cloneDeep(newParams) + // 刷新界面 currentKey.value++ })