解决登录过期的问题
This commit is contained in:
parent
ca6d3fc8c3
commit
571237bb0e
@ -124,7 +124,7 @@
|
||||
title: '正在登录中'
|
||||
})
|
||||
let res = await loginAccount(that.formData);
|
||||
encrypt.encode('ACT', this.formData);
|
||||
encrypt.encode('ACT', that.formData);
|
||||
this.$store.commit('SET_USERINFO', {
|
||||
user: data,
|
||||
token: res.data.token
|
||||
|
@ -36,6 +36,7 @@
|
||||
<script>
|
||||
import { Toast } from '../../libs/uniApi';
|
||||
import { changePassword } from "@/api/oaUser.js"
|
||||
import encrypt from "@/utils/encrypt.js"
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -91,6 +92,10 @@
|
||||
mask: true,
|
||||
title: '加载中'
|
||||
})
|
||||
// 密码修改后重新加密缓存
|
||||
let nowData = encrypt.decode('ACT');
|
||||
nowData.password = this.formData.password;
|
||||
encrypt.encode('ACT', nowData);
|
||||
// #ifdef APP-PLUS
|
||||
return uni.switchTab({
|
||||
url: '/pages/oaHome/oaHome',
|
||||
|
@ -1,7 +1,11 @@
|
||||
import { commonAuth } from '@/api/pubic.js'
|
||||
import { loginMobile } from '@/api/user.js'
|
||||
import { loginAccount } from '@/api/oaUser.js'
|
||||
import Routine from '@/libs/routine.js'
|
||||
import Cache from '@/utils/cache';
|
||||
import encrypt from '@/utils/encrypt.js';
|
||||
import oaHttp from '@/utils/oahttp.js';
|
||||
|
||||
const state = {
|
||||
userInfo: JSON.parse(Cache.get('USER_INFO') || '{}') || null,
|
||||
token: Cache.get("TOKEN") || null
|
||||
@ -43,10 +47,30 @@ const mutations = {
|
||||
state.token = data.token
|
||||
Cache.set("USER_INFO", data.user, time)
|
||||
Cache.set("TOKEN", data.token, time)
|
||||
}
|
||||
},
|
||||
SET_TOKEN(state, data) {
|
||||
let time = Cache.time();
|
||||
state.token = data.token;
|
||||
Cache.set("TOKEN", data.token, time);
|
||||
},
|
||||
};
|
||||
|
||||
const actions = {
|
||||
RE_LOGIN({ state, commit }, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let fromData = encrypt.decode('ACT');
|
||||
loginAccount({ ...fromData }).then((res) => {
|
||||
commit('SET_TOKEN', res.data);
|
||||
oaHttp[data.method](data.url, data.data, data.opt).then((e) => {
|
||||
resolve(e);
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
}).catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
MobileLogin({ state, commit }, force) {
|
||||
let data = {
|
||||
auth_token: uni.getStorageSync('auth_token'),
|
||||
|
@ -1,11 +1,15 @@
|
||||
import Base64 from "@/utils/base64.js"
|
||||
import cryptoJS from "crypto-js"
|
||||
|
||||
const key_code = 'gxzhptxiaochengxu_1';
|
||||
|
||||
// 加密
|
||||
const encode = (key, data='')=>{
|
||||
try{
|
||||
let str;
|
||||
typeof data == 'object'? str = JSON.stringify(data) : str = data;
|
||||
uni.setStorageSync(key, Base64.encode(str))
|
||||
str = cryptoJS.AES.encrypt(str, key_code).toString();
|
||||
uni.setStorageSync(key, str)
|
||||
return true;
|
||||
}catch(e){
|
||||
console.log(e);
|
||||
@ -17,7 +21,7 @@ const encode = (key, data='')=>{
|
||||
const decode = (key)=>{
|
||||
try{
|
||||
let str = uni.getStorageSync(key);
|
||||
str = Base64.decode(str);
|
||||
str = cryptoJS.AES.decrypt(str, key_code).toString(cryptoJS.enc.Utf8);
|
||||
isJSON(str) ? str = JSON.parse(str) : null;
|
||||
return str;
|
||||
}catch(e){
|
||||
|
@ -52,21 +52,29 @@ function baseRequestTwo(url, method, data, {
|
||||
method: method || 'GET',
|
||||
header: {
|
||||
...header
|
||||
|
||||
},
|
||||
data: method != 'GET' ? data || {} : {},
|
||||
params: method == 'GET' ? data : {},
|
||||
success: (res) => {
|
||||
// uni.hideLoading()
|
||||
if (noVerify)
|
||||
// reslove(res.data, res);
|
||||
reslove(res.data);
|
||||
else if (res.data.code == -1) {
|
||||
store.commit("LOGOUT");
|
||||
store.commit("SET_REQUEST", false);
|
||||
// 如果登录超时,自动重新登录并且继续发送请求
|
||||
store.dispatch("RE_LOGIN", {
|
||||
url: url,
|
||||
method: method,
|
||||
data: data,
|
||||
opt: {
|
||||
noAuth,
|
||||
noVerify
|
||||
}
|
||||
}).then((e)=>{
|
||||
reslove(e);
|
||||
}).catch((err)=>{
|
||||
reject(res.data);
|
||||
})
|
||||
// store.commit("SET_REQUEST", false);
|
||||
} else if (res.data.code == 0) {
|
||||
// uni.hideLoading();
|
||||
if (res.data.msg != '无登录信息') {
|
||||
uni.showToast({
|
||||
title: res.data.msg || '请检查网络',
|
||||
@ -84,12 +92,8 @@ function baseRequestTwo(url, method, data, {
|
||||
toLogin();
|
||||
reject(res.data);
|
||||
} else if (res.data.code == 501) {
|
||||
// uni.reLaunch({
|
||||
// url: '/pages/error/index'
|
||||
// })
|
||||
reject(res.data);
|
||||
} else {
|
||||
// uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: res.data.msg || '请检查网络',
|
||||
icon: 'none'
|
||||
|
Loading…
x
Reference in New Issue
Block a user