//页面初始化 window.onload=function(){ if (typeof(document.onselectstart) != "undefined") { // IE禁止元素选取 document.onselectstart = function (event){ if(event.target.tagName!="INPUT"){ return false; } } } DeviceControlService.init(); CenterSettingService.init(); AccessAuthService.init(); WebSocketBase.socket.onerror = function () { logEvent("DeviceControlService startSession callback"); let tips = "终端链接失败" ModalStyle(tips, 'pathN') }; 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) } function showToast(title){ $('#toastErrTips').html(title); $('#loading_mask').hide(); $('#toastErrorBox').fadeIn('slow') setTimeout(()=>{ $('#toastErrorBox').fadeOut('slow') },2000) } function changeInput(obj){ if(obj.value!=''){ $('#btn-downLoad').removeAttr('disabled'); }else{ $('#btn-downLoad').attr('disabled','disabled'); } } /** * @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=60000; /** * @description: 下载集中配置 * @param {type} * @return: */ let ti = 29; let timeChange = null; function clock () { if (ti > 0) { ti = ti - 1; document.getElementById('restart-time').innerHTML = ti; } else { clearInterval(timeChange); ti = 29; $('#boxRestart').fadeOut('slow'); exitTipsColck(); DeviceService.RebootShell(); } }; function restart(){ clearInterval(timeChange); ti = 29; $('#boxRestart').fadeOut('slow'); exitTipsColck(); DeviceService.RebootShell(); } function downLoad(){ let req = new Request(),reqIn ={}; // req.downloadv2 = 1; let IsNull = RegExpNull(reqIn) if(IsNull) return false $('#loadContent').fadeIn('slow') // timeoutFn let timeoutFn= setTimeout(function(){ $('#loadContent').fadeOut('slow') let tips = '请求超时' showToast(tips); },timeout) CenterSettingService.Downloadv2(req, function(ret) { logEvent("Download ret: "+JSON.stringify(ret)); console.log("Download ret: "+JSON.stringify(ret)); if(ret){ clearTimeout(timeoutFn); $('#loadContent').fadeOut('slow') if(ret.downloadStat==2){ let tips = ret.strErrMsg ModalStyle(tips,'pathN'); return false } let tips = '下载集中配置成功' ModalStyle(tips,'pathY') document.getElementById("urlConfigAddr").innerHTML = ret.CenterConfigUrl; } }) } function downLoadv3(value){ if(value=='auto'){ let req = new Request(); $('#loading_mask').fadeIn('slow'); let timeoutFn= setTimeout(function(){ $('#loading_mask').fadeOut('slow'); let tips = '请求超时' showToast(tips); },timeout) CenterSettingService.Downloadv3(req, function(ret) { logEvent("Download ret: "+JSON.stringify(ret)); console.log("Download ret: "+JSON.stringify(ret)); if(ret){ clearInterval(timeChange); clearTimeout(timeoutFn); $('#loading_mask').fadeOut('slow'); if(ret.downloadStat==1){ // document.getElementById("configUrl").innerHTML = ret.retCenterConfigUrl; $('#boxRestart').fadeIn(); timeChange = setInterval(clock, 1000); }else if(ret.downloadStat==3 || ret.downloadStat==2){ let tips = ret.strErrMsg?ret.strErrMsg:'集中配置下载失败'; showToast(tips); return false }else { let msg = ret.strErrMsg?ret.strErrMsg:'集中配置下载失败'; let tips = msg + ',请联系总行信息部处理,是否进行手动下载?'; $('#modalErrorBox').fadeIn('slow'); $('#modalErrTips').html(tips); return false } } }) }else{ $('#ManuallyDownloadError').html(""); $('#ManuallyDownloadError').hide(); let req = new Request(),reqIn ={}; let data = document.getElementsByTagName('input'); reqIn.reqCenterConfigUrl = data['centerConfigUrl'].value; req = Object.assign({},req,reqIn) $('#loading_mask').fadeIn('slow'); let timeoutFn= setTimeout(function(){ $('#loading_mask').fadeOut('slow'); let tips = '请求超时' ModalStyle(tips,'pathN') },timeout) CenterSettingService.Downloadv3(req, function(ret) { logEvent("Download ret: "+JSON.stringify(ret)); console.log("Download ret: "+JSON.stringify(ret)); if(ret){ clearInterval(timeChange); clearTimeout(timeoutFn); $('#loading_mask').fadeOut('slow'); if(ret.downloadStat==1){ exit(); // document.getElementById("configUrl").innerHTML = ret.retCenterConfigUrl; $('#boxRestart').fadeIn(); timeChange = setInterval(clock, 1000); }else if(ret.downloadStat==3){ exit(); let tips = ret.strErrMsg?ret.strErrMsg:'集中配置是最新版本'; showToast(tips); return false }else { let msg = ret.strErrMsg?ret.strErrMsg:'集中配置下载失败'; $('#ManuallyDownloadError').html(msg); $('#ManuallyDownloadError').show(); return false } } }) } } let HostUrl = "" //准入服务地址 function getAccessUrl(){ let req = new Request() let timeoutFn= setTimeout(function(){ $('#loadContent').fadeOut('slow'); let tips = '请求超时' showToast(tips); },5000) CenterSettingService.GetAccessUrl(req, function(ret) { logEvent("GetAccessUrl ret: "+JSON.stringify(ret)); console.log("GetAccessUrl ret: "+JSON.stringify(ret)); if(ret){ clearTimeout(timeoutFn); $('#loadContent').fadeOut('slow') // let tips = '获取准入服务地址成功' // ModalStyle(tips,'pathY') HostUrl = ret.HostUrl document.getElementById("urlAccessAddr").innerHTML= ret.HostUrl; } }) } /** * @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') } } }) } // 扫码登录后接收code window.onmessage = (event) => { console.log('event----',event) if (event && event.data.code) { //接收code参数,格式{code: "********",state:"***********"} ResetRSA(event.data.code) $('.iframe-box').fadeOut(); $('.result-wrap').fadeIn(); $('.tipsing').html('重置设备密钥中,稍后自动重启应用···') let date = +new Date let dateTime = getFamtterTimer(date) $('#currDate').html(dateTime) } }; /** * @description: 密钥初始化 * @param {type} * @return: */ function ResetRSA(code){ let data = document.getElementsByTagName('input'); let req = new Request(),reqIn={}; reqIn.strAuthServer = HostUrl; // reqIn.nAuthPort = Number( data['accessPort'].value) todo reqIn.strUserID = code //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 = '88888888' //默认值,后台不做校验 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') },timeout) logEvent("AccessAuthService->InitializeNew"); //重置密钥 AccessAuthService.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') setTimeout(()=>{ DeviceService.RebootShell() //初始化成功后自动重启应用 },3000) } } else{ let tips = '重置密钥失败' ModalStyle(tips,'pathN') } }); } function closeModal(value){ if(value=='modal'){ $('#modalBox').fadeOut('slow') }else{ $('#modalErrorBox').fadeOut('slow') } } function showManuallyDownloadModal(){ $('#modalErrorBox').fadeOut('slow'); $('#ManuallyDownload').fadeIn('slow'); } function exit(){ // document.getElementById("urlConfigAddr").innerHTML =""; // document.getElementById("urlAccessAddr").innerHTML = ""; // document.getElementsByTagName('input')['centerConfigUrl'].value=""; $('#ManuallyDownloadError').html(""); $('#ManuallyDownloadError').hide(); $('#btn-downLoad').attr('disabled','disabled'); // 进入的方式,决定退出的方式 if(window.location.href.indexOf('errPage')>-1){ $('.iframeDiv').fadeOut(); $('.iframe-box').fadeOut(); $('.result-wrap').fadeOut(); $('#ManuallyDownload').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') } }