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.4 KiB
68 lines
1.4 KiB
let app = getApp();
|
|
|
|
function request(method, url, data) {
|
|
return new Promise((resolve) => {
|
|
uni.request({
|
|
method: method,
|
|
url: url,
|
|
data: data,
|
|
header: {
|
|
'Accept': "*/*",
|
|
'content-type': 'application/json;charset=utf-8',
|
|
'Authorization': app.globalData.token
|
|
}, //有的时候这里不一定是 token 还可能是 Authorization
|
|
success(res) {
|
|
resolve(res)
|
|
if (res.statusCode === 401 || res.data.return_code == 102014 || res.data.return_code ==
|
|
104001) {
|
|
app.globalData.userInfo = '';
|
|
app.globalData.token = '';
|
|
uni.setStorage({
|
|
key: "user",
|
|
data: ''
|
|
})
|
|
uni.setStorage({
|
|
key: "token",
|
|
data: ''
|
|
})
|
|
uni.showToast({
|
|
title: '登录信息过期,请重新授权',
|
|
icon: 'none',
|
|
duration: 2000,
|
|
success() {
|
|
setTimeout(() => {
|
|
uni.reLaunch({
|
|
url:'/pages/login/login/login'
|
|
})
|
|
}, 2000);
|
|
}
|
|
})
|
|
}
|
|
},
|
|
fail(err) {
|
|
uni.showToast({
|
|
title: '请求失败',
|
|
icon: 'none',
|
|
duration: 1500,
|
|
success() {
|
|
setTimeout(() => {
|
|
uni.reLaunch({
|
|
url:'/pages/login/login/login'
|
|
})
|
|
}, 2000);
|
|
}
|
|
})
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
|
|
function POST(method, url, data) {
|
|
return request(method, url, data)
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
POST
|
|
}
|
|
|