This commit is contained in:
姜棚 2021-12-10 19:50:40 +08:00
parent 5f09e49a5d
commit 322d311fbf
2 changed files with 91 additions and 9 deletions

View File

@ -106,6 +106,82 @@ const upload = (method, url, params, responseType) => {
} );
return http.then(response => response).catch(error => console.error('Error:', error));
}
const getData = (method, url, params, responseType) => {
var obj = null;
if (method == "get") {
obj = {
headers: new Headers({
'authorization': sessionStorage.getItem("authorization")
})
}
if (params) {
let paramsArray = [];
//拼接参数
Object.keys(params).forEach(key => paramsArray.push(key + '=' + params[key]))
if (url.search(/\?/) === -1) {
url += '?' + paramsArray.join('&')
} else {
url += '&' + paramsArray.join('&')
}
}
}
let http = fetch(url, obj).then(res =>{
window.timeshow=res.headers.get('Date-Time');
if(res.status==200){
console.log("当前返回",res.body)
return res.text()
}else{
switch (res.status) {
// 401: 未登录
case 401:
res.json().then(response =>{
if(response.code==403){
Notify.clear();
Notify.error(response.message);
setTimeout(() => {
window.location.href='/';
}, 2000)
}else if(response.code==401){
Notify.clear();
Notify.error(response.message);
}
}
).catch();
break;
}
}
} );
return http.then(response =>response).catch(error => console.error('Error:', error));
}
const req = (method, url, params, responseType) => {
var obj = null;
@ -325,7 +401,7 @@ export const resKeyEmail = (id, params) => {
// 兑换码管理
//兑换码管理列表
export const getCodesList = (params) => {
return req('get', baseurl + "/codes", params)
return getData('get', baseurl + "/codes", params)
}
//获取兑换码明细

View File

@ -303,14 +303,20 @@ export default class acclist extends React.Component{
data.key_word=key_word;
}
getCodesList(data).then(res=>{
handelResponse(res,(response,msg)=>{
const codeList_data=response.data;
const {total}=response;
_self.setState({codeList:codeList_data,total});
},(err)=>{
})
console.log(777777)
console.log(res)
let response = JSON.parse(res)
if(response.code == 200)
{
console.log(response)
const codeList_data= response.data.data;
const {total}=response.data.total;
_self.setState({codeList:codeList_data,total});
}
}).catch(err=>{
});
}