|
|
|
@ -1,4 +1,7 @@
|
|
|
|
|
import { message } from "antd";
|
|
|
|
|
import { DEV } from './env/dev'
|
|
|
|
|
|
|
|
|
|
// 是否写死请求地址
|
|
|
|
|
const hardCode = true;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GET 请求
|
|
|
|
@ -13,14 +16,14 @@ export function getRequest(url: string, params: object) {
|
|
|
|
|
.join('&');
|
|
|
|
|
|
|
|
|
|
// 拼接查询字符串到 URL
|
|
|
|
|
let urlWithParams = url;
|
|
|
|
|
let urlWithParams = ((hardCode ? DEV.PROXY_SERVER : '')) + url;
|
|
|
|
|
if (queryString) {
|
|
|
|
|
urlWithParams += `?${queryString}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fetch(urlWithParams, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
mode: "cors",
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
|
|
|
@ -40,7 +43,7 @@ export function getRequest(url: string, params: object) {
|
|
|
|
|
* @returns {Promise} - 返回一个 Promise 对象,包含 response 数据或 error 信息
|
|
|
|
|
*/
|
|
|
|
|
export function postRequest(url: string, data: object) {
|
|
|
|
|
return fetch('http://127.0.0.1:8088' + url, {
|
|
|
|
|
return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
@ -48,7 +51,7 @@ export function postRequest(url: string, data: object) {
|
|
|
|
|
'User-Agent': '',
|
|
|
|
|
'sec-ch-ua': ''
|
|
|
|
|
},
|
|
|
|
|
mode:"cors",
|
|
|
|
|
mode: "cors",
|
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
@ -68,12 +71,12 @@ export function postRequest(url: string, data: object) {
|
|
|
|
|
export function postFormDataRequest(url: string, data: object) {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
for (const key in data) {
|
|
|
|
|
formData.append(key, data[key]);
|
|
|
|
|
formData.append(key, data[key]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
mode: "cors",
|
|
|
|
|
body: formData
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
@ -91,9 +94,9 @@ export function postFormDataRequest(url: string, data: object) {
|
|
|
|
|
*/
|
|
|
|
|
export function deleteRequest(url: string, params: object) {
|
|
|
|
|
const searchParams = new URLSearchParams(params);
|
|
|
|
|
return fetch(`${url}?${searchParams.toString()}`, {
|
|
|
|
|
return fetch(`${((hardCode ? DEV.PROXY_SERVER : '')) + url}?${searchParams.toString()}`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
mode: "cors",
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
if (!response.ok) { throw new Error('请求失败'); }
|
|
|
|
@ -110,12 +113,12 @@ export function deleteRequest(url: string, params: object) {
|
|
|
|
|
* @returns {Promise} - 返回一个 Promise 对象,表示请求的结果(成功或失败)
|
|
|
|
|
*/
|
|
|
|
|
export function putRequest(url: string, data: object) {
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, {
|
|
|
|
|
method: 'PUT',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
mode:"cors",
|
|
|
|
|
mode: "cors",
|
|
|
|
|
body: JSON.stringify(data)
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
@ -133,9 +136,9 @@ export function putRequest(url: string, data: object) {
|
|
|
|
|
* @returns {Promise} - 返回一个 Promise 对象,包含文件 blob 数据或 error 信息
|
|
|
|
|
*/
|
|
|
|
|
export function downloadFile(url: string, fileName?: string) {
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
mode:"cors",
|
|
|
|
|
mode: "cors",
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
if (!response.ok) { throw new Error('下载失败'); }
|
|
|
|
@ -160,10 +163,10 @@ export function downloadFile(url: string, fileName?: string) {
|
|
|
|
|
* @returns {Promise} - 返回一个 Promise 对象,表示请求的结果(成功或失败)
|
|
|
|
|
*/
|
|
|
|
|
export function uploadFile(url: string, formData: any) {
|
|
|
|
|
return fetch(url, {
|
|
|
|
|
return fetch(((hardCode ? DEV.PROXY_SERVER : '')) + url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: formData,
|
|
|
|
|
mode:"cors"
|
|
|
|
|
mode: "cors"
|
|
|
|
|
})
|
|
|
|
|
.then(response => {
|
|
|
|
|
if (!response.ok) { throw new Error('上传失败'); }
|
|
|
|
|