const commonUrl = "http://app-api.huizhuanq.com";//公共路径
// 参数: url:请求地址
// param:请求参数
// way:请求方式
// res:回调函数
function urlRequest(url, param, way, afterSuccess) {
// 获取自定义的code
let code = uni.getStorageSync('code')
// 进行请求
console.log(commonUrl+url)
uni.request({
url: commonUrl+url,
data: JSON.stringify(Object.assign(param)),
header: {
'Authorization': uni.getStorageSync("token"),
'Accept': 'application/json',
'Content-Type': 'application/json',
},
// 获取设置请求方式
method: way,
success: (data) => {
if (data.data.status === 401) {
uni.switchTab({
url:'/pages/index'
})
} else {
afterSuccess(data)
}
return date;
}
})
}
接口调用
json.urlRequest('/auth/code','','GET',
function (res) {
console.log("666666666666666666666666666")
console.log(res);
})