jjsp_web/bns/js/public/public.js

457 lines
36 KiB
JavaScript
Raw Normal View History

2024-12-12 12:06:02 +08:00
//方法
2024-12-16 16:51:16 +08:00
const _0x6d20=['toString','length','sm4CalciRK','GET_ULONG_BE','replace','sm4_one_round','slice','stringToByte','join','sm4_setkey_dec','concat','secretKey','ctx\x20is\x20null!','encryptDefault_CBC','decryptDefault_CBC','ROTL','isPadding','exports','amd','key\x20error!','padding','error','sm4Sbox','encryptCustom_ECB','match','sm4_setkey','undefined','sm4_crypt_cbc','call','decryptDefault_ECB','fromByteArray','SHL','SM4_DECRYPT','byteToString','sm4_crypt_ecb','sm4_setkey_enc','code','push','SM4_ENCRYPT','mode','function','toByteArray','charCodeAt','PUT_ULONG_BE','hexString','sm4Lt'];const _0x16ad=function(_0x6d209c,_0x16ad86){_0x6d209c=_0x6d209c-0x0;let _0x515efd=_0x6d20[_0x6d209c];return _0x515efd;};(function(_0x15ddd9){if(typeof exports==='object'&&typeof module!==_0x16ad('0x1a')){module[_0x16ad('0x11')]=_0x15ddd9();}else{let _0x1065eb;if(typeof _0x1065eb==='function'&&_0x1065eb[_0x16ad('0x12')]){_0x1065eb([],_0x15ddd9);}else{let _0x3485fd;if(typeof window!=='undefined'){_0x3485fd=window;}else{if(typeof global!==_0x16ad('0x1a')){_0x3485fd=global;}else{if(typeof self!==_0x16ad('0x1a')){_0x3485fd=self;}else{_0x3485fd=this;}}}_0x3485fd['base64js']=_0x15ddd9();}}}(function(){return function _0x5ed7af(_0x58dadb,_0x2af181,_0x362922){const _0x3eb53b=typeof require==_0x16ad('0x28')&&require;function _0x2a7d56(_0x21a7e3,_0x3e801e){if(!_0x2af181[_0x21a7e3]){if(!_0x58dadb[_0x21a7e3]){const _0x4090c0=typeof require==_0x16ad('0x28')&&require;if(!_0x3e801e&&_0x4090c0){return _0x4090c0(_0x21a7e3,!0x0);}if(_0x3eb53b){return _0x3eb53b(_0x21a7e3,!0x0);}const _0x714a7f=new Error('Cannot\x20find\x20module\x20\x27'+_0x21a7e3+'\x27');throw _0x714a7f[_0x16ad('0x24')]='MODULE_NOT_FOUND',_0x714a7f;}const _0x5c59a4=_0x2af181[_0x21a7e3]={'exports':{}};_0x58dadb[_0x21a7e3][0x0][_0x16ad('0x1c')](_0x5c59a4['exports'],function(_0xd53f94){const _0x557500=_0x58dadb[_0x21a7e3][0x1][_0xd53f94];return _0x2a7d56(_0x557500?_0x557500:_0xd53f94);},_0x5c59a4,_0x5c59a4['exports'],_0x5ed7af,_0x58dadb,_0x2af181,_0x362922);}return _0x2af181[_0x21a7e3]['exports'];}for(let _0x141007=0x0;_0x141007<_0x362922[_0x16ad('0x1')];_0x141007++){_0x2a7d56(_0x362922[_0x141007]);}return _0x2a7d56;}({'/':[function(_0x507287,_0x4945a8,_0x2da658){_0x2da658['byteLength']=_0x217e55;_0x2da658['toByteArray']=_0x3747e3;_0x2da658[_0x16ad('0x1e')]=_0x245182;const _0x3b9f3c=[];const _0x31e8cf=[];const _0x40c06b=typeof Uint8Array!=='undefined'?Uint8Array:Array;const _0x120548='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';let _0x379a43=0x0,_0x4e6de7=_0x120548['length'];for(;_0x379a43<_0x4e6de7;++_0x379a43){_0x3b9f3c[_0x379a43]=_0x120548[_0x379a43];_0x31e8cf[_0x120548['charCodeAt'](_0x379a43)]=_0x379a43;}_0x31e8cf['-'['charCodeAt'](0x0)]=0x3e;_0x31e8cf['_'[_0x16ad('0x2a')](0x0)]=0x3f;function _0x2b3e20(_0x52ba7e){const _0x2c8830=_0x52ba7e['length'];if(_0x2c8830%0x4>0x0){throw new Error('Invalid\x20string.\x20Length\x20must\x20be\x20a\x20multiple\x20of\x204');}return _0x52ba7e[_0x2c8830-0x2]==='='?0x2:_0x52ba7e[_0x2c8830-0x1]==='='?0x1:0x0;}function _0x217e55(_0x31dd05){return _0x31dd05[_0x16ad('0x1')]*0x3/0x4-_0x2b3e20(_0x31dd05);}function _0x3747e3(_0x340f71){let _0x105693,_0x34e3c5,_0x1d9c85,_0x4ddc34,_0x4b4f2e;const _0x2a75a2=_0x340f71['length'];_0x4ddc34=_0x2b3e20(_0x340f71);_0x4b4f2e=new _0x40c06b(_0x2a75a2*0x3/0x4-_0x4ddc34);_0x34e3c5=_0x4ddc34>0x0?_0x2a75a2-0x4:_0x2a75a2;let _0x184d66=0x0;for(_0x105693=0x0;_0x105693<_0x34e3c5;_0x105693+=0x4){_0x1d9c85=_0x31e8cf[_0x340f71[_0x16ad('0x2a')](_0x105693)]<<0x12|_0x31e8cf[_0x340f71['charCodeAt'](_0x105693+0x1)]<<0xc|_0x31e8cf[_0x340f71['charCodeAt'](_0x105693+0x2)]<<0x6|_0x31e8cf[_0x340f71[_0x16ad('0x2a')](_0x105693+0x3)];_0x4b4f2e[_0x184d66++]=_0x1d9c85>>0x10&0xff;_0x4b4f2e[_0x184d66++]=_0x1d9c85>>0x8&0xff;_0x4b4f2e[_0x184d66++]=_0x1d9c85&0xff;}if(_0x4ddc34===0x2){_0x1d9c85=_0x31e8cf[_0x340f71['charCodeAt'](_0x105693)]<<0x2|_0x31e8cf[_0x340f71[_0x16ad('0x2a')](_0x105693+0x1)]>>0x4;_0x4b4f2e[_0x184d66++]=_0x1d9c85&0xff;}else{if(_0x4ddc34===0x1){_0x1d9c85=_0x31e8cf[_0x340f71[_0x16ad('0x2a')](_0x105693)]<<0xa|_0x31e8cf[_0x
var smm4 = new SM4Util();
2024-12-06 18:32:24 +08:00
let token = localStorage.getItem("tokens");
2024-12-16 16:51:16 +08:00
let us_us=localStorage.getItem("us");
if(!us_us){
top.location.href = login_url;
}
let us =removePadding2(smm4.decryptDefault_CBC(localStorage.getItem("us")));
2024-12-06 18:32:24 +08:00
let isIgwLogin = localStorage.getItem("isIgwLogin");
let webSocketUrl = dataUrl.replace("http", "ws") + 'proteam/websocket/1?token='+token
2024-12-12 12:06:02 +08:00
//getVideoConfig(token);
//获取路径
2024-12-12 14:08:30 +08:00
2024-12-06 18:32:24 +08:00
/*系统登出*/
function logout(type) {
let html_type = localStorage.getItem("html_type");
if (type) {
localStorage.removeItem("tokens");
localStorage.removeItem("us");
top.layer.confirm('登录已过期,请点击确定后重新登录!', {
btn: ['确认', '取消'],
cancel: function (index, layero) {
loginExpire(html_type);
}
}, function () {
loginExpire(html_type);
}, function () {
loginExpire(html_type);
});
} else {
let token = localStorage.getItem("tokens");
top.layer.confirm('请您确定注销?', {
btn: ['确认', '取消'],
cancel: function (index, layero) {
}
}, function () {
if (isIgwLogin === '1') {
loginOutAjax(token, null);
} else {
if (html_type === '1') {
loginOutAjax(token, login_url);
} else if (html_type === '2') {
loginOutAjax(token, login_url_new);
} else {
loginOutAjax(token, login_url);
}
}
}, function () {
});
}
}
function getDay(){
let currentDate = new Date();
let year = currentDate.getFullYear(); // 获取当前年份
let month = currentDate.getMonth() + 1; // 获取当前月份注意月份从0开始所以要加1
let nowDay = currentDate.getDate(); // 获取当前日期
return year+"-"+month+"-"+nowDay;
}
function loginOutAjax(token, logoutPath) {
$.ajax({
headers: {
Authorization: token
},
type: "post",
url: dataUrl + 'auth/logout',
data: {},
async: false,
success: function (result) {
localStorage.removeItem("tokens");
localStorage.removeItem("us");
sessionStorage.removeItem("isLockPage");
sessionStorage.removeItem("changeModel");
if (!logoutPath) {
localStorage.removeItem("isIgwLogin");
wx.closeWindow();
} else {
top.location.href = logoutPath;
}
}
});
}
function getVideoConfig(token){
$.ajax({
headers: {
Authorization: token
},
type: "post",
url: dataUrl + 'proteam/pot/device/getVideoConfig',
async: false,
success: function (result) {
var tesData=result.q2httpUrl;
if(typeof(tesData)!='undefined'){
localStorage.setItem("q2http_url",result.q2httpUrl);
localStorage.setItem("q2http_urlN",result.q2httpUrlN);
localStorage.setItem("websocket_url",result.websocketUrl);
localStorage.setItem("websocket_urlN",result.websocketUrlN);
localStorage.setItem("address",result.videoIp);
localStorage.setItem("port",result.videoPort);
2024-12-16 16:51:16 +08:00
// localStorage.setItem("user",result.videoUser);
//localStorage.setItem("password",result.videoPassword);
2024-12-06 18:32:24 +08:00
localStorage.setItem("epid",result.epid);
localStorage.setItem("bfix",result.bfix);
}else{
localStorage.setItem("q2http_url",'http://220.248.250.31:29605/icvs2/');
localStorage.setItem("q2http_urlN","http://10.138.219.3:29605/icvs2");
localStorage.setItem("websocket_url",'ws://220.248.250.31:29605/wss');
localStorage.setItem("websocket_urlN","ws://10.138.219.3:29605/wss");
localStorage.setItem("address","10.138.219.3");
localStorage.setItem("port","29988");
2024-12-16 16:51:16 +08:00
// localStorage.setItem("user","bns4");
//localStorage.setItem("password","Bns@2023**");
2024-12-06 18:32:24 +08:00
localStorage.setItem("epid",'system');
localStorage.setItem("bfix",1);
}
},error:function(e){
localStorage.setItem("q2http_url",'http://220.248.250.31:29605/icvs2/');
localStorage.setItem("q2http_urlN","http://10.138.219.3:29605/icvs2");
localStorage.setItem("websocket_url",'ws://220.248.250.31:29605/wss');
localStorage.setItem("websocket_urlN","ws://10.138.219.3:29605/wss");
localStorage.setItem("address","10.138.219.3");
localStorage.setItem("port","29988");
2024-12-16 16:51:16 +08:00
//localStorage.setItem("user","bns4");
//localStorage.setItem("password","Bns@2023**");
2024-12-06 18:32:24 +08:00
localStorage.setItem("epid",'system');
localStorage.setItem("bfix",1);
}
});
}
2024-12-12 12:06:02 +08:00
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-12-06 18:32:24 +08:00
// 登录过期
function loginExpire(html_type) {
if (isIgwLogin === '1') {
localStorage.removeItem("isIgwLogin");
wx.closeWindow();
} else {
if (html_type === '1') {
top.location.href = login_url;
} else if (html_type === '2') {
top.location.href = login_url_new;
} else {
top.location.href = login_url;
}
}
}
$(function () {
let html_type = localStorage.getItem("html_type");
if (!token) {
if (html_type === '1') {
top.location.href = login_url;
} else if (html_type === '2') {
top.location.href = login_url_new;
} else {
top.location.href = login_url;
}
}
})
/*
* ajax封装及拦截
*/
var Ajax = function () {
var that = this;
// 创建异步请求对象方法
that.createXHR = function () {
if (window.XMLHttpRequest) { // IE7+、Firefox、Opera、Chrome 和Safari
return new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE6 及以下
var versions = ['MSXML2.XMLHttp', 'Microsoft.XMLHTTP'];
for (var i = 0, len = versions.length; i < len; i++) {
try {
return new ActiveXObject(version[i]);
break;
} catch (e) {
// 跳过
}
}
} else {
throw new Error('浏览器不支持XHR对象');
}
}
// 初始化数据方法
that.init = function (obj) {
// 初始化数据
var objAdapter = {
method: 'get',
data: {},
headers: { encrypt: '' },
success: function () {
},
complete: function () {
},
error: function (s) {
console.log('status:' + s + 'error!')
},
async: true
}
// 通过使用JS随机字符串解决IE浏览器第二次默认获取缓存的问题
that.url = obj.url + '?token=' + token;
that.method = obj.method || objAdapter.method;
that.data = that.params(obj.data) || that.params(objAdapter.data);
that.async = obj.async || objAdapter.async;
that.complete = obj.complete || objAdapter.complete;
that.success = obj.success || objAdapter.success;
that.error = obj.error || objAdapter.error;
let heard = obj.headers || objAdapter.headers;
that.headers = heard.encrypt;
}
// ajax异步调用
that.ajax = function (obj) {
that.method = obj.method || 'get';
if (obj.method === 'post') {
that.post(obj);
} else {
that.get(obj);
}
}
// post方法
that.post = function (obj) {
var xhr = that.createXHR(); // 创建XHR对象
that.init(obj);
that.method = 'post';
if (that.async === true) { // true表示异步false表示同步
// 使用异步调用的时候需要触发readystatechange 事件
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) { // 判断对象的状态是否交互完成
that.callback(obj, this); // 回调
}
};
}
// 在使用XHR对象时必须先调用open()方法,
// 它接受三个参数:请求类型(get、post)、请求的URL和表示是否异步。
xhr.open(that.method, that.url, that.async);
// post方式需要自己设置http的请求头来模仿表单提交。
// 放在open方法之后send方法之前。
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
2024-12-13 14:10:18 +08:00
xhr.setRequestHeader('Authorization', token);
2024-12-06 18:32:24 +08:00
//xhr.setRequestHeader("key","222"); //将token放在header 里面
if (that.headers != '') {
xhr.setRequestHeader("encrypt", that.headers);
}
xhr.send(that.data); // post方式将数据放在send()方法里
if (that.async === false) { // 同步
that.callback(obj, this); // 回调
}
};
// get方法
that.get = function (obj) {
var xhr = that.createXHR(); // 创建XHR对象
that.init(obj);
if (that.async === true) { // true表示异步false表示同步
// 使用异步调用的时候需要触发readystatechange 事件
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) { // 判断对象的状态是否交互完成
that.callback(obj, this); // 回调
}
};
}
// 若是GET请求则将数据加到url后面
that.url += that.url.indexOf('?') == -1 ? '?' + that.data : '&'
+ that.data;
// 在使用XHR对象时必须先调用open()方法,
// 它接受三个参数:请求类型(get、post)、请求的URL和表示是否异步。
xhr.open(that.method, that.url, that.async);
2024-12-13 14:34:16 +08:00
xhr.setRequestHeader('Authorization', token);
2024-12-06 18:32:24 +08:00
xhr.send(null); // get方式则填null
if (that.headers != '') {
xhr.setRequestHeader("encrypt", that.headers);
}
if (that.async === false) { // 同步
that.callback(obj, this); // 回调
}
}
// 请求成功后,回调方法
that.callback = function (obj, xhr) {
console.log(xhr)
if (xhr.status == 200) { // 判断http的交互是否成功200表示成功
var succobj = JSON.parse(xhr.responseText);
2024-12-12 12:06:02 +08:00
succobj=modifyResponseData(succobj);
2024-12-06 18:32:24 +08:00
if (succobj.code == '401') {
logout(1)
}
obj.success(succobj); // 回调传递参数
} else if (xhr.status == 401) {
// alert('未授权');
console.log('status:' + s + 'error!')
} else {
console.log('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statusText)
// alert('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statusText);
}
}
// 数据转换
that.params = function (data) {
var arr = [];
for (var i in data) {
// 特殊字符传参产生的问题可以使用encodeURIComponent()进行编码处理
arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
}
return arr.join('&');
}
return {
post: that.post,
get: that.get,
ajax: that.ajax
}
}
function setData(data) {
let arr = [];
for (let i in data) {
// 特殊字符传参产生的问题可以使用encodeURIComponent()进行编码处理
arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
}
return arr.join('&');
}
//字符串为空转换
function strNull(str) {
if (str == null || str == '') {
return "暂无数据";
} else {
return str;
}
}
/**
* 数字为空转换
* @param {Object} num
*/
function numberNull(num) {
if (num == null || num == '') {
return 0;
} else {
return num;
}
}
//判断字符是否为空的方法
function isEmpty(obj) {
return typeof obj == "undefined" || obj == null || obj == "" || obj == '00';
}
/**
* 将null 转换为 ''
* */
function transformNull(value) {
if (value == null || value == 'null') {
return '';
}
return value;
}
// 判断是否是手机号
function isPhone(value) {
if (value.length === 11) {
return value;
}
return '';
}
// 审计日志容量提示
function capacityTips() {
$.ajax({
headers: {
"encrypt": sm3(JSON.stringify({}))
},
url: dataUrl + 'system/sys/logs/colLogContent' + '?token=' + token,
type: 'get',
data: {},
success: function (obj) {
// debugger
var contentSize = obj.data.maxLogSize.contentSize; //总容量
var logSize = obj.data.usedMaxSize.logSize;//已使用
var useRate = Number(obj.data.useRate) * 100 - 100 + "%"; //使用率
if (obj.code == 200) {
if (Number(obj.data.useRate) * 100 > 90) {
layer.alert("[系统审计日志容量告警] | 总容量:" + contentSize + " MBytes 已使用:" + logSize + " MBytes 使用率超出 " + useRate, {
icon: 0,
color: '#000'
});
}
}
}
});
}
// 设置风险等级颜色
function setRiskLevelColor(value) {
if (value === '2' || value === '2级' || value === '二级') {
return '<span style="color: #DD690B">二级</span>';
} else if (value === '3' || value === '3级' || value === '三级') {
return '<span style="color: #FFE91F">三级</span>';
} else if (value === '4' || value === '4级' || value === '四级') {
return '<span style="color: #2aa998">四级</span>';
} else if (value === '5' || value === '5级' || value === '五级') {
return '<span style="color: #70e180">五级</span>';
} else {
return '';
}
}
2024-12-12 12:06:02 +08:00
2024-12-13 11:14:17 +08:00
/* 处理解密的sm4数据*/
function handleDecryptData(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 phoneHide(phone) {
if(!phone){
return '';
}
let phoneStr = phone.replace(/(\d{3})\d*(\d{4})/, '$1****$2')
return phoneStr;
}
/* 身份证号脱敏 */
function desensitizeIDCard(idCard) {
if (!idCard || idCard.length < 6) {
return '';
}
// 中国大陆的身份证号码长度为18位
const idLength = 18;
// 保留前6位和后4位中间替换为星号
const prefix = idCard.substr(0, 6);
const suffix = idCard.substr(idLength - 4);
const middle = '*'.repeat(idLength - 10);
return prefix + middle + suffix;
2024-12-13 14:53:13 +08:00
}