Skip to content

Commit 2882d6e

Browse files
committed
perf(form): perf form in modal
1 parent 733afdd commit 2882d6e

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"vite-plugin-html": "^2.0.0-beta.6",
9898
"vite-plugin-mock": "^2.0.0-rc.2",
9999
"vite-plugin-purge-icons": "^0.6.0",
100-
"vite-plugin-pwa": "^0.4.0",
100+
"vite-plugin-pwa": "^0.4.1",
101101
"vite-plugin-style-import": "^0.4.6",
102102
"vue-eslint-parser": "^7.4.1",
103103
"yargs": "^16.2.0"

src/components/Form/src/BasicForm.vue

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,19 @@
3333
<script lang="ts">
3434
import type { FormActionType, FormProps, FormSchema } from './types/form';
3535
import type { AdvanceState } from './types/hooks';
36-
import type { CSSProperties, Ref, WatchStopHandle } from 'vue';
37-
38-
import { defineComponent, reactive, ref, computed, unref, onMounted, watch, toRefs } from 'vue';
36+
import type { CSSProperties, Ref } from 'vue';
37+
38+
import {
39+
defineComponent,
40+
reactive,
41+
ref,
42+
computed,
43+
unref,
44+
onMounted,
45+
watch,
46+
toRefs,
47+
nextTick,
48+
} from 'vue';
3949
import { Form, Row } from 'ant-design-vue';
4050
import FormItem from './components/FormItem';
4151
import FormAction from './components/FormAction.vue';
@@ -51,6 +61,7 @@
5161
import { useFormEvents } from './hooks/useFormEvents';
5262
import { createFormContext } from './hooks/useFormContext';
5363
import { useAutoFocus } from './hooks/useAutoFocus';
64+
import { useModalContext } from '/@/components/Modal';
5465
5566
import { basicProps } from './props';
5667
import { useDesign } from '/@/hooks/web/useDesign';
@@ -62,6 +73,7 @@
6273
emits: ['advanced-change', 'reset', 'submit', 'register'],
6374
setup(props, { emit }) {
6475
const formModel = reactive<Recordable>({});
76+
const modalFn = useModalContext();
6577
6678
const advanceState = reactive<AdvanceState>({
6779
isAdvanced: true,
@@ -188,11 +200,15 @@
188200
}
189201
);
190202
191-
const stopWatch: WatchStopHandle = watch(
203+
watch(
192204
() => getSchema.value,
193205
(schema) => {
206+
nextTick(() => {
207+
// Solve the problem of modal adaptive height calculation when the form is placed in the modal
208+
modalFn?.redoModalHeight?.();
209+
});
194210
if (unref(isInitedDefaultRef)) {
195-
return stopWatch();
211+
return;
196212
}
197213
if (schema?.length) {
198214
initDefault();

src/components/Form/src/hooks/useFormValues.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { isArray, isFunction, isObject, isString, isNullOrUnDef } from '/@/utils/is';
22
import { dateUtil } from '/@/utils/dateUtil';
33

4-
import { unref, nextTick } from 'vue';
4+
import { unref } from 'vue';
55
import type { Ref, ComputedRef } from 'vue';
66
import type { FieldMapToTime, FormSchema } from '../types/form';
7-
import { useModalContext } from '/@/components/Modal';
87

98
interface UseFormValuesContext {
109
transformDateFuncRef: Ref<Fn>;
@@ -20,7 +19,6 @@ export function useFormValues({
2019
getSchema,
2120
formModel,
2221
}: UseFormValuesContext) {
23-
const modalFn = useModalContext();
2422
// Processing form values
2523
function handleFormValues(values: Recordable) {
2624
if (!isObject(values)) {
@@ -85,10 +83,6 @@ export function useFormValues({
8583
}
8684
});
8785
defaultValueRef.value = obj;
88-
nextTick(() => {
89-
// Solve the problem of modal adaptive height calculation when the form is placed in the modal
90-
modalFn?.redoModalHeight?.();
91-
});
9286
}
9387

9488
return { handleFormValues, initDefault };

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7722,10 +7722,10 @@ vite-plugin-purge-icons@^0.6.0:
77227722
"@purge-icons/generated" "^0.6.0"
77237723
rollup-plugin-purge-icons "^0.6.0"
77247724

7725-
vite-plugin-pwa@^0.4.0:
7726-
version "0.4.0"
7727-
resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.4.0.tgz#be7723315beed00ca7f9d23b24c5b1356276747c"
7728-
integrity sha512-+qsqpR6QgkxY8IdSyjHDGz5L5+3pbXKVP2KztqMeamu8Rpki45kEUMrdhloFSPiSNA7L+xS/U6WDyNe+u0IP4A==
7725+
vite-plugin-pwa@^0.4.1:
7726+
version "0.4.1"
7727+
resolved "https://registry.npmjs.org/vite-plugin-pwa/-/vite-plugin-pwa-0.4.1.tgz#eae03c4dd10cd51600c08fd1aaa179a92577c456"
7728+
integrity sha512-UvcdW93FT0+2dRSLasQtvJepBwXj+UTcvzBekca6YuVdn/MTdEX01J/QqPL+v3KUZBnNM2MAOFpLIkZ3wi9t8g==
77297729
dependencies:
77307730
debug "^4.3.2"
77317731
fast-glob "^3.2.5"

0 commit comments

Comments
 (0)