From 322d311fbf5533a2d784008424d5ac3228c0694f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E6=A3=9A?= <849005670@qq.com> Date: Fri, 10 Dec 2021 19:50:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/api.js | 78 ++++++++++++++++++++++++++++- src/pages/exchangecode/list/list.js | 22 +++++--- 2 files changed, 91 insertions(+), 9 deletions(-) diff --git a/src/assets/api.js b/src/assets/api.js index fe862257..e4b4e4c4 100644 --- a/src/assets/api.js +++ b/src/assets/api.js @@ -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) } //获取兑换码明细 diff --git a/src/pages/exchangecode/list/list.js b/src/pages/exchangecode/list/list.js index 17f96c22..660ce9ea 100644 --- a/src/pages/exchangecode/list/list.js +++ b/src/pages/exchangecode/list/list.js @@ -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=>{ }); }