本时支付宝小程序

This commit is contained in:
唐明明
2020-09-24 11:08:03 +08:00
parent 11e0df1cc8
commit 6a67082c25
510 changed files with 20316 additions and 2 deletions

71
api/api.js Executable file
View File

@@ -0,0 +1,71 @@
let apiUrl = "https://www.ysd-bs.com/api/",
timeout = 30000
let request = (obj) => {
return new Promise((resolve, reject) => {
my.request({
url : apiUrl + obj.url || '',
headers : obj.header || { 'content-type': 'application/json' },
method : obj.method || 'GET',
data : obj.data || {},
timeout : timeout,
success : (res) => {
if (res.data.status_code == '200') {
resolve(res.data)
} else if (res.data.status_code == '401') {
my.showToast({
type : "fail",
content : "接口请求失败未登录err" + res.data.message
});
}else {
reject(err)
}
},
fail : (err) => {
if(err.status == 401){
// 清理缓存
my.clearStorageSync()
// 清理全局数据
getApp().globalData.userInfo = {}
getApp().globalData.isUser = false
getApp().globalData.token = ""
// 提示信息
my.alert({
title : '提示',
content : '登录状态已过期,请重新登录',
success : res => {
my.redirectTo({
url: '../login/login'
});
}
});
}else{
reject(err)
}
}
});
})
}
let userinfo = (obj) => {
return request({
url : "users/info",
header : {
"Authorization": obj
},
method : "POST"
}).then(res=>{
getApp().globalData.userInfo = res.data
return res.data
}).catch(err=>{
my.showToast({
type : "fail",
content: "未登录,获取信息失败"
})
})
}
export default {
request,
userinfo
}