From c9e8eab9835c6f72f84552f694582d9a27f6328c Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 11 十月 2024 16:50:31 +0800 Subject: [PATCH] # --- zy-acs-flow/src/map/settings/CopyDrawer.jsx | 44 +++++++++++++++++++++++++++++++++++--------- 1 files changed, 35 insertions(+), 9 deletions(-) diff --git a/zy-acs-flow/src/map/settings/CopyDrawer.jsx b/zy-acs-flow/src/map/settings/CopyDrawer.jsx index 075dc5b..2229124 100644 --- a/zy-acs-flow/src/map/settings/CopyDrawer.jsx +++ b/zy-acs-flow/src/map/settings/CopyDrawer.jsx @@ -46,6 +46,26 @@ ], }; + +const validateIncrement = (value, deviceType, sprite, translate) => { + if (!value) { + return true; + } + switch (deviceType) { + case DEVICE_TYPE.SHELF: + if (!sprite?.data?.row || !sprite?.data?.bay) { + return translate('page.map.settings.map.copy.valid.shelf'); + } + break; + default: + if (!sprite?.data?.no) { + return translate('page.map.settings.map.copy.valid.common'); + } + break; + } + return true; +}; + const getDefaultFormValues = (value = {}) => ({ copyDirect: value.copyDirect || '', copyCount: value.copyCount || '', @@ -62,7 +82,7 @@ const deviceType = sprite?.data?.type; const incrementOptions = incrementOptionsMap[deviceType] - const { control, handleSubmit, reset, watch, setValue } = useForm({ + const { control, handleSubmit, reset, watch, setValue, formState: { errors } } = useForm({ defaultValues: getDefaultFormValues(value), }); @@ -90,12 +110,8 @@ } const onFormSubmit = (data) => { - if (data) { - console.log(data); - } - if (handleOnCopy) { - handleOnCopy(data); - } + console.log(data); + handleOnCopy?.(data); notify.info(translate('common.response.success')); }; @@ -184,6 +200,7 @@ <Controller name="autoIncrement" control={control} + rules={{ validate: (value) => validateIncrement(value, deviceType, sprite, translate) }} render={({ field }) => ( <FormControlLabel control={ @@ -197,6 +214,11 @@ /> )} /> + {errors.autoIncrement && ( + <Typography color="error"> + {errors.autoIncrement.message} + </Typography> + )} </Grid> {(!!incrementOptions?.length && autoIncrement) && ( @@ -214,7 +236,9 @@ value={field.value} exclusive onChange={(event, value) => { - field.onChange(value); + if (value !== null) { + field.onChange(value); + } }} fullWidth > @@ -247,7 +271,9 @@ value={field.value} exclusive onChange={(event, value) => { - field.onChange(value); + if (value !== null) { + field.onChange(value); + } }} fullWidth > -- Gitblit v1.9.1