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

---
 src/views/troubleshooting/index.vue                                         |    1 
 src/views/careabout/index.vue                                               |   12 ++
 src/views/delayHiddenDangerRectification/rectificationDelayHiddenDanger.vue |   51 +++++++++-
 src/api/sgyhpczl/fileUtils.js                                               |   17 +++
 src/views/dangerDetails/dnagerDetails.vue                                   |   45 ++++++++-
 src/views/hiddenDangerReview/recheckHiddenDangerList.vue                    |   45 ++++++++-
 src/api/sgyhpczl/troubleshooting.js                                         |   14 --
 src/views/Issuedbysuperiors/superiorsSend.vue                               |   46 ++++++++-
 src/views/hiddenDangerRectification/sendHiddenDangerList.vue                |   45 ++++++++-
 9 files changed, 234 insertions(+), 42 deletions(-)

diff --git a/src/api/sgyhpczl/fileUtils.js b/src/api/sgyhpczl/fileUtils.js
new file mode 100644
index 0000000..5884f07
--- /dev/null
+++ b/src/api/sgyhpczl/fileUtils.js
@@ -0,0 +1,17 @@
+import request from '@/utils/request';
+import {getTokenAndVerify} from "@/api/sgyhpczl/auth";
+
+//下载文件
+export function downloadFile(params) {
+    return request({
+        headers: {
+            'token': getTokenAndVerify().token,
+            'verify': getTokenAndVerify().verify
+        },
+        url: '/taboi/file/dowloand_do',
+        method: 'GET',
+        contentType: "multipart/form-data",
+        responseType:'blob',
+        params:params?params:{}
+    });
+}
diff --git a/src/api/sgyhpczl/troubleshooting.js b/src/api/sgyhpczl/troubleshooting.js
index 610645a..2dbe1f1 100644
--- a/src/api/sgyhpczl/troubleshooting.js
+++ b/src/api/sgyhpczl/troubleshooting.js
@@ -32,20 +32,6 @@
         data
     });
 }
-//下载文件
-export function dowloand_do(params) {
-    return request({
-        headers: {
-            'token': getTokenAndVerify().token,
-            'verify': getTokenAndVerify().verify
-        },
-        url: '/taboi/file/dowloand_do',
-        method: 'GET',
-        contentType: "multipart/form-data",
-        responseType:'blob',
-        params:params?params:{}
-    });
-}
 //新增/编辑
 export function addOrEdit(data) {
     return request({
diff --git a/src/views/Issuedbysuperiors/superiorsSend.vue b/src/views/Issuedbysuperiors/superiorsSend.vue
index f0ff93b..5688cfa 100644
--- a/src/views/Issuedbysuperiors/superiorsSend.vue
+++ b/src/views/Issuedbysuperiors/superiorsSend.vue
@@ -296,10 +296,11 @@
                                         >
                                         <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>
                                         </template>
                                     </el-table-column>
                                     <el-table-column
@@ -387,7 +388,7 @@
 import {getDangerDetails, getWfRecordList} from "@/api/sgyhpczl/recheckCancellationNumber";
 import {company_next_step_do} from "@/api/sgyhpczl/Issuedbysuperiors";
 import {getUserInfo} from "@/api/sgyhpczl/hiddenDangerManagement";
-
+import {downloadFile} from "@/api/sgyhpczl/fileUtils";
 
 export default {
     components: {Titlename},
@@ -497,7 +498,40 @@
             this.$router.push({
                 path: "/recheckCancellationNumber"
             })
-        }
+        },
+        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>
diff --git a/src/views/careabout/index.vue b/src/views/careabout/index.vue
index 3f5d990..416f99c 100644
--- a/src/views/careabout/index.vue
+++ b/src/views/careabout/index.vue
@@ -156,7 +156,11 @@
         </el-row>
        <el-table :data="tableData" style="width: 100%"  @selection-change="handleSelectionChange" v-loading="listLoading">
             <el-table-column type="selection" width="55" align="center"></el-table-column>
-            <el-table-column prop="number" label="编号" align="center" width="120"></el-table-column>
+            <el-table-column prop="number" label="编号" align="center" width="120">
+                <template slot-scope="scope">
+                    <div class="blue-font-color" @click="showDetails(scope.row)">{{ scope.row.number }}</div>
+                </template>
+            </el-table-column>
             <el-table-column prop="check_branch" label="检查部门" align="center" width="120"></el-table-column>
             <el-table-column prop="check_man" label="检查人" align="center" width="120"></el-table-column>
             <el-table-column prop="checktype" label="检查类别" align="center"></el-table-column>
@@ -426,6 +430,12 @@
                     }
                 })
             },
+            showDetails(row){
+                this.$router.push({
+                    path: "/dangerDetails",
+                    query:{"id":row.id}
+                })
+            },
             typeChange(val){
                 this.listQuery.type = val;
                 if (val == 1){
diff --git a/src/views/dangerDetails/dnagerDetails.vue b/src/views/dangerDetails/dnagerDetails.vue
index 26a7a4c..65b0885 100644
--- a/src/views/dangerDetails/dnagerDetails.vue
+++ b/src/views/dangerDetails/dnagerDetails.vue
@@ -295,10 +295,11 @@
                                         >
                                         <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>
                                         </template>
                                     </el-table-column>
                                     <el-table-column
@@ -331,6 +332,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},
@@ -465,7 +467,40 @@
                         path:"/hiddenDangerRectification"
                     })
                 }
-            }
+            },
+            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>
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>
diff --git a/src/views/hiddenDangerRectification/sendHiddenDangerList.vue b/src/views/hiddenDangerRectification/sendHiddenDangerList.vue
index bd318b2..2b75bb3 100644
--- a/src/views/hiddenDangerRectification/sendHiddenDangerList.vue
+++ b/src/views/hiddenDangerRectification/sendHiddenDangerList.vue
@@ -292,10 +292,11 @@
                                         width="260">
                                         <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>
                                         </template>
                                     </el-table-column>
                                     <el-table-column
@@ -391,6 +392,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},
@@ -518,7 +520,40 @@
                 this.$router.push({
                     path:"/hiddenDangerRectification"
                 })
-            }
+            },
+            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>
diff --git a/src/views/hiddenDangerReview/recheckHiddenDangerList.vue b/src/views/hiddenDangerReview/recheckHiddenDangerList.vue
index 197dfd3..88d3929 100644
--- a/src/views/hiddenDangerReview/recheckHiddenDangerList.vue
+++ b/src/views/hiddenDangerReview/recheckHiddenDangerList.vue
@@ -296,10 +296,11 @@
                                         width="260">
                                         <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>
                                         </template>
                                     </el-table-column>
                                     <el-table-column
@@ -431,6 +432,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},
@@ -533,7 +535,40 @@
             this.$router.push({
                 path: "/recheckCancellationNumber"
             })
-        }
+        },
+        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>
diff --git a/src/views/troubleshooting/index.vue b/src/views/troubleshooting/index.vue
index 88d9cb1..5a18dcc 100644
--- a/src/views/troubleshooting/index.vue
+++ b/src/views/troubleshooting/index.vue
@@ -213,6 +213,7 @@
 import {getPageList, dowloand_do, addOrEdit, del, revoke, put} from "@/api/sgyhpczl/troubleshooting";
 import {uploadFile} from "@/api/sgyhpczl/hiddenDangerRectification";
 import {deepClone} from '@/utils'
+import {downloadFile} from "@/api/sgyhpczl/fileUtils";
 
 import {
   initYHLX,

--
Gitblit v1.9.2