Ver código fonte

feat: 添加下载功能到数据表格,支持文件下载

xieyong 3 dias atrás
pai
commit
2bc542710c
2 arquivos alterados com 33 adições e 3 exclusões
  1. 22 3
      src/components/addDoc/main.vue
  2. 11 0
      src/components/addDoc/util.js

+ 22 - 3
src/components/addDoc/main.vue

@@ -34,11 +34,20 @@
         <el-link
           type="primary"
           :underline="false"
-          icon="el-icon-edit"
+          icon="el-icon-view"
           @click="browseOpen(row)"
         >
           浏览
         </el-link>
+        <el-link
+          type="primary"
+          :underline="false"
+          icon="el-icon-download"
+          class="ele-action"
+          @click="downloadOpen(row)"
+        >
+          下载
+        </el-link>
 
         <el-popconfirm
           v-if="type != 'view'"
@@ -88,7 +97,7 @@
   import fileEdit from './file-edit.vue';
   import browse from './browse.vue';
   import { queryIds } from './api';
-  import { setFileUrl } from './util.js';
+  import { setFileUrl, setDownloadUrl } from './util.js';
   import tableColumnsMixin from '@/mixins/tableColumnsMixin.js';
 
   export default {
@@ -172,7 +181,7 @@
           {
             columnKey: 'action',
             label: '操作',
-            width: 200,
+            width: 240,
             align: 'center',
             resizable: false,
             slot: 'action',
@@ -220,6 +229,16 @@
       browseOpen(row) {
         window.open(setFileUrl(row));
       },
+      downloadOpen(row) {
+        const url = setDownloadUrl(row);
+        const link = document.createElement('a');
+        link.href = url;
+        link.target = '_blank';
+        link.download = row.storagePath[0]?.name || '';
+        document.body.appendChild(link);
+        link.click();
+        document.body.removeChild(link);
+      },
       addFile() {
         this.$emit(
           'success',

+ 11 - 0
src/components/addDoc/util.js

@@ -64,6 +64,17 @@ export function setFileUrl(row) {
     fileNames[fileNames.length - 1];
   return '/kkfile/onlinePreview?url=' + btoa(url);
 }
+export function setDownloadUrl(row) {
+  let file = row.storagePath[0];
+  let fileNames = file.storePath.split('/');
+  return (
+    window.location.origin +
+    '/api/main/file/getFile?objectName=' +
+    file.storePath +
+    '&fullfilename=' +
+    fileNames[fileNames.length - 1]
+  );
+}
 export function setFolderList(data) {
   //递归过滤文件夹权限
   data.forEach((item) => {