initPsd.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. AccessAuthService.init();
  12. WebSocketBase.socket.onerror = function () {
  13. logEvent("HealthManagerService startSession callback");
  14. let tips = "终端链接失败"
  15. ModalStyle(tips, 'pathN')
  16. };
  17. logEvent("initinar onload");
  18. };
  19. /**
  20. * @description: modal显示设置
  21. * @param {type}
  22. * @return:
  23. */
  24. function ModalStyle(tips,pathType){
  25. $('#loadContent').fadeOut('slow')
  26. $('#errTips').html(tips);
  27. let path = (pathType == 'pathY') ? './images/success.png' : './images/fail.png'
  28. }
  29. /**
  30. * @description: 输入不为null校验
  31. * @param {type}
  32. * @return:
  33. */
  34. function RegExpNull(vals){
  35. let IsNull = false;
  36. let RegxNull = /\S/;
  37. for(let item in vals){
  38. if( !RegxNull.test(vals[item]) ){
  39. let tips = '信息填写不完整'
  40. ModalStyle(tips,'pathN');
  41. IsNull = true
  42. break;
  43. }
  44. }
  45. return IsNull;
  46. }
  47. let timeout=60000;
  48. /**
  49. * @description: 下载集中配置
  50. * @param {type}
  51. * @return:
  52. */
  53. let ti = 29;
  54. let timeChange = null;
  55. function clock () {
  56. if (ti > 0) {
  57. ti = ti - 1;
  58. document.getElementById('restart-time').innerHTML = ti;
  59. } else {
  60. clearInterval(timeChange);
  61. ti = 29;
  62. $('#boxRestart').fadeOut('slow');
  63. exitTipsColck();
  64. DeviceService.RebootShell();
  65. }
  66. };
  67. function restart(){
  68. clearInterval(timeChange);
  69. ti = 29;
  70. $('#boxRestart').fadeOut('slow');
  71. exitTipsColck();
  72. DeviceService.RebootShell();
  73. }
  74. // 扫码登录后接收code
  75. window.onmessage = (event) => {
  76. console.log('event----',event)
  77. if (event && event.data.code) {
  78. //接收code参数,格式{code: "********",state:"***********"}
  79. ResetRSA(event.data.code)
  80. $('.iframe-box').fadeOut();
  81. $('.result-wrap').fadeIn();
  82. $('.tipsing').html('重置设备密钥中,稍后自动重启应用···')
  83. let date = +new Date
  84. let dateTime = getFamtterTimer(date)
  85. $('#currDate').html(dateTime)
  86. }
  87. };
  88. /**
  89. * @description: 密钥初始化
  90. * @param {type}
  91. * @return:
  92. */
  93. function ResetRSA(code){
  94. let req = new Request(),reqIn={};
  95. // reqIn.strAuthServer = HostUrl;
  96. reqIn.strUserID = code
  97. reqIn.strPassword = '88888888' //默认值,后台不做校验
  98. req.timeout = 60000
  99. req = Object.assign({},req,reqIn)
  100. if(reqIn.strUserID==''){
  101. let tips = '用户名不能为空'
  102. ModalStyle(tips,'pathN')
  103. return;
  104. }
  105. $('#loadContent').fadeIn('slow')
  106. // timeoutFn
  107. let timeoutFn= setTimeout(function(){
  108. $('#loadContent').fadeOut('slow')
  109. let tips = '请求超时'
  110. ModalStyle(tips,'pathN')
  111. },timeout)
  112. logEvent("AccessAuthService->InitializeNew");
  113. //重置密钥
  114. AccessAuthService.InitializeNew(req, function(ret) {
  115. logEvent("InitializeNew ret: "+JSON.stringify(ret));
  116. console.log("InitializeNew ret: "+JSON.stringify(ret));
  117. if(ret){
  118. $('#loadContent').fadeOut('slow');
  119. clearTimeout(timeoutFn)
  120. }
  121. if(ret.errorCode == 0) {
  122. if(ret.Errcode !== 0)
  123. {
  124. let tips = Number(ret.Errcode).toString(16)+ (ret.ErrMsg?ret.ErrMsg:'重置密钥失败')
  125. ModalStyle(tips,'pathN')
  126. }else{
  127. let tips = '加载DES主密钥成功'
  128. ModalStyle(tips,'pathY')
  129. setTimeout(()=>{
  130. DeviceService.RebootShell() //初始化成功后自动重启应用
  131. },3000)
  132. }
  133. }
  134. else{
  135. let tips = '重置密钥失败'
  136. ModalStyle(tips,'pathN')
  137. }
  138. });
  139. }
  140. function exit(){
  141. // 进入的方式,决定退出的方式
  142. if(window.location.href.indexOf('errPage')>-1){
  143. $('.iframeDiv').fadeOut();
  144. $('.iframe-box').fadeOut();
  145. $('.result-wrap').fadeOut();
  146. }else{
  147. let req = {};
  148. req.messageType = 0;
  149. req.command = 'ChromiumClose';
  150. sendRequest(req);
  151. }
  152. }
  153. function sendRequest(request){
  154. try{
  155. window.cefQuery({
  156. request: JSON.stringify(request),
  157. onSuccess: function() {
  158. console.log('window.cefQuery success');
  159. },
  160. onFailure: function(error_code, error_message) {
  161. console.log('window.cefQuery error,'+error_message + ' (' + error_code + ')');
  162. let tips = error_code + error_message
  163. ModalStyle(tips,'pathN')
  164. }
  165. });
  166. }
  167. catch(ex) {
  168. console.log('window.cefQuery exception ',ex);
  169. let tips = '退出失败'
  170. ModalStyle(tips,'pathN')
  171. }
  172. }