mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-10-01 17:56:39 +08:00
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
// import { getCookie } from "../../plugins/until/until.js";
|
|
export default {
|
|
state: {
|
|
des: '这个存储用户登录逻辑操作',
|
|
loginState: false, //登录状态
|
|
},
|
|
/* 存储修改状态的静态方法 */
|
|
mutations: {
|
|
/* 设置登录状态 */
|
|
SET_LOGIN_STATE(state, value) {
|
|
state.loginState = value
|
|
},
|
|
},
|
|
/* 存储修改数据的动态方法 */
|
|
actions: {
|
|
/**
|
|
* 判断是否登录
|
|
* context
|
|
* app vue 实例
|
|
*/
|
|
checkLoginState(context, app) {
|
|
let key = context.rootState.userKey;
|
|
let mobile = app.$cookies.get(key);
|
|
let isHasToken = false;
|
|
if (mobile == undefined || !mobile || mobile == 'mobile') {
|
|
isHasToken = false;
|
|
} else {
|
|
isHasToken = true;
|
|
/* 更新用户数据 */
|
|
if (!context.rootState.user.userInfo) {
|
|
context.dispatch('getUserInfo', app, {
|
|
root: true
|
|
});
|
|
}
|
|
}
|
|
context.commit('SET_LOGIN_STATE', isHasToken);
|
|
},
|
|
/**
|
|
* 退出登录
|
|
* @param {Object} context 上下文
|
|
* @param {Object} app vue 实例
|
|
*/
|
|
logout(context, app){
|
|
let userKey = context.rootState.userKey;
|
|
let tokenKey = context.rootState.tokenKey;
|
|
app.$cookies.remove(userKey);
|
|
app.$cookies.remove(tokenKey);
|
|
context.commit('SET_USER_INFO', null, {
|
|
root: true
|
|
});
|
|
context.commit('SET_INDEX_USER_INFO', null, {
|
|
root: true
|
|
});
|
|
localStorage.removeItem(tokenKey)
|
|
}
|
|
}
|
|
}
|