#
luxiaotao1123
2024-10-11 920e52029ffad0bd2486ddeb583c3f25d1fa152a
zy-acs-flow/src/map/settings/ConfigSettings.jsx
@@ -36,8 +36,9 @@
    const notify = useNotification();
    const translate = useTranslate();
    const { control, handleSubmit, reset, watch, setValue } = useForm({
    const { control, handleSubmit, reset, watch, setValue, unregister } = useForm({
        defaultValues: getFormDefaultValues(sprite?.data),
        shouldUnregister: true,
    });
    useEffect(() => {
@@ -46,16 +47,32 @@
        }
    }, [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) {
            unregister('row');
            unregister('bay');
        }
    }, [rowValue, bayValue, setValue]);
    }, [deviceType, unregister]);
    useEffect(() => {
        if (deviceType === DEVICE_TYPE.SHELF) {
            if (rowValue != null && bayValue != null && rowValue !== '' && bayValue !== '') {
                setValue('no', `${rowValue}-${bayValue}`);
            } else {
                setValue('no', '');
            }
        }
    }, [
        setValue,
        deviceType,
        rowValue,
        bayValue,
    ]);
    const onFormSubmit = (data) => {
        if (sprite && sprite.data) {
@@ -74,7 +91,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 +102,7 @@
                                            {...field}
                                            label={translate('page.map.settings.config.shelf.row')}
                                            type="number"
                                            value={field.value ?? ''}
                                            fullWidth
                                            onChange={(e) => {
                                                field.onChange(e);
@@ -102,6 +120,7 @@
                                            {...field}
                                            label={translate('page.map.settings.config.shelf.bay')}
                                            type="number"
                                            value={field.value ?? ''}
                                            fullWidth
                                            onChange={(e) => {
                                                field.onChange(e);
@@ -113,20 +132,21 @@
                        </>
                    )}
                    {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>
@@ -146,7 +166,7 @@
                                        {...field}
                                        label="No"
                                        type="text"
                                        value={field.value || ''}
                                        value={field.value ?? ''}
                                        fullWidth
                                        onChange={(e) => {
                                            field.onChange(e);