mirror of
https://gitee.com/java110/PropertyApp.git
synced 2026-02-24 05:46:09 +08:00
优化回话失效bug
This commit is contained in:
parent
f478b45ec1
commit
cb1a41a8f8
@ -65,8 +65,9 @@ export function loadCategoryMenus(_that, _data) {
|
||||
reslove(_data);
|
||||
},
|
||||
fail: function(e) {
|
||||
console.log(123123123,e)
|
||||
wx.showToast({
|
||||
title: "服务器异常了",
|
||||
title: e,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
|
||||
@ -55,6 +55,7 @@ export function login(userName, passwd) {
|
||||
uni.setStorageSync(java110Config.USER_INFO, _userInfo);
|
||||
uni.setStorageSync(java110Config.TOKEN, data.token);
|
||||
let afterOneHourDate = date.addHour(new Date(), 1);
|
||||
//let afterOneHourDate = date.addMinutes(new Date(), 1);
|
||||
wx.setStorageSync(java110Config.LOGIN_FLAG, {
|
||||
sessionKey: _tmpUserInfo.userName,
|
||||
expireTime: afterOneHourDate.getTime(),
|
||||
@ -96,10 +97,7 @@ export function hasSession() {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
//跳转至登录页面
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
reject('回话已失效');
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ export function getHeaders(){
|
||||
'req-time': getDateYYYYMMDDHHMISS(),
|
||||
'sign': '1234567',
|
||||
'user-id': '-1',
|
||||
'X-Requested-With':'XMLHttpRequest',
|
||||
// #ifndef H5
|
||||
cookie: '_java110_token_=' + uni.getStorageSync('token')
|
||||
// #endif
|
||||
|
||||
@ -1,42 +1,83 @@
|
||||
|
||||
import {hasSession} from './api/Java110SessionApi.js'
|
||||
import {
|
||||
hasSession
|
||||
} from './api/Java110SessionApi.js'
|
||||
|
||||
import java110Config from './Java110Config.js'
|
||||
|
||||
import {wxuuid} from './utils/SeqUtil.js'
|
||||
import {
|
||||
wxuuid
|
||||
} from './utils/SeqUtil.js'
|
||||
|
||||
import {getDateYYYYMMDDHHMISS} from './utils/DateUtil.js'
|
||||
import {
|
||||
getDateYYYYMMDDHHMISS
|
||||
} from './utils/DateUtil.js'
|
||||
|
||||
export default{
|
||||
export default {
|
||||
/**
|
||||
* 请求
|
||||
* @param {Object} _reqObj 请求内容
|
||||
*/
|
||||
request:function(_reqObj) {
|
||||
request: function(_reqObj) {
|
||||
//检查是否登录成功
|
||||
hasSession()
|
||||
.then((_data)=>{
|
||||
//重写token
|
||||
// #ifndef H5
|
||||
_reqObj.header.cookie = '_java110_token_=' + uni.getStorageSync('token');
|
||||
// #endif
|
||||
//console.log(_reqObj);
|
||||
uni.request(_reqObj);
|
||||
})
|
||||
|
||||
.then((_data) => {
|
||||
//重写token
|
||||
// #ifndef H5
|
||||
_reqObj.header.cookie = '_java110_token_=' + uni.getStorageSync('token');
|
||||
// #endif
|
||||
//console.log(_reqObj);
|
||||
|
||||
let _success = _reqObj.success;
|
||||
let _fail = _reqObj.fail;
|
||||
//todo 拦截成功
|
||||
_reqObj.success = function(_res) {
|
||||
if (_res.statusCode == 401) {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(!_success){
|
||||
return;
|
||||
}
|
||||
_success(_res);
|
||||
}
|
||||
//todo 拦截失败
|
||||
_reqObj.fail = function(_res) {
|
||||
if (_res.statusCode == 401) {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
return;
|
||||
}
|
||||
if(!_fail){
|
||||
return;
|
||||
}
|
||||
_fail(_res);
|
||||
}
|
||||
|
||||
uni.request(_reqObj);
|
||||
}, err => {
|
||||
//跳转至登录页面
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/login'
|
||||
});
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 header
|
||||
*/
|
||||
export function getHeaders(){
|
||||
export function getHeaders() {
|
||||
return {
|
||||
'app-id': java110Config.AppId,
|
||||
'transaction-id': wxuuid(),
|
||||
'req-time': getDateYYYYMMDDHHMISS(),
|
||||
'sign': '1234567',
|
||||
'user-id': '-1',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
// #ifndef H5
|
||||
cookie: '_java110_token_=' + uni.getStorageSync('token')
|
||||
// #endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user