From 736c3a104826f9851f9d8bee6a77b2218e4026b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E5=AE=BE?= Date: Sat, 8 Apr 2023 10:26:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(ProForm):=20=E8=B0=83=E6=95=B4=E6=95=88?= =?UTF-8?q?=E9=AA=8C=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/components/src/ProForm/utils/index.tsx | 12 ++++++++++++ packages/components/src/ProForm/widgets/index.tsx | 12 ++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/components/src/ProForm/utils/index.tsx b/packages/components/src/ProForm/utils/index.tsx index 5e30d75d..017bc35d 100644 --- a/packages/components/src/ProForm/utils/index.tsx +++ b/packages/components/src/ProForm/utils/index.tsx @@ -173,3 +173,15 @@ export const fromValidate = (rules: FromValidateProps[] = []) => { }); return errorObj; }; + +/** + * 判断rules 里面是 required 是否存在 + */ +export const isRequired = (rules: any[] = []): boolean => { + if (rules.length === 0) return false; + const requireds = rules.find((item) => item.required) || []; + if (requireds && requireds.length > 0) { + return true; + } + return false; +}; diff --git a/packages/components/src/ProForm/widgets/index.tsx b/packages/components/src/ProForm/widgets/index.tsx index 799f6b1f..32e430c3 100644 --- a/packages/components/src/ProForm/widgets/index.tsx +++ b/packages/components/src/ProForm/widgets/index.tsx @@ -15,6 +15,7 @@ import CheckBox from './CheckBox'; import SelectMultiple from './SelectMultiple'; import Upload from './Upload'; import SearchTree from './SearchTree'; +import { isRequired } from '../utils'; /** * @@ -62,12 +63,11 @@ export function getFormFields( const name = key; const Widget = widgetsList[widget]; fields[name] = { - label: - otherProps.rules && otherProps.rules.length > 0 ? ( - {label} - ) : ( - label - ), + label: isRequired(otherProps.rules) ? ( + {label} + ) : ( + label + ), children: , ...otherProps, initialValue,