mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-11 18:10:49 +08:00
feat:为DiscoverSource接口添加依赖关系字典,优化过滤参数的watch逻辑
This commit is contained in:
@@ -1243,6 +1243,8 @@ export interface DiscoverSource {
|
||||
filter_params: { [key: string]: any }
|
||||
// 过滤参数UI配置
|
||||
filter_ui: RenderProps[]
|
||||
// UI依赖关系字典
|
||||
depends?: { [key: string]: string[] }
|
||||
}
|
||||
|
||||
// 推荐的数据源
|
||||
|
||||
@@ -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++
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user