Yansen 8 mesi fa
parent
commit
df62e4f709
4 ha cambiato i file con 20 aggiunte e 15 eliminazioni
  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 Vedi File

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

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

@@ -17,7 +17,8 @@ export const updateInvoiceFill = (id, data) => request(`/invoice/${id}`, { data,
17 17
  * @param {*} data
18 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 Vedi File

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

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

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