Browse Source

#修改已知问题

jc-wangyt 3 ngày trước cách đây
mục cha
commit
adfe315219
1 tập tin đã thay đổi với 28 bổ sung14 xóa
  1. 28 14
      src/views/alarm/index.vue

+ 28 - 14
src/views/alarm/index.vue

@@ -180,21 +180,35 @@ export default {
         // 处理导出成功逻辑
         const blob = new Blob([res], { type: 'application/vnd.ms-excel' });
         try {
-          const fileHandle = await window.showSaveFilePicker({
-            suggestedName: `告警数据_${this.currentMonth}.xlsx`,
-            types: [
-              {
-                description: 'Excel文件',
-                accept: {
-                  'application/vnd.ms-excel': ['.xlsx']
+          // 检查是否支持 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('导出成功');
+              ]
+            });
+            const writable = await fileHandle.createWritable();
+            await writable.write(blob);
+            await writable.close();
+            this.$message.success('导出成功');
+          } else {
+            // 降级方案:使用传统的下载方式
+            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);
           // 如果用户取消选择,不显示错误信息