1
0

dry_container_schedule.html 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>{{ title }}</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- 新 Bootstrap4 核心 CSS 文件 -->
  8. <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
  9. <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
  10. <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  11. <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
  12. <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
  13. <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
  14. <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  15. <!--可用來建立使用者小圖示-->
  16. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  17. <style>
  18. .newcondition_css {
  19. padding: 10px;
  20. margin-top: 10px;
  21. background-color:honeydew;
  22. }
  23. hr {
  24. margin-top: 5px;
  25. margin-bottom: 5px;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <!-- <h6>感測器數值</h6>
  31. 入料儲豆槽液位計高度(cm) : !測試時請用生豆高度! {{input_UltraSonic.UltraSonic}}
  32. <div id="input_UltraSonic" d={{input_UltraSonic.UltraSonic}} style="display:none"></div>
  33. <br>
  34. 設定空桶高度應低於 10
  35. <br>
  36. 乾燥槽液位計高度(cm) : !測試時請用生豆高度! {{tank_UltraSonic.UltraSonic}}
  37. <div id="tank_UltraSonic" d={{tank_UltraSonic.UltraSonic}} style="display:none"></div>
  38. <br> -->
  39. <!-- <h6>入料排程</h6>
  40. 設定入料儲豆槽生豆高度(cm) :
  41. <input name="schedule_input_height" id="schedule_input_height" type="text" style="width:100px;" value="70">
  42. <br>
  43. 設定吸料時間(s) :
  44. <input name="schedule_tank_vacuumin" id="schedule_tank_vacuumin" type="text" style="width:100px;" value="5">
  45. <br>
  46. 設定放料時間(s) :
  47. <input name="schedule_tank_vacuumout" id="schedule_tank_vacuumout" type="text" style="width:100px;" value="10">
  48. <br>
  49. 設定乾燥槽生豆高度(cm) :
  50. <input name="schedule_tank_height" id="schedule_tank_height" type="text" style="width:100px;" value="70">
  51. <br>
  52. 入料時馬達轉速(rpm) :
  53. <input name="schedule_tank_motorrpm" id="schedule_tank_motorrpm" type="text" style="width:100px;" value="10">
  54. <br>
  55. <button type="submit" class="btn btn-primary" onclick="schedule_Start()">開始入料</button> -->
  56. <script>
  57. function schedule_Start() {
  58. //word = document.getElementById("schedule_SOP").innerHTML;
  59. //document.getElementById("schedule_SOP").innerHTML = word+'<br>*';
  60. var schedule_input_height = $("input[name=schedule_input_height]").val();
  61. var schedule_tank_vacuumin = $("input[name=schedule_tank_vacuumin]").val();
  62. var schedule_tank_vacuumout = $("input[name=schedule_tank_vacuumout]").val();
  63. var schedule_tank_height = $("input[name=schedule_tank_height]").val();
  64. var schedule_tank_motorrpm = $("input[name=schedule_tank_motorrpm]").val();
  65. var tank_UltraSonic = parseInt(document.getElementById('tank_UltraSonic').getAttribute('d'));
  66. // 入料判斷
  67. if (schedule_input_height <= input_UltraSonic) {
  68. console.log('儲豆槽達指定高度')
  69. console.log('tank_UltraSonic:' + tank_UltraSonic)
  70. if (tank_UltraSonic <= 10) {
  71. var DRY_STATE = 'Ready'
  72. console.log('乾燥桶為空, 狀態為 Ready, 準備入料')
  73. // 開始入料
  74. while (schedule_tank_height >= tank_UltraSonic) {
  75. // 真空吸料機 ON
  76. var data = { "tank-number": "1", "command": "tank_vacuum_status", "value": "on" };
  77. console.log('data:', data)
  78. /*
  79. $.post('/mqtt/{{tid}}', data, function (res) {
  80. console.log('真空吸料機 '+res)
  81. }, 'text')
  82. */
  83. // 吸料時間
  84. var time = new Date();
  85. while ((new Date() - time) < schedule_tank_vacuumin * 1000) { }
  86. // 真空吸料機 OFF
  87. var data = { "tank-number": "1", "command": "tank_vacuum_status", "value": "off" };
  88. console.log('data:', data)
  89. /*
  90. $.post('/mqtt/{{tid}}', data, function (res) {
  91. console.log('真空吸料機 '+ res)
  92. }, 'text')
  93. */
  94. // 放料時間
  95. var time = new Date();
  96. while ((new Date() - time) < schedule_tank_vacuumout * 1000) { }
  97. location.reload();
  98. }
  99. console.log('乾燥桶生豆以達指定高度, 入料結束')
  100. } else { console.log('乾燥桶不為空, 無法入料') }
  101. } else { console.log('儲豆槽未達指定高度, 無法入料') }
  102. }
  103. </script>
  104. <!-- [物件]文字輸入框 選擇後連結 [動作]文字輸入框 -->
  105. <script>
  106. dry_object = new Array();
  107. dry_object[0] = ["-"]; // 制動器 / 感測器
  108. dry_object[1] = ["on", "off"]; // 入料真空吸料機
  109. dry_object[2] = ["on", "off"]; // 真空吸料機
  110. dry_object[3] = ["ON 吸料", "OFF 排氣"]; // 入料三通閥
  111. dry_object[4] = ["0", "10", "20", "30", "40", "50"]; // 馬達
  112. dry_object[5] = ["on", "off"]; // 鼓風機
  113. dry_object[6] = ["on", "off"]; // 加熱器 1
  114. dry_object[7] = ["on", "off"]; // 加熱器 2
  115. dry_object[8] = ["on", "off"]; // 蝴蝶閥
  116. dry_object[9] = ["on", "off"]; // 消毒電磁閥
  117. dry_object[10] = ["on", "off"]; // 排水電磁閥
  118. dry_object[11] = ["on", "off"]; // 夾層進水電磁閥
  119. dry_object[12] = ["on", "off"]; // 溫控開關
  120. dry_object[13] = ["0.0", "28.0", "30.0", "32.0", "34.0", "36.0", "38.0", "40.0", "42.0", "44.0", "46.0", "48.0", "50.0"]; // 設定溫度
  121. dry_object[14] = ["on", "off"]; // 出料真空吸料機
  122. dry_object[15] = ["1", "5", "10", "30", "60"]; // 暫停秒數
  123. // dry_object[14] = ["on", "off"]; // 入料儲豆槽_液位計
  124. // dry_object[15] = ["on", "off"]; // 液位計
  125. // dry_object[16] = ["on", "off"]; // SHT11_溫度
  126. // dry_object[17] = ["on", "off"]; // SHT11_濕度
  127. // dry_object[18] = ["on", "off"]; // 土壤三合一_溫度
  128. // dry_object[19] = ["on", "off"]; // 土壤三合一_濕度
  129. // dry_object[20] = ["on", "off"]; // 土壤三合一_EC
  130. // dry_object[21] = ["on", "off"]; // 氣壓
  131. // dry_object[22] = ["on", "off"]; // 出料儲豆槽_液位計
  132. function renew(obj_num, index) {
  133. var Value="";
  134. for(var i=0; i<dry_object[index].length; i++){
  135. Value = Value + '<option value=' + dry_object[index][i] + '> ' + dry_object[index][i] + '</option>';
  136. }
  137. var sectorSelect = document.getElementById("do_act" + obj_num);
  138. // console.log("sectorSelect: " + sectorSelect)
  139. sectorSelect.innerHTML = Value;
  140. }
  141. </script>
  142. <br>
  143. <div id="box">
  144. <div id="newcondition_1" class="newcondition_css">
  145. <!-- 總 條件 -->
  146. <div id="condition1">
  147. <!-- 子條件 1_1-->
  148. <div id="condition1_1">
  149. 條件
  150. <select id="cond_z1_1">
  151. <option value="if">if</option>
  152. <option value="while">while</option>
  153. </select>
  154. <select id="cond_tank1_1">
  155. <option value="D1">乾燥桶 D1</option>
  156. <option value="D2">乾燥桶 D2</option>
  157. <option value="D3">乾燥桶 D3</option>
  158. <option value="D4">乾燥桶 D4</option>
  159. <option value="D5">乾燥桶 D5</option>
  160. <option value="D6">乾燥桶 D6</option>
  161. <option value="D7">乾燥桶 D7</option>
  162. <option value="D8">乾燥桶 D8</option>
  163. <option value="D9">乾燥桶 D9</option>
  164. <option value="D10">乾燥桶 D10</option>
  165. <option value="D11">乾燥桶 D11</option>
  166. <option value="D12">乾燥桶 D12</option>
  167. </select>
  168. <select id="cond_a1_1">
  169. <option value="">制動器 / 感測器</option>
  170. <optgroup label="制動器">
  171. <option value="input_vacuum_status">入料真空吸料機</option>
  172. <option value="tank_vacuum_status">真空吸料機</option>
  173. <option value="tank_threewayvalve_input_status">入料三通閥</option>
  174. <option value="tank_motor_status">馬達</option>
  175. <option value="tank_blower_status">鼓風機</option>
  176. <option value="tank_heater1_status">加熱器 1</option>
  177. <option value="tank_heater2_status">加熱器 2</option>
  178. <option value="tank_diskvalve_status">蝴蝶閥</option>
  179. <option value="tank_solenoid_disinfect_status">消毒電磁閥</option>
  180. <option value="tank_solenoid_water_out_status">排水電磁閥</option>
  181. <option value="outer_solenoid_water_status">夾層進水電磁閥</option>
  182. <option value="tank_temp_enable">溫控開關</option>
  183. <option value="tank_temp">設定溫度</option>
  184. <option value="output_vacuum">出料真空吸料機</option>
  185. </optgroup>
  186. <optgroup label="感測器">
  187. <option value="input_UltraSonic">入料儲豆槽_液位計(cm)</option>
  188. <option value="tank_UltraSonic">液位計(cm)</option>
  189. <option value="tank_SHT11_Temp">SHT11_溫度(℃)</option>
  190. <option value="tank_SHT11_Humidity">SHT11_濕度(%)</option>
  191. <option value="tank_soil_Temp">土壤三合一_溫度(℃)</option>
  192. <option value="tank_soil_Humidity">土壤三合一_濕度(%)</option>
  193. <option value="tank_soil_EC">土壤三合一_EC(%)</option>
  194. <option value="tank_PA">氣壓(PA)</option>
  195. <option value="output_UltraSonic">出料儲豆槽_液位計(cm)</option>
  196. </optgroup>
  197. </select>
  198. <select id="cond_b1_1">
  199. <option value="equal">==</option>
  200. <option value="morethan">&gt;=</option>
  201. <option value="lessthan">&lt;=</option>
  202. </select>
  203. <input list="cond_list_c1_1" id="cond_c1_1">
  204. <datalist id="cond_list_c1_1">
  205. <option value="on">
  206. <option value="off">
  207. <option value="(或請自行輸入數值)">
  208. </datalist>
  209. <input type="button" id="cond_add1_1" value="條件++" onclick="cond_add(cond_add1_1);"><br>
  210. <script>
  211. var cond_add_child_i = 1 // 這是子條件
  212. function cond_add(evt) { // cond_add1_1 下一個是 cond_add1(條件)_2(子條件)
  213. evt.style.display = "none"; // 不顯示原按鈕
  214. var condadd_parent_num = String(evt.id).split('_')[1].slice(3, ) // 把第一個條件的編號記下
  215. // console.log("condadd_parent_num: " + condadd_parent_num)
  216. cond_add_child_i++
  217. var html = '';
  218. html +=
  219. '<div id="condition' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  220. '<select id="cond_d' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  221. '<option value="and">and</option>' +
  222. '<option value="or">or</option>' +
  223. '</select>' +
  224. '<select id="cond_a' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  225. '<optgroup label="制動器">' +
  226. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  227. '<option value="tank_vacuum_status">真空吸料機</option>' +
  228. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  229. '<option value="tank_motor_status">馬達</option>' +
  230. '<option value="tank_blower_status">鼓風機</option>' +
  231. '<option value="tank_heater1_status">加熱器 1</option>' +
  232. '<option value="tank_heater2_status">加熱器 2</option>' +
  233. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  234. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  235. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  236. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  237. '<option value="tank_temp_enable">溫控開關</option>' +
  238. '<option value="tank_temp">設定溫度</option>' +
  239. '<option value="output_vacuum">出料真空吸料機</option>' +
  240. '</optgroup>' +
  241. '<optgroup label="感測器">' +
  242. '<option value="input_UltraSonic">入料儲豆槽_液位計(cm)</option>' +
  243. '<option value="tank_UltraSonic">液位計(cm)</option>' +
  244. '<option value="tank_SHT11_Temp">SHT11_溫度(℃)</option>' +
  245. '<option value="tank_SHT11_Humidity">SHT11_濕度(%)</option>' +
  246. '<option value="tank_soil_Temp">土壤三合一_溫度(℃)</option>' +
  247. '<option value="tank_soil_Humidity">土壤三合一_濕度(%)</option>' +
  248. '<option value="tank_soil_EC">土壤三合一_EC(%)</option>' +
  249. '<option value="tank_PA">氣壓(PA)</option>' +
  250. '<option value="output_UltraSonic">出料儲豆槽_液位計(cm)</option>' +
  251. '</optgroup>' +
  252. '</select>' +
  253. '<select id="cond_b' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  254. '<option value="equal">==</option>' +
  255. '<option value="morethan">&gt;=</option>' +
  256. '<option value="lessthan">&lt;=</option>' +
  257. '</select>' +
  258. '<input list="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '" id="cond_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  259. '<datalist id="cond_list_c' + condadd_parent_num + '_' + cond_add_child_i + '">' +
  260. '<option value="on">' +
  261. '<option value="off">' +
  262. '<option value="(或請自行輸入數值)">' +
  263. '</datalist>' +
  264. '<input type="button" id="cond_del' + condadd_parent_num + '_' + cond_add_child_i + '" value="條件--" onclick="cond_del(\'' + condadd_parent_num + '_' + cond_add_child_i + '\');">' +
  265. '<input type="button" id="cond_add' + condadd_parent_num + '_' + cond_add_child_i + '" value="條件++" onclick="cond_add(cond_add' + condadd_parent_num + '_' + cond_add_child_i + ');"><br>' +
  266. '</div>';
  267. var divbox = document.getElementById('condition' + condadd_parent_num);
  268. divbox.insertAdjacentHTML('beforeend', html);
  269. }
  270. function cond_del(evt) {
  271. // console.log('evt: ' + evt)
  272. var del_cond_child = document.getElementById('condition' + evt);
  273. // console.log("del_cond_child: " + del_cond_child)
  274. del_cond_child.innerHTML = ""
  275. var parentObj = del_cond_child.parentNode; // 取得欲刪除 div 的父類別
  276. parentObj.removeChild(del_cond_child) // 刪除 div
  277. // 上一個按鈕要顯示出來
  278. var del_cond_parent_num = String(evt).split('_')[0]
  279. var del_cond_child_num = String(evt).split('_')[1]
  280. // console.log('del_cond_parent_num: ' + del_cond_parent_num)
  281. // console.log('del_cond_child_num: ' + del_cond_child_num)
  282. var button_return_id = document.getElementById('cond_add' + del_cond_parent_num + '_' + String(parseInt(del_cond_child_num)-1));
  283. // console.log("test: " + 'cond_add' + del_cond_parent_num + '_' + String(parseInt(del_cond_child_num)-1))
  284. // console.log("button_return_id: " + button_return_id) // null
  285. if (button_return_id == null) {
  286. var button_return_id = document.getElementById('cond_add' + del_cond_parent_num + '_1');
  287. }
  288. button_return_id.style.display = "inline";
  289. }
  290. </script>
  291. </div>
  292. </div>
  293. <div id="action1">
  294. <div id="action1_1">
  295. 物件 :
  296. <select id="do_obj1_1" onChange="renew('1_1', this.selectedIndex);">
  297. <option value="">制動器</option>
  298. <option value="input_vacuum_status">入料真空吸料機</option>
  299. <option value="tank_vacuum_status">真空吸料機</option>
  300. <option value="tank_threewayvalve_input_status">入料三通閥</option>
  301. <option value="tank_motor_status">馬達</option>
  302. <option value="tank_blower_status">鼓風機</option>
  303. <option value="tank_heater1_status">加熱器 1</option>
  304. <option value="tank_heater2_status">加熱器 2</option>
  305. <option value="tank_diskvalve_status">蝴蝶閥</option>
  306. <option value="tank_solenoid_disinfect_status">消毒電磁閥</option>
  307. <option value="tank_solenoid_water_out_status">排水電磁閥</option>
  308. <option value="outer_solenoid_water_status">夾層進水電磁閥</option>
  309. <option value="tank_temp_enable">溫控開關</option>
  310. <option value="tank_temp">設定溫度</option>
  311. <option value="output_vacuum_status">出料真空吸料機</option>
  312. <option value="time.sleep">暫停秒數</option>
  313. </select>
  314. 動作 :
  315. <select id="do_act1_1">
  316. <option value="">請由左方選取物件
  317. </select>
  318. <input type="button" id="act_add1_1" value="物件動作++" onclick="act_add(act_add1_1);"><br>
  319. </div>
  320. <script>
  321. var act_add_child_i = 1
  322. function act_add(evt) {
  323. evt.style.display = "none";
  324. var actadd_parent_num = String(evt.id).split('_')[1].slice(3, )
  325. // console.log("actadd_parent_num: " + actadd_parent_num)
  326. act_add_child_i++;
  327. var html = '';
  328. html +=
  329. '<div id="action' + actadd_parent_num + '_' + act_add_child_i + '">' +
  330. '物件 : ' +
  331. '<select id="do_obj' + actadd_parent_num + '_' + act_add_child_i + '" onChange="renew(\'' + actadd_parent_num + '_' + act_add_child_i + '\', this.selectedIndex);">' +
  332. '<option value="">制動器</option>' +
  333. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  334. '<option value="tank_vacuum_status">真空吸料機</option>' +
  335. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  336. '<option value="tank_motor_status">馬達</option>' +
  337. '<option value="tank_blower_status">鼓風機</option>' +
  338. '<option value="tank_heater1_status">加熱器 1</option>' +
  339. '<option value="tank_heater2_status">加熱器 2</option>' +
  340. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  341. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  342. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  343. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  344. '<option value="tank_temp_enable">溫控開關</option>' +
  345. '<option value="tank_temp">設定溫度</option>' +
  346. '<option value="output_vacuum_status">出料真空吸料機</option>' +
  347. '<option value="time.sleep">暫停秒數</option>' +
  348. '</select>' +
  349. '動作 : ' +
  350. '<select id="do_act' + actadd_parent_num + '_' + act_add_child_i + '">' +
  351. '<option value="">請由左方選取物件</option>' +
  352. '</select>' +
  353. '<input type="button" id="act_del' + actadd_parent_num + '_' + act_add_child_i + '" value="物件動作--" onclick="act_del(\'' + actadd_parent_num + '_' + act_add_child_i + '\');">' +
  354. '<input type="button" id="act_add' + actadd_parent_num + '_' + act_add_child_i + '" value="物件動作++" onclick="act_add(act_add' + actadd_parent_num + '_' + act_add_child_i + ');"><br>' +
  355. '</div>';
  356. var divbox = document.getElementById('action' + actadd_parent_num);
  357. divbox.insertAdjacentHTML('beforeend', html);
  358. }
  359. function act_del(evt) {
  360. var del_action = document.getElementById('action' + evt);
  361. del_action.innerHTML = ""
  362. var parentObj = del_action.parentNode; // 取得欲刪除 div 的父類別
  363. parentObj.removeChild(del_action) // 刪除 div
  364. var del_act_parent_num = String(evt).split('_')[0]
  365. var del_act_child_num = String(evt).split('_')[1]
  366. // console.log('del_act_parent_num: ' + del_act_parent_num)
  367. // console.log('del_act_child_num: ' + del_act_child_num)
  368. var button_return_id = document.getElementById('act_add' + del_act_parent_num + '_' + String(parseInt(del_act_child_num)-1));
  369. // console.log("test: " + 'cond_add' + del_act_parent_num + '_' + String(parseInt(del_act_child_num)-1))
  370. // console.log("button_return_id: " + button_return_id) // null
  371. if (button_return_id == null) {
  372. var button_return_id = document.getElementById('act_add' + del_act_parent_num + '_1');
  373. }
  374. button_return_id.style.display = "inline";
  375. }
  376. </script>
  377. </div>
  378. <input type="button" id="add1" value="條件物件動作++" onclick="Add(add1);">
  379. </div>
  380. <script>
  381. var new_condition_i = 1
  382. function Add(evt) { // 網頁初始按鈕 onclick="Add(add1);
  383. evt.style.display = "none"; // 元素不顯示。將 add1 的 input-button 不顯示
  384. new_condition_i++; // 設定編號用
  385. // var div = document.createElement('div'); // 輸出 <div></div>。此時並不會顯示,
  386. // 需透過 appendChild()、insertBefore() 或 replaceChild() 等方法將新元素加入至指定的位置之後才會顯示。
  387. // var cond_number = String(evt).slice(3, ) // 目前的 condition 條件物件動作 數 (最外層)
  388. // var cond_a = 'cond_a' + cond_number + '_' + new_condition_i; // [條件] 左方 : 制動器感測器
  389. // var cond_b = 'cond_b' + cond_number + '_' + new_condition_i; // [條件] 中間 : > / = / <
  390. // var cond_c = 'cond_c' + cond_number + '_' + new_condition_i; // [條件] 右方 : ON / OFF / 數值
  391. // var cond_d = 'cond_d' + cond_number + '_' + new_condition_i; // 條件] 最左方條件連接 : and / or
  392. // div.id = 'newcondition_' + new_condition_i; // 設定 div 的 id
  393. // div.style.marginTop = "10px"; // 新增的 div 設定 marginTop 屬性值
  394. var html = ''
  395. // 新增的條件
  396. html +=
  397. '<div id="newcondition_' + new_condition_i + '" class="newcondition_css">' +
  398. // 新增的分隔線
  399. // '<hr size="50" width="100%">' +
  400. '<div id="condition' + new_condition_i + '">' +
  401. '<div id="condition' + new_condition_i + '_1">' +
  402. '條件 : ' +
  403. '<select id="cond_z' + new_condition_i + '_1">' +
  404. '<option value="if">if</option>' +
  405. '<option value="while">while</option>' +
  406. '</select>' +
  407. '<select id="cond_tank' + new_condition_i + '_1">' +
  408. '<option value="D1">乾燥桶 D1</option>' +
  409. '<option value="D2">乾燥桶 D2</option>' +
  410. '<option value="D3">乾燥桶 D3</option>' +
  411. '<option value="D4">乾燥桶 D4</option>' +
  412. '<option value="D5">乾燥桶 D5</option>' +
  413. '<option value="D6">乾燥桶 D6</option>' +
  414. '<option value="D7">乾燥桶 D7</option>' +
  415. '<option value="D8">乾燥桶 D8</option>' +
  416. '<option value="D9">乾燥桶 D9</option>' +
  417. '<option value="D10">乾燥桶 D10</option>' +
  418. '<option value="D11">乾燥桶 D11</option>' +
  419. '<option value="D12">乾燥桶 D12</option>' +
  420. '</select>' +
  421. '<select id="cond_a' + new_condition_i + '_1">' +
  422. '<option value="">制動器 / 感測器</option>' +
  423. '<optgroup label="制動器">' +
  424. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  425. '<option value="tank_vacuum_status">真空吸料機</option>' +
  426. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  427. '<option value="tank_motor_status">馬達</option>' +
  428. '<option value="tank_blower_status">鼓風機</option>' +
  429. '<option value="tank_heater1_status">加熱器 1</option>' +
  430. '<option value="tank_heater2_status">加熱器 2</option>' +
  431. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  432. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  433. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  434. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  435. '<option value="tank_temp_enable">溫控開關</option>' +
  436. '<option value="tank_temp">設定溫度</option>' +
  437. '<option value="output_vacuum_status">出料真空吸料機</option>' +
  438. '<option value="time.sleep">暫停秒數</option>' +
  439. '</select>' +
  440. '</optgroup>' +
  441. '<optgroup label="感測器">' +
  442. '<option value="input_UltraSonic">入料儲豆槽_液位計(cm)</option>' +
  443. '<option value="tank_UltraSonic">液位計(cm)</option>' +
  444. '<option value="tank_SHT11_Temp">SHT11_溫度(℃)</option>' +
  445. '<option value="tank_SHT11_Humidity">SHT11_濕度(%)</option>' +
  446. '<option value="tank_soil_Temp">土壤三合一_溫度(℃)</option>' +
  447. '<option value="tank_soil_Humidity">土壤三合一_濕度(%)</option>' +
  448. '<option value="tank_soil_EC">土壤三合一_EC(%)</option>' +
  449. '<option value="tank_PA">氣壓(PA)</option>' +
  450. '<option value="output_UltraSonic">出料儲豆槽_液位計(cm)</option>' +
  451. '</optgroup>' +
  452. '</select>' +
  453. '<select id="cond_b' + new_condition_i + '_1">' +
  454. '<option value="equal">==</option>' +
  455. '<option value="morethan">&gt;=</option>' +
  456. '<option value="lessthan">&lt;=</option>' +
  457. '</select>' +
  458. '<input list="cond_list_c' + new_condition_i + '_1" id="cond_c' + new_condition_i + '_1">' +
  459. '<datalist id="cond_list_c' + new_condition_i + '_1">' +
  460. '<option value="on">' +
  461. '<option value="off">' +
  462. '<option value="(或請自行輸入數值)">' +
  463. '</datalist>' +
  464. '<input type="button" id="cond_add' + new_condition_i + '_1" value="條件++" onclick="cond_add(cond_add' + new_condition_i + '_1)"><br>' +
  465. '</div></div>';
  466. // 新增的物件動作
  467. html +=
  468. '<div id="action' + new_condition_i + '">' +
  469. '<div id="action' + new_condition_i + '_1">' +
  470. '物件 : ' +
  471. '<select id="do_obj' + new_condition_i + '_1" onChange="renew(\''+ new_condition_i + '_1\', this.selectedIndex);">' +
  472. '<option value="">制動器</option>' +
  473. '<option value="input_vacuum_status">入料真空吸料機</option>' +
  474. '<option value="tank_vacuum_status">真空吸料機</option>' +
  475. '<option value="tank_threewayvalve_input_status">入料三通閥</option>' +
  476. '<option value="tank_motor_status">馬達</option>' +
  477. '<option value="tank_blower_status">鼓風機</option>' +
  478. '<option value="tank_heater1_status">加熱器 1</option>' +
  479. '<option value="tank_heater2_status">加熱器 2</option>' +
  480. '<option value="tank_diskvalve_status">蝴蝶閥</option>' +
  481. '<option value="tank_solenoid_disinfect_status">消毒電磁閥</option>' +
  482. '<option value="tank_solenoid_water_out_status">排水電磁閥</option>' +
  483. '<option value="outer_solenoid_water_status">夾層進水電磁閥</option>' +
  484. '<option value="tank_temp_enable">溫控開關</option>' +
  485. '<option value="tank_temp">設定溫度</option>' +
  486. '<option value="output_vacuum_status">出料真空吸料機</option>' +
  487. '<option value="time.sleep">暫停秒數</option>' +
  488. '</select>' +
  489. '動作 : ' +
  490. '<select id="do_act' + new_condition_i + '_1">' +
  491. '<option value="">請由左方選取物件' +
  492. '</select>' +
  493. '<input type="button" id="act_add' + new_condition_i + '_1" value="物件動作++" onclick="act_add(act_add' + new_condition_i + '_1);"><br>' +
  494. '</div>' +
  495. '</div>' +
  496. // 新增的 條件物件動作++ 條件物件動作-- 按鈕
  497. '<input type="button" id="del' + new_condition_i + '" value="條件物件動作--" onclick="Delete(' + new_condition_i + ');"><br>' +
  498. '<input type="button" id="add' + new_condition_i + '" value="條件物件動作++" onclick="Add(add' + new_condition_i + ');">' +
  499. '</div>' ;
  500. var divbox = document.getElementById('box');
  501. divbox.insertAdjacentHTML('beforeend', html);
  502. };
  503. function Delete(evt) {
  504. var del_condition = document.getElementById('newcondition_' + evt);
  505. del_condition.innerHTML = ""
  506. var parentObj = del_condition.parentNode; // 取得欲刪除 div 的父類別
  507. parentObj.removeChild(del_condition) // 刪除 div
  508. // 上一個按鈕要顯示出來
  509. var button_return_id = document.getElementById('add' + String(parseInt(evt)-1));
  510. if (button_return_id == null) {
  511. var button_return_id = document.getElementById('add1');
  512. }
  513. // console.log('button_return_id: ' + button_return_id)
  514. button_return_id.style.display = "block"; // 元素顯示。顯示前一個 input-button
  515. };
  516. </script>
  517. <!-- 新增加的 newcondition_(編號) 會加在這裡 -->
  518. </div>
  519. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  520. <br>
  521. <input type="button" id="test" value="取值測試" onclick="test();"><br>
  522. <span id="value_test"> ( 取值測試 ) </span><br>
  523. <span id="command_test"> ( command 測試 ) </span><br>
  524. <input type="button" id="test" value="ajax 測試" onclick="AJAXtest();">
  525. <script>
  526. var set_Schedule = '';
  527. function test(){
  528. // console.log("new_condition_i: " + new_condition_i) // 總數 : 條件物件動作
  529. // console.log("cond_add_child_i: " + cond_add_child_i) // 總數 : 子 條件
  530. // console.log("act_add_child_i: " + act_add_child_i) // 總數 : 子 物件動作
  531. // set_Schedule += 'set_Schedule = { ';
  532. set_Schedule = '{ ';
  533. var command_test = '';
  534. // 條件物件動作 取值
  535. for (let z = 1; z <= new_condition_i; z++) {
  536. // if-while 取值
  537. try {
  538. var cond_z_value = document.getElementById("cond_z" + z + "_1").value;
  539. console.log("cond_z" + z + "_1: " + cond_z_value)
  540. set_Schedule += '"cond_z' + z + '_1": "' + cond_z_value + '", ' ;
  541. } catch (error) {
  542. if (error.name == 'TypeError') {
  543. console.log("cond_z" + z + "_1: null")
  544. } else {
  545. alert("cond_z" + z + "_1: " + error.name)
  546. break
  547. }
  548. }
  549. // 桶槽號碼 取值
  550. try {
  551. var cond_tank_value = document.getElementById("cond_tank" + z + "_1").value;
  552. console.log("cond_tank" + z + "_1: " + cond_tank_value)
  553. set_Schedule += '"cond_tank' + z + '_1": "' + cond_tank_value + '", ' ;
  554. } catch (error) {
  555. if (error.name == 'TypeError') {
  556. console.log("cond_tank" + z + "_1: null")
  557. } else {
  558. alert("cond_tank" + z + "_1: " + error.name)
  559. break
  560. }
  561. }
  562. // 子 條件 取值
  563. for (let x = 1; x <= cond_add_child_i; x++) {
  564. // 子條件取值 : 條件連接 and or
  565. if (x > 1) {
  566. try {
  567. var cond_d_value = document.getElementById("cond_d" + z + "_" + x).value;
  568. // console.log("cond_d" + z + "_" + x + ": " + cond_d_value)
  569. set_Schedule += '"cond_d' + z + '_' + x + '": "' + cond_d_value + '", ' ;
  570. } catch (error) {
  571. if (error.name == 'TypeError') {
  572. // console.log("cond_d" + z + "_" + x + ": null")
  573. } else {
  574. alert("cond_d" + z + "_" + x + ": " + error.name)
  575. break
  576. }
  577. }
  578. }
  579. try {
  580. var cond_a_value = document.getElementById("cond_a" + z + "_" + x).value;
  581. // console.log("cond_a" + z + "_" + x + ": " + cond_a_value)
  582. set_Schedule += '"cond_a' + z + '_' + x + '": "' + cond_a_value + '", ' ;
  583. if (cond_a_value == '') {
  584. alert('條件欄位輸入有誤, 請再次確認')
  585. break
  586. }
  587. } catch (error) {
  588. if (error.name == 'TypeError') {
  589. // console.log("cond_a" + z + "_" + x + ": null")
  590. } else {
  591. alert("cond_a" + z + "_" + x + ": " + error.name)
  592. break
  593. }
  594. }
  595. // 子條件取值 : 條件中 > = <
  596. try {
  597. var cond_b_value = document.getElementById("cond_b" + z + "_" + x).value;
  598. // console.log("cond_b" + z + "_" + x + ": " + cond_b_value)
  599. set_Schedule += '"cond_b' + z + '_' + x + '": "' + cond_b_value + '", ' ;
  600. if (cond_b_value == '') {
  601. alert('條件欄位輸入有誤, 請再次確認')
  602. break
  603. }
  604. } catch (error) {
  605. if (error.name == 'TypeError') {
  606. // console.log("cond_b" + z + "_" + x + ": null")
  607. } else {
  608. alert("cond_b" + z + "_" + x + ": " + error.name)
  609. break
  610. }
  611. }
  612. // 子條件取值 : 條件右 ON / OFF / 輸入數值
  613. try {
  614. var cond_c_value = document.getElementById("cond_c" + z + "_" + x).value;
  615. // console.log("cond_c" + z + "_" + x + ": " + cond_c_value)
  616. set_Schedule += '"cond_c' + z + '_' + x + '": "' + cond_c_value + '", ' ;
  617. if (cond_c_value == '') {
  618. alert('條件欄位輸入有誤, 請再次確認')
  619. break
  620. }
  621. } catch (error) {
  622. if (error.name == 'TypeError') {
  623. // console.log("cond_c" + z + "_" + x + ": null")
  624. } else {
  625. alert("cond_c" + z + "_" + x + ": " + error.name)
  626. break
  627. }
  628. }
  629. }
  630. // 子 物件動作 取值
  631. for (let y = 1; y <= act_add_child_i; y++) {
  632. // 子物件動作取值 : 物件 do_obj1_1
  633. try {
  634. var do_obj_value = document.getElementById("do_obj" + z + "_" + y).value;
  635. if (do_obj_value == '') {
  636. alert('物件欄位輸入有誤, 請再次確認')
  637. break
  638. }
  639. // console.log("do_obj" + z + "_" + y + ": " + do_obj_value)
  640. set_Schedule += '"do_obj' + z + '_' + y + '": "' + do_obj_value + '", ' ;
  641. command_test += '{"tank_num": "' + cond_tank_value + '", "command": "' + do_obj_value + '", "value":"';
  642. } catch (error) {
  643. if (error.name == 'TypeError') {
  644. // console.log("do_obj" + z + "_" + y + ": null")
  645. } else {
  646. alert("do_obj" + z + "_" + y + ": " + error.name)
  647. break
  648. }
  649. }
  650. // 子物件動作取值 : 動作 do_act1_1
  651. try {
  652. var do_act_value = document.getElementById("do_act" + z + "_" + y).value;
  653. if (do_act_value == '') {
  654. alert('動作欄位輸入有誤, 請再次確認')
  655. break
  656. }
  657. // console.log("do_act" + z + "_" + y + ": " + do_act_value)
  658. set_Schedule += '"do_act' + z + '_' + y + '": "' + do_act_value + '", ' ;
  659. command_test += do_act_value + ' }';
  660. } catch (error) {
  661. if (error.name == 'TypeError') {
  662. // console.log("do_obj" + z + "_" + y + ": null")
  663. } else {
  664. alert("do_act" + z + "_" + y + ": " + error.name)
  665. break
  666. }
  667. }
  668. }
  669. }
  670. console.log('-- test FINISH --')
  671. // 整理資料用
  672. set_Schedule += '"": ""}' ;
  673. console.log('set_Schedule: ' + set_Schedule)
  674. $('#value_test').text('set_Schedule: ' + set_Schedule)
  675. $('#command_test').text('command_test: ' + command_test)
  676. }
  677. function AJAXtest(params) {
  678. test();
  679. var schedule_data = {
  680. "condition":new_condition_i,
  681. "cond_add_child":cond_add_child_i,
  682. "act_add_child":act_add_child_i,
  683. "set_Schedule":set_Schedule
  684. };
  685. $.get('/dry_block_set', schedule_data, function (res) {
  686. // console.log("res.condition: " + res.condition)
  687. // console.log("res.cond_add_child: " + res.cond_add_child)
  688. // console.log("res.act_add_child: " + res.act_add_child)
  689. console.log("res.set_Schedule: " + res.set_Schedule)
  690. }, 'json');
  691. }
  692. </script>
  693. <br>
  694. </body>
  695. </html>