公共参数,登录后本地缓存

This commit is contained in:
Jimmy 2020-12-23 18:42:23 +08:00
parent f194075ffc
commit 9c2e22aa18
3 changed files with 91 additions and 57 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:;">admin</a>
<a href="javascript:;">@userName</a>
<dl class="layui-nav-child">
<dd>
<a href="javascript:;" layuimini-content-href="page/user-setting.html" data-title="基本资料"
@ -163,7 +163,8 @@
});
$('.login-out').on("click", function () {
layer.msg('退出登录成功', function () {
layui.data('UserInfo', null);
layer.msg('退出登录成功', { time: 500 }, function () {
window.location = 'page/login.html';
});
});
@ -173,6 +174,7 @@
if (isLogin != 1) {
window.location = 'page/login.html';
}
var userName = UserInfo.userName;
});
</script>
</body>

View File

@ -0,0 +1,10 @@
//WebApi公关部分url
var apiUrl = 'http://localhost:21021';
//返回WebApiUrl公共部分
function GetWebApiUrl(s) {
return apiUrl;
}

View File

@ -2,18 +2,18 @@
<html>
<head>
<meta charset="UTF-8">
<meta charset="UTF-8" />
<title>ProManager</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="Access-Control-Allow-Origin" content="*" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no" />
<link rel="stylesheet" href="../lib/layui-v2.5.5/css/layui.css" media="all" />
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<style>
.main-body {
@ -135,7 +135,7 @@
width: 74px;
height: 74px;
background: #fff;
opacity: .1;
opacity: 0.1;
border-radius: 0 74px 0 0;
position: absolute;
left: 0;
@ -147,7 +147,7 @@
width: 94px;
height: 94px;
background: #fff;
opacity: .1;
opacity: 0.1;
border-radius: 50%;
position: absolute;
right: -16px;
@ -241,7 +241,7 @@
.login-main .login-bottom .login-btn {
width: 288px;
height: 40px;
background-color: #1E9FFF;
background-color: #1e9fff;
border-radius: 16px;
margin: 24px auto 0;
text-align: center;
@ -283,7 +283,7 @@
color: #fff;
}
@media screen and (max-width:428px) {
@media screen and (max-width: 428px) {
.login-main {
width: 360px !important;
}
@ -316,80 +316,102 @@
<div class="item">
<span class="icon icon-3"></span>
<input type="password" name="password" lay-verify="required" placeholder="请输入密码" maxlength="20">
<input type="password" name="password" lay-verify="required" placeholder="请输入密码"
maxlength="20" />
<span class="bind-password icon icon-4"></span>
</div>
</div>
<div class="layui-form-item" style="text-align:center; width:100%;height:100%;margin:0px;">
<button class="login-btn" lay-submit="" lay-filter="login">立即登录</button>
<div class="layui-form-item" style="text-align: center; width: 100%; height: 100%; margin: 0px">
<button class="login-btn" lay-submit="" lay-filter="login">
立即登录
</button>
</div>
</form>
</div>
</div>
<div class="footer">
© 矿洞科技工作室
</div>
<div class="footer">© 矿洞科技工作室</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../js/md5/md5.js" charset="utf-8"></script>
<script src="../js/PublicParameters/PublicParameters.js" charset="utf-8"></script>
<script>
layui.use(['form', 'jquery'], function () {
layui.use(["form", "jquery"], function () {
var $ = layui.jquery,
form = layui.form,
layer = layui.layer;
// 登录过期的时候跳出ifram框架
if (top.location != self.location) top.location = self.location;
//if (top.location != self.location) top.location = self.location;
$('.bind-password').on('click', function () {
if ($(this).hasClass('icon-5')) {
$(this).removeClass('icon-5');
$("input[name='password']").attr('type', 'password');
$(".bind-password").on("click", function () {
if ($(this).hasClass("icon-5")) {
$(this).removeClass("icon-5");
$("input[name='password']").attr("type", "password");
} else {
$(this).addClass('icon-5');
$("input[name='password']").attr('type', 'text');
$(this).addClass("icon-5");
$("input[name='password']").attr("type", "text");
}
});
// 进行登录操作
form.on('submit(login)', function (data) {
form.on("submit(login)", function (data) {
data = data.field;
if (data.username == '') {
layer.msg('用户名不能为空');
if (data.username == "") {
layer.msg("用户名不能为空");
return false;
}
if (data.password == '') {
layer.msg('密码不能为空');
if (data.password == "") {
layer.msg("密码不能为空");
return false;
}
var password=b64_md5(data.password);
var apiUrl = 'http://localhost:21021/api/services/app/UserInfo/GetLoginUser';
var password = b64_md5(data.password);
var apiUrl = GetWebApiUrl();
$.ajax({
url: apiUrl, //请求的url地址
dataType: "json", //返回格式为json
url: apiUrl + "/api/services/app/UserInfo/GetLoginUser", //请求的url地址
dataType: "json", //返回格式为json
//async: false,//请求是否异步默认为异步这也是ajax重要特性
data: { "Account": data.username, "PassWord": password }, //参数值
type: "GET", //请求方式
data: { Account: data.username, PassWord: password }, //参数值
type: "GET", //请求方式
success: function (req) {
//请求成功时处理
alert(22)
var result = req.result;
var totalCount = result.totalCount;
if (totalCount > 1) {
layer.msg("存在多个重复账号,请联系管理员!");
return false;
}
if (totalCount == 0) {
layer.msg("账号或密码有误,请检查!");
return false;
}
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,
});
layer.msg('登录成功', { time: 500 }, function () {
window.location = '../index.html';
});
}
},
error: function (xhr, textStatus, errorThrown) {
error: function () {
/*错误信息处理*/
alert("进入error---");
alert("状态码:" + xhr.status);
alert("状态:" + xhr.readyState);//当前状态,0-未初始化1-正在载入2-已经载入3-数据进行交互4-完成。
alert("错误信息:" + xhr.statusText);
alert("返回响应信息:" + xhr.responseText);//这里是详细的信息
alert("请求状态:" + textStatus); alert(errorThrown); alert("请求失败");
}
layer.msg("登录失败,请重试!");
return false;
},
});
// layer.msg('登录成功', function () {
// window.location = '../index.html';
// });
return false;
});
});