64 lines
1.3 KiB
JavaScript
64 lines
1.3 KiB
JavaScript
import api from './driverapi.js'
|
|
import variable from '@/api/commonVariable.js'
|
|
|
|
export const myRequest = (options) => {
|
|
return new Promise((resolve, reject) => {
|
|
uni.request({
|
|
url: api.baseUrl + options.url,
|
|
method: options.method || 'POST',
|
|
header: {
|
|
token: uni.getStorageSync('token'),
|
|
// terminal: variable.whatType,
|
|
// 'Content-Type': 'application/x-www-form-urlencoded'
|
|
},
|
|
data: options.data || {},
|
|
success: (res) => {
|
|
resolve(res.data)
|
|
if(res.data.code==200){
|
|
|
|
}
|
|
else if (res.data.code == 401) {
|
|
|
|
uni.reLaunch({
|
|
url: '/pages/login/login'
|
|
})
|
|
uni.removeStorage({
|
|
key: 'token',
|
|
success() {
|
|
uni.removeStorage({
|
|
key: 'user_info',
|
|
success() {
|
|
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
}else{
|
|
uni.hideLoading()
|
|
uni.stopPullDownRefresh();
|
|
// uni.showToast({
|
|
// icon:'none',
|
|
// title: res.data.msg,
|
|
// duration: 2000,
|
|
// })
|
|
}
|
|
// 接口成功可以在此写成功需要的步骤
|
|
if (res.data.code != 1) {
|
|
// uni.showToast({
|
|
// title: res.data.msg,
|
|
// icon: 'none'
|
|
// });
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
uni.showToast({
|
|
title: '请求接口失败',
|
|
icon: 'none'
|
|
})
|
|
reject(err)
|
|
}
|
|
})
|
|
})
|
|
}
|