Prechádzať zdrojové kódy

#修复已知问题

jc-wangyt 3 dní pred
rodič
commit
4a4ac6c3d9
1 zmenil súbory, kde vykonal 60 pridanie a 50 odobranie
  1. 60 50
      src/views/alarm/index.vue

+ 60 - 50
src/views/alarm/index.vue

@@ -168,59 +168,69 @@ export default {
     },
     // 处理导出
     handleExport() {
-      const loading = this.$loading({
-        lock: true,
-        text: '正在下载...',
-        spinner: 'el-icon-loading',
-        background: 'rgba(0, 0, 0, 0.7)'
-      });
+      // 显示确认对话框
+      this.$confirm(`确定要导出 ${this.currentMonth} 月份的告警数据吗?`, '导出确认', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        const loading = this.$loading({
+          lock: true,
+          text: '正在下载...',
+          spinner: 'el-icon-loading',
+          background: 'rgba(0, 0, 0, 0.7)'
+        });
 
-      // exportAlarmData(this.currentMonth).then(res => {
-      exportNewAlarmData(this.currentMonth).then(async (res) => {
-        // 处理导出成功逻辑
-        const blob = new Blob([res], { type: 'application/vnd.ms-excel' });
-        try {
-          // 检查是否支持 File System Access API (仅在安全上下文可用)
-          if (typeof window.showSaveFilePicker === 'function') {
-            const fileHandle = await window.showSaveFilePicker({
-              suggestedName: `告警数据_${this.currentMonth}.xlsx`,
-              types: [
-                {
-                  description: 'Excel文件',
-                  accept: {
-                    'application/vnd.ms-excel': ['.xlsx']
+        // exportAlarmData(this.currentMonth).then(res => {
+        exportNewAlarmData(this.currentMonth).then(async (res) => {
+          // 处理导出成功逻辑
+          const blob = new Blob([res], { type: 'application/vnd.ms-excel' });
+          try {
+            // 检查是否支持 File System Access API (仅在安全上下文可用)
+            if (typeof window.showSaveFilePicker === 'function') {
+              const fileHandle = await window.showSaveFilePicker({
+                suggestedName: `告警数据_${this.currentMonth}.xlsx`,
+                types: [
+                  {
+                    description: 'Excel文件',
+                    accept: {
+                      'application/vnd.ms-excel': ['.xlsx']
+                    }
                   }
-                }
-              ]
-            });
-            const writable = await fileHandle.createWritable();
-            await writable.write(blob);
-            await writable.close();
-            this.$message.success('导出成功');
-          } else {
-            // 降级方案:使用传统的下载方式
-            // 注意:在非安全上下文(如HTTP或本地IP)中,浏览器不允许选择保存位置
-            // 文件将下载到浏览器默认的下载目录
-            const url = URL.createObjectURL(blob);
-            const a = document.createElement('a');
-            a.href = url;
-            a.download = `告警数据_${this.currentMonth}.xlsx`;
-            document.body.appendChild(a);
-            a.click();
-            document.body.removeChild(a);
-            URL.revokeObjectURL(url);
-            this.$message.success('导出成功(文件已保存到默认下载目录)');
-          }
-        } catch (error) {
-          console.error('导出失败:', error);
-          // 如果用户取消选择,不显示错误信息
-          if (error.name !== 'AbortError') {
-            this.$message.error('导出失败');
+                ]
+              });
+              const writable = await fileHandle.createWritable();
+              await writable.write(blob);
+              await writable.close();
+              this.$message.success('导出成功');
+            } else {
+              // 降级方案:使用传统的下载方式
+              // 注意:在非安全上下文(如HTTP或本地IP)中,浏览器不允许选择保存位置
+              // 文件将下载到浏览器默认的下载目录
+              const url = URL.createObjectURL(blob);
+              const a = document.createElement('a');
+              a.href = url;
+              a.download = `告警数据_${this.currentMonth}.xlsx`;
+              document.body.appendChild(a);
+              a.click();
+              document.body.removeChild(a);
+              URL.revokeObjectURL(url);
+              this.$message.success('导出成功(文件已保存到默认下载目录)');
+            }
+          } catch (error) {
+            console.error('导出失败:', error);
+            // 如果用户取消选择,不显示错误信息
+            if (error.name !== 'AbortError') {
+              this.$message.error('导出失败');
+            }
           }
-        }
-      }).finally(() => {
-        loading.close();
-      })
+        }).finally(() => {
+          loading.close();
+        })
+      }).catch(() => {
+        // 用户取消导出
+        this.$message.info('已取消导出');
+      });
     }
   }
 }