2024-03-26 19:52:42 +08:00
|
|
|
|
const token = sessionStorage.getItem("zhgd_token");
|
|
|
|
|
|
const us = sessionStorage.getItem("zhgd_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;
|
2024-03-29 15:25:34 +08:00
|
|
|
|
|
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) {
|
|
|
|
|
|
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");
|
|
|
|
|
|
if (zhgd_type === "2") {
|
|
|
|
|
|
top.location.href = login_sg_page;
|
|
|
|
|
|
} else if (zhgd_type === "1") {
|
|
|
|
|
|
top.location.href = login_sc_page;
|
|
|
|
|
|
}
|
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() {
|
|
|
|
|
|
if (zhgd_type === "2") {
|
|
|
|
|
|
top.location.href = login_sg_page;
|
|
|
|
|
|
} else if (zhgd_type === "1") {
|
|
|
|
|
|
top.location.href = login_sc_page;
|
2024-04-10 15:41:38 +08:00
|
|
|
|
}else {
|
|
|
|
|
|
top.location.href = login_sc_page;
|
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
|
|
|
|
}
|