post: function(params){
var _this = this;
if (plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
mui.confirm('网络异常,请检查网络设置!','提示',['确认'],function(e){})
return
}
var token = this.getToken();
mui.ajax(params.api,{
data: params.data || {},
type: 'post',
headers:{'Authorization': 'Bearer ' + token},
success: function(res){
_this.handleRes(params,res);
},
error: function(xhr,type,errorThrown){
plus.nativeUI.toast('请求失败')
console.log(JSON.stringify(xhr))
console.log(JSON.stringify(type))
console.log(JSON.stringify(errorThrown))
if(xhr.status != 0){
plus.nativeUI.toast('系统繁忙,请稍后再试。'+ xhr.status +';')
}
}
})
},
get: function(params){
if (plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
mui.confirm('网络异常,请检查网络设置!','提示',['确认'],function(e){})
return
}
var _this = this;
var token = this.getToken();
// console.log(token)
mui.ajax(params.api,{
data: params.data || {},
type:'get',
headers:{'Authorization': 'Bearer ' + token},
success: function(res){
_this.handleRes(params,res);
},
error: function(xhr,type,errorThrown){
console.log(JSON.stringify(xhr))
console.log(JSON.stringify(type))
console.log(JSON.stringify(errorThrown))
if(xhr.status!=0){
plus.nativeUI.toast('系统繁忙,请稍后再试。'+xhr.status+';')
}
}
})
},
getToken: function(){
var t = plus.storage.getItem('token');
return t;
},
handleRes: function(params,res){
// console.log(JSON.stringify(res))
plus.nativeUI.closeWaiting();
if(typeof res == 'string' ){
console.log("处理完成")
res = JSON.parse(res)
}
if(res.code == '10000'){
params.success && params.success(res)
} else {
if(res.code == '20001'){
console.log("授权失效或未授权")
plus.nativeUI.toast('授权失效或未授权,请重新登录')
console.log(plus.storage.removeItem('token'))
plus.storage.removeItem('token');
plus.storage.removeItem('userInfo');
setTimeout(function(){
plus.runtime.restart();
},2000)
}else{
params.error && params.error(res);
}
}
},
随笔 - 77
文章 - 0
评论 - 0
阅读 -
21309
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了