Browse Source

导出表格

gzb
wangzhonglu 9 months ago
parent
commit
ac13ec3604

+ 2
- 0
public/index.html View File

@@ -32,6 +32,8 @@
32 32
     <script src="/librarys/echarts@5.4.3/echarts.min.js"></script>
33 33
     <script src="/librarys/echarts-liquidfill@3.1.0/echarts-liquidfill.min.js"></script>
34 34
     <script src="/librarys/echarts-wordcloud@2.1.0/echarts-wordcloud.min.js"></script>
35
+    <script src="/librarys/xlsx/xlsx-style.full.min.js"></script>
36
+    <script src="/librarys/xlsx/xlsx.extendscript.js"></script>
35 37
     <script src="./librarys/clipboard@2.0.11/clipboard.js"></script>
36 38
     <script src="/ckeditor_4.16.2_full/ckeditor.js"></script>
37 39
   </body>

+ 20
- 0
public/librarys/xlsx/xlsx-style.full.min.js
File diff suppressed because it is too large
View File


+ 30878
- 0
public/librarys/xlsx/xlsx.extendscript.js
File diff suppressed because it is too large
View File


+ 16
- 1
src/api/log.js View File

@@ -58,7 +58,22 @@ export const logAppStart_add = (data) => setRequest("logAppStart/add", data);
58 58
 export const logAppStart_list_install = (data) =>
59 59
   setRequest("logAppStart/list_install", data);
60 60
 /**
61
- * 7.9.1 设备导出-列表
61
+ * 7.9.1 设备导出-列表(平台、区域)
62 62
  */
63 63
 export const logDeviceBind_list = (data) =>
64 64
   setRequest("logDeviceBind/list", data);
65
+/**
66
+ * 7.9.2 设备导出-列表导出(平台、区域)
67
+ */
68
+export const logDeviceBind_list_all = (data) =>
69
+  setRequest("logDeviceBind/list_all", data);
70
+/**
71
+ * 7.9.3 设备导出-用户导出
72
+ */
73
+export const logDeviceBind_list_user = (data) =>
74
+  setRequest("logDeviceBind/list_user", data);
75
+/**
76
+ * 7.9.4 设备导出-列表学校
77
+ */
78
+export const logDeviceBind_list_school = (data) =>
79
+  setRequest("logDeviceBind/list_school", data);

+ 74
- 0
src/utils/exportToExcel.js View File

@@ -0,0 +1,74 @@
1
+import XLSX2 from "xlsx";
2
+import XLSX from "xlsx-style";
3
+const workbook2blob = (workbook) => {
4
+  // 生成excel的配置项
5
+  let wopts = {
6
+    // 要生成的文件类型
7
+    bookType: "xlsx",
8
+    // 是否生成Shared String Table,官方解释是,如果开启生成速度会下降,但在低版本IOS设备上有更好的兼容性
9
+    bookSST: false,
10
+    type: "binary"
11
+  };
12
+  let wbout = XLSX.write(workbook, wopts);
13
+  // 将字符串转ArrayBuffer
14
+  function s2ab(s) {
15
+    let buf = new ArrayBuffer(s.length);
16
+    let view = new Uint8Array(buf);
17
+    for (let i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xff;
18
+    return buf;
19
+  }
20
+  let buf = s2ab(wbout);
21
+  let blob = new Blob([buf], {
22
+    type: "application/octet-stream"
23
+  });
24
+  return blob;
25
+};
26
+// 将blob对象 创建bloburl,然后用a标签实现弹出下载框
27
+const openDownloadDialog = (blob, fileName) => {
28
+  if (typeof blob === "object" && blob instanceof Blob) {
29
+    blob = URL.createObjectURL(blob); // 创建blob地址
30
+  }
31
+  let aLink = document.createElement("a");
32
+  aLink.href = blob;
33
+  // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,有时候 file:///模式下不会生效
34
+  aLink.download = fileName || "";
35
+  let event;
36
+  if (window.MouseEvent) event = new MouseEvent("click");
37
+  //   移动端
38
+  else {
39
+    event = document.createEvent("MouseEvents");
40
+    event.initMouseEvent(
41
+      "click",
42
+      true,
43
+      false,
44
+      window,
45
+      0,
46
+      0,
47
+      0,
48
+      0,
49
+      0,
50
+      false,
51
+      false,
52
+      false,
53
+      false,
54
+      0,
55
+      null
56
+    );
57
+  }
58
+  aLink.dispatchEvent(event);
59
+};
60
+/**
61
+ * 导出Excel表格
62
+ * @param sheetListInfo {list:数组数据, name: sheet名称}
63
+ * @param excelName Excel表格名称
64
+ */
65
+export const exportToExcel = (sheetListInfo, excelName) => {
66
+  const wb = XLSX2.utils.book_new();
67
+  for (const sheetItem of sheetListInfo) {
68
+    const sheet = XLSX2.utils.json_to_sheet(sheetItem.list);
69
+    XLSX2.utils.book_append_sheet(wb, sheet, sheetItem.name);
70
+  }
71
+  const workbookBlob = workbook2blob(wb);
72
+  // 导出最后的总表
73
+  openDownloadDialog(workbookBlob, excelName + ".xlsx");
74
+};

+ 12
- 4
src/views/platformSection/log/deviceExport.vue View File

@@ -10,9 +10,9 @@
10 10
           style="width: 150px"
11 11
         />
12 12
       </div>
13
-      <Button type="primary" class="primary_btn" @click="toExport()"
13
+      <!-- <Button type="primary" class="primary_btn" @click="toExport()"
14 14
         >导出</Button
15
-      >
15
+      > -->
16 16
     </div>
17 17
     <div class="table_wrap">
18 18
       <Table :columns="columns" :data="searchForm.list">
@@ -40,7 +40,7 @@
40 40
 </template>
41 41
 
42 42
 <script>
43
-import { logDeviceBind_list } from "@/api/log";
43
+import { logDeviceBind_list, logDeviceBind_list_all } from "@/api/log";
44 44
 export default {
45 45
   data() {
46 46
     return {
@@ -129,7 +129,15 @@ export default {
129 129
         }
130 130
       });
131 131
     },
132
-    toExport() {}
132
+    toExport() {
133
+      logDeviceBind_list_all({}).then((data) => {
134
+        if (data.code === 0) {
135
+          console.log("---logDeviceBind_list_all---->", data.obj);
136
+        } else {
137
+          this.$Message.error(data.msg);
138
+        }
139
+      });
140
+    }
133 141
   }
134 142
 };
135 143
 </script>

+ 2
- 0
vue.config.js View File

@@ -44,6 +44,8 @@ module.exports = defineConfig({
44 44
       vuex: "Vuex",
45 45
       echarts: "echarts",
46 46
       axios: "axios",
47
+      xlsx: "XLSX2",
48
+      "xlsx-style": "XLSX",
47 49
       "view-design": "iview",
48 50
       "crypto-js": "CryptoJS"
49 51
     }

Loading…
Cancel
Save