You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

68 lines
1.7 KiB

// let baseUrl = 'http://192.168.66.221:8000'
// let baseUrl = 'http://192.168.66.16:8084'
// let baseUrl = 'https://ggl.xingtongworld.com'
// baseUrl = 'https://ggl.dingguagua.vip'
// baseUrl = 'https://apps.dingguagua.vip'
// let baseUrl = 'https://apps.dingguagua.vip'
let baseUrl = 'http://intp.xingtongworld.com'
let API = {
baseUrl: baseUrl,
// 登录
getWxCode(data, success, fail){
API.sendRequest('get', data, '/wechat/login/getWxCode', success, fail)
},
// 通用api
request(url, data, success, fail, boolean=true){
API.sendRequest('post', data, url, success, fail, boolean)
},
sendRequest(method, data, url, success, fail, boolean){
let types = '';
if (method == 'POST') {
types = 'application/x-www-form-urlencoded'
} else {
types = 'application/json';
}
let requestObj = {}
if(boolean){
requestObj.header = {
'Content-Type': types,
'Accept': 'application/json, text/javascript, */*; q=0.01',
// 'Authorization': uni.getStorageSync('user_token')||''
'token': uni.getStorageSync('user_token')||''
}
}
uni.request({
url:baseUrl+url,
method: method,
data: data,
...requestObj,
success(res) {
// 200=成功, 400 = 失败错误返回、404 token验证失败 ,403 token已过2小时失效
if(res.data.code==1){
success && success(res.data);
return;
}
uni.showToast({
title: res.data.msg || res.msg,
icon: 'none'
})
if(res.data.code==403 || res.data.code==201){
uni.removeStorageSync('user_token');
// setTimeout(()=>{
// uni.reLaunch({
// url: '/pages/login/login'
// // url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
// })
// }, 1000)
}
}
})
}
}
export default API;