預約系統 IOS / Android Windows

index4.html 49KB

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