Jelajahi Sumber

feat: 添加关机和注销操作的二次确认对话框 (src/components/ExitModal.tsx)

- 重构handleExit函数,拆分为handleExit和executeAction
- 使用Modal.confirm为关机和注销操作添加二次确认
- 关闭程序操作保持直接执行,无需确认
- 改进错误处理逻辑
sw 1 Minggu lalu
induk
melakukan
bba14608d1
1 mengubah file dengan 36 tambahan dan 8 penghapusan
  1. 36 8
      src/components/ExitModal.tsx

+ 36 - 8
src/components/ExitModal.tsx

@@ -32,16 +32,44 @@ const ExitModal: React.FC<ExitModalProps> = ({ visible, onClose }) => {
   const dispatch = useDispatch();
 
   const handleExit = async (type: 'close' | 'logout' | 'shutdown') => {
+    // 对危险操作进行二次确认
+    const isDangerousOperation = type === 'shutdown' || type === 'logout';
+    if (isDangerousOperation) {
+      const confirmMessages = {
+        shutdown: {
+          title: '确认关机',
+          content: '确定要关闭系统吗?此操作将关闭计算机。',
+        },
+        logout: {
+          title: '确认注销',
+          content: '确定要注销当前用户吗?您将退出登录状态。',
+        },
+      };
+
+      const config = confirmMessages[type];
+
+      Modal.confirm({
+        title: config.title,
+        content: config.content,
+        okText: '确认',
+        cancelText: '取消',
+        centered: true,
+        onOk: async () => {
+          await executeAction(type);
+        },
+      });
+      return;
+    }
+
+    // 非危险操作直接执行
+    await executeAction(type);
+  };
+
+  const executeAction = async (type: 'close' | 'logout' | 'shutdown') => {
     try {
       let result;
       let actionName = '';
 
-      // 添加操作确认
-      const isDangerousOperation = type === 'shutdown' || type === 'logout';
-      if (isDangerousOperation) {
-        // 这里可以添加二次确认逻辑,暂时省略,直接执行
-      }
-
       switch (type) {
         case 'close':
           actionName = '关闭程序';
@@ -62,13 +90,13 @@ const ExitModal: React.FC<ExitModalProps> = ({ visible, onClose }) => {
           return;
       }
 
-      if (result.success) {
+      if (result && result.success) {
         message.success(`${actionName}操作已执行`);
         if (type === 'close') {
           // 关闭程序操作会直接退出,不需要关闭弹框
           return;
         }
-      } else {
+      } else if (result) {
         // 处理不同类型的错误
         if (result.requiresAdmin) {
           message.warning({