Browse Source

供应商附件管理:打开新窗口下载

002390 1 year ago
parent
commit
cfff2ad8c1
2 changed files with 37 additions and 11 deletions
  1. 10 1
      src/api/purchase/supAtttachment.js
  2. 27 10
      src/views/purchase/SupAtttachment/index.vue

+ 10 - 1
src/api/purchase/supAtttachment.js

@@ -1,10 +1,19 @@
 import request from '@/utils/request'
 import request from '@/utils/request'
 
 
-// 物料分工详情
+// 查询文件列表
 export function referFile(params) {
 export function referFile(params) {
   return request({
   return request({
     url: `/refer/file/${params.code}`,
     url: `/refer/file/${params.code}`,
     method: 'get',
     method: 'get',
     params,
     params,
   })
   })
+}
+
+// 下载
+export function download(data) {
+  return request({
+    url: `/download`,
+    method: 'post',
+    data,
+  })
 }
 }

+ 27 - 10
src/views/purchase/SupAtttachment/index.vue

@@ -1,6 +1,6 @@
 <!-- 供应商附件管理 -->
 <!-- 供应商附件管理 -->
 <script>
 <script>
-import { referFile } from "@/api/purchase/supAtttachment";
+import { referFile, download } from "@/api/purchase/supAtttachment";
 import useColumns from "./columns";
 import useColumns from "./columns";
 export default {
 export default {
   name: "SupAtttachment",
   name: "SupAtttachment",
@@ -34,8 +34,29 @@ export default {
       }
       }
     },
     },
     // 下载
     // 下载
-    useDownload(row) {
-      window.open(row.url, "_self");
+    async useDownload(row) {
+      try {
+        this.$modal.loading("请稍候...");
+        let formData = new FormData();
+        formData.append("url", row.url);
+        await download(formData).then((res) => {
+          var blob = new Blob([res], {
+            type: "image/jpeg",
+          });
+          const link = document.createElement("a");
+
+          link.href = URL.createObjectURL(blob);
+          link.download = row.name; // 这里填保存成的文件名
+          link.click();
+          URL.revokeObjectURL(link.href);
+        });
+      } catch (error) {
+      } finally {
+        this.$modal.closeLoading();
+      }
+    },
+    useDbclick(row) {
+      window.open(row.url);
     },
     },
   },
   },
   async created() {
   async created() {
@@ -63,17 +84,13 @@ export default {
       index
       index
       pagination
       pagination
       storage-key="SupAtttachmentSuperTable"
       storage-key="SupAtttachmentSuperTable"
-      @row-dblclick="useDownload"
+      @row-dblclick="useDbclick"
       @pagination="getList(page)"
       @pagination="getList(page)"
     >
     >
       <ux-table-column fixed="right" title="操作" align="center" width="100">
       <ux-table-column fixed="right" title="操作" align="center" width="100">
         <template slot-scope="scope">
         <template slot-scope="scope">
-          <el-link
-            type="primary"
-            :href="scope.row.url"
-            :underline="false"
-            icon="el-icon-download"
-            >下载</el-link
+          <el-button type="text" @click="useDownload(scope.row)" :size="size"
+            >下载</el-button
           >
           >
         </template>
         </template>
       </ux-table-column>
       </ux-table-column>