初始化
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
// const baseUrl = "https://pandamimi.lzyyj.com/prod-api";
|
||||
// const baseUrl = "http://192.168.31.121:9221";
|
||||
|
||||
import baseUrl from "./baseUrl.js"
|
||||
// const baseUrl = bootUrl
|
||||
export function request ( optaions ) {
|
||||
let { url, method, data, header1 } = optaions
|
||||
method = method || "GET"
|
||||
data = data || {}
|
||||
header1 = header1 || {
|
||||
Authorization: uni.getStorageSync('token')
|
||||
}
|
||||
// console.log(com.getCacheToken("userInfo").token)
|
||||
return new Promise((reslove,reject)=>{
|
||||
uni.request({
|
||||
url: baseUrl + url,
|
||||
method,
|
||||
header: header1,
|
||||
data,
|
||||
success: (res) => {
|
||||
if(res.data.code == 401 ){
|
||||
uni.showToast({ title: '登录已失效,请重新登录!', icon: 'none' });
|
||||
uni.removeStorageSync('userInfo');
|
||||
uni.removeStorageSync('token');
|
||||
setTimeout(()=>{
|
||||
uni.navigateTo({ url: '/pages/user/login' });
|
||||
}, 1000);
|
||||
}else if(res.data.code != 200){
|
||||
reject(res)
|
||||
uni.showToast({ title: res.data.msg, icon: 'none', duration: 2000 });
|
||||
}else {
|
||||
reslove(res.data)
|
||||
}
|
||||
|
||||
},
|
||||
fail: () => {
|
||||
reject()
|
||||
},
|
||||
complete: () => {
|
||||
uni.hideLoading()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user