From 9bfc581627fc8475fda5bac423a5b76ea4f00df5 Mon Sep 17 00:00:00 2001
From: cqf
Date: 星期六, 21 五月 2022 17:37:57 +0800
Subject: [PATCH] 文件下载

---
 src/views/delayHiddenDangerRectification/rectificationDelayHiddenDanger.vue |   51 +++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/src/views/delayHiddenDangerRectification/rectificationDelayHiddenDanger.vue b/src/views/delayHiddenDangerRectification/rectificationDelayHiddenDanger.vue
index f3724fa..4e58d63 100644
--- a/src/views/delayHiddenDangerRectification/rectificationDelayHiddenDanger.vue
+++ b/src/views/delayHiddenDangerRectification/rectificationDelayHiddenDanger.vue
@@ -297,10 +297,15 @@
                                         >
                                         <template slot-scope="scope">
                                             <span size="medium">{{ scope.row.content }}</span>
-                                            <a v-for="item in scope.row.realFileName"
-                                               :href="scope.row.url+'/'+item">
-                                                {{ item.split("fileName=")[1] }}
-                                            </a>
+                                            <span v-for="item in scope.row.realFileName">
+                                                <el-link  type="primary" @click="downloadFile(subFile(item))">
+                                                    {{subFile(item)}}
+                                                </el-link>
+                                            </span>
+<!--                                            <a v-for="item in scope.row.realFileName"-->
+<!--                                               :href="scope.row.url+'/'+item">-->
+<!--                                                {{ item.split("fileName=")[1] }}-->
+<!--                                            </a>-->
                                         </template>
                                     </el-table-column>
                                     <el-table-column
@@ -316,7 +321,7 @@
                 </el-form>
                 <el-form :model="sendData" :rules="rules" ref="sendData" label-width="150px" class="demo-ruleForm"
                          style="margin: 0 14% 0 16%;">
-                    >
+
                     <el-row>
                         <el-col :span="22">
                             <el-form-item label="发送流程" prop="name">
@@ -397,6 +402,7 @@
 <script>
 import Titlename from "../../components/Titlename/index.vue";
 import {sendDangerNext, getDangerDetails, getWfRecordList} from "@/api/sgyhpczl/recheckCancellationNumber";
+import {downloadFile} from "@/api/sgyhpczl/fileUtils";
 
 export default {
     components: {Titlename},
@@ -517,7 +523,40 @@
             this.$router.push({
                 path: "/delayHiddenDangerRectification"
             })
-        }
+        },
+        subFile(fileName){
+            return  fileName.substring(fileName.indexOf("fileName=")+9)
+        },
+        downloadFile(path){
+            let params = {
+                type: 0,
+                fileName: path,
+            };
+            downloadFile(params).then((res) => {
+                if(res.data.type=='text/json'){
+                    const reader  = new FileReader();
+                    reader.readAsText(res.data, 'utf-8');
+                    reader.onload = e => {
+                        this.$message({
+                            type: "error",
+                            message: JSON.parse(reader.result).msg,
+                            duration: 3000,
+                        });
+                    }
+                } else {
+                    let blob = new Blob([res.data], {type: 'application/octet-stream'})
+                    console.log(blob)
+                    let blobUrl = window.URL.createObjectURL(blob)
+                    let downloadElement = document.createElement('a')
+                    downloadElement.href = blobUrl
+                    downloadElement.download = path
+                    document.body.appendChild(downloadElement)
+                    downloadElement.click()
+                    document.body.removeChild(downloadElement)
+                    window.URL.revokeObjectURL(blobUrl)
+                }
+            });
+        },
     }
 }
 </script>

--
Gitblit v1.9.2