瀏覽代碼

前端逻辑已完成

lifuquan 10 月之前
父節點
當前提交
1ae978b3a5
共有 3 個文件被更改,包括 14 次插入6 次删除
  1. 1 1
      index.html
  2. 4 1
      src/request/reportInfo.js
  3. 9 4
      src/views/EnergyConsumptionStatisticsReport.vue

+ 1 - 1
index.html

@@ -5,7 +5,7 @@
   <meta charset="UTF-8" />
   <link rel="icon" type="image/svg+xml" href="/vite.svg" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
-  <title>Vite + Vue</title>
+  <title>节能减排</title>
 </head>
 
 <body>

+ 4 - 1
src/request/reportInfo.js

@@ -7,4 +7,7 @@ export const postForSMonthAll = async () =>
     await request.post("/cost/api/report/smonth/all")
 
 export const postForDownload = async reportInfo =>
-    await request.post("/cost/api/report/download", reportInfo)
+    await request.get("/cost/api/report/download", {
+        params: reportInfo,
+        responseType: 'blob'
+    })

+ 9 - 4
src/views/EnergyConsumptionStatisticsReport.vue

@@ -47,9 +47,7 @@ const checkSMonth = (time) => {
 }
 
 const refreshTableData = (month) => {
-  console.log(month);
   postForReportInfoBySMonth(month).then(res => {
-    console.log(res);
     if (res.success) {
       tableData.value = res.data
     } else {
@@ -58,10 +56,17 @@ const refreshTableData = (month) => {
   }).catch(() => ElMessage.error("出错了"))
 }
 
-// TODO download还未实现
 const handleDownload = (scope) => {
   postForDownload(scope.row)
-    .then(res => console.log(res))
+    .then(res => {
+      let blob = new Blob([res])
+      let url = window.URL.createObjectURL(blob)
+      let a = document.createElement('a')
+      a.href = url
+      a.download = scope.row.displayName
+      a.click()
+      window.URL.revokeObjectURL(url)
+    })
     .catch(() => ElMessage.error("出错了"))
 }