wszhyWx/api/nvuerequest.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-09-28 10:07:02 +00:00
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)
2023-10-07 08:53:26 +00:00
if(res.data.code==200){
}
else if (res.data.code == 401) {
2023-09-28 10:07:02 +00:00
uni.reLaunch({
url: '/pages/login/login'
})
uni.removeStorage({
key: 'token',
success() {
uni.removeStorage({
key: 'user_info',
success() {
}
});
}
});
2023-10-07 08:53:26 +00:00
}else{
uni.hideLoading()
uni.stopPullDownRefresh();
uni.showToast({
icon:'none',
title: res.data.msg,
duration: 2000,
})
2023-09-28 10:07:02 +00:00
}
// 接口成功可以在此写成功需要的步骤
if (res.data.code != 1) {
// uni.showToast({
// title: res.data.msg,
// icon: 'none'
// });
}
},
fail: (err) => {
uni.showToast({
title: '请求接口失败',
icon: 'none'
})
reject(err)
}
})
})
}