优化登录机制

This commit is contained in:
Jimmy 2020-12-24 16:24:19 +08:00
parent e156baa8d7
commit 7e3ea37e67
2 changed files with 29 additions and 20 deletions

View File

@ -61,7 +61,7 @@
<a href="javascript:;" data-check-screen="full"><i class="fa fa-arrows-alt"></i></a>
</li>
<li class="layui-nav-item layuimini-setting">
<a href="javascript:;">@userName</a>
<a href="javascript:;"><span id="sp_UserName"></span></a>
<dl class="layui-nav-child">
<dd>
<a href="javascript:;" layuimini-content-href="page/user-setting.html" data-title="基本资料"
@ -163,18 +163,22 @@
});
$('.login-out').on("click", function () {
layui.data('UserInfo', null);
layui.sessionData('UserInfo', null);
layer.msg('退出登录成功', { time: 500 }, function () {
window.location = 'page/login.html';
});
});
var UserInfo = layui.data('UserInfo');
var isLogin = UserInfo.isLogin;
if (isLogin != 1) {
var CurrUserInfo = layui.sessionData('CurrUserInfo');
if (CurrUserInfo.data != undefined) {
if (CurrUserInfo.data.isLogin != 1) {
window.location = 'page/login.html';
}
}
else {
window.location = 'page/login.html';
}
var userName = UserInfo.userName;
document.getElementById("sp_UserName").innerText = CurrUserInfo.data.userName;
});
</script>
</body>

View File

@ -386,20 +386,25 @@
if (totalCount == 1) {
//登陆成功,设置登录用户信息
var UserInfo = result.items[0];
layui.data('UserInfo', {
key: 'userid', value: UserInfo.id,
key: 'account', value: UserInfo.account,
key: 'userName', value: UserInfo.userName,
key: 'workNo', value: UserInfo.workNo,
key: 'sex', value: UserInfo.sex,
key: 'deptID', value: UserInfo.deptID,
key: 'deptName', value: UserInfo.deptName,
key: 'postID', value: UserInfo.postID,
key: 'postName', value: UserInfo.postName,
key: 'cellPhoneNum', value: UserInfo.cellPhoneNum,
key: 'powerLevel', value: UserInfo.powerLevel,
key: 'isAdmin', value: UserInfo.isAdmin,
key: 'isLogin', value: 1,
layui.sessionData('CurrUserInfo', {
key: 'data',
value:
{
userid: UserInfo.id,
account: UserInfo.account,
userName: UserInfo.userName,
workNo: UserInfo.workNo,
sex: UserInfo.sex,
deptID: UserInfo.deptID,
deptName: UserInfo.deptName,
postID: UserInfo.postID,
postName: UserInfo.postName,
cellPhoneNum: UserInfo.cellPhoneNum,
powerLevel: UserInfo.powerLevel,
isAdmin: UserInfo.isAdmin,
isLogin: 1
}
});
layer.msg('登录成功', { time: 500 }, function () {
window.location = '../index.html';