預約系統 IOS / Android Windows

index.html 43KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  5. <meta name="description" content="">
  6. <meta name="author" content="">
  7. <script src="js/mqttws31.min.js" type="text/javascript"></script>
  8. <script src="js/jquery-3.5.1.min.js"></script>
  9. <script src="js/teacrypt.js" type="text/javascript"></script>
  10. <script type="text/javascript">
  11. var message999;
  12. var message0 ;
  13. var message4 ;
  14. var message9 ;
  15. var message6;
  16. var message7 ;
  17. var message2 ;
  18. var issame=false;
  19. var vvqrcd= '';
  20. var orgcycle='';
  21. var fincycle='';
  22. var orgtimestamp='';
  23. var isconn = false;
  24. var CID = '';
  25. var ID = '';
  26. var PW = '';
  27. var TYPE = '';
  28. var client;
  29. var kname='';
  30. var myclientid='';
  31. var tt = '';
  32. var st = '';
  33. var et = '';
  34. var idx = '';
  35. var cy='';
  36. var vtype='';
  37. var vtttt='';
  38. var isget = false;
  39. var isget2 = false;
  40. var isget3 = false;
  41. var vtstpqr='';
  42. var vcyd='';
  43. var vmqtt='';
  44. var SN='';
  45. var SubID='';
  46. var vsn='';
  47. var vobj;
  48. var isgetv=false;
  49. var intervalID;
  50. var ooodata='';
  51. var is2='';
  52. var account='';
  53. var ngui = require('nw.gui');
  54. var nwin = ngui.Window.get();
  55. function init()
  56. {
  57. try
  58. {
  59. nwin.show();
  60. nwin.maximize();
  61. var vmycid= localStorage.getItem('mycid');
  62. if (!!vmycid)
  63. {
  64. document.getElementById("scales").checked = true;
  65. document.getElementById("ItemUSSer").value=vmycid;
  66. }
  67. //input
  68. // CID = getUrlParameter('CID');
  69. //PW= getUrlParameter('PW');
  70. // SubID = getUrlParameter('SubID');
  71. ID = '00000000';
  72. TYPE= 'PC';
  73. //query
  74. //SN = getUrlParameter('SN');
  75. //vmqtt = getUrlParameter('MQTT');
  76. //kkid= getUrlParameter('ID');
  77. //Cname= getUrlParameter('CNAME');
  78. // var sstitle =Cname+'(#'+SubID+') ';
  79. // vvqrcd= vobj.data.data.CardID;
  80. //vvqrcd= getUrlParameter('qrcd');
  81. // account=CID+'_'+SubID;
  82. // document.getElementById("btn100").innerHTML ='帳號 : '+account;
  83. // document.getElementById("btn900").innerHTML ='密碼需為英數字 8-16 碼 ';
  84. //vvqrcd=vvqrcd.replaceAll('-','=');
  85. //updateOutput('init');
  86. /*
  87. CID = getUrlParameter('CID');
  88. ID = getUrlParameter('ID');
  89. PW= getUrlParameter('PW');
  90. TYPE= getUrlParameter('TYPE');
  91. */
  92. //myclientid="Giga"+CID+"1-"+ parseInt(Math.random() * 100000000, 10);
  93. // client.connect( {onSuccess: onConnect});
  94. // client.connect( {onSuccess: onConnect, onFailure : onFailedConnect,timeout: 3,keepAliveInterval: 35,cleanSession : false});
  95. //alert(orgcycle);
  96. //updateOutput('CID='+CID);
  97. //updateOutput('ID='+ID);
  98. //updateOutput('PW='+PW);
  99. //updateOutput('TYPE='+TYPE);
  100. if (TYPE=='ANDROID')
  101. {
  102. connect();
  103. }
  104. vsn='';
  105. }catch(e)
  106. {
  107. alert(e);
  108. }
  109. }
  110. function onConnectionLost(message)
  111. {
  112. //alert('連線失敗或重複登入');
  113. //document.location = "index.html?TYPE=PC&ID=00000000";
  114. // client.connect( {onSuccess: onConnect, onFailure : onFailedConnect});
  115. client.connect( {onSuccess: onConnect, onFailure : onFailedConnect,timeout: 6,keepAliveInterval: 30});
  116. }
  117. function onMessageArrived(message)
  118. {
  119. //alert(message.payloadString);
  120. var vres = message.payloadString;
  121. //return;
  122. var vobj = JSON.parse( vres);
  123. is2='002';
  124. var jsonString = "{\"action\":\"decode\", \"serial\":\"002\",\"data\":\""+vobj.data+"\"}";
  125. if (TYPE=='IOS')
  126. {
  127. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  128. }
  129. if (TYPE=='ANDROID')
  130. {
  131. webSocket.send(jsonString);
  132. }
  133. if (TYPE=='PC')
  134. {
  135. isgetv=true;
  136. vres = teaDecrypt(vobj.data,'75$095huOQ77kKv!');
  137. //alert(vres);
  138. var vobj2 = JSON.parse( vres);
  139. //alert(vobj2.success);
  140. if (vobj2.success===true)
  141. {
  142. var vnewpw=vobj2.data.token;
  143. if ( document.getElementById("scales").checked==false)
  144. {
  145. //alert('ch');
  146. localStorage.setItem('mycid','');
  147. }else
  148. {
  149. localStorage.setItem('mycid',CID+'_'+SubID);
  150. }
  151. //return;
  152. //alert(SN);
  153. //alert(vmqtt);
  154. document.location = "index1.html??ID=00000000&SubID="+SubID+"&CID="+CID+"&PW="+vnewpw+"&TYPE=PC&SN="+SN+"&MQTT="+vmqtt;
  155. }
  156. else
  157. {
  158. clearInterval(intervalID);
  159. alert('帳號密碼錯誤');
  160. }
  161. is2='';
  162. }
  163. }
  164. function onFailedConnect()
  165. {
  166. //alert('連線異常');
  167. }
  168. function onConnect()
  169. {
  170. isconn=true;
  171. client.subscribe('ReservePC'+CID+'1-'+SubID);
  172. try
  173. {
  174. //alert('conn');
  175. }
  176. catch(e)
  177. {
  178. alert(e);
  179. }
  180. //alert('c');
  181. }
  182. </script>
  183. <title>預約 QR Code</title>
  184. <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  185. </head>
  186. <body class="text-center" onload="init()">
  187. <div>
  188. <div class="card" style="width: 480px ;box-shadow: 0px 0px 1px 1px rgba(0,0,0,0.1);margin: 21px auto;background-color:#FFFFFF;">
  189. <div style="margin: 16px 0 0px 4px;background-color:#FFFFFF;" >
  190. </div>
  191. <div style="text-align:center">
  192. <!-- <h1 class="h3 mb-3 font-weight-normal">預收貨款</h1> -->
  193. <!-- <form class="form-signin" id="senddocument"> -->
  194. <br>
  195. <div style="margin: 3px 9px 3px 9px;text-align:left;">
  196. <label style="margin: 5px 0px 5px 0px;font-family:Roboto_Light;font-size:24px;color:#646464;border:none;width: 100px;">帳號&nbsp:&nbsp </label><input id="ItemUSSer" style="height:40px;box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);margin: 5px 0px 5px 0px;font-family:Roboto_Light;font-size:20px;color:#646464;border:none;width:calc(99% - 100px);" placeholder="" required>
  197. <label style="margin: 5px 0px 5px 0px;font-family:Roboto_Light;font-size:24px;color:#646464;border:none;width: 100px;">密碼&nbsp:&nbsp </label><input type="password" id="ItemNOSer" style="height:40px;box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);margin: 5px 0px 5px 0px;font-family:Roboto_Light;font-size:20px;color:#646464;border:none;width:calc(99% - 100px);" placeholder="" required></div>
  198. <input type="checkbox" id="scales" name="scales" /><label for="scales">儲存帳號</label>
  199. <div style="margin: 3px 9px 3px 9px;text-align:left;">
  200. </br>
  201. <table style="width: 100%">
  202. <tbody>
  203. <tr>
  204. <td style="width: 33.3%"><button type="button" style="border-color: #dcdcdc;border-width: 1px;border-color: #dcdcdc;border-width: 1px;margin: 0px 0px 20px 0px;color:#787878;font-family: Roboto_Light; font-size: 24px;width: 110px; height: 60px; background-color: rgba(255, 0, 20, 0.2);width:100%;" onclick="btndddel()" hidden>刪除</button></td><td style="width: 33.3%"><button type="button" style="border-color: #dcdcdc;border-width: 1px;border-color: #dcdcdc;border-width: 1px;margin: 0px 0px 20px 0px;color:#787878;font-family: Roboto_Light; font-size: 24px;width: 110px; height: 60px; background-color: #cce8fc;width:100%;" onclick="ok123()">登入</button> </td><td style="width: 33.3%"><button type="button" style="border-color: #dcdcdc;border-width: 1px;border-color: #dcdcdc;border-width: 1px;margin: 0px 0px 20px 0px;color:#FFFFFF;font-family: Roboto_Light; font-size: 24px;width: 110px; height: 60px; background-color: #64c800;width:100%;" onclick="btnSaveqr()" hidden>預約</button></td>
  205. </tr>
  206. </tbody>
  207. </table>
  208. </div>
  209. </div>
  210. <div>
  211. V.240103-2
  212. </div>
  213. <div id="output" style="display:none">
  214. <h2>Output</h2>
  215. </div>
  216. <script type="text/javascript">
  217. var vvpw;
  218. var vvsn;
  219. function ok123()
  220. {
  221. const isValidPasswordChar = str => {
  222. const regex =/^[A-Za-z0-9_.]+$/;
  223. return regex.test(str)
  224. };
  225. var accou ;
  226. //alert(accou);
  227. var subi ;
  228. var bigaccou;
  229. try
  230. {
  231. var iserror = false;
  232. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss");
  233. var vacc= document.getElementById("ItemUSSer").value;
  234. bigaccou=vacc;
  235. const myArray = vacc.split('_');
  236. try
  237. {
  238. accou = myArray[0];
  239. //alert(accou);
  240. subi = myArray[1];
  241. //alert(subi);
  242. CID = accou;
  243. SubID = subi;
  244. if (accou.length!=12)
  245. {
  246. alert('帳密錯誤');
  247. return;
  248. }
  249. if (subi.length!=1)
  250. {
  251. alert('帳密錯誤');
  252. return;
  253. }
  254. }
  255. catch(e)
  256. {
  257. //alert(e);
  258. iserror=true;
  259. }
  260. if (iserror)
  261. {
  262. alert('帳密錯誤');
  263. return;
  264. }
  265. var vwpw= document.getElementById("ItemNOSer").value;
  266. // alert(vwpw);
  267. if (isValidPasswordChar(vwpw))
  268. {
  269. }else
  270. {
  271. alert('密碼需為英數字');
  272. return;
  273. }
  274. if( (vwpw.length>16)||(vwpw.length<8))
  275. {
  276. alert('密碼長度需介於8~16之間');
  277. return;
  278. }
  279. /*
  280. if (bigaccou==='886235000025_7' && vwpw==='1234567890' )
  281. {
  282. alert('OK');
  283. document.location = "index1.html??ID=00000000&SubID=7&CID=886235000025&PassWord=2a1y1aqHEuwuoWb8&TYPE=PC&SN=2700219080008&MQTT=aws.gigatech.tw";
  284. return;
  285. }
  286. else
  287. {
  288. alert('帳密錯誤');
  289. return;
  290. }
  291. */
  292. if (bigaccou.startsWith('886235'))
  293. {
  294. vmqtt = "intercom.nxt.tw";
  295. }
  296. else
  297. {
  298. vmqtt = "aws.gigatech.tw";
  299. }
  300. myclientid="GigaPC"+accou+"1-"+subi;
  301. client = new Paho.MQTT.Client(vmqtt, Number(8083), myclientid);
  302. client.onMessageArrived = onMessageArrived;
  303. client.onConnectionLost = onConnectionLost;
  304. //client.connect( {onSuccess: onConnect, onFailure : onFailedConnect});
  305. client.connect( {onSuccess: onConnect, onFailure : onFailedConnect,timeout: 6,keepAliveInterval: 30});
  306. if (bigaccou.startsWith('886235'))
  307. {
  308. fetch('http://intercom.nxt.tw:8006/Common/CloudCMS/dealer/fast.ashx?action=getvvv&CID='+CID)
  309. .then(res => {
  310. return res.json();
  311. }).then(result => {
  312. const myArray2 = result.data.split(',');
  313. if (result.success==false)
  314. {
  315. alert('未授權電腦版本使用')
  316. return;
  317. }
  318. var vvcango;
  319. try
  320. {
  321. vvpw=myArray2[1];
  322. vvsn=myArray2[0];
  323. vvcango = myArray2[2];
  324. }catch(e)
  325. {
  326. alert('未授權電腦版本使用')
  327. return;
  328. }
  329. if (vvcango==='Y')
  330. {
  331. }
  332. else
  333. {
  334. alert('未授權電腦版本使用')
  335. return;
  336. }
  337. SN = vvsn;
  338. // alert(vvpw);
  339. // alert(vvsn);
  340. //return;
  341. //2a1y1aqHEuwuoWb8
  342. var message="{\"action\":\"mqttverifyRemoteKeyAccount\",\"data\":{\"Command\":\"User="+subi+"&Account="+accou+"_"+subi+"&PassWord="+vvpw+"&WebPassWord="+vwpw+"\",\"SerialNo\":\"ReservePC"+accou+"1-"+subi+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  343. // alert(message);
  344. //return;
  345. var vivi=0;
  346. is2='001';
  347. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+message+"}";
  348. if (TYPE=='IOS')
  349. {
  350. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  351. }
  352. if (TYPE=='ANDROID')
  353. {
  354. //alert('001 websocket sent');
  355. webSocket.send(jsonString);
  356. }
  357. if (TYPE=='PC')
  358. {
  359. message = teaEncrypt(message,'75$095huOQ77kKv!');
  360. var ress = message;
  361. intervalID = setInterval(() => {
  362. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  363. message4.destinationName = vvsn;//'2700219080008';//SN ;
  364. message4.retained = false;
  365. message4.qos = 0;
  366. if (isconn)
  367. {
  368. client.send(message4);
  369. }
  370. // clearInterval(intervalID);
  371. if (vivi>15)
  372. {
  373. clearInterval(intervalID);
  374. alert('連線逾時');
  375. }
  376. else
  377. {
  378. vivi++;
  379. }
  380. }, 400);
  381. }
  382. });
  383. }
  384. else
  385. {
  386. fetch('http://aws.gigatech.tw:8006/Common/CloudCMS/dealer/fast.ashx?action=getvvv&CID='+CID)
  387. .then(res => {
  388. return res.json();
  389. }).then(result => {
  390. const myArray2 = result.data.split(',');
  391. if (result.success==false)
  392. {
  393. alert('未授權電腦版本使用')
  394. return;
  395. }
  396. var vvcango;
  397. try
  398. {
  399. vvpw=myArray2[1];
  400. vvsn=myArray2[0];
  401. vvcango = myArray2[2];
  402. }catch(e)
  403. {
  404. alert('未授權電腦版本使用')
  405. return;
  406. }
  407. if (vvcango==='Y')
  408. {
  409. }
  410. else
  411. {
  412. alert('未授權PC版本使用')
  413. return;
  414. }
  415. SN = vvsn;
  416. // alert(vvpw);
  417. // alert(vvsn);
  418. //return;
  419. //2a1y1aqHEuwuoWb8
  420. var message="{\"action\":\"mqttverifyRemoteKeyAccount\",\"data\":{\"Command\":\"User="+subi+"&Account="+accou+"_"+subi+"&PassWord="+vvpw+"&WebPassWord="+vwpw+"\",\"SerialNo\":\"ReservePC"+accou+"1-"+subi+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  421. //alert(message);
  422. //return;
  423. var vivi=0;
  424. is2='001';
  425. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+message+"}";
  426. if (TYPE=='IOS')
  427. {
  428. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  429. }
  430. if (TYPE=='ANDROID')
  431. {
  432. //alert('001 websocket sent');
  433. webSocket.send(jsonString);
  434. }
  435. if (TYPE=='PC')
  436. {
  437. message = teaEncrypt(message,'75$095huOQ77kKv!');
  438. var ress = message;
  439. intervalID = setInterval(() => {
  440. // alert(vivi);
  441. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  442. message4.destinationName = vvsn;//'2700219080008';//SN ;
  443. message4.retained = false;
  444. message4.qos = 0;
  445. if (isconn)
  446. {
  447. client.send(message4);
  448. }
  449. // clearInterval(intervalID);
  450. if (vivi>15)
  451. {
  452. clearInterval(intervalID);
  453. alert('連線逾時');
  454. }
  455. else
  456. {
  457. vivi++;
  458. }
  459. }, 400);
  460. }
  461. });
  462. }
  463. }catch(e)
  464. {
  465. alert(e);
  466. }
  467. }
  468. function btnSaveTmp()
  469. {
  470. try
  471. {
  472. issame=false;
  473. //alert(idx);
  474. var vvee1='';
  475. var vvee2='';
  476. var vvee3='';
  477. var cycy='';
  478. var st1 = '0000' ;
  479. var et1= '0000' ;
  480. var st2 = '0000' ;
  481. var et2= '0000' ;
  482. var st3 = '0000' ;
  483. var et3= '0000' ;
  484. //12345
  485. var vItemNOSer=document.getElementById("ItemNOSer").value;
  486. if (vItemNOSer.length<1)
  487. {
  488. alert('請輸入密碼');
  489. return;
  490. }
  491. if((document.getElementById("sd").value<1) || (document.getElementById("ed").value<1) ||(document.getElementById("sdt1").value<1) || (document.getElementById("sdt2").value<1))
  492. {
  493. alert('請輸入開始與結束日期時間');
  494. return;
  495. }
  496. var vsdsd=document.getElementById("sd").value+'T'+document.getElementById("sdt1").value;
  497. //alert(vsdsd);
  498. //return;
  499. var veded =document.getElementById("ed").value+'T'+document.getElementById("sdt2").value;
  500. //alert(veded);
  501. if ((vsdsd.length<2)|| (veded.length<2))
  502. {
  503. alert('請輸入開始與結束日期時間');
  504. return;
  505. }
  506. //alert('pass');
  507. if (vsdsd.length>16)
  508. {
  509. vsdsd=vsdsd.substring(0,16);
  510. }
  511. if (veded.length>16)
  512. {
  513. veded=veded.substring(0,16);
  514. }
  515. vsdsd=vsdsd.replace('T','_');
  516. vsdsd=vsdsd.replace('-','/');
  517. vsdsd=vsdsd.replace('-','/');
  518. veded=veded.replace('T','_');
  519. veded=veded.replace('-','/');
  520. veded=veded.replace('-','/');
  521. vsdsd=vsdsd.substring(2,vsdsd.length);
  522. veded=veded.substring(2,veded.length);
  523. //alert(vsdsd);
  524. //alert(veded);
  525. var vtstp=vsdsd+','+veded;
  526. //alert(vtstp);
  527. //return;
  528. //if (document.getElementById("d11").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png')
  529. if (document.getElementById("d11").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  530. {
  531. vvee1='1';
  532. //alert('bgreen');
  533. }else
  534. {
  535. vvee1='0';
  536. //alert('bgrey');
  537. }
  538. if (document.getElementById("d12").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  539. {
  540. vvee1=vvee1+'1';
  541. }else
  542. {
  543. vvee1=vvee1+'0';
  544. }
  545. if (document.getElementById("d13").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  546. {
  547. vvee1=vvee1+'1';
  548. }else
  549. {
  550. vvee1=vvee1+'0';
  551. }
  552. if (document.getElementById("d14").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  553. {
  554. vvee1=vvee1+'1';
  555. }else
  556. {
  557. vvee1=vvee1+'0';
  558. }
  559. if (document.getElementById("d15").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  560. {
  561. vvee1=vvee1+'1';
  562. }else
  563. {
  564. vvee1=vvee1+'0';
  565. }
  566. if (document.getElementById("d16").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  567. {
  568. vvee1=vvee1+'1';
  569. }else
  570. {
  571. vvee1=vvee1+'0';
  572. }
  573. if (document.getElementById("d17").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  574. {
  575. vvee1=vvee1+'1';
  576. }else
  577. {
  578. vvee1=vvee1+'0';
  579. }
  580. //alert(vvee1);
  581. if (document.getElementById("d21").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  582. {
  583. vvee2='1';
  584. //alert('bgreen');
  585. }else
  586. {
  587. vvee2='0';
  588. //alert('bgrey');
  589. }
  590. if (document.getElementById("d22").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  591. {
  592. vvee2=vvee2+'1';
  593. }else
  594. {
  595. vvee2=vvee2+'0';
  596. }
  597. if (document.getElementById("d23").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  598. {
  599. vvee2=vvee2+'1';
  600. }else
  601. {
  602. vvee2=vvee2+'0';
  603. }
  604. if (document.getElementById("d24").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  605. {
  606. vvee2=vvee2+'1';
  607. }else
  608. {
  609. vvee2=vvee2+'0';
  610. }
  611. if (document.getElementById("d25").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  612. {
  613. vvee2=vvee2+'1';
  614. }else
  615. {
  616. vvee2=vvee2+'0';
  617. }
  618. if (document.getElementById("d26").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  619. {
  620. vvee2=vvee2+'1';
  621. }else
  622. {
  623. vvee2=vvee2+'0';
  624. }
  625. if (document.getElementById("d27").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  626. {
  627. vvee2=vvee2+'1';
  628. }else
  629. {
  630. vvee2=vvee2+'0';
  631. }
  632. // alert(vvee2);
  633. if (document.getElementById("d31").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  634. {
  635. vvee3='1';
  636. //alert('bgreen');
  637. }else
  638. {
  639. vvee3='0';
  640. //alert('bgrey');
  641. }
  642. if (document.getElementById("d32").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  643. {
  644. vvee3=vvee3+'1';
  645. }else
  646. {
  647. vvee3=vvee3+'0';
  648. }
  649. if (document.getElementById("d33").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  650. {
  651. vvee3=vvee3+'1';
  652. }else
  653. {
  654. vvee3=vvee3+'0';
  655. }
  656. if (document.getElementById("d34").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  657. {
  658. vvee3=vvee3+'1';
  659. }else
  660. {
  661. vvee3=vvee3+'0';
  662. }
  663. if (document.getElementById("d35").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  664. {
  665. vvee3=vvee3+'1';
  666. }else
  667. {
  668. vvee3=vvee3+'0';
  669. }
  670. if (document.getElementById("d36").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  671. {
  672. vvee3=vvee3+'1';
  673. }else
  674. {
  675. vvee3=vvee3+'0';
  676. }
  677. if (document.getElementById("d37").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  678. {
  679. vvee3=vvee3+'1';
  680. }else
  681. {
  682. vvee3=vvee3+'0';
  683. }
  684. //alert(vvee3);
  685. var ktype = '1';
  686. if (vvee1=='0000000')
  687. {
  688. }else
  689. {
  690. ktype='2';
  691. st1 = document.getElementById("st1").value.replace(':','') ;
  692. et1= document.getElementById("et1").value.replace(':','') ;
  693. if (st1.length==0 || et1.length==0)
  694. {
  695. alert('請選擇時段1的起始與結束時間');
  696. return;
  697. }
  698. }
  699. if (vvee2=='0000000')
  700. {
  701. }else
  702. {
  703. ktype='2';
  704. st2 = document.getElementById("st2").value.replace(':','') ;
  705. et2= document.getElementById("et2").value.replace(':','') ;
  706. if (st2.length==0 || et2.length==0)
  707. {
  708. alert('請選擇時段2的起始與結束時間');
  709. return;
  710. }
  711. }
  712. if (vvee3=='0000000')
  713. {
  714. }else
  715. {
  716. ktype='2';
  717. st3 = document.getElementById("st3").value.replace(':','') ;
  718. et3= document.getElementById("et3").value.replace(':','') ;
  719. //alert(st3.length)
  720. if (st3.length==0 || et3.length==0)
  721. {
  722. alert('請選擇時段3的起始與結束時間');
  723. return;
  724. }
  725. }
  726. //alert(ktype);
  727. if (ktype=='2')
  728. {
  729. cycy=vvee1+','+st1 +','+ et1+','+ vvee2+','+st2+','+et2+','+vvee3+','+st3+','+et3;
  730. }
  731. else
  732. {
  733. //cycy='';
  734. }
  735. // alert(ktype);
  736. //updateOutput('cycy='+cycy);
  737. //alert(cycy);
  738. fincycle='';
  739. fincycle= document.getElementById("ItemNOSer").value+';';
  740. fincycle=fincycle+ vtstp+';';
  741. fincycle=fincycle+cycy+';';
  742. //alert(cycy);
  743. // alert(fincycle);
  744. if (orgcycle==fincycle)
  745. {
  746. issame=true;
  747. // alert('相同');
  748. }
  749. if (issame)
  750. {
  751. alert('OK');
  752. window.history.go(-1);
  753. }
  754. else
  755. {
  756. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss");
  757. //alert(document.getElementById("ItemNOSer").value);
  758. vtttt = document.getElementById("ItemNOSer").value;
  759. // alert(ktype);
  760. // return;
  761. var edata ="{\"action\":\"mqttupdateRemoteKey\",\"data\":{\"Command\":\"PassWord="+PW+"&ReGenerate=1&Stat=0&Type="+ktype+"&IndexID="+idx+"&TimeStamp="+vtstp+"&Cycle="+cycy+"&UserID="+ID+"&Title="+vtttt+"\",\"SerialNo\":\"ReservePC"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  762. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+edata+"}";
  763. vsn='001';
  764. isget2=false;
  765. // updateOutput(jsonString);
  766. //alert(jsonString
  767. if (TYPE=='IOS')
  768. {
  769. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  770. }
  771. if (TYPE=='ANDROID')
  772. {
  773. webSocket.send(jsonString);
  774. }
  775. if (TYPE=='PC')
  776. {
  777. //alert(edata);
  778. selfendecode(edata);
  779. }
  780. }
  781. }catch(e)
  782. {
  783. alert(e);
  784. }
  785. }
  786. function senttoother()
  787. {
  788. try
  789. {
  790. message999 = new Paho.MQTT.Message( "modify,"+idx+","+SubID+","+kname );
  791. // alert('send to other = '+ "modify,"+idx+","+SubID+","+kname );
  792. message999.qos = 0;
  793. message999.retained = false;
  794. for (var iii = 1; iii < 9; iii++)
  795. {
  796. if ( iii.toString() !=SubID.toString())
  797. {
  798. message999.destinationName = 'ReservePC'+CID+'1-'+iii.toString() ;
  799. client.send(message999);
  800. }
  801. }
  802. }
  803. catch(e)
  804. {
  805. alert(e);
  806. }
  807. }
  808. function btnSaveqr()
  809. {
  810. issame=false;
  811. //alert(idx);
  812. var vvee1='';
  813. var vvee2='';
  814. var vvee3='';
  815. var cycy='';
  816. var st1 = '0000' ;
  817. var et1= '0000' ;
  818. var st2 = '0000' ;
  819. var et2= '0000' ;
  820. var st3 = '0000' ;
  821. var et3= '0000' ;
  822. //var vsdsd=document.getElementById("sd").value;
  823. //var veded =document.getElementById("ed").value;
  824. var vsdsd=document.getElementById("sd").value+'T'+document.getElementById("sdt1").value;
  825. //alert(vsdsd);
  826. //return;
  827. var veded =document.getElementById("ed").value+'T'+document.getElementById("sdt2").value;
  828. if (vsdsd.length>16)
  829. {
  830. vsdsd=vsdsd.substring(0,16);
  831. }
  832. if (veded.length>16)
  833. {
  834. veded=veded.substring(0,16);
  835. }
  836. //var vsdsd=document.getElementById("sd").value.format("yyyy/MM/dd_HH:mm");
  837. //vsdsd=vsdsd.substring(0,16);
  838. //alert(vsdsd);
  839. //return;
  840. //12345
  841. var vItemNOSer=document.getElementById("ItemNOSer").value;
  842. if (vItemNOSer.length<1)
  843. {
  844. alert('請輸入預約人');
  845. return;
  846. }
  847. if((document.getElementById("sd").value<1) || (document.getElementById("ed").value<1) ||(document.getElementById("sdt1").value<1) || (document.getElementById("sdt2").value<1))
  848. {
  849. alert('請輸入開始與結束日期時間');
  850. return;
  851. }
  852. var vsdsd=document.getElementById("sd").value+'T'+document.getElementById("sdt1").value;
  853. //alert(vsdsd);
  854. //return;
  855. var veded =document.getElementById("ed").value+'T'+document.getElementById("sdt2").value;
  856. //alert(veded);
  857. if ((vsdsd.length<2)|| (veded.length<2))
  858. {
  859. alert('請輸入開始與結束日期時間');
  860. return;
  861. }
  862. vsdsd=vsdsd.replace('T','_');
  863. vsdsd=vsdsd.replace('-','/');
  864. vsdsd=vsdsd.replace('-','/');
  865. veded=veded.replace('T','_');
  866. veded=veded.replace('-','/');
  867. veded=veded.replace('-','/');
  868. vsdsd=vsdsd.substring(2,vsdsd.length);
  869. veded=veded.substring(2,veded.length);
  870. //alert(vsdsd);
  871. //alert(veded);
  872. var vtstp=vsdsd+','+veded;
  873. vtstpqr=vtstp;
  874. vtstpqr=vtstpqr.replace('_',' ');
  875. vtstpqr=vtstpqr.replace('_',' ');
  876. vtstpqr=vtstpqr.replace(',','~');
  877. //alert(vtstp);
  878. //return;
  879. if (document.getElementById("d11").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  880. {
  881. vvee1='1';
  882. //alert('bgreen');
  883. }else
  884. {
  885. vvee1='0';
  886. //alert('bgrey');
  887. }
  888. if (document.getElementById("d12").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  889. {
  890. vvee1=vvee1+'1';
  891. }else
  892. {
  893. vvee1=vvee1+'0';
  894. }
  895. if (document.getElementById("d13").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  896. {
  897. vvee1=vvee1+'1';
  898. }else
  899. {
  900. vvee1=vvee1+'0';
  901. }
  902. if (document.getElementById("d14").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  903. {
  904. vvee1=vvee1+'1';
  905. }else
  906. {
  907. vvee1=vvee1+'0';
  908. }
  909. if (document.getElementById("d15").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  910. {
  911. vvee1=vvee1+'1';
  912. }else
  913. {
  914. vvee1=vvee1+'0';
  915. }
  916. if (document.getElementById("d16").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  917. {
  918. vvee1=vvee1+'1';
  919. }else
  920. {
  921. vvee1=vvee1+'0';
  922. }
  923. if (document.getElementById("d17").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  924. {
  925. vvee1=vvee1+'1';
  926. }else
  927. {
  928. vvee1=vvee1+'0';
  929. }
  930. //alert(vvee1);
  931. if (document.getElementById("d21").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  932. {
  933. vvee2='1';
  934. //alert('bgreen');
  935. }else
  936. {
  937. vvee2='0';
  938. //alert('bgrey');
  939. }
  940. if (document.getElementById("d22").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  941. {
  942. vvee2=vvee2+'1';
  943. }else
  944. {
  945. vvee2=vvee2+'0';
  946. }
  947. if (document.getElementById("d23").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  948. {
  949. vvee2=vvee2+'1';
  950. }else
  951. {
  952. vvee2=vvee2+'0';
  953. }
  954. if (document.getElementById("d24").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  955. {
  956. vvee2=vvee2+'1';
  957. }else
  958. {
  959. vvee2=vvee2+'0';
  960. }
  961. if (document.getElementById("d25").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  962. {
  963. vvee2=vvee2+'1';
  964. }else
  965. {
  966. vvee2=vvee2+'0';
  967. }
  968. if (document.getElementById("d26").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  969. {
  970. vvee2=vvee2+'1';
  971. }else
  972. {
  973. vvee2=vvee2+'0';
  974. }
  975. if (document.getElementById("d27").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  976. {
  977. vvee2=vvee2+'1';
  978. }else
  979. {
  980. vvee2=vvee2+'0';
  981. }
  982. // alert(vvee2);
  983. if (document.getElementById("d31").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  984. {
  985. vvee3='1';
  986. //alert('bgreen');
  987. }else
  988. {
  989. vvee3='0';
  990. //alert('bgrey');
  991. }
  992. if (document.getElementById("d32").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  993. {
  994. vvee3=vvee3+'1';
  995. }else
  996. {
  997. vvee3=vvee3+'0';
  998. }
  999. if (document.getElementById("d33").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  1000. {
  1001. vvee3=vvee3+'1';
  1002. }else
  1003. {
  1004. vvee3=vvee3+'0';
  1005. }
  1006. if (document.getElementById("d34").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  1007. {
  1008. vvee3=vvee3+'1';
  1009. }else
  1010. {
  1011. vvee3=vvee3+'0';
  1012. }
  1013. if (document.getElementById("d35").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  1014. {
  1015. vvee3=vvee3+'1';
  1016. }else
  1017. {
  1018. vvee3=vvee3+'0';
  1019. }
  1020. if (document.getElementById("d36").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  1021. {
  1022. vvee3=vvee3+'1';
  1023. }else
  1024. {
  1025. vvee3=vvee3+'0';
  1026. }
  1027. if (document.getElementById("d37").style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  1028. {
  1029. vvee3=vvee3+'1';
  1030. }else
  1031. {
  1032. vvee3=vvee3+'0';
  1033. }
  1034. //alert(vvee3);
  1035. var ktype = '1';
  1036. if (vvee1=='0000000')
  1037. {
  1038. }else
  1039. {
  1040. ktype='2';
  1041. st1 = document.getElementById("st1").value.replace(':','') ;
  1042. et1= document.getElementById("et1").value.replace(':','') ;
  1043. if (st1.length==0 || et1.length==0)
  1044. {
  1045. alert('請選擇時段1的起始與結束時間');
  1046. return;
  1047. }
  1048. }
  1049. if (vvee2=='0000000')
  1050. {
  1051. }else
  1052. {
  1053. ktype='2';
  1054. st2 = document.getElementById("st2").value.replace(':','') ;
  1055. et2= document.getElementById("et2").value.replace(':','') ;
  1056. if (st2.length==0 || et2.length==0)
  1057. {
  1058. alert('請選擇時段2的起始與結束時間');
  1059. return;
  1060. }
  1061. }
  1062. if (vvee3=='0000000')
  1063. {
  1064. }else
  1065. {
  1066. ktype='2';
  1067. st3 = document.getElementById("st3").value.replace(':','') ;
  1068. et3= document.getElementById("et3").value.replace(':','') ;
  1069. //alert(st3.length)
  1070. if (st3.length==0 || et3.length==0)
  1071. {
  1072. alert('請選擇時段3的起始與結束時間');
  1073. return;
  1074. }
  1075. }
  1076. if (ktype=='2')
  1077. {
  1078. cycy=vvee1+','+st1 +','+ et1+','+ vvee2+','+st2+','+et2+','+vvee3+','+st3+','+et3;
  1079. vcyd='';
  1080. var vcy = cycy.split(',');
  1081. let days=[];
  1082. if (vcy[0]=='0000000')
  1083. {
  1084. }else
  1085. {
  1086. if (vcy[0].substring(0,1)=='1')
  1087. days.push('日');
  1088. if (vcy[0].substring(1,2)=='1')
  1089. days.push('一');
  1090. if (vcy[0].substring(2,3)=='1')
  1091. days.push('二');
  1092. if (vcy[0].substring(3,4)=='1')
  1093. days.push('三');
  1094. if (vcy[0].substring(4,5)=='1')
  1095. days.push('四');
  1096. if (vcy[0].substring(5,6)=='1')
  1097. days.push('五');
  1098. if (vcy[0].substring(6,7)=='1')
  1099. days.push('六');
  1100. vcy[1]=vcy[1].substring(0,2)+':'+vcy[1].substring(2,4);
  1101. vcy[2]=vcy[2].substring(0,2)+':'+vcy[2].substring(2,4);
  1102. vcyd=vcyd+'#1.'+vcy[1]+'~'+vcy[2]+' '+' '+days.join(',');
  1103. }
  1104. days=[];
  1105. if (vcy[3]=='0000000')
  1106. {
  1107. }else
  1108. {
  1109. if (vcy[3].substring(0,1)=='1')
  1110. days.push('日');
  1111. if (vcy[3].substring(1,2)=='1')
  1112. days.push('一');
  1113. if (vcy[3].substring(2,3)=='1')
  1114. days.push('二');
  1115. if (vcy[3].substring(3,4)=='1')
  1116. days.push('三');
  1117. if (vcy[3].substring(4,5)=='1')
  1118. days.push('四');
  1119. if (vcy[3].substring(5,6)=='1')
  1120. days.push('五');
  1121. if (vcy[3].substring(6,7)=='1')
  1122. days.push('六');
  1123. vcy[4]=vcy[4].substring(0,2)+':'+vcy[4].substring(2,4);
  1124. vcy[5]=vcy[5].substring(0,2)+':'+vcy[5].substring(2,4);
  1125. vcyd=vcyd+'#2.'+vcy[4]+'~'+vcy[5]+' '+' '+days.join(',');
  1126. }
  1127. days=[];
  1128. if (vcy[6]=='0000000')
  1129. {
  1130. }else
  1131. {
  1132. if (vcy[6].substring(0,1)=='1')
  1133. days.push('日');
  1134. if (vcy[6].substring(1,2)=='1')
  1135. days.push('一');
  1136. if (vcy[6].substring(2,3)=='1')
  1137. days.push('二');
  1138. if (vcy[6].substring(3,4)=='1')
  1139. days.push('三');
  1140. if (vcy[6].substring(4,5)=='1')
  1141. days.push('四');
  1142. if (vcy[6].substring(5,6)=='1')
  1143. days.push('五');
  1144. if (vcy[6].substring(6,7)=='1')
  1145. days.push('六');
  1146. vcy[7]=vcy[7].substring(0,2)+':'+vcy[7].substring(2,4);
  1147. vcy[8]=vcy[8].substring(0,2)+':'+vcy[8].substring(2,4);
  1148. vcyd=vcyd+'#3.'+vcy[7]+'~'+vcy[8]+' '+' '+days.join(',');
  1149. }
  1150. }
  1151. else
  1152. {
  1153. //cycy='';
  1154. }
  1155. fincycle='';
  1156. fincycle= document.getElementById("ItemNOSer").value+';';
  1157. fincycle=fincycle+ vtstp+';';
  1158. fincycle=fincycle+cycy+';';
  1159. //alert(cycy);
  1160. // alert(fincycle);
  1161. if (orgcycle==fincycle)
  1162. {
  1163. issame=true;
  1164. // alert('相同');
  1165. }
  1166. vtttt = document.getElementById("ItemNOSer").value;
  1167. if (issame)
  1168. {
  1169. vsn='';
  1170. try
  1171. {
  1172. vtttt = document.getElementById("ItemNOSer").value;
  1173. var jsonString = "{\"action\":\"shareQr\", \"serial\":\"001\",\"data\":{\"name\":\""+kname+"\",\"note\":\""+vtttt+"\",\"QRCode\":\""+vvqrcd+"\",\"time\":\""+vtstpqr+"\",\"cycle\":\""+vcyd+"\"}}";
  1174. if (TYPE=='IOS')
  1175. {
  1176. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1177. }
  1178. if (TYPE=='ANDROID')
  1179. {
  1180. webSocket.send(jsonString);
  1181. }
  1182. if (TYPE=='PC')
  1183. {
  1184. shareQrPC(jsonString);
  1185. }
  1186. }catch(e)
  1187. {
  1188. //alert(e);
  1189. alert('連線異常');
  1190. }
  1191. }
  1192. else
  1193. {
  1194. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
  1195. // alert(document.getElementById("ItemNOSer").value);
  1196. vtttt = document.getElementById("ItemNOSer").value;
  1197. // alert(ktype);
  1198. // return;
  1199. var edata456 ="{\"action\":\"mqttupdateRemoteKey\",\"data\":{\"Command\":\"PassWord="+PW+"&ReGenerate=1&Stat=1&Type="+ktype+"&IndexID="+idx+"&TimeStamp="+vtstp+"&Cycle="+cycy+"&UserID="+ID+"&Title="+vtttt+"\",\"SerialNo\":\"ReservePC"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  1200. var jsonString333 = "{\"action\":\"encode\", \"serial\":\"003\",\"data\":"+edata456+"}";
  1201. vsn='003';
  1202. //updateOutput(jsonString);
  1203. //alert(jsonString);
  1204. //return;
  1205. if (TYPE=='IOS')
  1206. {
  1207. window.webkit.messageHandlers.WebToApp.postMessage(jsonString333);
  1208. }
  1209. if (TYPE=='ANDROID')
  1210. {
  1211. webSocket.send(jsonString333);
  1212. }
  1213. if (TYPE=='PC')
  1214. {
  1215. selfendecode(edata456);
  1216. }
  1217. }
  1218. }
  1219. function btnitemback(vid)
  1220. {
  1221. try
  1222. {
  1223. //alert(vid);
  1224. // alert(document.getElementById(vid).style.backgroundImage.slice(4, -1).replace(/"/g, ""));
  1225. if (document.getElementById(vid).style.backgroundImage.slice(4, -1).replace(/"/g, "").includes('bgreen.png'))
  1226. {
  1227. document.getElementById(vid).style.background="url('image/bgrey.png') no-repeat center/100%";
  1228. }else
  1229. {
  1230. document.getElementById(vid).style.background="url('image/bgreen.png') no-repeat center/100%";
  1231. }
  1232. }catch(e)
  1233. {
  1234. alert(e);
  1235. }
  1236. }
  1237. function btndddel()
  1238. {
  1239. var yes = confirm('確定刪除?');
  1240. if (yes) {
  1241. try
  1242. {
  1243. //alert('ue');
  1244. //return;
  1245. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
  1246. // alert(document.getElementById("ItemNOSer").value);
  1247. vtttt = document.getElementById("ItemNOSer").value;
  1248. // alert(ktype);
  1249. // return;
  1250. var edata3 ="";
  1251. edata3 ="{\"action\":\"mqttdeleteRemoteKey\",\"data\":{\"Command\":\"PassWord="+PW+"&IndexID="+idx+"&UserID="+ID+"\",\"SerialNo\":\"ReservePC"+CID+"1-"+SubID+"\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  1252. // alert(edata);
  1253. var jsonString4 ="";
  1254. jsonString4 = "{\"action\":\"encode\", \"serial\":\"101\",\"data\":"+edata3+"}";
  1255. vsn='101';
  1256. // updateOutput(jsonString);
  1257. //alert(jsonString);
  1258. //return;
  1259. if (TYPE=='IOS')
  1260. {
  1261. window.webkit.messageHandlers.WebToApp.postMessage(jsonString4);
  1262. }
  1263. if (TYPE=='ANDROID')
  1264. {
  1265. webSocket.send(jsonString4);
  1266. }
  1267. if (TYPE=='PC')
  1268. {
  1269. selfendecode(edata3);
  1270. }
  1271. }
  1272. catch(e)
  1273. {
  1274. alert('連線異常');
  1275. }
  1276. } else {
  1277. }
  1278. }
  1279. function getdoorlist()
  1280. {
  1281. var vt=new Date().format("yyyy/MM/dd_HH:mm:ss")
  1282. var edata ="{\"action\":\"mqttqueryCallList\",\"data\":{\"Command\":\"PassWord="+PW+"\",\"SerialNo\":\"ReservePC"+CID+"1\",\"TimeStamp\":\""+vt+"\",\"Token\":\"Gigatech23634857\"}}";
  1283. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+edata+"}";
  1284. vsn='001';
  1285. // updateOutput(jsonString);
  1286. isget2=false;
  1287. if (TYPE=='IOS')
  1288. {
  1289. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1290. }
  1291. if (TYPE=='ANDROID')
  1292. {
  1293. webSocket.send(jsonString);
  1294. }
  1295. if (TYPE=='PC')
  1296. {
  1297. selfendecode(edata);
  1298. }
  1299. }
  1300. </script>
  1301. <script type="text/javascript">
  1302. var webSocket;
  1303. var input = document.getElementById("input")
  1304. var output = document.getElementById("output");
  1305. var vdata="";
  1306. var isok=true;
  1307. var webSocket;
  1308. //var connectBtn = document.getElementById("connectBtn");
  1309. //var wsUrl = "ws://localhost:2980/";
  1310. // var wsUrl = "ws://192.168.0.27:2980/";
  1311. // var wsUrl = "ws://192.168.0.30:2980/";
  1312. var wsUrl = "ws://127.0.0.1:2980/";
  1313. //var wsUrl = "ws://192.168.0.25:2980/";
  1314. function connect()
  1315. {
  1316. // open the connection if one does not exist
  1317. if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED)
  1318. {
  1319. return;
  1320. }
  1321. // updateOutput("Trying to establish a WebSocket connection to <code>" + wsUrl + "</code>");
  1322. // Create a websocket
  1323. webSocket = new WebSocket(wsUrl);
  1324. webSocket.onopen = function(event) {
  1325. };
  1326. webSocket.onmessage = function(event)
  1327. {
  1328. var ress = event.data;
  1329. if (is2=='001' )
  1330. {
  1331. var vobj = JSON.parse( ress);
  1332. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}");
  1333. message4.destinationName = SN ;
  1334. message4.retained = false;
  1335. message4.qos = 0;
  1336. client.send(message4);
  1337. is2='002';
  1338. }
  1339. if (is2=='002' )
  1340. {
  1341. var vobj = JSON.parse(ress);
  1342. if (vobj.success===true)
  1343. {
  1344. alert('OK');
  1345. }
  1346. else
  1347. {
  1348. alert('失敗');
  1349. }
  1350. is2='';
  1351. }
  1352. };
  1353. webSocket.onclose = function(event) {
  1354. // updateOutput("Connection Closed");
  1355. //connectBtn.disabled = false;
  1356. //sendBtn.disabled = true;
  1357. };
  1358. }
  1359. function shareQr() {
  1360. var text = input.value;
  1361. var jsonString = "{\"action\":\"shareQr\", \"serial\":\"001\",\"data\":\""+text+"\"}";
  1362. //updateOutput(jsonString);
  1363. /// "WebToApp". 為我們和前端開發人員的約定
  1364. if (TYPE=='IOS')
  1365. {
  1366. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1367. }
  1368. if (TYPE=='ANDROID')
  1369. {
  1370. webSocket.send(jsonString);
  1371. }
  1372. }
  1373. function shareQrPC(message) {
  1374. message=message.replaceAll('=','-');
  1375. message=message.replaceAll('#','*');
  1376. // alert('shareQrPC '+message);
  1377. //alert("index4.html?idx="+vvvi+"&tt="+"&qrcd=&cy="+"&name="+kname+"&st="+"&et="+"&tp=1"+"&CID="+CID+"&ID="+kkid+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID);
  1378. //document.location = "index4.html?idx="+vvvi+"&tt="+"&qrcd=&cy="+"&name="+kname+"&st="+"&et="+"&tp=1"+"&CID="+CID+"&ID="+kkid+"&PW="+PW+"&TYPE="+TYPE+"&SN="+SN+"&MQTT="+vmqtt+"&SubID="+SubID+"&sqr="+message;
  1379. }
  1380. //self start
  1381. function selfendecode(message) {
  1382. if (vsn=='002'||vsn=='103')
  1383. {
  1384. isget=true;
  1385. // alert(vsn);
  1386. message = teaDecrypt(message,'75$095huOQ77kKv!');
  1387. // alert('002 or 103 '+message);
  1388. var ress = message;
  1389. vsn='104';
  1390. try
  1391. {
  1392. // var vobj = JSON.parse( ress);
  1393. //alert( vobj.data);
  1394. //var sevobj = JSON.parse( vobj);
  1395. // alert('de'+ ress);
  1396. senttoother();
  1397. alert('OK');
  1398. //23456
  1399. window.history.go(-1);
  1400. //document.location = "index2.html?KID="+ID +"&name="+ kname;
  1401. }catch(e)
  1402. {
  1403. alert(e);
  1404. }
  1405. }
  1406. if (vsn=='004')
  1407. {
  1408. //alert('004');
  1409. vsn='';
  1410. message = teaDecrypt(message,'75$095huOQ77kKv!');
  1411. isget3 = true;
  1412. var ress = message;
  1413. try
  1414. {
  1415. // alert('de'+ ress);
  1416. vobj = JSON.parse( ress);
  1417. var qrcd= vobj.data.CardID;
  1418. alert('004 '+message);
  1419. // var qrcd= vobj.data.data.CardID;
  1420. // alert( qrcd);
  1421. //var sevobj = JSON.parse( vobj);
  1422. // alert('de'+ ress);
  1423. //alert('OK');
  1424. //window.history.go(-1);
  1425. //document.location = "index2.html?KID="+ID +"&name="+ kname;
  1426. //"name":"健身房","note":"王大明09123456789","QRCode":"KaiZvhWz5dcUqkkuvAK0q6T/iw4dbE7CpGKDozTFL2LkH6g1YRdayW=="
  1427. // alert(vtttt);
  1428. //vcyd
  1429. var jsonString = "{\"action\":\"shareQr\", \"serial\":\"001\",\"data\":{\"name\":\""+kname+"\",\"note\":\""+vtttt+"\",\"QRCode\":\""+qrcd+"\",\"time\":\""+vtstpqr+"\",\"cycle\":\""+vcyd+"\"}}";
  1430. // alert(jsonString);
  1431. // updateOutput(jsonString);
  1432. /// "WebToApp". 為我們和前端開發人員的約定
  1433. orgcycle=fincycle;
  1434. vvqrcd=qrcd;
  1435. senttoother();
  1436. if (TYPE=='IOS')
  1437. {
  1438. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1439. }
  1440. if (TYPE=='ANDROID')
  1441. {
  1442. webSocket.send(jsonString);
  1443. }
  1444. if (TYPE=='PC')
  1445. {
  1446. shareQrPC(jsonString);
  1447. }
  1448. }catch(e)
  1449. {
  1450. alert(e);
  1451. }
  1452. }
  1453. if (vsn=='001')
  1454. {
  1455. try
  1456. {
  1457. // alert( '001');
  1458. message = teaEncrypt(message,'75$095huOQ77kKv!');
  1459. var ress = message;
  1460. // alert( ress);
  1461. isget2=true;
  1462. // vobj = JSON.parse( ress);
  1463. isget=false;
  1464. // vdata = "{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}";
  1465. }catch(e)
  1466. {
  1467. alert(e);
  1468. }
  1469. //updateOutput('---------------------------');
  1470. // updateOutput(vdata);
  1471. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  1472. message4.destinationName = SN ;
  1473. message4.retained = false;
  1474. message4.qos = 0;
  1475. var vivi = 0;
  1476. // client.send(message);
  1477. intervalID = setInterval(() => {
  1478. if (isget)
  1479. {
  1480. }
  1481. else
  1482. {
  1483. if (vivi>15)
  1484. {
  1485. clearInterval(intervalID);
  1486. alert('連線超過時間');
  1487. }else
  1488. {
  1489. vivi++;
  1490. if (isconn)
  1491. {
  1492. client.send(message4);
  1493. }
  1494. }
  1495. }
  1496. }, 400);
  1497. }
  1498. if (vsn=='101')
  1499. {
  1500. try
  1501. {
  1502. vsn='102';
  1503. // alert( '102');
  1504. message = teaEncrypt(message,'75$095huOQ77kKv!');
  1505. var ress = message;
  1506. // alert( ress);
  1507. // vobj = JSON.parse( ress);
  1508. isget=false;
  1509. // vdata = "{\"encrypt\":\"1\",\"data\":\""+message+"\"}";
  1510. //updateOutput('---------------------------');
  1511. // updateOutput(vdata);
  1512. message9 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  1513. message9.destinationName = SN ;
  1514. message9.retained = false;
  1515. message9.qos = 0;
  1516. var vivi = 0;
  1517. // client.send(message);
  1518. intervalID = setInterval(() => {
  1519. if (isget)
  1520. {
  1521. }
  1522. else
  1523. {
  1524. if (vivi>15)
  1525. {
  1526. clearInterval(intervalID);
  1527. alert('連線超過時間');
  1528. }else
  1529. {
  1530. if (isconn)
  1531. {
  1532. client.send(message9);
  1533. }
  1534. vivi++;
  1535. }
  1536. }
  1537. }, 400);
  1538. }catch(e)
  1539. {
  1540. alert(e);
  1541. }
  1542. }
  1543. if (vsn=='003')
  1544. {
  1545. try
  1546. {
  1547. // alert( '003');
  1548. message = teaEncrypt(message,'75$095huOQ77kKv!');
  1549. var ress = message;
  1550. // alert( ress);
  1551. // vobj = JSON.parse( ress);
  1552. isget3=false;
  1553. // vdata = "{\"encrypt\":\"1\",\"data\":\""+message+"\"}";
  1554. }catch(e)
  1555. {
  1556. alert(e);
  1557. }
  1558. //updateOutput('---------------------------');
  1559. // updateOutput(vdata);
  1560. message6= new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+message+"\"}");
  1561. message6.destinationName = SN ;
  1562. message6.retained = false;
  1563. message6.qos = 0;
  1564. //setTimeout(() => {
  1565. var vivi = 0;
  1566. intervalID = setInterval(() => {
  1567. if (isget3)
  1568. {
  1569. }
  1570. else
  1571. {
  1572. if (vivi>15)
  1573. {
  1574. alert('連線超過時間');
  1575. clearInterval(intervalID);
  1576. }else
  1577. {
  1578. vivi++;
  1579. if (isconn)
  1580. {
  1581. client.send(message6);
  1582. }
  1583. }
  1584. }
  1585. }, 400);
  1586. }
  1587. // updateOutput(message);
  1588. }
  1589. //self end
  1590. function AppToWeb(message)
  1591. {
  1592. if (is2=='001' )
  1593. {
  1594. var vobj = JSON.parse( message);
  1595. message4 = new Paho.MQTT.Message("{\"encrypt\":\"1\",\"data\":\""+vobj.data+"\"}");
  1596. message4.destinationName = SN ;
  1597. message4.retained = false;
  1598. message4.qos = 0;
  1599. client.send(message4);
  1600. is2='002';
  1601. }
  1602. else
  1603. {
  1604. var ress = message;
  1605. var vobj = JSON.parse(ress);
  1606. if (vobj.success===true)
  1607. {
  1608. alert('OK');
  1609. }
  1610. else
  1611. {
  1612. alert('失敗');
  1613. }
  1614. is2='';
  1615. }
  1616. }
  1617. function endode() {
  1618. var text = input.value;
  1619. var jsonString = "{\"action\":\"encode\", \"serial\":\"001\",\"data\":"+text+"}";
  1620. // updateOutput(jsonString);
  1621. /// "WebToApp". 為我們和前端開發人員的約定
  1622. if (TYPE=='IOS')
  1623. {
  1624. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1625. }
  1626. if (TYPE=='ANDROID')
  1627. {
  1628. webSocket.send(jsonString);
  1629. }
  1630. }
  1631. function decode() {
  1632. var text = input.value;
  1633. var jsonString = "{\"action\":\"decode\", \"serial\":\"001\",\"data\":\""+text+"\"}";
  1634. //updateOutput(jsonString);
  1635. /// "WebToApp". 為我們和前端開發人員的約定
  1636. if (TYPE=='IOS')
  1637. {
  1638. window.webkit.messageHandlers.WebToApp.postMessage(jsonString);
  1639. }
  1640. if (TYPE=='ANDROID')
  1641. {
  1642. webSocket.send(jsonString);
  1643. }
  1644. }
  1645. function updateOutput(text) {
  1646. output.innerHTML += "<br/>" + text;
  1647. }
  1648. </script>
  1649. <script>
  1650. var getUrlParameter = function getUrlParameter(sParam) {
  1651. var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  1652. sURLVariables = sPageURL.split('&'),
  1653. sParameterName,
  1654. i;
  1655. for (i = 0; i < sURLVariables.length; i++) {
  1656. sParameterName = sURLVariables[i].split('=');
  1657. if (sParameterName[0] === sParam) {
  1658. return sParameterName[1] === undefined ? true : sParameterName[1];
  1659. }
  1660. }
  1661. };
  1662. Date.prototype.format = function (format) {
  1663. //eg:format="yyyy-MM-dd hh:mm:ss";
  1664. if (!format) {
  1665. format = "yyyy-MM-dd hh:mm:ss";
  1666. }
  1667. var o = {
  1668. "M+": this.getMonth() + 1, // month
  1669. "d+": this.getDate(), // day
  1670. "H+": this.getHours(), // hour
  1671. "h+": this.getHours(), // hour
  1672. "m+": this.getMinutes(), // minute
  1673. "s+": this.getSeconds(), // second
  1674. "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
  1675. "S": this.getMilliseconds()
  1676. };
  1677. if (/(y+)/.test(format)) {
  1678. format = format.replace(RegExp.$1, (this.getFullYear() + "")
  1679. .substr(4 - RegExp.$1.length));
  1680. }
  1681. for (var k in o) {
  1682. if (new RegExp("(" + k + ")").test(format)) {
  1683. format = format.replace(RegExp.$1, RegExp.$1.length == 1
  1684. ? o[k]
  1685. : ("00" + o[k]).substr(("" + o[k]).length));
  1686. }
  1687. }
  1688. return format;
  1689. };
  1690. </script>
  1691. <br>
  1692. </body>
  1693. </html>