2024-08-26 17:24:26 +08:00
|
|
|
// http.js页面
|
|
|
|
//#ifdef APP-PLUS
|
|
|
|
//#endif
|
|
|
|
// 判断是H5
|
|
|
|
//#ifdef H5
|
|
|
|
// const BASE_URL = "/api";
|
|
|
|
const BASE_URL = "http://cdxy.qyff.86698.cn"
|
|
|
|
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',
|
|
|
|
'token': token
|
|
|
|
},
|
|
|
|
success: res => {
|
|
|
|
console.log(res)
|
|
|
|
uni.hideLoading()
|
|
|
|
if (res.data.code == 401) {
|
|
|
|
uni.reLaunch({
|
|
|
|
url: '/pages/login'
|
|
|
|
})
|
|
|
|
} 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()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2024-10-09 17:30:43 +08:00
|
|
|
|
2024-08-26 17:24:26 +08:00
|
|
|
export default {
|
|
|
|
request
|
|
|
|
}
|