initPsd.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //页面初始化
  2. window.onload=function(){
  3. if (typeof(document.onselectstart) != "undefined") {
  4. // IE禁止元素选取
  5. document.onselectstart = function (event){
  6. if(event.target.tagName!="INPUT"){
  7. return false;
  8. }
  9. }
  10. }
  11. DeviceControlService.init();
  12. CenterSettingService.init();
  13. InitializerService.init();
  14. WebSocketBase.socket.onerror = function () {
  15. logEvent("DeviceControlService startSession callback");
  16. let tips = "终端链接失败"
  17. ModalStyle(tips, 'pathN')
  18. };
  19. ReadCenterConfig('centerSetting');
  20. ReadCenterConfig('access');
  21. };
  22. /**
  23. * @description: modal显示设置
  24. * @param {type}
  25. * @return:
  26. */
  27. function ModalStyle(tips,pathType){
  28. $('#modalBox').fadeIn('slow')
  29. $('#errTips').html(tips);
  30. let path = (pathType == 'pathY') ? './images/success.png' : './images/fail.png'
  31. $('#modalBox img').attr('src', path)
  32. }
  33. /**
  34. * @description: 输入不为null校验
  35. * @param {type}
  36. * @return:
  37. */
  38. function RegExpNull(vals){
  39. let IsNull = false;
  40. let RegxNull = /\S/;
  41. for(let item in vals){
  42. if( !RegxNull.test(vals[item]) ){
  43. let tips = '信息填写不完整'
  44. ModalStyle(tips,'pathN');
  45. IsNull = true
  46. break;
  47. }
  48. }
  49. return IsNull;
  50. }
  51. /**
  52. * @description: IP地址校验
  53. * @param {type}
  54. * @return:
  55. */
  56. function onblurAddr(IPType){
  57. 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}$");
  58. let tips,IpAddr
  59. switch(IPType)
  60. {
  61. case 'config':
  62. IpAddr = $(".config input[name='configAddr']").val();
  63. tips = '集中配置地址格式不正确'
  64. break;
  65. case 'access':
  66. IpAddr = $(".setting input[name='accessAddr']").val();
  67. tips = '准入服务地址格式不正确'
  68. break;
  69. }
  70. if(IpAddr=='')return
  71. if( !RegxIP.test(IpAddr) ){
  72. ModalStyle(tips,'pathN')
  73. }
  74. }
  75. /**
  76. * @description: 下载集中配置
  77. * @param {type}
  78. * @return:
  79. */
  80. function downLoad(){
  81. let req = new Request(),reqIn ={};
  82. let data = document.getElementsByTagName('input');
  83. // reqIn.sSettingServer = data['configAddr'].value;
  84. // reqIn.nSettingPort = Number( data['configPoint'].value)
  85. reqIn.strAddr = data['configAddr'].value;
  86. reqIn.nPort = Number( data['configPoint'].value)
  87. req.timeout = 60000
  88. req = Object.assign({},req,reqIn)
  89. let IsNull = RegExpNull(reqIn)
  90. if(IsNull) return false
  91. $('#loadContent').fadeIn('slow')
  92. // InitializerService.DownloadCenterSetting(req, (ret)=> {
  93. CenterSettingService.Download(req, (ret)=> {
  94. logEvent("Download ret: "+JSON.stringify(ret));
  95. if(ret){
  96. $('#loadContent').fadeOut('slow')
  97. if(ret.errorCode !==0){
  98. let tips = (ret.errorCode == undefined) ? `[${ret.Errcode.toString(16)}]`+ ret.ErrMsg : `[${ret.errorCode}]`+ ret.errorMsg
  99. ModalStyle(tips,'pathN');
  100. return false
  101. }
  102. let tips = '下载集中配置成功'
  103. ModalStyle(tips,'pathY')
  104. // 读取配置文件
  105. ReadCenterConfig('access')
  106. // if(ret.Errcode !== 0)
  107. // {
  108. // let tips = `[${ret.Errcode.toString(16)}]`+ ret.ErrMsg
  109. // ModalStyle(tips,'pathN');
  110. // }else{
  111. // let tips = '下载集中配置成功'
  112. // ModalStyle(tips,'pathY')
  113. // // 读取配置文件
  114. // ReadCenterConfig()
  115. // }
  116. }
  117. })
  118. }
  119. /**
  120. * @description: 读取集中配置文件,注入密钥初始化url,port
  121. * @param {type}
  122. * @return:
  123. */
  124. function ReadCenterConfig(readType){
  125. $('#loadContent').fadeIn('slow')
  126. let req = new Request(),reqIn ={};
  127. if(readType==='access'){
  128. req.entityName = 'AccessAuthorization'
  129. req.key = 'Server'
  130. }else{
  131. req.entityName = 'CenterSetting'
  132. req.key = 'Server'
  133. }
  134. req.reserved1 = 0
  135. req.reserved2 = 0
  136. req.reserved3 = ''
  137. req.reserved4 = ''
  138. req.timeout = 60000
  139. DeviceControlService.ReadCenterConfigStr(req, (ret)=> {
  140. logEvent("ReadCenterConfigStr ret: "+JSON.stringify(ret));
  141. $('#loadContent').fadeOut('slow');
  142. if(ret.errorCode ===0){
  143. let result = JSON.parse(ret['{e12a3dc0-3a0b-47c4-a8c3-75190a42ae68}'] )
  144. let addr = result.value.split(' ')[0]
  145. let port = result.value.split(' ')[1]
  146. if(readType==='access'){
  147. $('.setting input[name=accessAddr]').val(addr)
  148. $('.setting input[name=accessPort]').val(port)
  149. }else{
  150. $('.config input[name=configAddr]').val(addr)
  151. $('.config input[name=configPoint]').val(port)
  152. }
  153. }else{
  154. let tips ='读取集中配置失败'
  155. ModalStyle(tips,'pathN')
  156. }
  157. })
  158. }
  159. /**
  160. * @description: 密钥初始化
  161. * @param {type}
  162. * @return:
  163. */
  164. function ResetRSA(){
  165. let data = document.getElementsByTagName('input');
  166. let req = new Request(),reqIn={};
  167. reqIn.strAuthServer = data['accessAddr'].value
  168. reqIn.nAuthPort = Number( data['accessPort'].value)
  169. reqIn.strUserID = data['account'].value
  170. reqIn.strPassword = data['password'].value
  171. req.timeout = 60000
  172. req = Object.assign({},req,reqIn)
  173. let IsNull = RegExpNull(reqIn)
  174. if(IsNull) return false
  175. $('#loadContent').fadeIn('slow')
  176. //重置密钥
  177. InitializerService.InitializeNew(req, (ret)=> {
  178. logEvent("InitializeNew ret: "+JSON.stringify(ret));
  179. console.log("InitializeNew ret: "+JSON.stringify(ret));
  180. if(ret){
  181. $('#loadContent').fadeOut('slow')
  182. }
  183. if(ret.errorCode == 0) {
  184. if(ret.Errcode !== 0)
  185. {
  186. let tips = `[${ret.Errcode.toString(16)}]`+ ret.ErrMsg
  187. ModalStyle(tips,'pathN')
  188. }else{
  189. let tips = '加载DES主密钥成功'
  190. ModalStyle(tips,'pathY')
  191. }
  192. }
  193. else{
  194. let tips = '重置密钥失败'
  195. ModalStyle(tips,'pathN')
  196. }
  197. });
  198. }
  199. function closeModal(){
  200. $('#modalBox').fadeOut('slow')
  201. }
  202. function exit(){
  203. // 进入的方式,决定退出的方式
  204. console.log('window.location',window.location,window.location.href.indexOf('errPage'))
  205. if(window.location.href.indexOf('errPage')>-1){
  206. $('.iframeDiv').fadeOut();
  207. }else{
  208. let req = {};
  209. req.messageType = 0;
  210. req.command = 'ChromiumClose';
  211. sendRequest(req);
  212. }
  213. }
  214. function sendRequest(request){
  215. try{
  216. window.cefQuery({
  217. request: JSON.stringify(request),
  218. onSuccess: function() {
  219. console.log('window.cefQuery success');
  220. } ,
  221. onFailure: function(error_code, error_message) {
  222. console.log('window.cefQuery error,'+error_message + ' (' + error_code + ')');
  223. let tips = error_code + error_message
  224. ModalStyle(tips,'pathN')
  225. }
  226. });
  227. }
  228. catch(ex) {
  229. console.log('window.cefQuery exception ',ex);
  230. let tips = '退出失败'
  231. ModalStyle(tips,'pathN')
  232. }
  233. }