Commit aa01d58c authored by duanledexianxianxian's avatar duanledexianxianxian 😁

sync code

parent 3c02868d
// import store from './utils/store';
export default {
baseUrl: 'http://platform.kuopu.net/9080',
baseUrl: 'http://127.0.0.1:8080',
storeNameSpace: 'kim',
headers: () => ({
Authorization:
'eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjEzMzQ2MDkwMTEsImxpZCI6Im91eWFuZ2JveXUifQ.eriHWClI-ST9CuEJuoU608KTKxIhf4XUxOSslzwT6K8',
}),
Authorization:
'eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOjMzLCJ1c24iOiLmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrofmrKfpmLPljZrlrociLCJzdGEiOjE1NjEzNDQyNDg5ODksImxpZCI6Im91eWFuZ2JveXUifQ.FbY-QQLgq8H9CWSo1FhCPgXZJQtte5lhAPC4W45mHmo',
}),
successCode: 'sys.success', // 后台正常返回错误编码
};
......@@ -40,10 +40,11 @@ export default {
effects: {
// 获取列表数据
*getList({ payload }, { call, put }) {
const { data } = yield call(service.getList, payload);
const result = yield call(service.getList, payload);
console.log(result);
yield put({
type: 'save',
payload: { ...data },
payload: { ...result.data },
});
},
// 增加
......
......@@ -26,15 +26,15 @@ class HttpRequest {
getInsideConfig() {
const config = {
baseURL: this.options.baseUrl,
baseURL: this.options.baseUrl, // baseURL
timeout: 10000,
responseType: 'json',
'x-requested-with': 'XMLHttpRequest',
withCredentials: false, // default
headers: {
'x-requested-with': 'XMLHttpRequest',
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
Accept: 'application/json',
withCredentials: false, // default
timeout: 10000,
responseType: 'json',
...this.options.headers,
},
};
......@@ -60,11 +60,13 @@ class HttpRequest {
// 响应拦截
instance.interceptors.response.use(
res => {
// success
this.destroy(url);
const { data, status } = res;
return { data, status, statusText: codeMessage[status] };
},
error => {
// error
this.destroy(url);
const errorResult = JSON.parse(JSON.stringify(error));
const errorInfo = error.response;
......
......@@ -20,12 +20,11 @@ const errorHandler = error => {
}
};
const axios = new HttpRequest({
baseUrl,
headers: headers() || {},
errorHandler,
});
/**
* 组装url
* @param {url} url
* @param {配置参数} more
*/
const mergeApi = (url, more) => {
if (more && more.apiPrefix && typeof more.apiPrefix === 'string') {
return `${config.apiPrefix}${url}`;
......@@ -36,45 +35,78 @@ const mergeApi = (url, more) => {
return url;
};
const axios = new HttpRequest({
baseUrl,
headers: headers() || {},
errorHandler,
});
/**
* 正常返回结果处理
* @param {返回请求数据} response
* @param {配置项} more
*/
const checkCode = (response, more) => {};
export default function request(url, options = {}, more = {}) {
let newOptions = options;
newOptions.url = url;
if (more.headers) {
newOptions = { ...options, headers: more.headers };
}
return axios.request(newOptions).then(response => checkCode(response, more));
}
const get = (url, data, more = {}) =>
axios.request({
method: 'get', // default
url: `${mergeApi(url, more)}`,
params: data,
...more,
});
request(
`${mergeApi(url, more)}`,
{
method: 'get', // default
params: data,
},
more,
);
const post = (url, data, more = {}) =>
axios.request({
method: 'post', // default
url: `${mergeApi(url, more)}`,
data,
...more,
});
request(
`${mergeApi(url, more)}`,
{
method: 'post', // default
data,
},
more,
);
const put = (url, data, more = {}) =>
axios.request({
method: 'put', // default
url: `${mergeApi(url, more)}`,
data,
...more,
});
request(
`${mergeApi(url, more)}`,
{
method: 'put', // default
data,
},
more,
);
const del = (url, data, more = {}) =>
axios.request({
method: 'delete', // default
url: `${mergeApi(url, more)}`,
data,
...more,
});
request(
`${mergeApi(url, more)}`,
{
method: 'delete', // default
data,
},
more,
);
const patch = (url, data, more = {}) =>
axios.request({
method: 'patch', // default
url: `${mergeApi(url, more)}`,
data,
...more,
});
request(
`${mergeApi(url, more)}`,
{
method: 'patch', // default
data,
...more,
},
more,
);
const formDataUpload = (url, data, more = {}) => {
const formData = new FormData();
......@@ -83,10 +115,7 @@ const formDataUpload = (url, data, more = {}) => {
formData.append(key, data[key]);
});
}
axios.request({
method: 'post', // default
url: `${mergeApi(url, more)}`,
data: formData,
post(`${mergeApi(url, more)}`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
......@@ -100,4 +129,4 @@ const uploadFile = (url, data, type = 'formData', more = {}) => {
}
};
export { axios as request, get, post, put, del, patch, uploadFile };
export { request, get, post, put, del, patch, uploadFile };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment