From a889e6d14e40f7a9c2a892db93a08254157b57af Mon Sep 17 00:00:00 2001 From: crazyair <645381995@qq.com> Date: Mon, 24 Aug 2020 11:18:00 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20required=20?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/yforms/package.json | 2 +- packages/yforms/src/YForm/scenes.tsx | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/yforms/package.json b/packages/yforms/package.json index 047e7ed..d0c59bb 100644 --- a/packages/yforms/package.json +++ b/packages/yforms/package.json @@ -1,6 +1,6 @@ { "name": "yforms", - "version": "1.2.6", + "version": "1.2.7", "description": "自定义表单组件", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/packages/yforms/src/YForm/scenes.tsx b/packages/yforms/src/YForm/scenes.tsx index d50a549..de12cb3 100644 --- a/packages/yforms/src/YForm/scenes.tsx +++ b/packages/yforms/src/YForm/scenes.tsx @@ -48,7 +48,9 @@ const scenes: YFormConfig = { if (itemProps.name && typeProps.type && typeProps.type !== 'list') { let hasRequired = false; forEach(rules, (item) => { - hasRequired = 'required' in item; + if ('required' in item) { + hasRequired = true; + } }); if (!hasRequired) { _itemProps.rules = [ @@ -58,7 +60,7 @@ const scenes: YFormConfig = { } } return { - itemProps: { ..._itemProps, ...itemProps }, + itemProps: { ...itemProps, ..._itemProps }, }; }, }, From 97d9b92714027d9667de4f3057c89165268f5cbe Mon Sep 17 00:00:00 2001 From: crazyair <645381995@qq.com> Date: Mon, 24 Aug 2020 11:18:49 +0800 Subject: [PATCH 2/5] docs: doc --- docs/changelog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 354835d..0f988c6 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -5,6 +5,12 @@ nav: order: 5 --- +## [1.2.7](https://github.com/crazyair/yforms/compare/v1.2.6...v1.2.7) (2020-08-24) + +### Bug Fixes + +- 修复 required 合并问题 ([a889e6d](https://github.com/crazyair/yforms/commit/a889e6d14e40f7a9c2a892db93a08254157b57af)) + ## [1.2.6](https://github.com/crazyair/yforms/compare/v1.2.5...v1.2.6) (2020-08-20) ### Bug Fixes From 1d6c6d957d727f5e77955e7fc45a9465e3fb5dca Mon Sep 17 00:00:00 2001 From: crazyair <645381995@qq.com> Date: Tue, 25 Aug 2020 14:34:33 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20minBtnLoadingT?= =?UTF-8?q?ime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/apis/index.md | 1 + docs/types/secureButton.md | 7 ++++--- packages/yforms/src/YForm/Form.tsx | 4 +++- packages/yforms/src/YForm/component/SecureButton.tsx | 10 +++++----- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/apis/index.md b/docs/apis/index.md index 73faec1..289a47e 100644 --- a/docs/apis/index.md +++ b/docs/apis/index.md @@ -30,6 +30,7 @@ nav: | onCancel | 点击取消、返回调用的方法(需用到 `submit` 类型) | () => void | - | | params | 当前表单状态(需用到 `submit` 类型) | ParamsObjType | - | | submitComponentProps | 与 `submit` 类型参数结合使用(用户无需传) | YFormSubmitComponentProps | - | +| minBtnLoadingTime | 按钮最低 loading 时间 | number | 500 | ## YForm.Items diff --git a/docs/types/secureButton.md b/docs/types/secureButton.md index c3dc234..de48ca2 100644 --- a/docs/types/secureButton.md +++ b/docs/types/secureButton.md @@ -18,9 +18,10 @@ nav: ## API -| 参数 | 说明 | 类型 | 默认值 | -| -------- | ---------------- | ---- | ------ | -| onLoaded | 请求成功后的回调 | - | true | +| 参数 | 说明 | 类型 | 默认值 | +| ----------------- | --------------------- | ------ | ------ | +| onLoaded | 请求成功后的回调 | - | true | +| minBtnLoadingTime | 按钮最低 loading 时间 | number | 500 | ## FAQ diff --git a/packages/yforms/src/YForm/Form.tsx b/packages/yforms/src/YForm/Form.tsx index 9a3bf6f..671baeb 100644 --- a/packages/yforms/src/YForm/Form.tsx +++ b/packages/yforms/src/YForm/Form.tsx @@ -83,6 +83,7 @@ export interface YFormProps extends Omit, YFormConfi params?: ParamsType; oldValues?: T; offset?: YFormItemProps['offset']; + minBtnLoadingTime?: number; } export function useFormatFieldsValue() { @@ -135,6 +136,7 @@ const InternalForm = React.memo((thisProps) => { submitComponentProps, submit, initialValues, + minBtnLoadingTime = 500, ...rest } = _props; const [form] = useForm(propsForm); @@ -224,7 +226,7 @@ const InternalForm = React.memo((thisProps) => { handleReset({ type: 'onSubmit' }); }, // loading 时间不到 0.5s 的加载 0.5s,超过的立刻结束。 - end - begin > 500 ? 0 : 500, + end - begin > minBtnLoadingTime ? 0 : minBtnLoadingTime, ); } catch (error) { warning(false, error || 'onSubmit error'); diff --git a/packages/yforms/src/YForm/component/SecureButton.tsx b/packages/yforms/src/YForm/component/SecureButton.tsx index ce20903..7c5d46c 100644 --- a/packages/yforms/src/YForm/component/SecureButton.tsx +++ b/packages/yforms/src/YForm/component/SecureButton.tsx @@ -3,11 +3,11 @@ import { Button } from 'antd'; import { ButtonProps } from 'antd/lib/button'; export interface YFormSecureButtonProps { - componentProps?: ButtonProps & { onLoaded?: () => void }; + componentProps?: ButtonProps & { onLoaded?: () => void; minBtnLoadingTime?: number }; } const SecureButton: React.FC = (props) => { - const { onClick, onLoaded, ...rest } = props; + const { onClick, onLoaded, minBtnLoadingTime = 500, ...rest } = props; const [loading, setLoading] = useState(false); const timeOut = useRef(null); @@ -19,7 +19,7 @@ const SecureButton: React.FC = (props) (end: number, begin: number, err?: any) => { if (err) { setLoading(false); - } else if (end - begin > 500) { + } else if (end - begin > minBtnLoadingTime) { // 如果 onClick 执行时间大于 0.5s,就立刻取消 loading setLoading(false); if (onLoaded) onLoaded(); @@ -28,10 +28,10 @@ const SecureButton: React.FC = (props) timeOut.current = window.setTimeout(() => { setLoading(false); if (onLoaded) onLoaded(); - }, 500); + }, minBtnLoadingTime); } }, - [onLoaded], + [onLoaded, minBtnLoadingTime], ); const handleClick = async (e: React.MouseEvent) => { From 06b9a2c928a225f1d47547735069633bfe419380 Mon Sep 17 00:00:00 2001 From: crazyair <645381995@qq.com> Date: Tue, 25 Aug 2020 14:59:00 +0800 Subject: [PATCH 4/5] feat: card --- docs/types/card.md | 27 ++++++++++++++ docs/types/demo/card.tsx | 37 ++++++++++++++++++++ packages/yforms/src/YForm/ItemsType.tsx | 3 ++ packages/yforms/src/YForm/component/Card.tsx | 24 +++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 docs/types/card.md create mode 100644 docs/types/demo/card.tsx create mode 100644 packages/yforms/src/YForm/component/Card.tsx diff --git a/docs/types/card.md b/docs/types/card.md new file mode 100644 index 0000000..79bb7b3 --- /dev/null +++ b/docs/types/card.md @@ -0,0 +1,27 @@ +--- +title: card +nav: + title: Type +--- + +# Card + +卡片表单 + +## 何时使用 + +- 卡片样式展示表单使用 + +## 用例 + + + +## API + +### items + +为 YForm children 类型 + +### componentProps + +为 Card 类型 diff --git a/docs/types/demo/card.tsx b/docs/types/demo/card.tsx new file mode 100644 index 0000000..b6f8f41 --- /dev/null +++ b/docs/types/demo/card.tsx @@ -0,0 +1,37 @@ +import React from 'react'; +import { YForm } from 'yforms'; +import { YFormProps } from 'yforms/src/YForm/Form'; + +export default () => { + const onFinish = (values: any) => { + console.log('Success:', values); + }; + + return ( + + {[ + { + type: 'card', + label: '卡片', + items: [{ type: 'input', name: 'phone', label: '手机号' }], + }, + { + type: 'list', + name: 'card', + label: '卡片', + componentProps: { showRightIcons: false }, + items: ({ index, icons }): YFormProps['children'] => { + return [ + { + type: 'card', + componentProps: { title: `card_${index + 1}`, extra: icons }, + items: [{ type: 'input', name: [index, 'phone'], label: '手机号' }], + }, + ]; + }, + }, + { type: 'submit' }, + ]} + + ); +}; diff --git a/packages/yforms/src/YForm/ItemsType.tsx b/packages/yforms/src/YForm/ItemsType.tsx index ddf5eb4..accdc41 100644 --- a/packages/yforms/src/YForm/ItemsType.tsx +++ b/packages/yforms/src/YForm/ItemsType.tsx @@ -38,6 +38,7 @@ import { CustomModify, } from './ItemsTypeModify'; import Space, { YFormSpaceProps } from './component/Space'; +import Card, { YFormCardProps } from './component/Card'; export interface YFormFieldBaseProps { component?: React.ReactElement; @@ -101,6 +102,7 @@ export interface YFormItemsTypeDefine { select: { componentProps?: YSelectProps }; radio: { componentProps?: YRadioProps }; oneLine: YFormOneLineProps; + card: YFormCardProps; space: YFormSpaceProps; list: YFormListProps; submit: YFormSubmitProps; @@ -148,6 +150,7 @@ export const itemsType: YFormItemsType = { }, // 工具类 oneLine: { component: , modifyProps: oneLineModify }, + card: { component: }, list: { component: , hasFormItem: false }, button: { component: +
@@ -3754,6 +3757,9 @@ Object {
+
@@ -5159,6 +5165,9 @@ Object {
+