2024-08-22 17:00:16 +08:00
|
|
|
|
let form, layer;
|
|
|
|
|
|
layui.use(function () {
|
|
|
|
|
|
form = layui.form;
|
|
|
|
|
|
layer = layui.layer;
|
2025-10-17 10:23:41 +08:00
|
|
|
|
//获取浏览器路径
|
|
|
|
|
|
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("无自动登录参数");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-22 17:00:16 +08:00
|
|
|
|
form.on('submit(demo-login)', function (data) {
|
|
|
|
|
|
let field = data.field;
|
|
|
|
|
|
let loginType = "";
|
|
|
|
|
|
let hrefUrl = window.location.href;
|
2025-05-16 10:46:49 +08:00
|
|
|
|
console.log(hrefUrl)
|
2024-08-22 17:00:16 +08:00
|
|
|
|
if (hrefUrl && hrefUrl.indexOf("sg_login") > 0) {
|
|
|
|
|
|
loginType = "2"
|
|
|
|
|
|
} else if (hrefUrl && hrefUrl.indexOf("sc_login") > 0) {
|
|
|
|
|
|
loginType = "1"
|
2025-05-16 10:46:49 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
loginType = "2"
|
2024-08-22 17:00:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
const params = {
|
2024-11-26 11:56:05 +08:00
|
|
|
|
"username": sm2Encrypt(public_key,field.username),
|
|
|
|
|
|
"password": sm2Encrypt(public_key,field.password),
|
2024-08-22 17:00:16 +08:00
|
|
|
|
"loginType": loginType
|
|
|
|
|
|
}
|
2024-11-26 11:56:05 +08:00
|
|
|
|
console.log(params)
|
2024-08-22 17:00:16 +08:00
|
|
|
|
let encryptStr = encryptCBC(JSON.stringify(params));
|
|
|
|
|
|
ajaxRequest(login_url, "POST", encryptStr, true, function () {
|
2024-09-13 17:26:34 +08:00
|
|
|
|
console.log(1)
|
2024-08-22 17:00:16 +08:00
|
|
|
|
}, function (result) {
|
|
|
|
|
|
if (result.code === 200) {
|
2024-09-13 19:49:35 +08:00
|
|
|
|
const uss= sm4.encryptDefault_CBC(result.data.us);
|
|
|
|
|
|
top.layer.msg(result.msg, { icon: 1, time: 500 }, function () {
|
2024-08-22 17:00:16 +08:00
|
|
|
|
sessionStorage.setItem("zhgd_token", result.data.access_token);
|
2024-09-13 19:49:35 +08:00
|
|
|
|
sessionStorage.setItem("zhgd_us",uss);
|
2024-08-22 17:00:16 +08:00
|
|
|
|
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";
|
2025-05-16 10:46:49 +08:00
|
|
|
|
}else{
|
|
|
|
|
|
window.location.href = "pages/home/navigation.html";
|
2024-08-22 17:00:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} 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);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-10-17 10:23:41 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
*
|
|
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-08-22 17:00:16 +08:00
|
|
|
|
/* 请求错误 */
|
|
|
|
|
|
function errorFn(xhr, status, error) {
|
|
|
|
|
|
if (xhr.status === 0) {
|
|
|
|
|
|
// 网络连接失败
|
|
|
|
|
|
console.error("网络连接失败,请检查网络是否正常");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 请求出现其他错误
|
|
|
|
|
|
console.error("ajax请求错误:" + error);
|
|
|
|
|
|
}
|
2025-05-16 10:46:49 +08:00
|
|
|
|
}
|