From 7d549f074a154850d2b1d8c581503efaf2122207 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 11 十月 2024 16:02:40 +0800
Subject: [PATCH] #
---
zy-acs-flow/src/map/settings/CopyDrawer.jsx | 38 +++++++++++++++++---------------------
1 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/zy-acs-flow/src/map/settings/CopyDrawer.jsx b/zy-acs-flow/src/map/settings/CopyDrawer.jsx
index 41a495c..075dc5b 100644
--- a/zy-acs-flow/src/map/settings/CopyDrawer.jsx
+++ b/zy-acs-flow/src/map/settings/CopyDrawer.jsx
@@ -46,6 +46,15 @@
],
};
+const getDefaultFormValues = (value = {}) => ({
+ copyDirect: value.copyDirect || '',
+ copyCount: value.copyCount || '',
+ gap: 0.0,
+ autoIncrement: false,
+ incrementMode: 'ascending',
+ incrementValue: undefined,
+});
+
const CopyDrawer = (props) => {
const { open, onCancel, sprite, value, width = PAGE_DRAWER_WIDTH, handleOnCopy } = props;
const notify = useNotification();
@@ -53,18 +62,18 @@
const deviceType = sprite?.data?.type;
const incrementOptions = incrementOptionsMap[deviceType]
- const { control, handleSubmit, reset, watch, setValue, formState: { errors } } = useForm({
- defaultValues: {
- copyDirect: value?.copyDirect || '',
- copyCount: value?.copyCount || '',
- gap: 0.0,
- autoIncrement: false,
- incrementMode: 'ascending',
- },
+ const { control, handleSubmit, reset, watch, setValue } = useForm({
+ defaultValues: getDefaultFormValues(value),
});
const autoIncrement = useWatch({ control, name: 'autoIncrement' });
const incrementValue = useWatch({ control, name: 'incrementValue' });
+
+ useEffect(() => {
+ if (sprite && value && Object.keys(value).length > 0) {
+ reset(getDefaultFormValues(value));
+ }
+ }, [sprite, value, reset, incrementOptions, setValue]);
useEffect(() => {
if (autoIncrement && incrementOptions && incrementOptions.length > 0) {
@@ -75,19 +84,6 @@
setValue('incrementValue', undefined);
}
}, [autoIncrement, incrementOptions, setValue]);
-
- useEffect(() => {
- if (sprite && value && Object.keys(value).length > 0) {
- reset({
- copyDirect: value.copyDirect || '',
- copyCount: value.copyCount || '',
- gap: 0.0,
- autoIncrement: false,
- incrementMode: 'ascending',
- incrementValue: undefined,
- });
- }
- }, [sprite, value, reset, incrementOptions, setValue]);
const handleClose = () => {
onCancel();
--
Gitblit v1.9.1