初始化仓库
This commit is contained in:
52
request/api/request.js
Normal file
52
request/api/request.js
Normal file
@@ -0,0 +1,52 @@
|
||||
function request(url, params) {
|
||||
let baseURL = "https://app.xiaokang88.com/member"
|
||||
if (url.split('/').indexOf('newApi') !== -1) {
|
||||
baseURL = "https://shop.xiaokang88.com/member"
|
||||
|
||||
}
|
||||
url = url.replace('/oldApi', '');
|
||||
url = url.replace('/newApi', '');
|
||||
|
||||
// promise导出
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
// 基地址 + 传过来的地址
|
||||
url: baseURL + url,
|
||||
timeout: 8000, // 8秒超时时间,单位ms
|
||||
// 展开传过来的数据 请求方式 所需数据 wxfc279dcf921a38f7
|
||||
// store_id: '11001'
|
||||
...params,
|
||||
// 请求头
|
||||
header: {
|
||||
"authorization": 'Bearer ' + uni.getStorageSync("token"),
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
|
||||
// 成功钩子
|
||||
success(res) {
|
||||
if (res.data.errcode === 401) {
|
||||
uni.reLaunch({ url: '/pages/login/login' })
|
||||
}
|
||||
resolve(res)
|
||||
},
|
||||
// 失败钩子
|
||||
fail(err) {
|
||||
reject(err)
|
||||
uni.showToast({
|
||||
title: "请求失败",
|
||||
duration: 1500,
|
||||
mask: false,
|
||||
icon:"error"
|
||||
})
|
||||
},
|
||||
// 成功失败都会执行的钩子
|
||||
complete() {
|
||||
// 成功或者失败停止下拉刷新
|
||||
uni.stopPullDownRefresh()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 导出
|
||||
export default request
|
||||
Reference in New Issue
Block a user