From 0a7829811f6df7a6eb4e32ba5ba53b1db9f10e9c Mon Sep 17 00:00:00 2001
From: zhouwx <1175765986@qq.com>
Date: 星期三, 23 七月 2025 10:01:09 +0800
Subject: [PATCH] 修改

---
 src/views/work/onlineEducation/offlineEducation/index.vue |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/views/work/onlineEducation/offlineEducation/index.vue b/src/views/work/onlineEducation/offlineEducation/index.vue
index 2a9bd04..a4aab55 100644
--- a/src/views/work/onlineEducation/offlineEducation/index.vue
+++ b/src/views/work/onlineEducation/offlineEducation/index.vue
@@ -73,10 +73,14 @@
           <span>{{scope.row.passed == 0 ? '不合格':'合格'}}</span>
         </template>
       </el-table-column>
-      <el-table-column label="培训记录" prop="passed" align="center" width="130">
+      <el-table-column label="培训记录" prop="passed" align="center" width="180">
         <template #default="scope">
           <div v-for="item in scope.row.files" style="display: flex;flex-direction: column">
-            <el-link type="primary" @click="openFile(item.filePath)">{{item.fileName}}</el-link>
+            <div style="display: flex;flex-direction: column;align-items: center">
+              <el-link type="primary" @click="openFile(item.filePath)">{{item.fileName}}</el-link>
+              <el-button style="width: 50px;margin-bottom: 5px" size="small" @click="downloadFile(item)">下载</el-button>
+            </div>
+
           </div>
 
         </template>
@@ -111,6 +115,8 @@
 import {delStudent, getStudent} from "@/api/onlineEducation/student";
 import {delRecord, getRecord} from "@/api/onlineEducation/examRecord";
 import {renderAsync} from "docx-preview";
+import axios from "axios";
+import {getToken} from "@/utils/auth";
 
 
 const { proxy } = getCurrentInstance();
@@ -236,5 +242,23 @@
     }
   }
 }
-
+const downloadFile = (e)=>{
+  axios.get(import.meta.env.VITE_APP_BASE_API + '/' +e.filePath,{headers:{'Content-Type': 'application/json','Authorization': `${getToken()}`},responseType: 'blob'}).then(res=>{
+    if (res) {
+      const link = document.createElement('a')
+      let blob = new Blob([res.data],{type: res.data.type})
+      link.style.display = "none";
+      link.href = URL.createObjectURL(blob); // 创建URL
+      link.setAttribute("download", e.fileName);
+      document.body.appendChild(link);
+      link.click();
+      document.body.removeChild(link);
+    } else {
+      ElMessage({
+        type: 'warning',
+        message: '文件读取失败'
+      });
+    }
+  })
+}
 </script>

--
Gitblit v1.9.2