From f419bab0bbbbe2a65f450af0a4eb7f8c04ad7500 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 11 十月 2024 10:29:23 +0800 Subject: [PATCH] # --- zy-acs-flow/src/map/settings/ConfigSettings.jsx | 75 +++++++++++++++++++++---------------- 1 files changed, 43 insertions(+), 32 deletions(-) diff --git a/zy-acs-flow/src/map/settings/ConfigSettings.jsx b/zy-acs-flow/src/map/settings/ConfigSettings.jsx index 0d8124b..0e74d1b 100644 --- a/zy-acs-flow/src/map/settings/ConfigSettings.jsx +++ b/zy-acs-flow/src/map/settings/ConfigSettings.jsx @@ -19,39 +19,62 @@ import ConfirmButton from '../../page/components/ConfirmButton'; import { DEVICE_TYPE, - DEVICE_Z_INDEX, } from '../constants'; +import { useNotification } from '../Notification'; + +export const getFormDefaultValues = (data) => ({ + row: data?.row ?? '', + bay: data?.bay ?? '', + no: data?.no ?? '', + ...data, +}); const ConfigSettings = (props) => { - const { sprite, setSpriteSettings, onSubmit } = props; + const { sprite, onSubmit } = props; + const notify = useNotification(); const translate = useTranslate(); - const { control, handleSubmit, reset, watch } = useForm({ - defaultValues: { - ...sprite.data - }, + const { control, handleSubmit, reset, watch, setValue } = useForm({ + defaultValues: getFormDefaultValues(sprite?.data), }); - const updateSprite = (data) => { - }; + useEffect(() => { + if (sprite?.data) { + reset(getFormDefaultValues(sprite.data)); + } + }, [sprite, reset]); + + const rowValue = watch('row'); + const bayValue = watch('bay'); + + useEffect(() => { + if (rowValue != null && bayValue != null && rowValue !== '' && bayValue !== '') { + setValue('no', `${rowValue}-${bayValue}`); + } else { + setValue('no', ''); + } + }, [rowValue, bayValue, setValue]); const onFormSubmit = (data) => { - console.log(data); + if (sprite && sprite.data) { + Object.keys(data).forEach((key) => { + sprite.data[key] = data[key]; + }); + } if (onSubmit) { onSubmit(data); } + console.log(sprite.data); + notify.info(translate('common.response.success')); }; return ( <> <Box component="form" onSubmit={handleSubmit(onFormSubmit)} noValidate sx={{ mt: 0 }}> <Grid container spacing={1.4}> - {sprite?.data?.type === DEVICE_TYPE.SHELF && ( <> - <Grid item xs={6} pt={0} sx={{ - paddingTop: '8px !important', - }}> + <Grid item xs={6}> <Controller name="row" control={control} @@ -62,17 +85,13 @@ type="number" fullWidth onChange={(e) => { - const value = e.target.value; field.onChange(e); - updateSprite(); }} /> )} /> </Grid> - <Grid item xs={6} pt={0} sx={{ - paddingTop: '8px !important', - }}> + <Grid item xs={6}> <Controller name="bay" control={control} @@ -83,7 +102,6 @@ type="number" fullWidth onChange={(e) => { - const value = e.target.value; field.onChange(e); }} /> @@ -107,7 +125,6 @@ <> </> )} - <Grid item xs={12}> <Divider /> </Grid> @@ -117,10 +134,7 @@ {translate('page.map.settings.config.base.no')} </Typography> </Grid> */} - <Grid item xs={6} pt={0} sx={{ - paddingTop: '8px !important', - }}> - + <Grid item xs={6}> <Controller name="no" control={control} @@ -129,9 +143,9 @@ {...field} label="No" type="text" + value={field.value || ''} fullWidth onChange={(e) => { - const value = e.target.value; field.onChange(e); }} /> @@ -141,18 +155,15 @@ <Grid item xs={12} mt={2}> <Stack direction="row" spacing={2}> - <Button variant="contained" color="primary" onClick={() => { - }}> + <Button variant="contained" color="primary" type="submit"> {translate('ra.action.confirm')} </Button> </Stack> </Grid> - </Grid> </Box> </> - ) -} + ); +}; - -export default ConfigSettings; \ No newline at end of file +export default ConfigSettings; -- Gitblit v1.9.1