浏览代码

feat:修改重复下载时报错的问题

AmandaG 1 年之前
父节点
当前提交
94652e5e06
共有 1 个文件被更改,包括 28 次插入29 次删除
  1. 28 29
      src/views/Dashboard/src/components/BarChart.vue

+ 28 - 29
src/views/Dashboard/src/components/BarChart.vue

@@ -69,9 +69,6 @@ const downloadName = computed(() => {
 const isShowTooltips = computed(() => {
   return bar_data.value?.isShowTooltips
 })
-let header: any = []
-let data: any = []
-let sheetname: any = []
 const exportData = ({ filename }: any) => {
   $api
     .RevenueDownload({
@@ -80,6 +77,9 @@ const exportData = ({ filename }: any) => {
     })
     .then((res: any) => {
       if (res.code === 200) {
+        let header: any = []
+        let data: any = []
+        let sheetname: any = []
         let filterA = res.data.r2_cloumn.map((el: any) => {
           return el.dataIndex
         })
@@ -114,35 +114,34 @@ const exportData = ({ filename }: any) => {
           sheetname.push(result[i].sheetName)
           data.push(formatJson(result[i].filterVal, result[i].tableDatas))
         }
-      }
-    })
-    .finally(() => {
-      // 将表头插入数据数组中
-      for (let i = 0; i < header.length; i++) {
-        data[i].unshift(header[i])
-      }
-      let ws_name = sheetname
-      // 创建工作簿对象
-      let wb = XLSX.utils.book_new()
-      let ws: any = []
-      // 创建每个工作表并设置列宽
-      for (let j = 0; j < header.length; j++) {
-        ws.push(XLSX.utils.aoa_to_sheet(data[j]))
-        let arr: any = []
-        header[j].forEach((val: any) => {
-          arr.push({
-            wpx: 120
+        // 将表头插入数据数组中
+        for (let i = 0; i < header.length; i++) {
+          data[i].unshift(header[i])
+        }
+        let ws_name = sheetname
+        // 创建工作簿对象
+        let wb = XLSX.utils.book_new()
+        let ws: any = []
+        // 创建每个工作表并设置列宽
+        for (let j = 0; j < header.length; j++) {
+          ws.push(XLSX.utils.aoa_to_sheet(data[j]))
+          let arr: any = []
+          header[j].forEach((val: any) => {
+            arr.push({
+              wpx: 120
+            })
           })
-        })
-        ws[j]['!cols'] = arr
-      }
-      // 将工作表对象添加到工作簿中
-      for (let k = 0; k < header.length; k++) {
-        wb.SheetNames.push(ws_name[k])
-        wb.Sheets[ws_name[k]] = ws[k]
+          ws[j]['!cols'] = arr
+        }
+        // 将工作表对象添加到工作簿中
+        for (let k = 0; k < header.length; k++) {
+          wb.SheetNames.push(ws_name[k])
+          wb.Sheets[ws_name[k]] = ws[k]
+        }
+        XLSX.writeFile(wb, filename + '.xlsx') // 导出文件
       }
-      XLSX.writeFile(wb, filename + '.xlsx') // 导出文件
     })
+    .finally(() => {})
 }
 
 // 数额