| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- //页面初始化
- 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');
- };
- /**
- * @description: modal显示设置
- * @param {type}
- * @return:
- */
- function ModalStyle(tips,pathType){
- $('#modalBox').fadeIn('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')
- }
- }
- /**
- * @description: 下载集中配置
- * @param {type}
- * @return:
- */
- function downLoad(){
- let req = new Request(),reqIn ={};
- let data = document.getElementsByTagName('input');
-
- // reqIn.sSettingServer = data['configAddr'].value;
- // reqIn.nSettingPort = Number( data['configPoint'].value)
- 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')
- // InitializerService.DownloadCenterSetting(req, (ret)=> {
- CenterSettingService.Download(req, (ret)=> {
- logEvent("Download ret: "+JSON.stringify(ret));
- if(ret){
- $('#loadContent').fadeOut('slow')
- if(ret.errorCode !==0){
- let tips = (ret.errorCode == undefined) ? `[${ret.Errcode.toString(16)}]`+ ret.ErrMsg : `[${ret.errorCode}]`+ ret.errorMsg
- ModalStyle(tips,'pathN');
- return false
- }
- let tips = '下载集中配置成功'
- ModalStyle(tips,'pathY')
- // 读取配置文件
- ReadCenterConfig('access')
- // if(ret.Errcode !== 0)
- // {
- // let tips = `[${ret.Errcode.toString(16)}]`+ ret.ErrMsg
- // ModalStyle(tips,'pathN');
- // }else{
- // let tips = '下载集中配置成功'
- // ModalStyle(tips,'pathY')
- // // 读取配置文件
- // ReadCenterConfig()
- // }
- }
-
- })
- }
- /**
- * @description: 读取集中配置文件,注入密钥初始化url,port
- * @param {type}
- * @return:
- */
- function ReadCenterConfig(readType){
- $('#loadContent').fadeIn('slow')
- 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
- DeviceControlService.ReadCenterConfigStr(req, (ret)=> {
- logEvent("ReadCenterConfigStr ret: "+JSON.stringify(ret));
- $('#loadContent').fadeOut('slow');
- 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 ='读取集中配置失败'
- 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
- reqIn.strPassword = data['password'].value
- req.timeout = 60000
- req = Object.assign({},req,reqIn)
- let IsNull = RegExpNull(reqIn)
- if(IsNull) return false
- $('#loadContent').fadeIn('slow')
- //重置密钥
- InitializerService.InitializeNew(req, (ret)=> {
- logEvent("InitializeNew ret: "+JSON.stringify(ret));
- console.log("InitializeNew ret: "+JSON.stringify(ret));
- if(ret){
- $('#loadContent').fadeOut('slow')
- }
- if(ret.errorCode == 0) {
- if(ret.Errcode !== 0)
- {
- let tips = `[${ret.Errcode.toString(16)}]`+ 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')
- }
- }
|