hb_zhgd_screen/js/publics/public.js

151 lines
5.2 KiB
JavaScript
Raw Normal View History

2025-10-13 09:33:54 +08:00
const token = sessionStorage.getItem("zhgd_token");
let us = sessionStorage.getItem("zhgd_us");
let sm44=new SM4Util();
let zhgd_type = sessionStorage.getItem("zhgd_type");
const userArr = ['zhangyn','guest'];
// console.log(us)
if(us==null){
backLoginPage();
}
us=sm44.decryptDefault_CBC(us);
us=removePadding2(us);
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();
}
const roleCode = JSON.parse(us).roleCode;
const orgId = JSON.parse(us).orgId;
const userId = JSON.parse(us).userId;
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;
}
/* 退出登录 */
function loginout(type) {
if (type) {
sessionStorage.removeItem("zhgd_token");
sessionStorage.removeItem("zhgd_us");
sessionStorage.removeItem("zhgd_type");
top.layer.confirm('登录已过期,请点击确定后重新登录!', {
btn: ['确认', '取消'],
move: false,
cancel: function (index, layero) {
backLoginPage();
}
}, function () {
backLoginPage();
}, function () {
backLoginPage();
});
} else {
top.layer.confirm('请您确定注销?', {
btn: ['确认', '取消'],
move: false,
}, function () {
loginOutAjax();
}, function () {
});
}
// 登出请求
function loginOutAjax() {
ajaxRequest(login_out, "POST", null, true, function () {
}, function (result) {
if (result.code === 200) {
top.layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
sessionStorage.removeItem("zhgd_token");
sessionStorage.removeItem("zhgd_us");
sessionStorage.removeItem("zhgd_type");
let iscId=localStorage.getItem("iscKey");
top.window.location.href =SGCC_LOGIN_URL;
// if (zhgd_type === "2") {
// 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';
// } else if (zhgd_type === "1") {
// 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';
// }
});
} else if (result.code === 500) {
top.window.location.href =SGCC_LOGIN_URL;
layer.msg("登出失败", { icon: 2 });
}else if(result.code === 401 || result.code === 403){
backLoginPage();
}
}, function (xhr) {
errorFn(xhr)
});
}
}
/* 请求错误 */
function errorFn(xhr, status, error) {
if (xhr.status === 0) {
// 网络连接失败
console.error("网络连接失败,请检查网络是否正常");
} else {
// 请求出现其他错误
console.error("ajax请求错误" + error);
}
}
/* 返回登录页 */
function backLoginPage() {
let iscId=localStorage.getItem("iscKey");
top.window.location.href =SGCC_LOGIN_URL;
// if (zhgd_type === "2") {
// 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';
//
// } else if (zhgd_type === "1") {
// 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';
// }else {
// 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/sc_login.html';
// }
}
//判断字符是否为空的方法
function isEmpty(obj) {
return typeof obj == "undefined" || obj == null || obj == "" || obj == '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;
}