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.
|
|
|
const request = (options) => {
|
|
|
|
// 在这里可以对请求头进行一些设置
|
|
|
|
// 例如:
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
let token = uni.getStorageSync('token')
|
|
|
|
wx.request({
|
|
|
|
url: options.url || '',
|
|
|
|
method: options.method || 'GET',
|
|
|
|
data: options.data || {},
|
|
|
|
header: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
'Authorization': 'Bearer ' + token,
|
|
|
|
'tenant-id': 1
|
|
|
|
},
|
|
|
|
success: (res) => {
|
|
|
|
// console.log(res.data,'==========request========='); // 控制台显示数据信息
|
|
|
|
resolve(res)
|
|
|
|
if (res.data.code == 401) {
|
|
|
|
uni.showToast({
|
|
|
|
title: '账户token已过期,请重新登录',
|
|
|
|
duration: 2000,
|
|
|
|
icon: 'none',
|
|
|
|
success: () => {
|
|
|
|
uni.removeStorageSync("userInfo");
|
|
|
|
uni.removeStorageSync("token");
|
|
|
|
uni.removeStorageSync("refreshToken");
|
|
|
|
uni.removeStorageSync("teamId");
|
|
|
|
uni.removeStorageSync("realNameAuthFlag");
|
|
|
|
uni.removeStorageSync("version");
|
|
|
|
// uni.navigateBack({
|
|
|
|
// delta: 1
|
|
|
|
// });
|
|
|
|
uni.reLaunch({
|
|
|
|
url: '/pagesCenter/login/enter'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
fail: (err) => {
|
|
|
|
// 页面中弹框显示失败
|
|
|
|
uni.showToast({
|
|
|
|
title: '请求接口失败',
|
|
|
|
icon: "none"
|
|
|
|
})
|
|
|
|
// 返回错误消息
|
|
|
|
reject(err)
|
|
|
|
},
|
|
|
|
catch: (e) => {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
uni.$request = request
|