From 1cd63e45d43f29e1aa5c72a0e0cade384642613c Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 15 三月 2024 14:17:20 +0800
Subject: [PATCH] #
---
zy-asrs-flow/src/utils/http.js | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/zy-asrs-flow/src/utils/http.js b/zy-asrs-flow/src/utils/http.js
index b988b19..fb9e654 100644
--- a/zy-asrs-flow/src/utils/http.js
+++ b/zy-asrs-flow/src/utils/http.js
@@ -1 +1,97 @@
import { request } from '@umijs/max';
+import { message, Modal } from 'antd';
+
+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
+ }).then((res) => {
+ if (res.code === 200) {
+ if (fn) {
+ return fn(res);
+ } else {
+ return res;
+ }
+ } else {
+ message.error(res.msg)
+ }
+ });
+}
+
+const doPost = async (url, params, fn) => {
+ const res = await request(url, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data: { ...params }
+ });
+ if (fn) {
+ fn(res);
+ }
+ return res;
+}
+
+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: {
+ 'Content-Type': 'application/json'
+ },
+ data: { ...params }
+ }).then((res) => {
+ if (res.code === 200) {
+ if (fn) {
+ return fn(res);
+ } else {
+ return res;
+ }
+ } else {
+ message.error(res.msg)
+ }
+ });
+}
+
+const Http = { doGet, doGetPromise, doPost, doPostForm, doPostPromise, doPostBlob }
+
+export default Http;
\ No newline at end of file
--
Gitblit v1.9.1