From cd79b3bfdbc33ffa79fefcf5d6fde287a1c05c2f Mon Sep 17 00:00:00 2001
From: panzy <225@qq.com>
Date: 星期六, 21 五月 2022 11:58:19 +0800
Subject: [PATCH] 表格添加loding转圈 隐患汇总添加导出

---
 src/views/summaryPotentialSafetyHzards/index.vue |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/views/summaryPotentialSafetyHzards/index.vue b/src/views/summaryPotentialSafetyHzards/index.vue
index a647499..19e71cf 100644
--- a/src/views/summaryPotentialSafetyHzards/index.vue
+++ b/src/views/summaryPotentialSafetyHzards/index.vue
@@ -106,13 +106,13 @@
                         <el-button class="btn" size="small" type="primary" @click="queryData"
                         >汇总
                         </el-button>
-                        <el-button class="btn" size="small" type="primary" @click="close()"
+                        <el-button class="btn" size="small" type="primary" @click="exportData()"
                         >导出Excel
                         </el-button>
                     </el-form-item>
                 </div>
             </el-form>
-            <el-table
+            <el-table id="out-table"
                 :data="tableData"
                 v-loading="loading"
                 style="width: 100%">
@@ -157,7 +157,8 @@
 } from "@/api/sgyhpczl/initSelect";
 
 import {danger_summary} from "@/api/sgyhpczl/summaryPotentialSafetyHzards";
-
+import FileSaver from "file-saver";
+import XLSX from "xlsx";
 export default {
     name: "index",
     data() {
@@ -402,6 +403,34 @@
                 path: "/summaryList",
                 query: {"searchData": searchData}
             })
+        },
+        exportData(){
+            var xlsxParam = { raw: true };
+            /* 从表生成工作簿对象 */
+            var wb = XLSX.utils.table_to_book(
+                document.querySelector("#out-table"),
+                xlsxParam
+            );
+            /* 获取二进制字符串作为输出 */
+            var wbout = XLSX.write(wb, {
+                bookType: "xlsx",
+                bookSST: true,
+                type: "array",
+            });
+            try {
+                FileSaver.saveAs(
+                    //Blob 对象表示一个不可变、原始数据的类文件对象。
+                    //Blob 表示的不一定是JavaScript原生格式的数据。
+                    //File 接口基于Blob,继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
+                    //返回一个新创建的 Blob 对象,其内容由参数中给定的数组串联组成。
+                    new Blob([wbout], { type: "application/octet-stream" }),
+                    //设置导出文件名称
+                    "安全隐患汇总.xlsx"
+                );
+            } catch (e) {
+                if (typeof console !== "undefined") console.log(e, wbout);
+            }
+            return wbout;
         }
 
     }

--
Gitblit v1.9.2