From ff2b7ebf99e8aedccb3859ed9f049e49a9a613f1 Mon Sep 17 00:00:00 2001
From: Junjie <xjj@123>
Date: 星期三, 03 四月 2024 16:56:56 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/utils/http.js | 75 ++++++++++++++++++++++++++-----------
1 files changed, 52 insertions(+), 23 deletions(-)
diff --git a/zy-asrs-flow/src/utils/http.js b/zy-asrs-flow/src/utils/http.js
index 4743ae6..fb9e654 100644
--- a/zy-asrs-flow/src/utils/http.js
+++ b/zy-asrs-flow/src/utils/http.js
@@ -1,7 +1,18 @@
import { request } from '@umijs/max';
import { message, Modal } from 'antd';
-const doGet = (url, params, fn) => {
+const doGet = async (url, params) => {
+ const res = await request(url, {
+ method: 'GET',
+ params
+ });
+ if (res.code === 200) {
+ return res;
+ }
+ message.error(res.msg)
+}
+
+const doGetPromise = (url, params, fn) => {
return request(url, {
method: 'GET',
params
@@ -18,18 +29,50 @@
});
}
-const doGetSync = async (url, params) => {
+const doPost = async (url, params, fn) => {
const res = await request(url, {
- method: 'GET',
- params
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data: { ...params }
});
- if (res.code === 200) {
- return res;
+ if (fn) {
+ fn(res);
}
- message.error(res.msg)
+ return res;
}
-const doPost = (url, params, fn) => {
+const doPostForm = async (url, params, fn) => {
+ const res = await request(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'multipart/form-data'
+ },
+ data: params
+ });
+ if (fn) {
+ fn(res);
+ }
+ return res;
+}
+
+const doPostBlob = async (url, params, fn) => {
+ const res = await request(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data: { ...params },
+ responseType: 'blob'
+ });
+ if (fn) {
+ fn(res);
+ }
+ return res;
+}
+
+const doPostPromise = (url, params, fn) => {
return request(url, {
method: 'POST',
headers: {
@@ -49,20 +92,6 @@
});
}
-const doPostSync = async (url, params) => {
- const res = await request(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- data: { ...params }
- });
- if (res.code === 200) {
- return res;
- }
- message.error(res.msg)
-}
-
-const Http = { doGet, doGetSync, doPost, doPostSync }
+const Http = { doGet, doGetPromise, doPost, doPostForm, doPostPromise, doPostBlob }
export default Http;
\ No newline at end of file
--
Gitblit v1.9.1