Эх сурвалжийг харах

门户管理-运营服务-实现下载和下载量计算的功能

Sanmu8 1 жил өмнө
parent
commit
774b8b55f1

+ 6 - 5
src/api/portal/OPSERVICE/OPSERVICE.js

@@ -58,14 +58,15 @@ export function upload(data) {
   return request({
     url: '/common/upload',
     method: 'post',
-    data:data
+    data: data
   })
 }
 
-// 下载文件
-export function download(data) {
+// 获取文件流
+export function download(data,id) {
   return request({
-    url: '/common/download?fileName='+data,
-    method: 'get'
+    url: '/OPSERVICE/download?delete=false&fileName=' + data + '&id='+id,
+    method: 'get',
+    responseType: "blob"
   })
 }

+ 15 - 9
src/views/OPSERVICE/index.vue

@@ -116,7 +116,7 @@
       </el-table-column> -->
       <el-table-column label="下载次数" align="center" prop="download">
         <template slot-scope="scope">
-          {{ scope.row.download?scope.row.download:'暂无下载' }}
+          {{ scope.row.download ? scope.row.download : "暂无下载" }}
         </template>
       </el-table-column>
 
@@ -192,7 +192,7 @@
         </el-form-item>
 
         <el-form-item label="文件名称" prop="serviceName">
-          <el-input v-model="form.serviceName"></el-input>
+          <el-input v-model="form.serviceName" disabled></el-input>
         </el-form-item>
       </el-form>
       <div slot="footer" class="dialog-footer">
@@ -211,9 +211,10 @@ import {
   addOPSERVICE,
   updateOPSERVICE,
   upload,
-  download
+  download,
 } from "@/api/portal/OPSERVICE/OPSERVICE.js";
 
+import { saveAs } from "file-saver";
 export default {
   name: "OPSERVICE",
   data() {
@@ -284,6 +285,8 @@ export default {
           { required: true, message: "服务类型不能为空", trigger: "change" },
         ],
       },
+      setFileName: "", //保存文件名,点击下载时使用这个名字
+      downloadLoadingInstance:'',
     };
   },
   created() {
@@ -299,17 +302,20 @@ export default {
         this.loading = false;
       });
     },
-    handleDownload(row){
-      let fileName = row.serviceName
-      download(fileName).then(res=>{
-      })
+    handleDownload(row) {
+      this.setFileName = row.serviceName;
+      download(row.linkUrl,row.id).then((res) => {
+        const blob = new Blob([res]);
+        saveAs(blob, this.setFileName);
+        this.getList();
+      });
     },
     httprequest() {},
     uploadFile(file) {
       let formData = new FormData();
       formData.append("file", file);
       upload(formData).then((res) => {
-        this.form.linkUrl = res.url;
+        this.form.linkUrl = res.fileName;
         this.$set(this.form, "serviceName", res.originalFilename);
       });
     },
@@ -398,7 +404,7 @@ export default {
     handleDelete(row) {
       const ids = row.id || this.ids;
       this.$modal
-        .confirm('确定删除吗?')
+        .confirm("确定删除吗?")
         .then(function () {
           return delOPSERVICE(ids);
         })