ah_jjzhgd_webscreen/js/publics/public.js

140 lines
5.0 KiB
JavaScript
Raw Normal View History

2024-03-26 19:52:42 +08:00
const token = sessionStorage.getItem("zhgd_token");
2025-01-22 14:17:21 +08:00
let us = sessionStorage.getItem("zhgd_us");
let sm44=new SM4Util();
console.log(us)
us=sm44.decryptDefault_CBC(us);
us=removePadding2(us);
2024-06-11 11:16:54 +08:00
let zhgd_type = sessionStorage.getItem("zhgd_type");
if(!us){
if(!zhgd_type){
zhgd_type=localStorage.getItem("zhgd_type-noLogin");
}
if(!zhgd_type){
zhgd_type=2;
}
backLoginPage();
}
if(!token){
if(!zhgd_type){
zhgd_type=localStorage.getItem("zhgd_type-noLogin");
}
if(!zhgd_type){
zhgd_type=2;
}
backLoginPage();
}
2024-03-27 09:46:09 +08:00
const roleCode = JSON.parse(us).roleCode;
const orgId = JSON.parse(us).orgId;
const userId = JSON.parse(us).userId;
2025-01-22 14:17:21 +08:00
const nickName = JSON.parse(us).nickName;
const roleName = JSON.parse(us).roleName;
function removePadding2(decrypted) {
const lastByte = decrypted.charCodeAt(decrypted.length - 1);
if (lastByte <= 16) {
for (let i = decrypted.length - lastByte; i < decrypted.length; i++) {
if (decrypted.charCodeAt(i) !== lastByte) {
return decrypted; // 如果填充不正确,返回原始字符串
}
}
return decrypted.slice(0, -lastByte);
}
return decrypted;
}
2024-03-25 20:20:02 +08:00
/* 退出登录 */
function loginout(type) {
if (type) {
2024-03-26 19:52:42 +08:00
sessionStorage.removeItem("zhgd_token");
sessionStorage.removeItem("zhgd_us");
sessionStorage.removeItem("zhgd_type");
2024-03-25 20:20:02 +08:00
top.layer.confirm('登录已过期,请点击确定后重新登录!', {
btn: ['确认', '取消'],
move: false,
cancel: function (index, layero) {
2024-03-26 19:52:42 +08:00
backLoginPage();
2024-03-25 20:20:02 +08:00
}
}, function () {
2024-03-26 19:52:42 +08:00
backLoginPage();
2024-03-25 20:20:02 +08:00
}, function () {
2024-03-26 19:52:42 +08:00
backLoginPage();
2024-03-25 20:20:02 +08:00
});
} else {
top.layer.confirm('请您确定注销?', {
btn: ['确认', '取消'],
move: false,
}, function () {
loginOutAjax();
}, function () {
});
}
// 登出请求
function loginOutAjax() {
ajaxRequest(login_out, "POST", null, true, function () {
}, function (result) {
2025-01-22 14:17:21 +08:00
console.log(111)
2024-03-25 20:20:02 +08:00
if (result.code === 200) {
top.layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
2024-03-26 19:52:42 +08:00
sessionStorage.removeItem("zhgd_token");
sessionStorage.removeItem("zhgd_us");
sessionStorage.removeItem("zhgd_type");
2025-01-22 14:17:21 +08:00
let iscId=localStorage.getItem("iscKey");
2024-03-26 19:52:42 +08:00
if (zhgd_type === "2") {
2025-01-22 14:17:21 +08:00
window.location.href = login_sg_page;
// window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:8000/zhgd-web/sg_login.html';
2024-03-26 19:52:42 +08:00
} else if (zhgd_type === "1") {
2025-01-22 14:17:21 +08:00
window.location.href = login_sc_page;
// window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:8000/zhgd-web/sc_login.html';
2024-03-26 19:52:42 +08:00
}
2024-03-25 20:20:02 +08:00
});
} else if (result.code === 500) {
2024-04-10 15:41:38 +08:00
layer.msg("登出失败", { icon: 2 });
}else if(result.code === 401 || result.code === 403){
backLoginPage();
2024-03-25 20:20:02 +08:00
}
}, function (xhr) {
2024-04-20 11:59:21 +08:00
errorFn(xhr)
2024-03-25 20:20:02 +08:00
});
}
2024-03-26 19:52:42 +08:00
}
2024-03-29 15:25:34 +08:00
/* 请求错误 */
2024-04-20 11:59:21 +08:00
function errorFn(xhr, status, error) {
2024-03-29 15:25:34 +08:00
if (xhr.status === 0) {
// 网络连接失败
console.error("网络连接失败,请检查网络是否正常");
} else {
// 请求出现其他错误
console.error("ajax请求错误" + error);
}
}
2024-03-26 19:52:42 +08:00
/* 返回登录页 */
function backLoginPage() {
2025-01-22 14:17:21 +08:00
let iscId=localStorage.getItem("iscKey");
2024-03-26 19:52:42 +08:00
if (zhgd_type === "2") {
2025-01-22 14:17:21 +08:00
window.location.href = login_sg_page;
// window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:8000/zhgd-web/sg_login.html';
2024-03-26 19:52:42 +08:00
} else if (zhgd_type === "1") {
2025-01-22 14:17:21 +08:00
window.location.href = login_sc_page;
// window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:8000/zhgd-web/sc_login.html';
2024-04-10 15:41:38 +08:00
}else {
2025-01-22 14:17:21 +08:00
window.location.href = login_sc_page;
// window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:8000/zhgd-web/sc_login.html';
2024-03-26 19:52:42 +08:00
}
2024-03-30 20:51:14 +08:00
}
//判断字符是否为空的方法
function isEmpty(obj) {
return typeof obj == "undefined" || obj == null || obj == "" || obj == '00';
2024-04-20 11:59:21 +08:00
}
/**
* 获取当日时间
*/
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 dateStr = year + "-" + month + "-" + day;
return dateStr;
2024-03-25 20:20:02 +08:00
}