Browse Source

指定文件名下载excel

gangyj 2 năm trước cách đây
mục cha
commit
86d10f7df0
2 tập tin đã thay đổi với 24 bổ sung3 xóa
  1. 11 0
      src/api/exctab/excelmodel.js
  2. 13 3
      src/views/exctab/excelmodel/excelmodel.vue

+ 11 - 0
src/api/exctab/excelmodel.js

@@ -224,3 +224,14 @@ export const exctabcellUpdate = (row) => {
         data: row
     })
 }
+
+export const downExcelFile = (fileId) => {
+    return request({
+      url: '/api/blade-manager/exceltab/down-Excel-file',
+      method: 'get',
+      params: {
+        fileId,
+      },
+      responseType: 'arraybuffer'
+    })
+}

+ 13 - 3
src/views/exctab/excelmodel/excelmodel.vue

@@ -361,7 +361,7 @@
 
 <script>
 import { detailExcel, excelType, tabLazytree, getWbsTypeList, wbstree, selectByNodeTable, Excelmodify, uploadExcel, deleteExcelshu, deleteExcel ,tabLazytreeAll,
-          uploadcoverfileExcel} from '@/api/exctab/excelmodel'
+          uploadcoverfileExcel,downExcelFile} from '@/api/exctab/excelmodel'
 export default {
   data () {
     return {
@@ -637,8 +637,18 @@ export default {
       })
     },
     downloadExcel () {//下载excel表
-      this.downFile(this.from.fileUrl,"123456.xlsx");
-    //  window.open(this.from.fileUrl,'namexxx')
+      //this.downFile(this.from.fileUrl,"123456.xlsx");
+      //window.open(this.from.fileUrl,'namexxx')
+      const link = document.createElement('a')
+      downExcelFile(this.from.id).then((res)=>{
+        // 创建Blob对象,设置文件类型
+        let blob = new Blob([res.data], {type: "application/vnd.ms-excel"})
+        let objectUrl = URL.createObjectURL(blob) // 创建URL
+        link.href = objectUrl
+        link.download = this.from.extension // 自定义文件名
+        link.click() // 下载文件
+        URL.revokeObjectURL(objectUrl); // 释放内存
+      })
     },
     //#endregion