From 9b78832f6bc69c9832c1bf08366870c788479df6 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 11 十月 2024 11:11:23 +0800 Subject: [PATCH] # --- zy-acs-flow/src/map/settings/ConfigSettings.jsx | 52 ++++++++++++++++++++++++++-------------------------- 1 files changed, 26 insertions(+), 26 deletions(-) diff --git a/zy-acs-flow/src/map/settings/ConfigSettings.jsx b/zy-acs-flow/src/map/settings/ConfigSettings.jsx index 54bec87..b33dead 100644 --- a/zy-acs-flow/src/map/settings/ConfigSettings.jsx +++ b/zy-acs-flow/src/map/settings/ConfigSettings.jsx @@ -22,40 +22,42 @@ } from '../constants'; import { useNotification } from '../Notification'; -export const getFormDefaultValues = (data) => { - return { - row: data?.row ?? '', - bay: data?.bay ?? '', - no: data?.no ?? '', - ...data, - } -}; - const ConfigSettings = (props) => { const { sprite, onSubmit } = props; const notify = useNotification(); const translate = useTranslate(); const { control, handleSubmit, reset, watch, setValue } = useForm({ - defaultValues: getFormDefaultValues(sprite?.data), + defaultValues: { ...sprite?.data }, }); useEffect(() => { if (sprite?.data) { - reset(getFormDefaultValues(sprite.data)); + reset({ + ...sprite.data + }); } }, [sprite, reset]); + + const deviceType = sprite?.data?.type; const rowValue = watch('row'); const bayValue = watch('bay'); useEffect(() => { - if (rowValue != null && bayValue != null && rowValue !== '' && bayValue !== '') { - setValue('no', `${rowValue}-${bayValue}`); - } else { - setValue('no', ''); + if (deviceType === DEVICE_TYPE.SHELF) { + if (rowValue != null && bayValue != null && rowValue !== '' && bayValue !== '') { + setValue('no', `${rowValue}-${bayValue}`); + } else { + setValue('no', ''); + } } - }, [rowValue, bayValue, setValue]); + }, [ + setValue, + deviceType, + rowValue, + bayValue, + ]); const onFormSubmit = (data) => { if (sprite && sprite.data) { @@ -74,7 +76,7 @@ <> <Box component="form" onSubmit={handleSubmit(onFormSubmit)} noValidate sx={{ mt: 0 }}> <Grid container spacing={1.4}> - {sprite?.data?.type === DEVICE_TYPE.SHELF && ( + {deviceType === DEVICE_TYPE.SHELF && ( <> <Grid item xs={6}> <Controller @@ -85,6 +87,7 @@ {...field} label={translate('page.map.settings.config.shelf.row')} type="number" + value={field.value ?? ''} fullWidth onChange={(e) => { field.onChange(e); @@ -102,6 +105,7 @@ {...field} label={translate('page.map.settings.config.shelf.bay')} type="number" + value={field.value ?? ''} fullWidth onChange={(e) => { field.onChange(e); @@ -113,29 +117,25 @@ </> )} - {sprite?.data?.type === DEVICE_TYPE.CHARGE && ( + {deviceType === DEVICE_TYPE.CHARGE && ( <> </> )} - {sprite?.data?.type === DEVICE_TYPE.STATION && ( + {deviceType === DEVICE_TYPE.STATION && ( <> </> )} - {sprite?.data?.type === DEVICE_TYPE.POINT && ( + {deviceType === DEVICE_TYPE.POINT && ( <> </> )} + <Grid item xs={12}> <Divider /> </Grid> - {/* <Grid item xs={12}> - <Typography variant="inherit"> - {translate('page.map.settings.config.base.no')} - </Typography> - </Grid> */} <Grid item xs={6}> <Controller name="no" @@ -146,7 +146,7 @@ {...field} label="No" type="text" - value={field.value || ''} + value={field.value ?? ''} fullWidth onChange={(e) => { field.onChange(e); -- Gitblit v1.9.1