From 433112b25f5874d0957fbfbda39c7325d3117aa6 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 11 十月 2024 10:19:27 +0800
Subject: [PATCH] #

---
 zy-acs-flow/src/map/Notification.jsx            |   33 ++++++++++++----
 zy-acs-flow/src/map/MapPage.jsx                 |    2 
 zy-acs-flow/src/map/settings/ConfigSettings.jsx |   60 +++++++++++++++---------------
 3 files changed, 56 insertions(+), 39 deletions(-)

diff --git a/zy-acs-flow/src/map/MapPage.jsx b/zy-acs-flow/src/map/MapPage.jsx
index a0688d7..527f79d 100644
--- a/zy-acs-flow/src/map/MapPage.jsx
+++ b/zy-acs-flow/src/map/MapPage.jsx
@@ -81,7 +81,7 @@
         handleResize();
         window.addEventListener('resize', handleResize);
 
-        notify('Welcome to Rcs', 'info');
+        notify.info('Welcome to Rcs');
 
         return () => {
             if (websocket) {
diff --git a/zy-acs-flow/src/map/Notification.jsx b/zy-acs-flow/src/map/Notification.jsx
index ecfb3e7..de65c06 100644
--- a/zy-acs-flow/src/map/Notification.jsx
+++ b/zy-acs-flow/src/map/Notification.jsx
@@ -1,4 +1,4 @@
-import React, { createContext, useContext, useState, useCallback } from 'react';
+import React, { createContext, useContext, useState, useCallback, useMemo } from 'react';
 import { Snackbar, Alert, Portal, Slide } from '@mui/material';
 
 const NotificationContext = createContext();
@@ -18,12 +18,21 @@
         setNotification({ open: true, message, severity });
     }, []);
 
-    const handleClose = () => {
-        setNotification({ ...notification, open: false });
-    };
+    const handleClose = useCallback(() => {
+        setNotification((prev) => ({ ...prev, open: false }));
+    }, []);
+
+    const notify = useMemo(() => ({
+        info: (msg) => showNotification(msg, 'info'),
+        success: (msg) => showNotification(msg, 'success'),
+        warning: (msg) => showNotification(msg, 'warning'),
+        error: (msg) => showNotification(msg, 'error'),
+        // Optional: If you prefer 'warn' instead of 'warning', uncomment the line below
+        // warn: (msg) => showNotification(msg, 'warning'),
+    }), [showNotification]);
 
     return (
-        <NotificationContext.Provider value={showNotification}>
+        <NotificationContext.Provider value={notify}>
             {children}
             <Portal>
                 <Snackbar
@@ -33,11 +42,15 @@
                     TransitionComponent={SlideTransition}
                     anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
                     sx={{
-                        // mt: 12,
                         zIndex: 2000,
                     }}
                 >
-                    <Alert onClose={handleClose} severity={notification.severity} sx={{ width: '300px', zIndex: 2000 }}>
+                    <Alert
+                        onClose={handleClose}
+                        severity={notification.severity}
+                        sx={{ width: '300px', zIndex: 2000 }}
+                        variant="filled" // Optional: Use filled variant for better visibility
+                    >
                         {notification.message}
                     </Alert>
                 </Snackbar>
@@ -47,5 +60,9 @@
 };
 
 export const useNotification = () => {
-    return useContext(NotificationContext);
+    const context = useContext(NotificationContext);
+    if (!context) {
+        throw new Error('useNotification must be used within a NotificationProvider');
+    }
+    return context;
 };
diff --git a/zy-acs-flow/src/map/settings/ConfigSettings.jsx b/zy-acs-flow/src/map/settings/ConfigSettings.jsx
index 0d8124b..038d1ed 100644
--- a/zy-acs-flow/src/map/settings/ConfigSettings.jsx
+++ b/zy-acs-flow/src/map/settings/ConfigSettings.jsx
@@ -19,39 +19,51 @@
 import ConfirmButton from '../../page/components/ConfirmButton';
 import {
     DEVICE_TYPE,
-    DEVICE_Z_INDEX,
 } from '../constants';
+import { useNotification } from '../Notification';
 
 const ConfigSettings = (props) => {
-    const { sprite, setSpriteSettings, onSubmit } = props;
+    const { sprite, onSubmit } = props;
+    const notify = useNotification();
     const translate = useTranslate();
 
-    const { control, handleSubmit, reset, watch } = useForm({
+    const { control, handleSubmit, reset, watch, setValue } = useForm({
         defaultValues: {
-            ...sprite.data
+            ...sprite.data,
         },
     });
 
-    const updateSprite = (data) => {
-    };
+    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 +74,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 +91,6 @@
                                             type="number"
                                             fullWidth
                                             onChange={(e) => {
-                                                const value = e.target.value;
                                                 field.onChange(e);
                                             }}
                                         />
@@ -107,7 +114,6 @@
                         <>
                         </>
                     )}
-
                     <Grid item xs={12}>
                         <Divider />
                     </Grid>
@@ -117,10 +123,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 +132,9 @@
                                     {...field}
                                     label="No"
                                     type="text"
+                                    value={field.value || ''}
                                     fullWidth
                                     onChange={(e) => {
-                                        const value = e.target.value;
                                         field.onChange(e);
                                     }}
                                 />
@@ -141,18 +144,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