You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

308 lines
9.9 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* Created by ljx on 2019/4/25.
*/
$(function () {
//cookie数据保存格式是key=value;key=value;形式loginInfo为保存在cookie中的key值具体看controller代码
/*if(str != ""){
var userName = str.split("#")[0];
var userPwd = str.split("#")[1];
//自动填充用户名和密码
$("#userName").val(userName);
$("#userPwd").val(userPwd);
//并且选中复选框
$("#rememberMe").attr("checked", true);
}*/
//获取cookie
/*function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}*/
$("#forgetPwd").on("click", function () {
alert("请联系管理员进行修改密码!");
});
});
var banar = document.getElementById('banar');
var txt = document.getElementById('txt');
var sub = document.getElementById('sub');
var chang = document.getElementById('chang');
//创建一个数组,里面包含着随机验证码所能出现的全部字符
var allchar = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e",
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z"];
var result;
function randomChar() {
result = "";//创建空的字符串,方便等下接收值
//循环找出4的字符
for (var i = 0; i < 4; i++) {
//随机生成一个0-61的数字
var index = Math.floor(Math.random() * 36);
//将随机生成的数字作为数组的索引然后赋给result
//每次赋一个数组值循环4次最后就是4个字符
result += allchar[index];
}
//把随机生成的4个字符添加到ID为banar的div里面
banar.innerHTML = result;
//点击验证按钮,判断我们输入的值和随机生成的值是否一样?
//一样就弹出验证成功,不一样就弹出验证错误。
// sub.onclick = function () {
// if (txt.value == result) {
// alert("验证成功!!!");
// } else {
// alert("验证错误!!!");
// randomChar();//如果错误执行randomChar方法重新随机生成4个字符
// txt.value = "";//如果错误,我们输入的验证码等于空,方便我们再次输入
// }
// };
}
randomChar();
//点击"看不见换一张"时,执行randomChar方法重新随机生成4个字符我们输入的验证码等于空方便我们再次输入
chang.onclick = function () {
txt.value = "";
randomChar();
}
function login() {
var userName = $("#userName").val();
var userPwd = $("#userPwd").val();
var txt = $("#txt").val();
var rememberMeChecked = $("input[type='checkbox']").is(':checked');
var rememberMe = '';
if (rememberMeChecked) {
rememberMe = 'yes';
}
if (userName == '') {
return toastr.warning("用户名不能为空!");
}
if (userPwd == '') {
return toastr.warning("密码不能为空!");
}
if (txt == ''){
return toastr.warning("验证码不能为空!");
}
if(result != txt){
randomChar();
return toastr.warning("验证码错误!")
}
$.ajax({
type: "POST",
url: path + "/login",
data: {userName: userName, userPwd: userPwd, rememberMe: rememberMe},
success: function (data) {
if (data.code == 100) {
window.location.href = 'gatewayPage';
}
if (data.code == 200){
toastr.warning(data.msg);
}
},
})
}
var interval = "";
var qrCodeIdentity = "";
//获取扫码登录二维码
function handoffLogin() {
$.ajax({
type: "POST",
data: {loginTypeBitValue: 16, type: 3, projectUid: "cloudkey-fstth", ApplicationId: "fstth-wzh"},
url: path + '/font/getQRcode',
success: function (data) {
qrCodeIdentity = data.qrCodeIdentity;
$("#QRcordImg").prop("src", "data:image/jpeg;base64," + data.qrCodeBase64);
//轮询监听用户扫码
interval = setInterval(scanCodeLogin, 1000, qrCodeIdentity);
}
})
$("#switchHandoff").css("display", "none");
$("#switchHandoff2").css("display", "block");
}
function scanCodeLogin() {
$.ajax({
type: "POST",
data: {qrCodeIdentity: qrCodeIdentity},
url: path + '/font/getScanCode',
success: function (body) {
if (body.verifyStatus == 0) {
//扫码认证成功后撤销监听
clearInterval(interval);
$.ajax({
type: "POST",
data: {userToken: body.userToken},
url: path + '/font/getUserInfo',
success: function (tlte) {
if (tlte.msgType == 1) {
$.ajax({
type: "POST",
data: {userName: tlte.uid},
url: path + '/font/qRCodeLogin',
success: function (tltel) {
if (tltel.code == 100) {
window.location.href = tltel.extend.url;
} else {
$("#msg").text(tltel.msg);
}
}
})
} else {
alert("登录失败请重新登录")
}
}
})
}
}
})
}
function handoffLogin2() {
$("#switchHandoff").css("display", "block");
$("#switchHandoff2").css("display", "none");
clearInterval(interval);
}
$('body').keydown(function () {
if (event.keyCode == '13') {
login();
}
})
/**
* 判断是iframe框架跳出iframe框架使用top链接
*/
if (top.location != location) {
top.location.href = location.href;
}
$(function () {
//cookie数据保存格式是key=value;key=value;形式loginInfo为保存在cookie中的key值具体看controller代码
/*if(str != ""){
var userName = str.split("#")[0];
var userPwd = str.split("#")[1];
//自动填充用户名和密码
$("#userName").val(userName);
$("#userPwd").val(userPwd);
//并且选中复选框
$("#rememberMe").attr("checked", true);
}*/
//获取cookie
/*function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
}
return "";
}*/
$("#forgetPwd").on("click", function () {
alert("请联系管理员进行修改密码!");
});
$("#smdl").on("click", function () {
$.ajax({
type: "post",
url: "methodForEmrMedical/getErweima",
data: {
responseType: "code",
//clientId:"2017070411003376",
clientId: "2019111514014789",
selfSign: "true"
},
success: function (data) {
var requestId = "";
$.each(data, function (index, obj) {
//获取二维码
var imgBase64 = obj.imgBase64;
var zhdl = document.getElementById("zhdl");
var erweima = document.getElementById("erweima");
var erweimadiv = document.getElementById("erweimadiv");
//给img标签src属性赋值
erweima.setAttribute("src", "data:image/jpg;base64," + imgBase64);
requestId = obj.requestId;
erweimadiv.style.display = "block";
zhdl.style.display = "none";
return false;
});
polling(requestId);
},
})
});
function polling(requestId, delay = 1000) {
return new Promise((resolve, reject) => {
$.ajax({
type: "post",
url: "methodForEmrMedical/getUser",
data: {
requestId: requestId,
//clientId:"2017070411003376"
clientId: "2019111514014789"
},
success: function (data) {
$.each(data, function (index, obj) {
//轮询查询接口
if (obj === '未授权') { //是否继续轮询
setTimeout(() => {
resolve(polling(requestId, delay));
}, delay)
} else {
smlogin(obj);
resolve(obj);
}
return false;
})
}
})
})
}
function smlogin(user) {
$.ajax({
type: "post",
url: "methodForEmrMedical/smlogin",
data: {
openId: user.openId,
clientId: "2019111514014789"
},
success: function (data) {
if (data.isSuccess) {
window.location.href = data.url;
} else {
//window.location.href = data.url;
window.location.reload();
alert(data.msg);
}
}
})
}
});