function request(url, data, method = 'get', contentType = 1) {
let header = {
'content-type':contentType === 1 ? 'application/json' : 'application/x-www-form-urlencoded',
Authorization:uni.getStorageSync('authorization') != ''?uni.getStorageSync('authorization'):null
}
for (let property in data) {
if (data[property] == null) {
delete data[property]
}
}
return new Promise((resolve, reject) => {
uni.request({
url: baseUrl + url,
data,
method,
header,
success: (res) => {
if (res.statusCode == 200) {
resolve(res)
} else if (res.statusCode == 405) {
uni.showToast({
icon: 'none',
title: '请求方法错误',
duration: 1500
});
} else if (res.statusCode == 401) {
uni.showToast({
icon: 'none',
title: '未登录或登录状态已超时',
duration: 1500
});
setTimeout(() => {
uni.reLaunch({
url: '/pages/me/user/user',
});
}, 1500)
store.commit('logout')
} else {
uni.showToast({
icon: 'none',
title: '请求错误:' + res.statusCode,
duration: 1500
});
}
},
fail: (err) => {
console.log('request fail', err)
uni.showToast({
icon: 'none',
title: err.errMsg,
duration: 2000
});
reject(err)
}
})
})
}
import { request, urlList } from './common/url.js'
Vue.prototype.$http= request
Vue.prototype.$urlList = urlList
this.$http(this.$urlList.login, param, 'post').then(res => {
if (res.data.success) {
} else {
}
})