zhang
2025-07-03 9483baffba9a24a2a36fc8739fc65b59317d9142
zy-acs-flow/src/map/settings/ConfigSettings.jsx
@@ -22,43 +22,45 @@
} 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),
    const { control, handleSubmit, reset, watch, setValue, formState: { errors } } = useForm({
        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) {
        if (sprite?.data) {
            Object.keys(data).forEach((key) => {
                sprite.data[key] = data[key];
            });
@@ -66,7 +68,6 @@
        if (onSubmit) {
            onSubmit(data);
        }
        console.log(sprite.data);
        notify.info(translate('common.response.success'));
    };
@@ -74,7 +75,8 @@
        <>
            <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,9 +87,10 @@
                                            {...field}
                                            label={translate('page.map.settings.config.shelf.row')}
                                            type="number"
                                            value={field.value ?? ''}
                                            fullWidth
                                            onChange={(e) => {
                                                field.onChange(e);
                                                field.onChange(e.target.value === '' ? '' : Number(e.target.value));
                                            }}
                                        />
                                    )}
@@ -102,9 +105,10 @@
                                            {...field}
                                            label={translate('page.map.settings.config.shelf.bay')}
                                            type="number"
                                            value={field.value ?? ''}
                                            fullWidth
                                            onChange={(e) => {
                                                field.onChange(e);
                                                field.onChange(e.target.value === '' ? '' : Number(e.target.value));
                                            }}
                                        />
                                    )}
@@ -113,40 +117,41 @@
                        </>
                    )}
                    {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"
                            control={control}
                            rules={{
                                required: translate('ra.validation.required')    // warn msg
                            }}
                            render={({ field }) => {
                                return (
                                    <TextField
                                        {...field}
                                        label="No"
                                        label={translate('page.map.settings.config.base.no')}
                                        type="text"
                                        value={field.value || ''}
                                        value={field.value ?? ''}
                                        error={!!errors.no} // show red warn
                                        helperText={errors.no ? errors.no.message : null}   // show warn msg
                                        fullWidth
                                        onChange={(e) => {
                                            field.onChange(e);