139 lines
5.1 KiB
JavaScript
139 lines
5.1 KiB
JavaScript
let form, layer;
|
||
layui.use(function () {
|
||
form = layui.form;
|
||
layer = layui.layer;
|
||
//获取浏览器路径
|
||
let hrefUrl = window.location.href;
|
||
const url = new URL(hrefUrl);
|
||
const urlParam = new URLSearchParams(url.search);
|
||
//解析路径参数
|
||
const params = urlParam.get('params');
|
||
if(params){
|
||
//对参数进行解密
|
||
const jiemi =bnsCloudDecrypt(params);
|
||
//解密参数继续解析
|
||
const logingParam = new URLSearchParams(jiemi);
|
||
//获取账号密码
|
||
const username = logingParam.get('username');
|
||
const password = logingParam.get('password');
|
||
if(username && password){
|
||
//自己系统登录的方法
|
||
authLogin(username,password);
|
||
}
|
||
}else{
|
||
console.log("无自动登录参数");
|
||
}
|
||
|
||
form.on('submit(demo-login)', function (data) {
|
||
let field = data.field;
|
||
let loginType = "";
|
||
let hrefUrl = window.location.href;
|
||
console.log(hrefUrl)
|
||
if (hrefUrl && hrefUrl.indexOf("sg_login") > 0) {
|
||
loginType = "2"
|
||
} else if (hrefUrl && hrefUrl.indexOf("sc_login") > 0) {
|
||
loginType = "1"
|
||
}else{
|
||
loginType = "2"
|
||
}
|
||
const params = {
|
||
"username": sm2Encrypt(public_key,field.username),
|
||
"password": sm2Encrypt(public_key,field.password),
|
||
"loginType": loginType
|
||
}
|
||
console.log(params)
|
||
let encryptStr = encryptCBC(JSON.stringify(params));
|
||
ajaxRequest(login_url, "POST", encryptStr, true, function () {
|
||
console.log(1)
|
||
}, function (result) {
|
||
if (result.code === 200) {
|
||
const uss= sm4.encryptDefault_CBC(result.data.us);
|
||
top.layer.msg(result.msg, { icon: 1, time: 500 }, function () {
|
||
sessionStorage.setItem("zhgd_token", result.data.access_token);
|
||
sessionStorage.setItem("zhgd_us",uss);
|
||
const us = JSON.parse(result.data.us);
|
||
localStorage.setItem("zhgd_type-noLogin",us.jumpType);
|
||
sessionStorage.setItem("zhgd_type", us.jumpType);
|
||
// window.location.href = "http://localhost:9528/#/ywgllogin?ticket=5555";
|
||
if (us.jumpType === '2') {
|
||
window.location.href = "pages/home/navigation.html";
|
||
} else if (us.jumpType === '1') {
|
||
window.location.href = "pages/web/index.html";
|
||
}else{
|
||
window.location.href = "pages/home/navigation.html";
|
||
}
|
||
});
|
||
} else if (result.code === 500) {
|
||
layer.msg(result.msg, { icon: 2 });
|
||
}else if (result.code === 201) {
|
||
layer.msg(result.msg, { icon: 2 });
|
||
}
|
||
}, function (xhr, status, error) {
|
||
errorFn(xhr, status, error)
|
||
$('.layui-btn-fluid').empty().append('登 录');
|
||
}, "application/json", aqEnnable);
|
||
});
|
||
});
|
||
|
||
|
||
/**
|
||
*
|
||
* @param username
|
||
* @param password
|
||
*/
|
||
function authLogin( username, password){
|
||
const params = {
|
||
"username": sm2Encrypt(public_key,username),
|
||
"password": sm2Encrypt(public_key,password),
|
||
"loginType": "2"
|
||
}
|
||
console.log(params)
|
||
let encryptStr = encryptCBC(JSON.stringify(params));
|
||
ajaxRequest(login_url, "POST", encryptStr, true, function () {
|
||
console.log(1)
|
||
}, function (result) {
|
||
if (result.code === 200) {
|
||
const uss= sm4.encryptDefault_CBC(result.data.us);
|
||
top.layer.msg(result.msg, { icon: 1, time: 500 }, function () {
|
||
sessionStorage.setItem("zhgd_token", result.data.access_token);
|
||
sessionStorage.setItem("zhgd_us",uss);
|
||
const us = JSON.parse(result.data.us);
|
||
localStorage.setItem("zhgd_type-noLogin",us.jumpType);
|
||
sessionStorage.setItem("zhgd_type", us.jumpType);
|
||
// window.location.href = "http://localhost:9528/#/ywgllogin?ticket=5555";
|
||
if (us.jumpType === '2') {
|
||
window.location.href = "pages/home/navigation.html";
|
||
} else if (us.jumpType === '1') {
|
||
window.location.href = "pages/web/index.html";
|
||
}else{
|
||
window.location.href = "pages/home/navigation.html";
|
||
}
|
||
});
|
||
} else if (result.code === 500) {
|
||
layer.msg(result.msg, { icon: 2 });
|
||
}else if (result.code === 201) {
|
||
layer.msg(result.msg, { icon: 2 });
|
||
}
|
||
}, function (xhr, status, error) {
|
||
errorFn(xhr, status, error)
|
||
$('.layui-btn-fluid').empty().append('登 录');
|
||
}, "application/json", aqEnnable);
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/* 请求错误 */
|
||
function errorFn(xhr, status, error) {
|
||
if (xhr.status === 0) {
|
||
// 网络连接失败
|
||
console.error("网络连接失败,请检查网络是否正常");
|
||
} else {
|
||
// 请求出现其他错误
|
||
console.error("ajax请求错误:" + error);
|
||
}
|
||
}
|