瀏覽代碼

feat: (export) 导出api

gemercheung 2 年之前
父節點
當前提交
1f0179aaa1
共有 3 個文件被更改,包括 43 次插入27 次删除
  1. 26 14
      src/api/dashboard/analysis.ts
  2. 4 0
      src/utils/http/axios/index.ts
  3. 13 13
      src/views/dashboard/analysis/enterprise.vue

+ 26 - 14
src/api/dashboard/analysis.ts

@@ -46,21 +46,33 @@ export const bulletChatStaticsApi = (params: BasicStaticsParams) =>
   });
 
 export const bulletChatExportApi = (params: BasicStaticsParams) =>
-  defHttp.post<Blob>({
-    url: Api.bulletChatExport,
-    params,
-    headers: {
-      // @ts-ignore
-      ignoreCancelToken: true,
+  defHttp.post<Blob>(
+    {
+      url: Api.bulletChatExport,
+      params,
+      responseType: 'blob',
+      headers: {
+        // @ts-ignore
+        ignoreCancelToken: true,
+      },
     },
-  });
+    {
+      errorMessageMode: 'none',
+    },
+  );
 
 export const companyChatExportApi = (params: BasicStaticsParams) =>
-  defHttp.post<Blob>({
-    url: Api.bulletChatExport,
-    params,
-    headers: {
-      // @ts-ignore
-      ignoreCancelToken: true,
+  defHttp.post<Blob>(
+    {
+      url: Api.bulletChatExport,
+      params,
+      responseType: 'blob',
+      headers: {
+        // @ts-ignore
+        ignoreCancelToken: true,
+      },
     },
-  });
+    {
+      errorMessageMode: 'none',
+    },
+  );

+ 4 - 0
src/utils/http/axios/index.ts

@@ -110,6 +110,10 @@ const transform: AxiosTransform = {
     if (options.useResult) {
       return data;
     }
+    if (res.config.responseType === 'blob') {
+      return data;
+    }
+
     throw new Error(timeoutMsg || t('sys.api.apiRequestFailed'));
   },
 

+ 13 - 13
src/views/dashboard/analysis/enterprise.vue

@@ -166,19 +166,19 @@
     await userStaticsApi(searchInfo);
   });
   async function handleExport() {
-    await companyChatExportApi(searchInfo);
-    // const downloadBlob = new Blob([data], {
-    //   type: 'text/csv',
-    // });
-    // const url = URL.createObjectURL(downloadBlob);
-    // const a: HTMLAnchorElement = document.createElement('a');
-    // document.body.appendChild(a);
-    // a.style.display = 'none';
-    // a.href = url;
-    // const name = new Date().getTime();
-    // a.download = `${name}.csv`;
-    // a.click();
-    // window.URL.revokeObjectURL(url);
+    const data = await companyChatExportApi(searchInfo);
+    const downloadBlob = new Blob([data], {
+      type: 'application/msexcel',
+    });
+    const url = URL.createObjectURL(downloadBlob);
+    const a: HTMLAnchorElement = document.createElement('a');
+    document.body.appendChild(a);
+    a.style.display = 'none';
+    a.href = url;
+    const name = new Date().getTime();
+    a.download = `${name}.csv`;
+    a.click();
+    window.URL.revokeObjectURL(url);
   }
 
   setTimeout(() => {