Skip to content

Commit

Permalink
fix: 问题处理
Browse files Browse the repository at this point in the history
  • Loading branch information
yxh01132861 committed Nov 8, 2023
1 parent b8be310 commit 348e766
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,25 @@ const Internal = (props: ScaleSelectorProp) => {

// dataType 变更,引起可选类型变更,当 scale 为非自定义时自动填充当前类型
useEffect(() => {
const isValid = selectOptions.findIndex((item) => item.value === value?.type) !== -1;
// 初始,scale 填入默认值; 更新字段选择,判断此时的 scale 是否是有效,如果无效默认选中第一个
if (!value || (!value.isCustom && !isValid)) {
const val = selectOptions[0].value !== 'custom' ? selectOptions[0].value : undefined;
setSelectedType(val);
if (val) {
onChange?.({ isCustom: false, type: val });
let defaultSelectType: SelectType | undefined;

// 初始,scale 填入默认值
if (!value) {
defaultSelectType = selectOptions[0].value;
// 非自定义数据情况
} else if (!value.isCustom) {
// 判断 value 类型是否有效
const isValid = selectOptions.some((item) => item.value === value.type);
if (!isValid) {
defaultSelectType = selectOptions[0].value;
}
}

// 设置默认选中类型 当前传入类型除却 custom ;因图层样式类型中无 custom
if (defaultSelectType && defaultSelectType !== 'custom') {
setSelectedType(defaultSelectType);
onChange?.({ isCustom: false, type: defaultSelectType });
}
}, [selectOptions]);

// 自定义 scale 且数据 domain 发生更新时,自动计算默认值
Expand Down

0 comments on commit 348e766

Please sign in to comment.