205 lines
5.2 KiB
JavaScript
205 lines
5.2 KiB
JavaScript
var dataUrl ="http://192.168.0.38:42880/realnameweb/";//本地
|
|
|
|
|
|
var uuid=null;
|
|
var interval=null;
|
|
$(function(){
|
|
var remeberName = localStorage.getItem('remeberName');
|
|
var userName = localStorage.getItem('userName');
|
|
var remeberPass = localStorage.getItem('remeberPass');
|
|
var passWord = localStorage.getItem('passWord');
|
|
if (remeberName != null && remeberName == "true") {
|
|
$("#name").val(userName);
|
|
$("#jzname").prop("checked", true);
|
|
} else if (remeberName != null && remeberName == "true") {
|
|
$("#name").val("");
|
|
$("#jzname").prop("checked", "true");
|
|
}
|
|
if (remeberPass != null && remeberPass == "true") {
|
|
$("#pwd").val(passWord);
|
|
$("#jzpwd").prop("checked", true);
|
|
} else if (remeberPass != null && remeberPass == "true") {
|
|
$("#pwd").val("");
|
|
$("#jzpwd").prop("checked", false);
|
|
}
|
|
|
|
$("#qrCode").mouseover(function (e) {
|
|
$(this).attr("src", "img/login/QRcode1.png");
|
|
});
|
|
|
|
$("#qrCode").mouseout(function (e) {
|
|
$(this).attr("src", "img/login/QRcode2.png");
|
|
});
|
|
})
|
|
|
|
function showQrCode(){
|
|
$("#qrCodeDiv").css("display", "block");
|
|
$("#iForm").css("display", "none");
|
|
uuid=getUUID();
|
|
createQrCode();
|
|
interval=window.setInterval(function() {
|
|
console.log("定时器:"+uuid);
|
|
getUserLogin();
|
|
},1000);
|
|
killQrCode();
|
|
}
|
|
function goBack(){
|
|
$("#qrCodeDiv").css("display", "none");
|
|
$("#iForm").css("display", "block");
|
|
clearInterval(interval);
|
|
}
|
|
|
|
|
|
function login() {
|
|
var uName = $("#name").val();
|
|
var uPwd = $("#pwd").val();
|
|
var jzname = $("#jzname").prop("checked"); // 是否记住用户名
|
|
var jzpwd = $("#jzpwd").prop("checked"); // 是否记住密码
|
|
if (uName == "" && uPwd == "") {
|
|
return layer.alert("请输入用户名和密码", {
|
|
icon: 2,
|
|
time: 3000
|
|
});
|
|
}
|
|
if (uName != "" && uPwd == "") {
|
|
return layer.alert("请输入密码", {
|
|
icon: 2,
|
|
time: 3000
|
|
});
|
|
}
|
|
if (uName == "" && uPwd != "") {
|
|
return layer.alert("请输入用户名", {
|
|
icon: 2,
|
|
time: 3000
|
|
});
|
|
}
|
|
uName = encryptCBC(uName);
|
|
uPwd = encryptCBC(uPwd);
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: dataUrl + 'login',
|
|
data: {
|
|
username: uName,
|
|
password: uPwd
|
|
},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log("data", data);
|
|
var status = data.status;
|
|
if (status == "error") {
|
|
return layer.alert("用户名或密码有误", {
|
|
icon: 2,
|
|
time: 3000
|
|
});
|
|
} else {
|
|
var token = data.user.token;
|
|
var companyId = data.user.companyId;
|
|
localStorage.setItem('smzweb-token', token);
|
|
localStorage.setItem('companyId', companyId);
|
|
localStorage.setItem('remeberName', jzname);
|
|
localStorage.setItem('userName', uName);
|
|
localStorage.setItem('remeberPass', jzpwd);
|
|
localStorage.setItem('passWord', uPwd);
|
|
isLogin = true;
|
|
console.log("isLogin", isLogin);
|
|
window.location.href = "page/home/home.html";
|
|
}
|
|
}
|
|
});
|
|
}
|
|
//注册
|
|
function addUser(){
|
|
top.layer.open({
|
|
title: false,
|
|
type: 2,
|
|
content: 'registration.html',
|
|
area: ['60%', '96%'],
|
|
maxmin: false
|
|
});
|
|
}
|
|
//重置密码
|
|
function resetPwd(){
|
|
top.layer.open({
|
|
title: false,
|
|
type: 2,
|
|
content: 'resetPwd.html',
|
|
area: ['30%', '50%'],
|
|
maxmin: false
|
|
});
|
|
}
|
|
|
|
function getUserLogin(){
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: dataUrl + 'user/checkscan',
|
|
data: {uuid: uuid},
|
|
dataType: "json",
|
|
success: function(data) {
|
|
console.log("data", data);
|
|
var status = data.resMsg;
|
|
if(status == "success") {
|
|
clearInterval(interval);
|
|
window.location.href = "page/home/home.html";
|
|
}
|
|
}
|
|
});
|
|
}
|
|
var qrcode=null;
|
|
//生成二维码
|
|
function createQrCode(){
|
|
var nowTime=getNowTime();
|
|
console.log("二维码:"+uuid);
|
|
var loginUrl=dataUrl + 'user/scanlogin?createTime='+nowTime.toString()+"&token="+uuid;
|
|
qrcode = new QRCode("qrCodeImg", {
|
|
text: loginUrl,
|
|
width: 261,
|
|
height: 258,
|
|
colorDark : "#000000",
|
|
colorLight : "#ffffff",
|
|
});
|
|
document.getElementById('qrCodeImg').title="";
|
|
}
|
|
//清除二维码
|
|
function killQrCode(){
|
|
$("#qrCodeImg").empty();
|
|
qrcode.clear();
|
|
createQrCode();
|
|
}
|
|
/**
|
|
* 获取当日时间
|
|
*/
|
|
function getNowTime() {
|
|
var nowDate = new Date();
|
|
var year = nowDate.getFullYear();
|
|
var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) :
|
|
nowDate.getMonth() + 1;
|
|
var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
|
|
var h =nowDate.getHours()< 10 ? "0" + nowDate.getHours() : nowDate.getHours();
|
|
var m=nowDate.getMinutes()< 10 ? "0" + nowDate.getMinutes() : nowDate.getMinutes();
|
|
var s=nowDate.getSeconds()< 10 ? "0" + nowDate.getSeconds() : nowDate.getSeconds();
|
|
var dateStr = year + "-" + month + "-" + day+" "+h+":"+m+":"+s;
|
|
return dateStr;
|
|
}
|
|
|
|
//生成UUID
|
|
function getUUID() {
|
|
var s = [];
|
|
var hexDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
// var hexDigits = "0123456789abcdef";
|
|
for (var i = 0; i < 36; i++) {
|
|
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
}
|
|
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
|
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
|
s[8] = s[13] = s[18] = s[23] = "-";
|
|
var data = s.join("");
|
|
return data;
|
|
}
|
|
document.onkeydown = function(e) { // 回车提交表单
|
|
var theEvent = window.event || e;
|
|
var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
|
|
if (code == 13) {
|
|
login();
|
|
}
|
|
}
|