Commit 3ff70bb56f998cfc92a773676d75c06372d90658

Authored by Vben
1 parent 6afee415

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

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