From 00eb5df5169f06b7e53b9416a6933fa214c6b1c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=98=89=E8=B1=AA?= <42510293+ziyujiahao@users.noreply.github.com> Date: Fri, 16 Jan 2026 11:00:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E5=A4=96?= =?UTF-8?q?=E9=83=A8=E5=8F=82=E6=95=B0=E8=BF=87=E6=BB=A4=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=97=B6=E9=BB=98=E8=AE=A4=E5=80=BC=E5=A4=84=E7=90=86=20(#1780?= =?UTF-8?q?7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/data-visualization/dvMain.ts | 18 ++++- .../core-frontend/src/utils/componentUtils.ts | 71 +++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts index 5e4ad341af..dc290a8cc4 100644 --- a/core/core-frontend/src/store/modules/data-visualization/dvMain.ts +++ b/core/core-frontend/src/store/modules/data-visualization/dvMain.ts @@ -25,7 +25,11 @@ import { viewFieldTimeTrans } from '@/utils/viewUtils' import { useAppearanceStoreWithOut } from '@/store/modules/appearance' import { ElMessage } from 'element-plus-secondary' import { useI18n } from '@/hooks/web/useI18n' -import { filterEnumParams, filterEnumParamsReduce } from '@/utils/componentUtils' +import { + filterEnumParams, + filterEnumParamsReduce, + filterParamsOptions +} from '@/utils/componentUtils' import { formatterItem } from '@/views/chart/components/js/formatter' const { t } = useI18n() @@ -1276,6 +1280,18 @@ export const dvMainStore = defineStore('dataVisualization', { if (targetMatchMode === 'filter') { // do filter filterItem['optionFilter'] = queryParams + if (filterItem.defaultValueCheck) { + const result = filterParamsOptions( + deepCopy(filterItem['selectValue']), + deepCopy(queryParams) + ) + if (result) { + filterItem['selectValue'] = queryParams + filterItem['defaultValue'] = queryParams + } else { + filterItem.defaultValueCheck = false + } + } } else { if (!['1', '7'].includes(filterItem.displayType)) { // 查询组件除了时间组件 其他入参只支持文本 这里全部转为文本 diff --git a/core/core-frontend/src/utils/componentUtils.ts b/core/core-frontend/src/utils/componentUtils.ts index cb37a5aba1..fabf7da1cc 100644 --- a/core/core-frontend/src/utils/componentUtils.ts +++ b/core/core-frontend/src/utils/componentUtils.ts @@ -60,3 +60,74 @@ export const filterEnumMapSync = async componentData => { } } } + +export function filterParamsOptions(params, paramsOption) { + // 如果 params 为空,直接返回 null + if (!params || (Array.isArray(params) && params.length === 0)) { + return null + } + // 如果 paramsOption 为空,直接返回 null + if (!paramsOption || paramsOption.length === 0) { + return null + } + // 创建 paramsOption 集合和前缀集合用于快速查找 + const optionSet = new Set(paramsOption) + const prefixSet = new Set() + // 收集所有可能的父级前缀 + paramsOption.forEach(option => { + if (option.includes('-de-')) { + const parts = option.split('-de-') + // 收集所有前缀:父级、祖父级等 + for (let i = 1; i < parts.length; i++) { + const prefix = parts.slice(0, i).join('-de-') + prefixSet.add(prefix) + } + } + }) + + // 检查一个值是否在 paramsOption 中存在(考虑层级关系) + function checkValueExists(value) { + // 直接存在 + if (optionSet.has(value)) { + return true + } + // 如果是层级结构,检查所有父级前缀 + if (value.includes('-de-')) { + const parts = value.split('-de-') + + // 检查所有可能的父级前缀 + for (let i = 1; i < parts.length; i++) { + const prefix = parts.slice(0, i).join('-de-') + if (optionSet.has(prefix)) { + return true + } + } + } + + // 检查该值是否是某个选项的父级 + // 如:paramsOption 中有 "香橙店-de-浓郁椰奶",传入 "香橙店" 也应该匹配 + if ( + Array.from(optionSet).some(option => option.startsWith(value + '-de-') || option === value) + ) { + return true + } + // 检查该值是否是某个选项的前缀(通过 prefixSet) + if (prefixSet.has(value)) { + return true + } + return false + } + // 处理单值情况(字符串) + if (typeof params === 'string') { + return checkValueExists(params) ? params : null + } + // 处理数组情况 + if (Array.isArray(params)) { + // 过滤出存在的值 + const filtered = params.filter(value => typeof value === 'string' && checkValueExists(value)) + // 如果过滤后为空,返回 null,否则返回过滤后的数组 + return filtered.length > 0 ? filtered : null + } + // 其他类型返回 null + return null +}