initPsd.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. logEvent("initinar onload");
  22. };
  23. /**
  24. * @description: modal显示设置
  25. * @param {type}
  26. * @return:
  27. */
  28. function ModalStyle(tips,pathType){
  29. $('#modalBox').fadeIn('slow')
  30. $('#loadContent').fadeOut('slow')
  31. $('#errTips').html(tips);
  32. let path = (pathType == 'pathY') ? './images/success.png' : './images/fail.png'
  33. $('#modalBox img').attr('src', path)
  34. }
  35. /**
  36. * @description: 输入不为null校验
  37. * @param {type}
  38. * @return:
  39. */
  40. function RegExpNull(vals){
  41. let IsNull = false;
  42. let RegxNull = /\S/;
  43. for(let item in vals){
  44. if( !RegxNull.test(vals[item]) ){
  45. let tips = '信息填写不完整'
  46. ModalStyle(tips,'pathN');
  47. IsNull = true
  48. break;
  49. }
  50. }
  51. return IsNull;
  52. }
  53. /**
  54. * @description: IP地址校验
  55. * @param {type}
  56. * @return:
  57. */
  58. function onblurAddr(IPType){
  59. 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}$");
  60. let tips,IpAddr
  61. switch(IPType)
  62. {
  63. case 'config':
  64. IpAddr = $(".config input[name='configAddr']").val();
  65. tips = '集中配置地址格式不正确'
  66. break;
  67. case 'access':
  68. IpAddr = $(".setting input[name='accessAddr']").val();
  69. tips = '准入服务地址格式不正确'
  70. break;
  71. }
  72. if(IpAddr=='')return
  73. if( !RegxIP.test(IpAddr) ){
  74. ModalStyle(tips,'pathN')
  75. }
  76. }
  77. let timeout=6000;
  78. // let timeoutFn= setTimeout(function(){
  79. // $('#loadContent').fadeOut('slow')
  80. // let tips = '请求超时'
  81. // ModalStyle(tips,'pathN')
  82. // console.log('timeoutFn---setTimeout->')
  83. // },timeout)
  84. /**
  85. * @description: 下载集中配置
  86. * @param {type}
  87. * @return:
  88. */
  89. function downLoad(){
  90. let req = new Request(),reqIn ={};
  91. let data = document.getElementsByTagName('input');
  92. reqIn.strAddr = data['configAddr'].value;
  93. reqIn.nPort = Number( data['configPoint'].value)
  94. req.timeout = 60000
  95. req = Object.assign({},req,reqIn)
  96. let IsNull = RegExpNull(reqIn)
  97. if(IsNull) return false
  98. $('#loadContent').fadeIn('slow')
  99. // timeoutFn
  100. let timeoutFn= setTimeout(function(){
  101. $('#loadContent').fadeOut('slow')
  102. let tips = '请求超时'
  103. ModalStyle(tips,'pathN')
  104. console.log('timeoutFn--downLoad-setTimeout222->')
  105. },timeout)
  106. logEvent("CenterSettingService->downLoad");
  107. // InitializerService.DownloadCenterSetting(req, (ret)=> {
  108. CenterSettingService.Download(req, function(ret) {
  109. logEvent("Download ret: "+JSON.stringify(ret));
  110. if(ret){
  111. $('#loadContent').fadeOut('slow')
  112. clearTimeout(timeoutFn)
  113. if(ret.errorCode !==0){
  114. // let tips = (ret.errorCode == undefined) ? Number(ret.Errcode).toString(16)+ (ret.ErrMsg?ret.ErrMsg:'下载集中配置失败') : ret.errorCode + ret.errorMsg
  115. let tips = (ret.errorCode == undefined) ?(ret.ErrMsg?ret.ErrMsg:'下载集中配置失败:')+Number(ret.Errcode).toString(16) : '下载集中配置失败:'+ret.errorCode.toString(16)
  116. ModalStyle(tips,'pathN');
  117. return false
  118. }
  119. let tips = '下载集中配置成功'
  120. ModalStyle(tips,'pathY')
  121. // 读取配置文件
  122. ReadCenterConfig('access','readConfig')
  123. }
  124. })
  125. }
  126. /**
  127. * @description: 读取集中配置文件,注入密钥初始化url,port
  128. * @param {type}
  129. * @return:
  130. */
  131. function ReadCenterConfig(readType,readConfig){
  132. $('#loadContent').fadeIn('slow');
  133. let timeoutFn= setTimeout(function(){
  134. $('#loadContent').fadeOut('slow')
  135. let tips = '请求超时'
  136. ModalStyle(tips,'pathN')
  137. console.log('timeoutFn--ReadCenterConfig-setTimeout222->')
  138. },timeout)
  139. let req = new Request(),reqIn ={};
  140. if(readType==='access'){
  141. req.entityName = 'AccessAuthorization'
  142. req.key = 'Server'
  143. }else{
  144. req.entityName = 'CenterSetting'
  145. req.key = 'Server'
  146. }
  147. req.reserved1 = 0
  148. req.reserved2 = 0
  149. req.reserved3 = ''
  150. req.reserved4 = ''
  151. req.timeout = 60000
  152. logEvent("DeviceControlService->ReadCenterConfigStr");
  153. DeviceControlService.ReadCenterConfigStr(req, function(ret) {
  154. logEvent("ReadCenterConfigStr ret: "+JSON.stringify(ret));
  155. console.log('ReadCenterConfigStr----',ret)
  156. if(ret){
  157. $('#loadContent').fadeOut('slow');
  158. clearTimeout(timeoutFn)
  159. }
  160. if(ret.errorCode ===0){
  161. let result = JSON.parse(ret['{e12a3dc0-3a0b-47c4-a8c3-75190a42ae68}'] )
  162. let addr = result.value.split(' ')[0]
  163. let port = result.value.split(' ')[1]
  164. if(readType==='access'){
  165. $('.setting input[name=accessAddr]').val(addr)
  166. $('.setting input[name=accessPort]').val(port)
  167. }else{
  168. $('.config input[name=configAddr]').val(addr)
  169. $('.config input[name=configPoint]').val(port)
  170. }
  171. }else{
  172. let tips ='读取集中配置失败'+ret.errorCode.toString(16)
  173. if(readConfig==='readConfig'){
  174. ModalStyle(tips,'pathN')
  175. }
  176. }
  177. })
  178. }
  179. /**
  180. * @description: 密钥初始化
  181. * @param {type}
  182. * @return:
  183. */
  184. function ResetRSA(){
  185. let data = document.getElementsByTagName('input');
  186. let req = new Request(),reqIn={};
  187. reqIn.strAuthServer = data['accessAddr'].value
  188. reqIn.nAuthPort = Number( data['accessPort'].value)
  189. reqIn.strUserID = data['account'].value
  190. let agentId = data['account'].value;
  191. if(Number(reqIn.strUserID) ){
  192. if (agentId.trim().length == 8) {
  193. reqIn.strUserID = "SP" + agentId.trim();
  194. } else {
  195. reqIn.strUserID = "ST" + agentId.trim();
  196. }
  197. }
  198. reqIn.strPassword = data['password'].value
  199. req.timeout = 60000
  200. req = Object.assign({},req,reqIn)
  201. if(reqIn.strUserID==''){
  202. let tips = '用户名不能为空'
  203. ModalStyle(tips,'pathN')
  204. return;
  205. }
  206. if(reqIn.strPassword==''){
  207. let tips = '密码不能为空'
  208. ModalStyle(tips,'pathN')
  209. return;
  210. }
  211. let IsNull = RegExpNull(reqIn)
  212. if(IsNull) return false
  213. $('#loadContent').fadeIn('slow')
  214. // timeoutFn
  215. let timeoutFn= setTimeout(function(){
  216. $('#loadContent').fadeOut('slow')
  217. let tips = '请求超时'
  218. ModalStyle(tips,'pathN')
  219. console.log('timeoutFn--ReadCenterConfig-setTimeout222->')
  220. },timeout)
  221. logEvent("InitializerService->InitializeNew");
  222. //重置密钥
  223. InitializerService.InitializeNew(req, function(ret) {
  224. logEvent("InitializeNew ret: "+JSON.stringify(ret));
  225. console.log("InitializeNew ret: "+JSON.stringify(ret));
  226. if(ret){
  227. $('#loadContent').fadeOut('slow');
  228. clearTimeout(timeoutFn)
  229. }
  230. if(ret.errorCode == 0) {
  231. if(ret.Errcode !== 0)
  232. {
  233. let tips = Number(ret.Errcode).toString(16)+ (ret.ErrMsg?ret.ErrMsg:'重置密钥失败')
  234. ModalStyle(tips,'pathN')
  235. }else{
  236. let tips = '加载DES主密钥成功'
  237. ModalStyle(tips,'pathY')
  238. }
  239. }
  240. else{
  241. let tips = '重置密钥失败'
  242. ModalStyle(tips,'pathN')
  243. }
  244. });
  245. }
  246. function closeModal(){
  247. $('#modalBox').fadeOut('slow')
  248. }
  249. function exit(){
  250. // 进入的方式,决定退出的方式
  251. console.log('window.location',window.location,window.location.href.indexOf('errPage'))
  252. if(window.location.href.indexOf('errPage')>-1){
  253. $('.iframeDiv').fadeOut();
  254. }else{
  255. let req = {};
  256. req.messageType = 0;
  257. req.command = 'ChromiumClose';
  258. sendRequest(req);
  259. }
  260. }
  261. function sendRequest(request){
  262. try{
  263. window.cefQuery({
  264. request: JSON.stringify(request),
  265. onSuccess: function() {
  266. console.log('window.cefQuery success');
  267. },
  268. onFailure: function(error_code, error_message) {
  269. console.log('window.cefQuery error,'+error_message + ' (' + error_code + ')');
  270. let tips = error_code + error_message
  271. ModalStyle(tips,'pathN')
  272. }
  273. });
  274. }
  275. catch(ex) {
  276. console.log('window.cefQuery exception ',ex);
  277. let tips = '退出失败'
  278. ModalStyle(tips,'pathN')
  279. }
  280. }