initPsd.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. AccessAuthService.init();
  14. WebSocketBase.socket.onerror = function () {
  15. logEvent("DeviceControlService startSession callback");
  16. let tips = "终端链接失败"
  17. ModalStyle(tips, 'pathN')
  18. };
  19. logEvent("initinar onload");
  20. };
  21. /**
  22. * @description: modal显示设置
  23. * @param {type}
  24. * @return:
  25. */
  26. function ModalStyle(tips,pathType){
  27. $('#modalBox').fadeIn('slow')
  28. $('#loadContent').fadeOut('slow')
  29. $('#errTips').html(tips);
  30. let path = (pathType == 'pathY') ? './images/success.png' : './images/fail.png'
  31. $('#modalBox img').attr('src', path)
  32. }
  33. function showToast(title){
  34. $('#toastErrTips').html(title);
  35. $('#loading_mask').hide();
  36. $('#toastErrorBox').fadeIn('slow')
  37. setTimeout(()=>{
  38. $('#toastErrorBox').fadeOut('slow')
  39. },2000)
  40. }
  41. function changeInput(obj){
  42. if(obj.value!=''){
  43. $('#btn-downLoad').removeAttr('disabled');
  44. }else{
  45. $('#btn-downLoad').attr('disabled','disabled');
  46. }
  47. }
  48. /**
  49. * @description: 输入不为null校验
  50. * @param {type}
  51. * @return:
  52. */
  53. function RegExpNull(vals){
  54. let IsNull = false;
  55. let RegxNull = /\S/;
  56. for(let item in vals){
  57. if( !RegxNull.test(vals[item]) ){
  58. let tips = '信息填写不完整'
  59. ModalStyle(tips,'pathN');
  60. IsNull = true
  61. break;
  62. }
  63. }
  64. return IsNull;
  65. }
  66. /**
  67. * @description: IP地址校验
  68. * @param {type}
  69. * @return:
  70. */
  71. function onblurAddr(IPType){
  72. 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}$");
  73. let tips,IpAddr
  74. switch(IPType)
  75. {
  76. case 'config':
  77. IpAddr = $(".config input[name='configAddr']").val();
  78. tips = '集中配置地址格式不正确'
  79. break;
  80. case 'access':
  81. IpAddr = $(".setting input[name='accessAddr']").val();
  82. tips = '准入服务地址格式不正确'
  83. break;
  84. }
  85. if(IpAddr=='')return
  86. if( !RegxIP.test(IpAddr) ){
  87. ModalStyle(tips,'pathN')
  88. }
  89. }
  90. let timeout=60000;
  91. /**
  92. * @description: 下载集中配置
  93. * @param {type}
  94. * @return:
  95. */
  96. let ti = 29;
  97. let timeChange = null;
  98. function clock () {
  99. if (ti > 0) {
  100. ti = ti - 1;
  101. document.getElementById('restart-time').innerHTML = ti;
  102. } else {
  103. clearInterval(timeChange);
  104. ti = 29;
  105. $('#boxRestart').fadeOut('slow');
  106. exitTipsColck();
  107. DeviceService.RebootShell();
  108. }
  109. };
  110. function restart(){
  111. clearInterval(timeChange);
  112. ti = 29;
  113. $('#boxRestart').fadeOut('slow');
  114. exitTipsColck();
  115. DeviceService.RebootShell();
  116. }
  117. function downLoad(){
  118. let req = new Request(),reqIn ={};
  119. // req.downloadv2 = 1;
  120. let IsNull = RegExpNull(reqIn)
  121. if(IsNull) return false
  122. $('#loadContent').fadeIn('slow')
  123. // timeoutFn
  124. let timeoutFn= setTimeout(function(){
  125. $('#loadContent').fadeOut('slow')
  126. let tips = '请求超时'
  127. showToast(tips);
  128. },timeout)
  129. CenterSettingService.Downloadv2(req, function(ret) {
  130. logEvent("Download ret: "+JSON.stringify(ret));
  131. console.log("Download ret: "+JSON.stringify(ret));
  132. if(ret){
  133. clearTimeout(timeoutFn);
  134. $('#loadContent').fadeOut('slow')
  135. if(ret.downloadStat==2){
  136. let tips = ret.strErrMsg
  137. ModalStyle(tips,'pathN');
  138. return false
  139. }
  140. let tips = '下载集中配置成功'
  141. ModalStyle(tips,'pathY')
  142. document.getElementById("urlConfigAddr").innerHTML = ret.CenterConfigUrl;
  143. }
  144. })
  145. }
  146. function downLoadv3(value){
  147. if(value=='auto'){
  148. let req = new Request();
  149. $('#loading_mask').fadeIn('slow');
  150. let timeoutFn= setTimeout(function(){
  151. $('#loading_mask').fadeOut('slow');
  152. let tips = '请求超时'
  153. showToast(tips);
  154. },timeout)
  155. CenterSettingService.Downloadv3(req, function(ret) {
  156. logEvent("Download ret: "+JSON.stringify(ret));
  157. console.log("Download ret: "+JSON.stringify(ret));
  158. if(ret){
  159. clearInterval(timeChange);
  160. clearTimeout(timeoutFn);
  161. $('#loading_mask').fadeOut('slow');
  162. if(ret.downloadStat==1){
  163. // document.getElementById("configUrl").innerHTML = ret.retCenterConfigUrl;
  164. $('#boxRestart').fadeIn();
  165. timeChange = setInterval(clock, 1000);
  166. }else if(ret.downloadStat==3 || ret.downloadStat==2){
  167. let tips = ret.strErrMsg?ret.strErrMsg:'集中配置下载失败';
  168. showToast(tips);
  169. return false
  170. }else {
  171. let msg = ret.strErrMsg?ret.strErrMsg:'集中配置下载失败';
  172. let tips = msg + ',请联系总行信息部处理,是否进行手动下载?';
  173. $('#modalErrorBox').fadeIn('slow');
  174. $('#modalErrTips').html(tips);
  175. return false
  176. }
  177. }
  178. })
  179. }else{
  180. $('#ManuallyDownloadError').html("");
  181. $('#ManuallyDownloadError').hide();
  182. let req = new Request(),reqIn ={};
  183. let data = document.getElementsByTagName('input');
  184. reqIn.reqCenterConfigUrl = data['centerConfigUrl'].value;
  185. req = Object.assign({},req,reqIn)
  186. $('#loading_mask').fadeIn('slow');
  187. let timeoutFn= setTimeout(function(){
  188. $('#loading_mask').fadeOut('slow');
  189. let tips = '请求超时'
  190. ModalStyle(tips,'pathN')
  191. },timeout)
  192. CenterSettingService.Downloadv3(req, function(ret) {
  193. logEvent("Download ret: "+JSON.stringify(ret));
  194. console.log("Download ret: "+JSON.stringify(ret));
  195. if(ret){
  196. clearInterval(timeChange);
  197. clearTimeout(timeoutFn);
  198. $('#loading_mask').fadeOut('slow');
  199. if(ret.downloadStat==1){
  200. exit();
  201. // document.getElementById("configUrl").innerHTML = ret.retCenterConfigUrl;
  202. $('#boxRestart').fadeIn();
  203. timeChange = setInterval(clock, 1000);
  204. }else if(ret.downloadStat==3){
  205. exit();
  206. let tips = ret.strErrMsg?ret.strErrMsg:'集中配置是最新版本';
  207. showToast(tips);
  208. return false
  209. }else {
  210. let msg = ret.strErrMsg?ret.strErrMsg:'集中配置下载失败';
  211. $('#ManuallyDownloadError').html(msg);
  212. $('#ManuallyDownloadError').show();
  213. return false
  214. }
  215. }
  216. })
  217. }
  218. }
  219. let HostUrl = "" //准入服务地址
  220. function getAccessUrl(){
  221. let req = new Request()
  222. let timeoutFn= setTimeout(function(){
  223. $('#loadContent').fadeOut('slow');
  224. let tips = '请求超时'
  225. showToast(tips);
  226. },5000)
  227. CenterSettingService.GetAccessUrl(req, function(ret) {
  228. logEvent("GetAccessUrl ret: "+JSON.stringify(ret));
  229. console.log("GetAccessUrl ret: "+JSON.stringify(ret));
  230. if(ret){
  231. clearTimeout(timeoutFn);
  232. $('#loadContent').fadeOut('slow')
  233. // let tips = '获取准入服务地址成功'
  234. // ModalStyle(tips,'pathY')
  235. HostUrl = ret.HostUrl
  236. document.getElementById("urlAccessAddr").innerHTML= ret.HostUrl;
  237. }
  238. })
  239. }
  240. /**
  241. * @description: 读取集中配置文件,注入密钥初始化url,port
  242. * @param {type}
  243. * @return:
  244. */
  245. function ReadCenterConfig(readType,readConfig){
  246. $('#loadContent').fadeIn('slow');
  247. let timeoutFn= setTimeout(function(){
  248. $('#loadContent').fadeOut('slow')
  249. let tips = '请求超时'
  250. ModalStyle(tips,'pathN')
  251. console.log('timeoutFn--ReadCenterConfig-setTimeout222->')
  252. },timeout)
  253. let req = new Request(),reqIn ={};
  254. if(readType==='access'){
  255. req.entityName = 'AccessAuthorization'
  256. req.key = 'Server'
  257. }else{
  258. req.entityName = 'CenterSetting'
  259. req.key = 'Server'
  260. }
  261. req.reserved1 = 0
  262. req.reserved2 = 0
  263. req.reserved3 = ''
  264. req.reserved4 = ''
  265. req.timeout = 60000
  266. logEvent("DeviceControlService->ReadCenterConfigStr");
  267. DeviceControlService.ReadCenterConfigStr(req, function(ret) {
  268. logEvent("ReadCenterConfigStr ret: "+JSON.stringify(ret));
  269. console.log('ReadCenterConfigStr----',ret)
  270. if(ret){
  271. $('#loadContent').fadeOut('slow');
  272. clearTimeout(timeoutFn)
  273. }
  274. if(ret.errorCode ===0){
  275. let result = JSON.parse(ret['{e12a3dc0-3a0b-47c4-a8c3-75190a42ae68}'] )
  276. let addr = result.value.split(' ')[0]
  277. let port = result.value.split(' ')[1]
  278. if(readType==='access'){
  279. $('.setting input[name=accessAddr]').val(addr)
  280. $('.setting input[name=accessPort]').val(port)
  281. }else{
  282. $('.config input[name=configAddr]').val(addr)
  283. $('.config input[name=configPoint]').val(port)
  284. }
  285. }else{
  286. let tips ='读取集中配置失败'+ret.errorCode.toString(16)
  287. if(readConfig==='readConfig'){
  288. ModalStyle(tips,'pathN')
  289. }
  290. }
  291. })
  292. }
  293. // 扫码登录后接收code
  294. window.onmessage = (event) => {
  295. console.log('event----',event)
  296. if (event && event.data.code) {
  297. //接收code参数,格式{code: "********",state:"***********"}
  298. ResetRSA(event.data.code)
  299. $('.iframe-box').fadeOut();
  300. $('.result-wrap').fadeIn();
  301. $('.tipsing').html('重置设备密钥中,稍后自动重启应用···')
  302. let date = +new Date
  303. let dateTime = getFamtterTimer(date)
  304. $('#currDate').html(dateTime)
  305. }
  306. };
  307. /**
  308. * @description: 密钥初始化
  309. * @param {type}
  310. * @return:
  311. */
  312. function ResetRSA(code){
  313. let data = document.getElementsByTagName('input');
  314. let req = new Request(),reqIn={};
  315. reqIn.strAuthServer = HostUrl;
  316. // reqIn.nAuthPort = Number( data['accessPort'].value) todo
  317. reqIn.strUserID = code //data['account'].value
  318. // let agentId = data['account'].value;
  319. // if(Number(reqIn.strUserID) ){
  320. // if (agentId.trim().length == 8) {
  321. // reqIn.strUserID = "SP" + agentId.trim();
  322. // } else {
  323. // reqIn.strUserID = "ST" + agentId.trim();
  324. // }
  325. // }
  326. reqIn.strPassword = '88888888' //默认值,后台不做校验
  327. req.timeout = 60000
  328. req = Object.assign({},req,reqIn)
  329. if(reqIn.strUserID==''){
  330. let tips = '用户名不能为空'
  331. ModalStyle(tips,'pathN')
  332. return;
  333. }
  334. // if(reqIn.strPassword==''){
  335. // let tips = '密码不能为空'
  336. // ModalStyle(tips,'pathN')
  337. // return;
  338. // }
  339. let IsNull = RegExpNull(reqIn)
  340. if(IsNull) return false
  341. $('#loadContent').fadeIn('slow')
  342. // timeoutFn
  343. let timeoutFn= setTimeout(function(){
  344. $('#loadContent').fadeOut('slow')
  345. let tips = '请求超时'
  346. ModalStyle(tips,'pathN')
  347. },timeout)
  348. logEvent("AccessAuthService->InitializeNew");
  349. //重置密钥
  350. AccessAuthService.InitializeNew(req, function(ret) {
  351. logEvent("InitializeNew ret: "+JSON.stringify(ret));
  352. console.log("InitializeNew ret: "+JSON.stringify(ret));
  353. if(ret){
  354. $('#loadContent').fadeOut('slow');
  355. clearTimeout(timeoutFn)
  356. }
  357. if(ret.errorCode == 0) {
  358. if(ret.Errcode !== 0)
  359. {
  360. let tips = Number(ret.Errcode).toString(16)+ (ret.ErrMsg?ret.ErrMsg:'重置密钥失败')
  361. ModalStyle(tips,'pathN')
  362. }else{
  363. let tips = '加载DES主密钥成功'
  364. ModalStyle(tips,'pathY')
  365. setTimeout(()=>{
  366. DeviceService.RebootShell() //初始化成功后自动重启应用
  367. },3000)
  368. }
  369. }
  370. else{
  371. let tips = '重置密钥失败'
  372. ModalStyle(tips,'pathN')
  373. }
  374. });
  375. }
  376. function closeModal(value){
  377. if(value=='modal'){
  378. $('#modalBox').fadeOut('slow')
  379. }else{
  380. $('#modalErrorBox').fadeOut('slow')
  381. }
  382. }
  383. function showManuallyDownloadModal(){
  384. $('#modalErrorBox').fadeOut('slow');
  385. $('#ManuallyDownload').fadeIn('slow');
  386. }
  387. function exit(){
  388. // document.getElementById("urlConfigAddr").innerHTML ="";
  389. // document.getElementById("urlAccessAddr").innerHTML = "";
  390. // document.getElementsByTagName('input')['centerConfigUrl'].value="";
  391. $('#ManuallyDownloadError').html("");
  392. $('#ManuallyDownloadError').hide();
  393. $('#btn-downLoad').attr('disabled','disabled');
  394. // 进入的方式,决定退出的方式
  395. if(window.location.href.indexOf('errPage')>-1){
  396. $('.iframeDiv').fadeOut();
  397. $('.iframe-box').fadeOut();
  398. $('.result-wrap').fadeOut();
  399. $('#ManuallyDownload').fadeOut();
  400. }else{
  401. let req = {};
  402. req.messageType = 0;
  403. req.command = 'ChromiumClose';
  404. sendRequest(req);
  405. }
  406. }
  407. function sendRequest(request){
  408. try{
  409. window.cefQuery({
  410. request: JSON.stringify(request),
  411. onSuccess: function() {
  412. console.log('window.cefQuery success');
  413. },
  414. onFailure: function(error_code, error_message) {
  415. console.log('window.cefQuery error,'+error_message + ' (' + error_code + ')');
  416. let tips = error_code + error_message
  417. ModalStyle(tips,'pathN')
  418. }
  419. });
  420. }
  421. catch(ex) {
  422. console.log('window.cefQuery exception ',ex);
  423. let tips = '退出失败'
  424. ModalStyle(tips,'pathN')
  425. }
  426. }