From 443e32fec6aec9dfa2ca802246950dc3c36e6251 Mon Sep 17 00:00:00 2001
From: zhang <zc857179121@qq.com>
Date: 星期五, 25 七月 2025 15:35:12 +0800
Subject: [PATCH] 保存一个版本

---
 zy-acs-flow/src/map/Notification.jsx |   35 ++++++++++++++++++++++++++---------
 1 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/zy-acs-flow/src/map/Notification.jsx b/zy-acs-flow/src/map/Notification.jsx
index ecfb3e7..ed98f84 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,26 +18,39 @@
         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
                     open={notification.open}
-                    autoHideDuration={4000}
+                    autoHideDuration={3000}
                     onClose={handleClose}
                     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" // standard' | 'filled' | 'outlined
+                    >
                         {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;
 };

--
Gitblit v1.9.1