From d0628b492a779097b0569c2e29fde5ba91632b42 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 11 十月 2024 15:59:33 +0800 Subject: [PATCH] # --- zy-acs-flow/src/map/settings/CopyDrawer.jsx | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/zy-acs-flow/src/map/settings/CopyDrawer.jsx b/zy-acs-flow/src/map/settings/CopyDrawer.jsx index 60b46e2..41a495c 100644 --- a/zy-acs-flow/src/map/settings/CopyDrawer.jsx +++ b/zy-acs-flow/src/map/settings/CopyDrawer.jsx @@ -1,5 +1,5 @@ import React, { useEffect } from 'react'; -import { useForm, Controller } from 'react-hook-form'; +import { useForm, useWatch, Controller } from 'react-hook-form'; import { Box, Grid, @@ -15,7 +15,6 @@ Divider, Drawer, IconButton, - LinearProgress, Switch, FormControlLabel, FormLabel, @@ -64,16 +63,18 @@ }, }); + const autoIncrement = useWatch({ control, name: 'autoIncrement' }); + const incrementValue = useWatch({ control, name: 'incrementValue' }); + useEffect(() => { - if (watch('autoIncrement') && incrementOptions && incrementOptions.length > 0) { - const currentIncrementValue = watch('incrementValue'); - if (!currentIncrementValue) { + if (autoIncrement && incrementOptions && incrementOptions.length > 0) { + if (!incrementValue) { setValue('incrementValue', incrementOptions[0].value); } } else { setValue('incrementValue', undefined); } - }, [watch('autoIncrement'), incrementOptions, setValue, watch]); + }, [autoIncrement, incrementOptions, setValue]); useEffect(() => { if (sprite && value && Object.keys(value).length > 0) { @@ -95,7 +96,6 @@ const onFormSubmit = (data) => { if (data) { console.log(data); - } if (handleOnCopy) { handleOnCopy(data); @@ -203,7 +203,7 @@ /> </Grid> - {(!!incrementOptions?.length && watch('autoIncrement')) && ( + {(!!incrementOptions?.length && autoIncrement) && ( <Grid item xs={12}> <FormControl fullWidth> <FormLabel sx={{ mb: 1 }}> @@ -234,7 +234,7 @@ </Grid> )} - {watch('autoIncrement') && ( + {autoIncrement && ( <Grid item xs={12}> <FormControl fullWidth> <FormLabel sx={{ -- Gitblit v1.9.1