Browse Source

下载附件

1 year ago
parent
commit
0fab6796a0
2 changed files with 25 additions and 1 deletions
  1. 11 0
      src/api/portal/GARDENBASEDATA/GARDENBASEDATA.js
  2. 14 1
      src/views/GARDENBASEDATA/index.vue

+ 11 - 0
src/api/portal/GARDENBASEDATA/GARDENBASEDATA.js

@@ -69,3 +69,14 @@ export function importGARDENBASEDATA(data) {
     data,
   });
 }
+
+// 附件下载
+export function fileDownloadFun(data) {
+  return request({
+    url: '/common/download',
+    method: 'get',
+    params: data,
+    responseType: "blob"
+
+  })
+}

+ 14 - 1
src/views/GARDENBASEDATA/index.vue

@@ -354,7 +354,7 @@
           </el-select>
         </el-form-item >
         <el-form-item label="附件"  label-width="100px" prop="file">
-        <el-upload class="upload-demo" ref="upload" :file-list="fileList" :limit="1"  :before-upload="uploadFile" drag :auto-upload="false" action="#" multiple>
+        <el-upload class="upload-demo" :on-preview="downloadFile" ref="upload" :file-list="fileList" :limit="1"  :before-upload="uploadFile" drag :auto-upload="false" action="#" multiple>
           <i class="el-icon-upload"></i>
           <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
           
@@ -378,9 +378,12 @@ import {
   updateGARDENBASEDATA,
   getEnterprise,
   importGARDENBASEDATA,
+  fileDownloadFun,
 } from "@/api/portal/GARDENBASEDATA/GARDENBASEDATA";
 import "@riophae/vue-treeselect/dist/vue-treeselect.css";
 import selectTree from "@/components/selectTree";
+import { saveAs } from "file-saver";
+
 
 export default {
   name: "GARDENBASEDATA",
@@ -637,6 +640,16 @@ export default {
         };
       })
     },
+    // 点击文件下载
+    downloadFile(file){
+      let ip = process.env.VUE_APP_BASE_IP;
+      let path = ip + file.name;
+      let name = file.name;
+      fileDownloadFun({ fileName: path, delete: false }).then((res) => {
+        let bolb = new Blob([file.raw]);
+        saveAs(bolb, name);
+      });
+    },
     // 确定上传附件
     submitUpload() {
       this.$refs.upload.submit();