|
|
|
@ -1,17 +1,9 @@
|
|
|
|
|
import { getAuthorization, getStringParams, handleResponse, hostMap, createFormBody } from '@/request/client/utils';
|
|
|
|
|
import { IAuthType, IResponse } from '@/request/type';
|
|
|
|
|
|
|
|
|
|
export const post = async <T>(
|
|
|
|
|
url: string,
|
|
|
|
|
data: any,
|
|
|
|
|
authType: IAuthType = 'default',
|
|
|
|
|
revalidate = 20,
|
|
|
|
|
): Promise<IResponse<T>> => {
|
|
|
|
|
const token = await getAuthorization(authType);
|
|
|
|
|
// const host = hostMap[authType];
|
|
|
|
|
// const finallyUrl = `${host}${url}`;
|
|
|
|
|
const finallyUrl = `${url}`;
|
|
|
|
|
const response = await fetch(finallyUrl, {
|
|
|
|
|
export const post = async <T>(url: string, data: any, revalidate = 20): Promise<IResponse<T>> => {
|
|
|
|
|
const token = await getAuthorization();
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: token || '',
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
|
|
@ -27,19 +19,11 @@ export const post = async <T>(
|
|
|
|
|
return await handleResponse(response);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const get = async <T>(
|
|
|
|
|
url: string,
|
|
|
|
|
data: any = null,
|
|
|
|
|
authType: IAuthType = 'noToken',
|
|
|
|
|
revalidate = 20,
|
|
|
|
|
): Promise<IResponse<T>> => {
|
|
|
|
|
const token = await getAuthorization(authType);
|
|
|
|
|
const host = hostMap[authType];
|
|
|
|
|
const formatUrl = data ? `${url}?${getStringParams(data)}` : url;
|
|
|
|
|
const finallyUrl = `${host}${formatUrl}`;
|
|
|
|
|
const response = await fetch(finallyUrl, {
|
|
|
|
|
export const get = async <T>(url: string, data: any = null, revalidate = 20): Promise<IResponse<T>> => {
|
|
|
|
|
const token = await getAuthorization();
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: token,
|
|
|
|
|
Authorization: token || '',
|
|
|
|
|
},
|
|
|
|
|
method: 'GET',
|
|
|
|
|
next: {
|
|
|
|
@ -49,19 +33,11 @@ export const get = async <T>(
|
|
|
|
|
return await handleResponse(response);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const remove = async <T>(
|
|
|
|
|
url: string,
|
|
|
|
|
data: any = null,
|
|
|
|
|
authType: IAuthType = 'default',
|
|
|
|
|
revalidate = 20,
|
|
|
|
|
): Promise<IResponse<T>> => {
|
|
|
|
|
const token = await getAuthorization(authType);
|
|
|
|
|
const host = hostMap[authType];
|
|
|
|
|
const formatUrl = data ? `${url}?${getStringParams(data)}` : url;
|
|
|
|
|
const finallyUrl = `${host}${formatUrl}`;
|
|
|
|
|
const response = await fetch(finallyUrl, {
|
|
|
|
|
export const remove = async <T>(url: string, data: any = null, revalidate = 20): Promise<IResponse<T>> => {
|
|
|
|
|
const token = await getAuthorization();
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
headers: {
|
|
|
|
|
Authorization: token,
|
|
|
|
|
Authorization: token || '',
|
|
|
|
|
},
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
next: {
|
|
|
|
@ -72,12 +48,12 @@ export const remove = async <T>(
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const uploadFile = async <T>(url: string, file: File): Promise<IResponse<T>> => {
|
|
|
|
|
const token = await getAuthorization('default');
|
|
|
|
|
const token = await getAuthorization();
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', file);
|
|
|
|
|
const response = await fetch(url, {
|
|
|
|
|
headers: {
|
|
|
|
|
authorization: token,
|
|
|
|
|
authorization: token || '',
|
|
|
|
|
},
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: formData,
|
|
|
|
|