Просмотр исходного кода

新增入库详情附件下载功能

huang_an 2 лет назад
Родитель
Сommit
55294dc639

+ 14 - 0
src/api/system/file/index.js

@@ -1,4 +1,5 @@
 import request from '@/utils/request';
+import { download } from '@/utils/file';
 
 /**
  * 上传文件
@@ -66,3 +67,16 @@ export async function removeFiles(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+
+// 通过文件名获取文件流
+export async function getFile(params, fileName) {
+  console.log(params);
+  console.log(fileName);
+  const res = await request.get('/main/file/getFile', {
+    params,
+    responseType: 'blob'
+  });
+  console.log(res);
+  const arr = params.objectName.split('/');
+  download(res.data, fileName || arr[arr.length - 1]);
+}

+ 10 - 0
src/utils/file.js

@@ -0,0 +1,10 @@
+// 下载方法
+export function download(data, name) {
+  const a = document.createElement('a');
+  const url = window.URL.createObjectURL(data);
+  const filename = name;
+  a.href = url;
+  a.download = filename;
+  a.click();
+  window.URL.revokeObjectURL(url);
+}

+ 3 - 0
src/utils/request.js

@@ -13,6 +13,9 @@ const service = axios.create({
   baseURL: API_BASE_URL,
   transformResponse: [
     function (data) {
+      if (data instanceof Blob) {
+        return data;
+      }
       const json = JSONBIG({
         storeAsString: true
       });

+ 10 - 7
src/views/warehouseManagement/stockManagement/details.vue

@@ -100,13 +100,13 @@
               </el-col>
               <el-col :span="8">
                 <el-form-item label="附件:">
-                  <!-- <el-link
+                  <el-link
                     type="primary"
-                    v-for="(item, index) in infoData.contentImage"
-                    @click="contentImageDownload(item)"
+                    v-for="item in infoData.qualityFile"
+                    @click="download(item)"
                     :key="item.name"
                     >{{ item.name }}</el-link
-                  > -->
+                  >
                 </el-form-item>
               </el-col>
               <el-col :span="24">
@@ -518,10 +518,11 @@
 </template>
 
 <script>
+  import { getFile } from '@/api/system/file/index.js';
   // import { getInfo } from '@/api/stockManagement';
   import PageHeader from '@/components/PageHeader';
   import StatusStep from '@/components/StatusStep/common.vue';
-  // import { fileSystemDownload } from '@/utils';
+  import { fileSystemDownload } from '@/utils';
   import outin from '@/api/warehouseManagement/outin';
   import { getTreeByPid, allCategoryLevel } from '@/api/classifyManage';
 
@@ -702,8 +703,10 @@
 
         return a * b * c + { yuan: '元', wanyuan: '万元' }[row.univalenceUnit];
       },
-      contentImageDownload(item) {
-        fileSystemDownload(item);
+      download(row) {
+        if (row.storePath) {
+          getFile({ objectName: row.storePath }, row.name);
+        }
       },
       selectActive(num) {
         this.num = num;