Commit 1db72c8fe13384f24e9cc1bdc839d5e4176ea9b4
1 parent
db0bfc88
fix: fix form validate error
Showing
5 changed files
with
60 additions
and
31 deletions
CHANGELOG.en_US.md
1 | +## Wip | |
2 | + | |
3 | +### ⚡ Performance Improvements | |
4 | + | |
5 | +- Menu performance continues to be optimized and smoother | |
6 | +- Optimize lazy loading components and examples | |
7 | + | |
8 | +### 🎫 Chores | |
9 | + | |
10 | +- Delete menu background image | |
11 | +- Update the version of ʻant-design-vue`to`beta13` | |
12 | +- Update `vite` version to `rc.9` | |
13 | +- Exception page adjustment | |
14 | +- `BasicTitle` Color blocks are not displayed by default | |
15 | + | |
16 | +### 🐛 Bug Fixes | |
17 | + | |
18 | +- Fix table type problem after upgrade | |
19 | +- Fix the problem that the last submenu continues to be displayed when the menu is divided and there is no data in the left menu | |
20 | +- Fix the issue of ʻuseMessage` type | |
21 | +- Fix the problem that the form item setting `disabled` does not take effect | |
22 | +- Fix that ʻuseECharts`can't adapt when`resize`, and an error is reported | |
23 | +- Fix that `resize` is not deleted after ʻuseWatermark` is cleared | |
24 | +- Fix form verification problem | |
25 | + | |
1 | 26 | ## 2.0.0-rc.8 (2020-11-2) |
2 | 27 | |
3 | 28 | ### ✨ Features | ... | ... |
CHANGELOG.zh_CN.md
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | - 更新`ant-design-vue`版本为`beta13` |
12 | 12 | - 更新`vite`版本为`rc.9` |
13 | 13 | - 异常页调整 |
14 | -- `BasicTitle` Color blocks are not displayed by default | |
14 | +- `BasicTitle` 色块默认不显示 | |
15 | 15 | |
16 | 16 | ### 🐛 Bug Fixes |
17 | 17 | |
... | ... | @@ -21,6 +21,7 @@ |
21 | 21 | - 修复表单项设置`disabled`不生效问题 |
22 | 22 | - 修复`useECharts`在`resize`时不能自适应,报错 |
23 | 23 | - 修复`useWatermark`在清空后`resize`未删除 |
24 | +- 修复表单校验问题 | |
24 | 25 | |
25 | 26 | ## 2.0.0-rc.8 (2020-11-2) |
26 | 27 | ... | ... |
src/components/Form/src/BasicForm.vue
... | ... | @@ -28,16 +28,7 @@ |
28 | 28 | import type { Ref } from 'vue'; |
29 | 29 | import type { ValidateFields } from 'ant-design-vue/lib/form/interface'; |
30 | 30 | |
31 | - import { | |
32 | - defineComponent, | |
33 | - reactive, | |
34 | - ref, | |
35 | - computed, | |
36 | - unref, | |
37 | - toRef, | |
38 | - onMounted, | |
39 | - watchEffect, | |
40 | - } from 'vue'; | |
31 | + import { defineComponent, reactive, ref, computed, unref, toRef, onMounted, watch } from 'vue'; | |
41 | 32 | import { Form, Row } from 'ant-design-vue'; |
42 | 33 | import FormItem from './FormItem'; |
43 | 34 | import { basicProps } from './props'; |
... | ... | @@ -153,10 +144,16 @@ |
153 | 144 | actionState, |
154 | 145 | }); |
155 | 146 | |
156 | - watchEffect(() => { | |
157 | - if (!unref(getMergePropsRef).model) return; | |
158 | - setFieldsValue(unref(getMergePropsRef).model); | |
159 | - }); | |
147 | + watch( | |
148 | + () => unref(getMergePropsRef).model, | |
149 | + () => { | |
150 | + if (!unref(getMergePropsRef).model) return; | |
151 | + setFieldsValue(unref(getMergePropsRef).model); | |
152 | + }, | |
153 | + { | |
154 | + immediate: true, | |
155 | + } | |
156 | + ); | |
160 | 157 | |
161 | 158 | /** |
162 | 159 | * @description:设置表单 | ... | ... |
src/components/Form/src/FormItem.tsx
... | ... | @@ -14,6 +14,8 @@ import { createPlaceholderMessage } from './helper'; |
14 | 14 | import { upperFirst, cloneDeep } from 'lodash-es'; |
15 | 15 | |
16 | 16 | import { useItemLabelWidth } from './hooks/useLabelWidth'; |
17 | +import { ComponentType } from './types'; | |
18 | +import { isNumber } from '../../../utils/is'; | |
17 | 19 | |
18 | 20 | export default defineComponent({ |
19 | 21 | name: 'BasicFormItem', |
... | ... | @@ -145,6 +147,14 @@ export default defineComponent({ |
145 | 147 | return rules; |
146 | 148 | } |
147 | 149 | |
150 | + function handleValue(component: ComponentType, field: string) { | |
151 | + const val = (props.formModel as any)[field]; | |
152 | + if (['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(component)) { | |
153 | + return isNumber(val) && val ? `${val}` : val; | |
154 | + } | |
155 | + return val; | |
156 | + } | |
157 | + | |
148 | 158 | function renderComponent() { |
149 | 159 | const { |
150 | 160 | componentProps, |
... | ... | @@ -162,11 +172,7 @@ export default defineComponent({ |
162 | 172 | if (propsData[eventKey]) { |
163 | 173 | propsData[eventKey](e); |
164 | 174 | } |
165 | - if (e && e.target) { | |
166 | - (props.formModel as any)[field] = e.target.value; | |
167 | - } else { | |
168 | - (props.formModel as any)[field] = e; | |
169 | - } | |
175 | + (props.formModel as any)[field] = e && e.target ? e.target.value : e; | |
170 | 176 | }, |
171 | 177 | }; |
172 | 178 | const Comp = componentMap.get(component); |
... | ... | @@ -190,9 +196,8 @@ export default defineComponent({ |
190 | 196 | propsData.placeholder = placeholder; |
191 | 197 | propsData.codeField = field; |
192 | 198 | propsData.formValues = unref(getValuesRef); |
193 | - | |
194 | 199 | const bindValue = { |
195 | - [isCheck ? 'checked' : 'value']: (props.formModel as any)[field], | |
200 | + [isCheck ? 'checked' : 'value']: handleValue(component, field), | |
196 | 201 | }; |
197 | 202 | if (!renderComponentContent) { |
198 | 203 | return <Comp {...propsData} {...on} {...bindValue} />; | ... | ... |
src/components/Form/src/hooks/useFormAction.ts
... | ... | @@ -43,8 +43,6 @@ export function useFormAction({ |
43 | 43 | Object.keys(formModel).forEach((key) => { |
44 | 44 | (formModel as any)[key] = defaultValueRef.value[key]; |
45 | 45 | }); |
46 | - // @ts-ignore | |
47 | - // TODO 官方组件库类型定义错误,可以不传参数 | |
48 | 46 | formEl.clearValidate(); |
49 | 47 | emit('reset', toRaw(formModel)); |
50 | 48 | // return values; |
... | ... | @@ -58,10 +56,12 @@ export function useFormAction({ |
58 | 56 | const fields = unref(getSchema) |
59 | 57 | .map((item) => item.field) |
60 | 58 | .filter(Boolean); |
61 | - const formEl = unref(formElRef); | |
59 | + // const formEl = unref(formElRef); | |
60 | + | |
61 | + const validKeys: string[] = []; | |
62 | 62 | Object.keys(values).forEach((key) => { |
63 | 63 | const element = values[key]; |
64 | - if (fields.includes(key) && element !== undefined && element !== null) { | |
64 | + if (element !== undefined && element !== null && fields.includes(key)) { | |
65 | 65 | // 时间 |
66 | 66 | if (itemIsDateType(key)) { |
67 | 67 | if (Array.isArray(element)) { |
... | ... | @@ -76,11 +76,12 @@ export function useFormAction({ |
76 | 76 | } else { |
77 | 77 | (formModel as any)[key] = element; |
78 | 78 | } |
79 | - if (formEl) { | |
80 | - formEl.validateFields([key]); | |
81 | - } | |
79 | + validKeys.push(key); | |
82 | 80 | } |
83 | 81 | }); |
82 | + // if (formEl) { | |
83 | + // formEl.validateFields(validKeys); | |
84 | + // } | |
84 | 85 | } |
85 | 86 | /** |
86 | 87 | * @description: 根据字段名删除 |
... | ... | @@ -151,8 +152,8 @@ export function useFormAction({ |
151 | 152 | updateData.forEach((item) => { |
152 | 153 | unref(getSchema).forEach((val) => { |
153 | 154 | if (val.field === item.field) { |
154 | - const newScheam = deepMerge(val, item); | |
155 | - schema.push(newScheam as FormSchema); | |
155 | + const newSchema = deepMerge(val, item); | |
156 | + schema.push(newSchema as FormSchema); | |
156 | 157 | } else { |
157 | 158 | schema.push(val); |
158 | 159 | } | ... | ... |