Commit 3ff70bb56f998cfc92a773676d75c06372d90658

Authored by Vben
1 parent 6afee415

fix(form): improve warning prompt, fix #538

package.json
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
63 "devDependencies": { 63 "devDependencies": {
64 "@commitlint/cli": "^12.1.1", 64 "@commitlint/cli": "^12.1.1",
65 "@commitlint/config-conventional": "^12.1.1", 65 "@commitlint/config-conventional": "^12.1.1",
66 - "@iconify/json": "^1.1.331", 66 + "@iconify/json": "^1.1.333",
67 "@purge-icons/generated": "^0.7.0", 67 "@purge-icons/generated": "^0.7.0",
68 "@types/codemirror": "^0.0.109", 68 "@types/codemirror": "^0.0.109",
69 "@types/crypto-js": "^4.0.1", 69 "@types/crypto-js": "^4.0.1",
@@ -110,7 +110,7 @@ @@ -110,7 +110,7 @@
110 "stylelint-order": "^4.1.0", 110 "stylelint-order": "^4.1.0",
111 "ts-node": "^9.1.1", 111 "ts-node": "^9.1.1",
112 "typescript": "4.2.4", 112 "typescript": "4.2.4",
113 - "vite": "2.1.5", 113 + "vite": "2.2.3",
114 "vite-plugin-compression": "^0.2.4", 114 "vite-plugin-compression": "^0.2.4",
115 "vite-plugin-html": "^2.0.7", 115 "vite-plugin-html": "^2.0.7",
116 "vite-plugin-imagemin": "^0.3.0", 116 "vite-plugin-imagemin": "^0.3.0",
src/components/Form/src/BasicForm.vue
@@ -35,17 +35,7 @@ @@ -35,17 +35,7 @@
35 import type { AdvanceState } from './types/hooks'; 35 import type { AdvanceState } from './types/hooks';
36 import type { CSSProperties, Ref } from 'vue'; 36 import type { CSSProperties, Ref } from 'vue';
37 37
38 - import {  
39 - defineComponent,  
40 - reactive,  
41 - ref,  
42 - computed,  
43 - unref,  
44 - onMounted,  
45 - watch,  
46 - toRefs,  
47 - nextTick,  
48 - } from 'vue'; 38 + import { defineComponent, reactive, ref, computed, unref, onMounted, watch, nextTick } from 'vue';
49 import { Form, Row } from 'ant-design-vue'; 39 import { Form, Row } from 'ant-design-vue';
50 import FormItem from './components/FormItem.vue'; 40 import FormItem from './components/FormItem.vue';
51 import FormAction from './components/FormAction.vue'; 41 import FormAction from './components/FormAction.vue';
@@ -143,13 +133,8 @@ @@ -143,13 +133,8 @@
143 defaultValueRef, 133 defaultValueRef,
144 }); 134 });
145 135
146 - const { transformDateFunc, fieldMapToTime, autoFocusFirstItem } = toRefs(  
147 - unref(getProps)  
148 - ) as any;  
149 -  
150 const { handleFormValues, initDefault } = useFormValues({ 136 const { handleFormValues, initDefault } = useFormValues({
151 - transformDateFuncRef: transformDateFunc,  
152 - fieldMapToTimeRef: fieldMapToTime, 137 + getProps,
153 defaultValueRef, 138 defaultValueRef,
154 getSchema, 139 getSchema,
155 formModel, 140 formModel,
@@ -157,7 +142,7 @@ @@ -157,7 +142,7 @@
157 142
158 useAutoFocus({ 143 useAutoFocus({
159 getSchema, 144 getSchema,
160 - autoFocusFirstItem, 145 + getProps,
161 isInitedDefault: isInitedDefaultRef, 146 isInitedDefault: isInitedDefaultRef,
162 formElRef: formElRef as Ref<FormActionType>, 147 formElRef: formElRef as Ref<FormActionType>,
163 }); 148 });
src/components/Form/src/hooks/useAutoFocus.ts
1 import type { ComputedRef, Ref } from 'vue'; 1 import type { ComputedRef, Ref } from 'vue';
2 -import type { FormSchema, FormActionType } from '../types/form'; 2 +import type { FormSchema, FormActionType, FormProps } from '../types/form';
3 3
4 import { unref, nextTick, watchEffect } from 'vue'; 4 import { unref, nextTick, watchEffect } from 'vue';
5 5
6 interface UseAutoFocusContext { 6 interface UseAutoFocusContext {
7 getSchema: ComputedRef<FormSchema[]>; 7 getSchema: ComputedRef<FormSchema[]>;
8 - autoFocusFirstItem: Ref<boolean>; 8 + getProps: ComputedRef<FormProps>;
9 isInitedDefault: Ref<boolean>; 9 isInitedDefault: Ref<boolean>;
10 formElRef: Ref<FormActionType>; 10 formElRef: Ref<FormActionType>;
11 } 11 }
12 export async function useAutoFocus({ 12 export async function useAutoFocus({
13 getSchema, 13 getSchema,
14 - autoFocusFirstItem, 14 + getProps,
15 formElRef, 15 formElRef,
16 isInitedDefault, 16 isInitedDefault,
17 }: UseAutoFocusContext) { 17 }: UseAutoFocusContext) {
18 watchEffect(async () => { 18 watchEffect(async () => {
19 - if (unref(isInitedDefault) || !unref(autoFocusFirstItem)) return; 19 + if (unref(isInitedDefault) || !unref(getProps).autoFocusFirstItem) return;
20 await nextTick(); 20 await nextTick();
21 const schemas = unref(getSchema); 21 const schemas = unref(getSchema);
22 const formEl = unref(formElRef); 22 const formEl = unref(formElRef);
src/components/Form/src/hooks/useFormValues.ts
@@ -3,21 +3,19 @@ import { dateUtil } from &#39;/@/utils/dateUtil&#39;; @@ -3,21 +3,19 @@ import { dateUtil } from &#39;/@/utils/dateUtil&#39;;
3 3
4 import { unref } from 'vue'; 4 import { unref } from 'vue';
5 import type { Ref, ComputedRef } from 'vue'; 5 import type { Ref, ComputedRef } from 'vue';
6 -import type { FieldMapToTime, FormSchema } from '../types/form'; 6 +import type { FormProps, FormSchema } from '../types/form';
7 7
8 interface UseFormValuesContext { 8 interface UseFormValuesContext {
9 - transformDateFuncRef: Ref<Fn>;  
10 - fieldMapToTimeRef: Ref<FieldMapToTime>;  
11 defaultValueRef: Ref<any>; 9 defaultValueRef: Ref<any>;
12 getSchema: ComputedRef<FormSchema[]>; 10 getSchema: ComputedRef<FormSchema[]>;
  11 + getProps: ComputedRef<FormProps>;
13 formModel: Recordable; 12 formModel: Recordable;
14 } 13 }
15 export function useFormValues({ 14 export function useFormValues({
16 - transformDateFuncRef,  
17 - fieldMapToTimeRef,  
18 defaultValueRef, 15 defaultValueRef,
19 getSchema, 16 getSchema,
20 formModel, 17 formModel,
  18 + getProps,
21 }: UseFormValuesContext) { 19 }: UseFormValuesContext) {
22 // Processing form values 20 // Processing form values
23 function handleFormValues(values: Recordable) { 21 function handleFormValues(values: Recordable) {
@@ -31,12 +29,12 @@ export function useFormValues({ @@ -31,12 +29,12 @@ export function useFormValues({
31 if ((isArray(value) && value.length === 0) || isFunction(value)) { 29 if ((isArray(value) && value.length === 0) || isFunction(value)) {
32 continue; 30 continue;
33 } 31 }
34 - const transformDateFunc = unref(transformDateFuncRef); 32 + const transformDateFunc = unref(getProps).transformDateFunc;
35 if (isObject(value)) { 33 if (isObject(value)) {
36 - value = transformDateFunc(value); 34 + value = transformDateFunc?.(value);
37 } 35 }
38 if (isArray(value) && value[0]?._isAMomentObject && value[1]?._isAMomentObject) { 36 if (isArray(value) && value[0]?._isAMomentObject && value[1]?._isAMomentObject) {
39 - value = value.map((item) => transformDateFunc(item)); 37 + value = value.map((item) => transformDateFunc?.(item));
40 } 38 }
41 // Remove spaces 39 // Remove spaces
42 if (isString(value)) { 40 if (isString(value)) {
@@ -51,7 +49,7 @@ export function useFormValues({ @@ -51,7 +49,7 @@ export function useFormValues({
51 * @description: Processing time interval parameters 49 * @description: Processing time interval parameters
52 */ 50 */
53 function handleRangeTimeValue(values: Recordable) { 51 function handleRangeTimeValue(values: Recordable) {
54 - const fieldMapToTime = unref(fieldMapToTimeRef); 52 + const fieldMapToTime = unref(getProps).fieldMapToTime;
55 53
56 if (!fieldMapToTime || !Array.isArray(fieldMapToTime)) { 54 if (!fieldMapToTime || !Array.isArray(fieldMapToTime)) {
57 return values; 55 return values;
yarn.lock
@@ -1108,10 +1108,10 @@ @@ -1108,10 +1108,10 @@
1108 dependencies: 1108 dependencies:
1109 cross-fetch "^3.0.6" 1109 cross-fetch "^3.0.6"
1110 1110
1111 -"@iconify/json@^1.1.331":  
1112 - version "1.1.331"  
1113 - resolved "https://registry.npmjs.org/@iconify/json/-/json-1.1.331.tgz#5bd10c8764e24a973474992a35b56ea7e32a2115"  
1114 - integrity sha512-6YK6fJccOZYa01o6SV3WHNFWtfdP7+q9urn7s4OIFx0a6FTqole0BHGJ87ZsLp03N96TcGEY2nQGpv3MdezYKg== 1111 +"@iconify/json@^1.1.333":
  1112 + version "1.1.333"
  1113 + resolved "https://registry.npmjs.org/@iconify/json/-/json-1.1.333.tgz#d58b3d26c97963a1387b089f0c5accae1719fbea"
  1114 + integrity sha512-JcYRNdt9UUBGsH3U5P/Idw9jzZoDCokVyTUGfweHNRuH4r2xR4oVJgH/CyijdUd0BGZ4ztiO2iVBC1sysk67Yg==
1115 1115
1116 "@intlify/core-base@9.0.0": 1116 "@intlify/core-base@9.0.0":
1117 version "9.0.0" 1117 version "9.0.0"
@@ -9336,10 +9336,10 @@ vite-plugin-windicss@0.14.6: @@ -9336,10 +9336,10 @@ vite-plugin-windicss@0.14.6:
9336 debug "^4.3.2" 9336 debug "^4.3.2"
9337 windicss "^2.5.14" 9337 windicss "^2.5.14"
9338 9338
9339 -vite@2.1.5:  
9340 - version "2.1.5"  
9341 - resolved "https://registry.npmjs.org/vite/-/vite-2.1.5.tgz#4857da441c62f7982c83cbd5f42a00330f20c9c1"  
9342 - integrity sha512-tYU5iaYeUgQYvK/CNNz3tiJ8vYqPWfCE9IQ7K0iuzYovWw7lzty7KRYGWwV3CQPh0NKxWjOczAqiJsCL0Xb+Og== 9339 +vite@2.2.3:
  9340 + version "2.2.3"
  9341 + resolved "https://registry.npmjs.org/vite/-/vite-2.2.3.tgz#1acbdfa56ac00e00e7ccb6988f63f130c2f99dbb"
  9342 + integrity sha512-PtjyBL4GtACM+uT5q5hi2+AlMBbb6YI2b2bam6QI8ZdZt4FezseF0yZHQx0G+b3po9jIJ/GS5N9gc5Yq9Rue7g==
9343 dependencies: 9343 dependencies:
9344 esbuild "^0.9.3" 9344 esbuild "^0.9.3"
9345 postcss "^8.2.1" 9345 postcss "^8.2.1"