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++ })