张涛 8 months ago
parent
commit
3db2bba37b
4 changed files with 20 additions and 15 deletions
  1. 3
    3
      config/proxy.js
  2. 4
    3
      src/services/invoiceFill.js
  3. 2
    1
      src/utils/hooks/useExport.js
  4. 11
    8
      src/utils/request.js

+ 3
- 3
config/proxy.js View File

11
     // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
11
     // localhost:8000/api/** -> https://preview.pro.ant.design/api/**
12
     '/api/': {
12
     '/api/': {
13
       // 要代理的地址
13
       // 要代理的地址
14
-      target: 'http://192.168.89.25:7081',
14
+      target: 'http://192.168.89.13:7081',
15
       changeOrigin: true,
15
       changeOrigin: true,
16
       headers: {
16
       headers: {
17
-        origin: 'http://192.168.89.25:7081',
18
-        referer: 'http://192.168.89.25:7081',
17
+        origin: 'http://192.168.89.13:7081',
18
+        referer: 'http://192.168.89.13:7081',
19
       },
19
       },
20
     },
20
     },
21
   },
21
   },

+ 4
- 3
src/services/invoiceFill.js View File

17
  * @param {*} data
17
  * @param {*} data
18
  * @returns
18
  * @returns
19
  */
19
  */
20
- export const deleteInvoiceFill = (id) => request(`/invoice/${id}`, { method: 'delete' });
20
+export const deleteInvoiceFill = (id) => request(`/invoice/${id}`, { method: 'delete' });
21
 
21
 
22
- // 导出
23
-export const getExport = (params) => request(`/invoice/${params.invoiceId}/export`, { params, method: 'post' });
22
+// 导出
23
+export const getExport = (params) =>
24
+  request(`/invoice/${params.invoiceId}/export`, { params, method: 'post' ,download:true});

+ 2
- 1
src/utils/hooks/useExport.js View File

8
       if (typeof expFunc === 'function') {
8
       if (typeof expFunc === 'function') {
9
         setLoading(true);
9
         setLoading(true);
10
         expFunc(...args)
10
         expFunc(...args)
11
-          .then(() => {
11
+          .then((res) => {
12
+            console.log(res)
12
             setLoading(false);
13
             setLoading(false);
13
           })
14
           })
14
           .catch(() => {
15
           .catch(() => {

+ 11
- 8
src/utils/request.js View File

18
  *
18
  *
19
  */
19
  */
20
 
20
 
21
-function requestInterceptor (url, options) {
21
+function requestInterceptor(url, options) {
22
   const headers = options.headers || {};
22
   const headers = options.headers || {};
23
   const token = localStorage.getItem('token')
23
   const token = localStorage.getItem('token')
24
     ? { Authorization: localStorage.getItem('token') }
24
     ? { Authorization: localStorage.getItem('token') }
25
     : {};
25
     : {};
26
 
26
 
27
-  console.log('------------->', API_BASE)
27
+  console.log('------------->', API_BASE);
28
 
28
 
29
   const prefix = `${API_BASE}/api/admin`;
29
   const prefix = `${API_BASE}/api/admin`;
30
-  let requestType = 'json'
30
+  let requestType = 'json';
31
   if (options.data instanceof FormData) {
31
   if (options.data instanceof FormData) {
32
-    requestType = 'form'
32
+    requestType = 'form';
33
   }
33
   }
34
   return {
34
   return {
35
     url: `${prefix}${url}`,
35
     url: `${prefix}${url}`,
44
   };
44
   };
45
 }
45
 }
46
 
46
 
47
-async function responseInterceptor (response, ctx) {
47
+async function responseInterceptor(response, ctx) {
48
   const contextType = response.headers.get('content-type');
48
   const contextType = response.headers.get('content-type');
49
   if (contextType.indexOf('json') > -1) {
49
   if (contextType.indexOf('json') > -1) {
50
     const result = await response.clone().json();
50
     const result = await response.clone().json();
55
 
55
 
56
   if (contextType.indexOf('application/vnd.ms-excel') > -1) {
56
   if (contextType.indexOf('application/vnd.ms-excel') > -1) {
57
     const data = await response.clone().blob();
57
     const data = await response.clone().blob();
58
-    console.info(response)
58
+    console.info(response);
59
     const content = response.headers.get('content-disposition');
59
     const content = response.headers.get('content-disposition');
60
     const fileName = content.replace('attachment;filename=', '');
60
     const fileName = content.replace('attachment;filename=', '');
61
     downloadBlob(data, decodeURIComponent(fileName));
61
     downloadBlob(data, decodeURIComponent(fileName));
89
   responseInterceptors: [responseInterceptor],
89
   responseInterceptors: [responseInterceptor],
90
 };
90
 };
91
 
91
 
92
-export default (...args) => request(...args).then((r) => r.data);
92
+export default (...args) => {
93
 
93
 
94
-export function queryTable (apiRequest) {
94
+  return request(...args).then((r) => (args[1]?.download ? r: r.data ));
95
+};
96
+
97
+export function queryTable(apiRequest) {
95
   return function (params) {
98
   return function (params) {
96
     const { current, pageSize, ...leftParams } = params;
99
     const { current, pageSize, ...leftParams } = params;
97
     return apiRequest({
100
     return apiRequest({