修改客服用的request
This commit is contained in:
@ -1,6 +1,50 @@
|
||||
import axios from 'axios';
|
||||
import { WITH_REQUEST_BODY_METHODS } from './constants/http';
|
||||
import { HTTP_STATUS_CODE_MAP } from './constants/http';
|
||||
import { notification, message } from 'antd'
|
||||
|
||||
// Axios全局配置项
|
||||
axios.defaults.withCredentials = true //允许带cookie
|
||||
axios.defaults.baseURL = '';
|
||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=UTF-8';
|
||||
axios.defaults.headers['Authorization'] = '';
|
||||
|
||||
// Axios请求拦截器
|
||||
axios.interceptors.request.use(function (config) {
|
||||
config.headers['Authorization'] = window.sessionStorage.getItem('token') ? 'Bearer ' +/* '04152390-74f6-4eed-bd7d-f7110cdae419' */ window.sessionStorage.getItem('token') : null;
|
||||
config.headers['clientId']='bVS46ElU';
|
||||
config.headers['scope']=sessionStorage.getItem('scope')?JSON.parse(sessionStorage.getItem('scope')):'';
|
||||
return config;
|
||||
}, function (error) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
// Axios响应拦截器
|
||||
axios.interceptors.response.use(function (response) {
|
||||
const { data } = response;
|
||||
const { success = true } = data
|
||||
// 解构赋值 success默认设置为true,如果为false,说明返回错误
|
||||
if (!success) {
|
||||
// message.error(data.message);
|
||||
}
|
||||
|
||||
return response;
|
||||
}, function (error) {
|
||||
// const { response } = error;
|
||||
// if (response && response.status) {
|
||||
// const { status } = response;
|
||||
// const errText = HTTP_STATUS_CODE_MAP[status] || response.message;
|
||||
// notification.error({
|
||||
// message: `请求错误 ${status}`,
|
||||
// description: errText,
|
||||
// });
|
||||
// } else if (!response) {
|
||||
// notification.error({
|
||||
// message: '网络异常',
|
||||
// description: '您的网络状况不佳或异常,无法连接服务器!',
|
||||
// });
|
||||
// }
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
function paddingBaseURL(config) {
|
||||
return Object.assign(config);
|
||||
@ -75,36 +119,13 @@ export function $download(downloadUrl, params) {
|
||||
method: "post",
|
||||
url: downloadUrl,
|
||||
data: params,
|
||||
responseType: "blob",
|
||||
responseType: "blob", // 指定获取数据的类型为blob
|
||||
}
|
||||
).then(result => {
|
||||
// const { data } = result;
|
||||
resolve(result);
|
||||
}).catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 上传附件
|
||||
* @param {uploadUrl} 接口路径 params:接口参数
|
||||
* @params formData封装的数据
|
||||
* @returns {Promise}
|
||||
*/
|
||||
export function $upload(uploadUrl, params) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(uploadUrl, {
|
||||
method: 'POST',
|
||||
body: params.params,
|
||||
headers:{
|
||||
'Authorization':sessionStorage.getItem('token')?'Bearer '+sessionStorage.getItem('token'):null
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
return response.json()
|
||||
}).then(json => {
|
||||
resolve(json)
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user