programing sendcard

This commit is contained in:
wzdwc
2020-04-20 23:25:57 +08:00
parent b3682878ad
commit 47f3225e29
19 changed files with 578 additions and 412 deletions
+33 -33
View File
@@ -1,33 +1,33 @@
import axios, {AxiosRequestConfig, Method} from 'axios';
import cookie from 'js-cookie';
const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => {
const origin = 'http://127.0.0.1:7001/node';
if (!url) {
return Promise.reject('Request url is null!');
}
const token = cookie.get('token');
const headers = {
Authorization: `Bearer ${token}`,
};
url = `${origin}${url}`;
const option: AxiosRequestConfig = {
url,
method,
timeout,
data: body,
withCredentials: true,
headers,
};
try {
const result = await axios(option);
if (result.data.code === '000000') {
return result.data;
} else {
throw result.data;
}
} catch (e) {
throw e;
}
};
export default request;
import axios, {AxiosRequestConfig, Method} from 'axios';
import cookie from 'js-cookie';
const request = async ({method = 'post' as Method, url = '', body = {}, timeout = 8000}) => {
const origin = 'http://127.0.0.1:7001/node';
if (!url) {
return Promise.reject('Request url is null!');
}
const token = cookie.get('token');
const headers = {
Authorization: `Bearer ${token}`,
};
url = `${origin}${url}`;
const option: AxiosRequestConfig = {
url,
method,
timeout,
data: body,
withCredentials: true,
headers,
};
try {
const result = await axios(option);
if (result.data.code === '000000') {
return result.data;
} else {
throw result.data;
}
} catch (e) {
throw e;
}
};
export default request;