54 lines
1.1 KiB
JavaScript
54 lines
1.1 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 == 401) {
|
|
|
|
uni.reLaunch({
|
|
url: '/pages/login/login'
|
|
})
|
|
uni.removeStorage({
|
|
key: 'token',
|
|
success() {
|
|
uni.removeStorage({
|
|
key: 'user_info',
|
|
success() {
|
|
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
}
|
|
// 接口成功可以在此写成功需要的步骤
|
|
if (res.data.code != 1) {
|
|
// uni.showToast({
|
|
// title: res.data.msg,
|
|
// icon: 'none'
|
|
// });
|
|
}
|
|
},
|
|
fail: (err) => {
|
|
uni.showToast({
|
|
title: '请求接口失败',
|
|
icon: 'none'
|
|
})
|
|
reject(err)
|
|
}
|
|
})
|
|
})
|
|
}
|