From 3ca0cef98744036f58d859a2ec32d027c839f502 Mon Sep 17 00:00:00 2001 From: simplexiao <81275881+simplexiao@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:54:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20scale=20=E5=88=9D=E5=A7=8B=E5=A1=AB?= =?UTF-8?q?=E5=85=85=E9=97=AE=E9=A2=98=20(#72)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: yxh01132861 Co-authored-by: lvisei --- .../components/ScaleSelector/index.tsx | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/li-p2/src/LayerAttribute/components/ScaleSelector/index.tsx b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/index.tsx index 711008e0..53fd6e03 100644 --- a/packages/li-p2/src/LayerAttribute/components/ScaleSelector/index.tsx +++ b/packages/li-p2/src/LayerAttribute/components/ScaleSelector/index.tsx @@ -76,19 +76,25 @@ const Internal = (props: ScaleSelectorProp) => { // dataType 变更,引起可选类型变更,当 scale 为非自定义时自动填充当前类型 useEffect(() => { - if (!value) return; - // 非自定义数据 - if (!value.isCustom) { + let defaultSelectType: SelectType | undefined; + + // 初始,scale 填入默认值 + if (!value) { + defaultSelectType = selectOptions[0].value; + // 非自定义数据情况 + } else if (!value.isCustom) { // 判断 value 类型是否有效 - const isValid = selectOptions.findIndex((item) => item.value === value.type) === -1; - if (isValid) { - const val = selectOptions[0].value !== 'custom' ? selectOptions[0].value : undefined; - setSelectedType(val); - if (val) { - onChange?.({ isCustom: false, type: val }); - } + const isValid = selectOptions.some((item) => item.value === value.type); + if (!isValid) { + defaultSelectType = selectOptions[0].value; } } + + // 设置默认选中类型;因类型推断问题,当前传入类型去除 custom + if (defaultSelectType && defaultSelectType !== 'custom') { + setSelectedType(defaultSelectType); + onChange?.({ isCustom: false, type: defaultSelectType }); + } }, [selectOptions]); // 自定义 scale 且数据 domain 发生更新时,自动计算默认值