| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- //页面初始化
- window.onload=function(){
- if (typeof(document.onselectstart) != "undefined") {
- // IE禁止元素选取
- document.onselectstart = function (event){
- if(event.target.tagName!="INPUT"){
- return false;
- }
- }
- }
- DeviceControlService.init();
- CenterSettingService.init();
- InitializerService.init();
- WebSocketBase.socket.onerror = function () {
- logEvent("DeviceControlService startSession callback");
- let tips = "终端链接失败"
- ModalStyle(tips, 'pathN')
- };
- ReadCenterConfig('centerSetting');
- ReadCenterConfig('access');
- logEvent("initinar onload");
- };
- /**
- * @description: modal显示设置
- * @param {type}
- * @return:
- */
- function ModalStyle(tips,pathType){
- $('#modalBox').fadeIn('slow')
- $('#loadContent').fadeOut('slow')
- $('#errTips').html(tips);
- let path = (pathType == 'pathY') ? './images/success.png' : './images/fail.png'
- $('#modalBox img').attr('src', path)
- }
- /**
- * @description: 输入不为null校验
- * @param {type}
- * @return:
- */
- function RegExpNull(vals){
- let IsNull = false;
- let RegxNull = /\S/;
- for(let item in vals){
- if( !RegxNull.test(vals[item]) ){
- let tips = '信息填写不完整'
- ModalStyle(tips,'pathN');
- IsNull = true
- break;
- }
- }
- return IsNull;
- }
- /**
- * @description: IP地址校验
- * @param {type}
- * @return:
- */
- function onblurAddr(IPType){
- let RegxIP = new RegExp("^((25[0-5]|2[0-4]\\d|[1]{1}\\d{1}\\d{1}|[1-9]{1}\\d{1}|\\d{1})($|(?!\\.$)\\.)){4}$");
- let tips,IpAddr
- switch(IPType)
- {
- case 'config':
- IpAddr = $(".config input[name='configAddr']").val();
- tips = '集中配置地址格式不正确'
- break;
- case 'access':
- IpAddr = $(".setting input[name='accessAddr']").val();
- tips = '准入服务地址格式不正确'
- break;
- }
- if(IpAddr=='')return
- if( !RegxIP.test(IpAddr) ){
- ModalStyle(tips,'pathN')
- }
- }
- let timeout=6000;
- // let timeoutFn= setTimeout(function(){
- // $('#loadContent').fadeOut('slow')
- // let tips = '请求超时'
- // ModalStyle(tips,'pathN')
- // console.log('timeoutFn---setTimeout->')
- // },timeout)
-
- /**
- * @description: 下载集中配置
- * @param {type}
- * @return:
- */
- function downLoad(){
- let req = new Request(),reqIn ={};
- let data = document.getElementsByTagName('input');
- reqIn.strAddr = data['configAddr'].value;
- reqIn.nPort = Number( data['configPoint'].value)
- req.timeout = 60000
- req = Object.assign({},req,reqIn)
- let IsNull = RegExpNull(reqIn)
- if(IsNull) return false
- $('#loadContent').fadeIn('slow')
- // timeoutFn
- let timeoutFn= setTimeout(function(){
- $('#loadContent').fadeOut('slow')
- let tips = '请求超时'
- ModalStyle(tips,'pathN')
- console.log('timeoutFn--downLoad-setTimeout222->')
- },timeout)
- logEvent("CenterSettingService->downLoad");
- // InitializerService.DownloadCenterSetting(req, (ret)=> {
- CenterSettingService.Download(req, function(ret) {
- logEvent("Download ret: "+JSON.stringify(ret));
- if(ret){
- $('#loadContent').fadeOut('slow')
- clearTimeout(timeoutFn)
- if(ret.errorCode !==0){
- // let tips = (ret.errorCode == undefined) ? Number(ret.Errcode).toString(16)+ (ret.ErrMsg?ret.ErrMsg:'下载集中配置失败') : ret.errorCode + ret.errorMsg
- let tips = (ret.errorCode == undefined) ?(ret.ErrMsg?ret.ErrMsg:'下载集中配置失败:')+Number(ret.Errcode).toString(16) : '下载集中配置失败:'+ret.errorCode.toString(16)
- ModalStyle(tips,'pathN');
- return false
- }
- let tips = '下载集中配置成功'
- ModalStyle(tips,'pathY')
- // 读取配置文件
- ReadCenterConfig('access','readConfig')
- }
-
- })
- }
- /**
- * @description: 读取集中配置文件,注入密钥初始化url,port
- * @param {type}
- * @return:
- */
- function ReadCenterConfig(readType,readConfig){
- $('#loadContent').fadeIn('slow');
- let timeoutFn= setTimeout(function(){
- $('#loadContent').fadeOut('slow')
- let tips = '请求超时'
- ModalStyle(tips,'pathN')
- console.log('timeoutFn--ReadCenterConfig-setTimeout222->')
- },timeout)
- let req = new Request(),reqIn ={};
- if(readType==='access'){
- req.entityName = 'AccessAuthorization'
- req.key = 'Server'
- }else{
- req.entityName = 'CenterSetting'
- req.key = 'Server'
- }
- req.reserved1 = 0
- req.reserved2 = 0
- req.reserved3 = ''
- req.reserved4 = ''
- req.timeout = 60000
- logEvent("DeviceControlService->ReadCenterConfigStr");
-
- DeviceControlService.ReadCenterConfigStr(req, function(ret) {
- logEvent("ReadCenterConfigStr ret: "+JSON.stringify(ret));
- console.log('ReadCenterConfigStr----',ret)
- if(ret){
- $('#loadContent').fadeOut('slow');
- clearTimeout(timeoutFn)
- }
- if(ret.errorCode ===0){
- let result = JSON.parse(ret['{e12a3dc0-3a0b-47c4-a8c3-75190a42ae68}'] )
- let addr = result.value.split(' ')[0]
- let port = result.value.split(' ')[1]
- if(readType==='access'){
- $('.setting input[name=accessAddr]').val(addr)
- $('.setting input[name=accessPort]').val(port)
- }else{
- $('.config input[name=configAddr]').val(addr)
- $('.config input[name=configPoint]').val(port)
- }
-
- }else{
- let tips ='读取集中配置失败'+ret.errorCode.toString(16)
- if(readConfig==='readConfig'){
- ModalStyle(tips,'pathN')
- }
- }
-
- })
- }
- /**
- * @description: 密钥初始化
- * @param {type}
- * @return:
- */
- function ResetRSA(){
- let data = document.getElementsByTagName('input');
- let req = new Request(),reqIn={};
- reqIn.strAuthServer = data['accessAddr'].value
- reqIn.nAuthPort = Number( data['accessPort'].value)
- reqIn.strUserID = data['account'].value
- let agentId = data['account'].value;
- if(Number(reqIn.strUserID) ){
- if (agentId.trim().length == 8) {
- reqIn.strUserID = "SP" + agentId.trim();
- } else {
- reqIn.strUserID = "ST" + agentId.trim();
- }
- }
- reqIn.strPassword = data['password'].value
- req.timeout = 60000
- req = Object.assign({},req,reqIn)
- if(reqIn.strUserID==''){
- let tips = '用户名不能为空'
- ModalStyle(tips,'pathN')
- return;
- }
- if(reqIn.strPassword==''){
- let tips = '密码不能为空'
- ModalStyle(tips,'pathN')
- return;
- }
- let IsNull = RegExpNull(reqIn)
- if(IsNull) return false
- $('#loadContent').fadeIn('slow')
- // timeoutFn
- let timeoutFn= setTimeout(function(){
- $('#loadContent').fadeOut('slow')
- let tips = '请求超时'
- ModalStyle(tips,'pathN')
- console.log('timeoutFn--ReadCenterConfig-setTimeout222->')
- },timeout)
- logEvent("InitializerService->InitializeNew");
- //重置密钥
- InitializerService.InitializeNew(req, function(ret) {
- logEvent("InitializeNew ret: "+JSON.stringify(ret));
- console.log("InitializeNew ret: "+JSON.stringify(ret));
- if(ret){
- $('#loadContent').fadeOut('slow');
- clearTimeout(timeoutFn)
- }
- if(ret.errorCode == 0) {
- if(ret.Errcode !== 0)
- {
- let tips = Number(ret.Errcode).toString(16)+ (ret.ErrMsg?ret.ErrMsg:'重置密钥失败')
- ModalStyle(tips,'pathN')
- }else{
- let tips = '加载DES主密钥成功'
- ModalStyle(tips,'pathY')
- }
- }
- else{
- let tips = '重置密钥失败'
- ModalStyle(tips,'pathN')
- }
- });
- }
- function closeModal(){
- $('#modalBox').fadeOut('slow')
- }
- function exit(){
- // 进入的方式,决定退出的方式
- console.log('window.location',window.location,window.location.href.indexOf('errPage'))
- if(window.location.href.indexOf('errPage')>-1){
- $('.iframeDiv').fadeOut();
- }else{
- let req = {};
- req.messageType = 0;
- req.command = 'ChromiumClose';
- sendRequest(req);
- }
- }
- function sendRequest(request){
- try{
- window.cefQuery({
- request: JSON.stringify(request),
- onSuccess: function() {
- console.log('window.cefQuery success');
- },
- onFailure: function(error_code, error_message) {
- console.log('window.cefQuery error,'+error_message + ' (' + error_code + ')');
- let tips = error_code + error_message
- ModalStyle(tips,'pathN')
- }
- });
- }
- catch(ex) {
- console.log('window.cefQuery exception ',ex);
- let tips = '退出失败'
- ModalStyle(tips,'pathN')
- }
- }
|