118 lines
4.1 KiB
JavaScript
118 lines
4.1 KiB
JavaScript
const token = sessionStorage.getItem("zhgd_token");
|
||
const us = sessionStorage.getItem("zhgd_us");
|
||
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();
|
||
}
|
||
const roleCode = JSON.parse(us).roleCode;
|
||
const orgId = JSON.parse(us).orgId;
|
||
const userId = JSON.parse(us).userId;
|
||
|
||
/* 退出登录 */
|
||
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");
|
||
if (zhgd_type === "2") {
|
||
window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:21624/zhgd-web/sg_login.html';
|
||
} else if (zhgd_type === "1") {
|
||
window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:21624/zhgd-web/sc_login.html';
|
||
}
|
||
});
|
||
} else if (result.code === 500) {
|
||
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");
|
||
if (zhgd_type === "2") {
|
||
window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:21624/zhgd-web/sg_login.html';
|
||
|
||
} else if (zhgd_type === "1") {
|
||
window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:21624/zhgd-web/sc_login.html';
|
||
|
||
}else {
|
||
window.location.href = 'http://iscssotest.ah.sgcc.com.cn/isc_sso/logout?iscUserId='+iscId+'&service=http://27.50.49.56:21624/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;
|
||
} |