Browse Source

fix: 业务table组件批量导出完善及日志导出功能

Tong 2 years ago
parent
commit
1ab3f4f4fc

+ 1 - 1
src/api/monitor/LogApi.ts

@@ -7,7 +7,7 @@ enum Api {
   LogAdd = '/sys/log/add',
   LogEdit = '/sys/log/edit',
   LogRemove = '/sys/log/removeByIds',
-  LogExport = '/sys/log/removeByIds',
+  LogExport = '/sys/log/export/operation',
 }
 
 /**

+ 14 - 4
src/components/TableCard/src/BasicTable.vue

@@ -65,6 +65,7 @@
   import { useTableFooter } from './hooks/useTableFooter';
   import { useDesign } from '/@/hooks/web/useDesign';
   import { useMessage } from '/@/hooks/web/useMessage';
+  import { downloadByBase64 } from '/@/utils/file/download';
 
   import { omit } from 'lodash-es';
   import { basicProps } from './props';
@@ -235,13 +236,22 @@
       // 批量导出
       async function batchExport() {
         // const selectRow = getSelectRows();
-        if (!innerPropsRef.value.batchDelApi || !isFunction(innerPropsRef.value.batchDelApi)) {
+        if (
+          !innerPropsRef.value.batchExportApi ||
+          !isFunction(innerPropsRef.value.batchExportApi)
+        ) {
           createMessage.error('未找到批量操作入口!');
           return;
         }
-        // const keys = getSelectRowKeys();
-        // await innerPropsRef.value.batchDelApi(keys);
-        // createMessage.success('删除成功!');
+        const keys = getSelectRowKeys();
+        await innerPropsRef.value.batchExportApi(keys).then(res => {
+          console.log('res::::::::', res && res);
+          if (res && res.fileName && res.base64) {
+            downloadByBase64(res.base64, res.fileName + '.xlsx');
+          } else {
+            createMessage.error('获取导出文件失败!');
+          }
+        });
       }
       const {
         getViewColumns,

+ 26 - 8
src/utils/file/base64Conver.ts

@@ -2,17 +2,35 @@
  * @description: base64 to blob
  */
 export function dataURLtoBlob(base64Buf: string): Blob {
+  // 导出专用
   const arr = base64Buf.split(',');
-  const typeItem = arr[0];
-  const mime = typeItem.match(/:(.*?);/)![1];
-  const bstr = window.atob(arr[1]);
-  let n = bstr.length;
-  const u8arr = new Uint8Array(n);
-  while (n--) {
-    u8arr[n] = bstr.charCodeAt(n);
+  if (arr.length == 1) {
+    const typeItem = arr[0];
+    debugger;
+    // const mime = typeItem.match(/:(.*?);/)![1];
+    const bstr = window.atob(typeItem);
+    let n = bstr.length;
+    const u8arr = new Uint8Array(n);
+    while (n--) {
+      u8arr[n] = bstr.charCodeAt(n);
+    }
+    return new Blob([u8arr], {
+      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+    });
+  } else {
+    const typeItem = arr[0];
+    debugger;
+    const mime = typeItem.match(/:(.*?);/)![1];
+    const bstr = window.atob(arr[1]);
+    let n = bstr.length;
+    const u8arr = new Uint8Array(n);
+    while (n--) {
+      u8arr[n] = bstr.charCodeAt(n);
+    }
+    return new Blob([u8arr], { type: mime });
   }
-  return new Blob([u8arr], { type: mime });
 }
+
 /**
  * img url to base64
  * @param url

+ 1 - 1
src/views/monitor/operLog/index.vue

@@ -140,7 +140,7 @@
     api: LogQueryPage,
     batchDelApi: LogRemove,
     batchExportApi: LogExport, // 目前调用的是删除接口
-    exportAuthList: ['sys:log:export'],
+    exportAuthList: ['sys:log:export:login:operation'],
     delAuthList: ['sys:log:remove'],
     rowKey: 'id',
     columns,