82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
|
//#ifdef H5
|
||
|
const BASE_URL = "http://211.137.105.198:8041"; // 测试
|
||
|
// const BASE_URL = "https://youkucmb.iq1.cn/api"; // 正式
|
||
|
|
||
|
export const baseUrl = BASE_URL;
|
||
|
//#endif
|
||
|
|
||
|
const request = (url, method, data = {}, showLoading = false) => {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
// const token = uni.getStorageSync('token')
|
||
|
const token = uni.getStorageSync("token");
|
||
|
if (showLoading) {
|
||
|
uni.showLoading({
|
||
|
title: ""
|
||
|
});
|
||
|
}
|
||
|
let api = baseUrl + url;
|
||
|
let tempData = data;
|
||
|
uni.request({
|
||
|
url: api,
|
||
|
data: tempData,
|
||
|
method: method,
|
||
|
header: {
|
||
|
"content-type": "application/json",
|
||
|
"front-token": token
|
||
|
},
|
||
|
success: (res) => {
|
||
|
uni.hideLoading();
|
||
|
if (res.data.code == 401) {
|
||
|
uni.removeStorageSync("token");
|
||
|
uni.removeStorageSync("opid");
|
||
|
uni.reLaunch({
|
||
|
url: "/pages/index/home"
|
||
|
});
|
||
|
} else {
|
||
|
resolve(res);
|
||
|
}
|
||
|
// let code = res.data.code
|
||
|
// if (code == 200) {
|
||
|
// console.log('接口正常api', api)
|
||
|
// console.log('接口正常入参', tempData)
|
||
|
// console.log('接口正常返参', res)
|
||
|
// let data = res.data.data;
|
||
|
// resolve(data);
|
||
|
// } else if (code == 2) {
|
||
|
// console.log('接口code==2api', api)
|
||
|
// console.log('接口code==2入参', tempData)
|
||
|
// console.log('接口code==2返参', res)
|
||
|
// reject(res);
|
||
|
// uni.removeStorageSync('token')
|
||
|
// uni.reLaunch({
|
||
|
// url: '/pages/login/login'
|
||
|
// })
|
||
|
// } else if (res.data.msg == "暂无数据!") {
|
||
|
// console.log('接口暂无数据api', api)
|
||
|
// console.log('接口暂无数据入参', tempData)
|
||
|
// console.log('接口暂无数据返参', res)
|
||
|
// resolve([]);
|
||
|
// } else {
|
||
|
// console.log('接口错误api', api)
|
||
|
// console.log('接口错误入参', tempData)
|
||
|
// console.log('接口错误返参', res)
|
||
|
// resolve(res);
|
||
|
// reject(res);
|
||
|
// }
|
||
|
},
|
||
|
fail: (error) => {
|
||
|
uni.hideLoading();
|
||
|
console.log("接口异常api", api);
|
||
|
console.log("接口异常入参", tempData);
|
||
|
console.log("接口异常返参", error);
|
||
|
reject(error);
|
||
|
},
|
||
|
complete() {
|
||
|
uni.hideLoading();
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
};
|
||
|
export default {
|
||
|
request
|
||
|
};
|