tower.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. var xhr = new XMLHttpRequest();
  2. var url = "tower/org";
  3. obj="";
  4. xhr.open("GET",url);
  5. xhr.onload = function(){
  6. obj = JSON.parse(xhr.responseText);
  7. //insertHTML();
  8. start();
  9. onChangeColumn1();
  10. onChangeColumn2();
  11. onChangeColumn3();
  12. click_button();
  13. };
  14. xhr.send();
  15. function insertHTML(data){
  16. var tower_select = document.getElementById('tower');
  17. //aria.innerHTML=data[0].tower_name;
  18. var inner='';
  19. for(var i=0;i<data.length;i++){
  20. inner=inner+'<button onclick="tower_info(\''+data[i].tower_name+'\');">'+data[i].tower_name+'</button>';
  21. console.log(inner);
  22. }
  23. tower_select.innerHTML=inner;
  24. }
  25. obj2 = "";
  26. function click_button() {
  27. //alert("click");
  28. companySelect=document.getElementById("company-list");
  29. factorySelect=document.getElementById("factory-list");
  30. departmentSelect=document.getElementById("department-list");
  31. towerGroupSelect=document.getElementById("towerGroup-list");
  32. if(companySelect.value!=0 && factorySelect.value!=0 && departmentSelect.value!=0 && towerGroupSelect.value!=0){
  33. var url2 = "tower/?company="+ companySelect.value + "&factory=" + factorySelect.value + "&department=" +departmentSelect.value + "&towerGroup=" +towerGroupSelect.value ;
  34. var xhr2 = new XMLHttpRequest();
  35. xhr2.open("GET",url2);
  36. xhr2.onload = function(){
  37. obj2 = JSON.parse(xhr2.responseText);
  38. insertHTML(obj2);
  39. tower_info("dev001");
  40. };
  41. xhr2.send();
  42. }
  43. }
  44. function tower_info(tower_str){
  45. tower = tower_str;
  46. console.log(tower);
  47. inner = "";
  48. for(var i=0;i<obj2.length;i++){
  49. if(obj2[i].tower_name == tower){
  50. // inner = '<p> DCS </P> '+
  51. // '<p> 入水溫度 = '+ obj2[i].tower_data.DCS.hotTemp + ' </P> ' +
  52. // '<p> 出水溫度 = '+ obj2[i].tower_data.DCS.coldTemp + ' </P> ' +
  53. // '<p> 水流量 = '+ obj2[i].tower_data.DCS.waterFlow + ' </P> ' +
  54. // '<p> 風扇馬達電流 = '+ obj2[i].tower_data.DCS.fanMotorCur + ' </P> ' +
  55. // '<p> 風扇馬達轉速頻率 = '+ obj2[i].tower_data.DCS.fanMotorSpeedFreq + ' </P><br> ' +
  56. // '<p> 風扇震動 </P> '+
  57. // '<p> 馬達震動 = '+ obj2[i].tower_data.Moter.ch01.Vrms + ' </P> ' +
  58. // '<p> 減速機震動 = '+ obj2[i].tower_data.Fan.reducer + ' </P> ' +
  59. // '<p> 靜壓機 = '+ obj2[i].tower_data.Fan.staticPressure + ' </P> ' +
  60. // '<p> 水流量 = '+ obj2[i].tower_data.Fan.waterFlow + ' </P> ' +
  61. // '<p> 濕求溫度 = '+ obj2[i].tower_data.Fan.wetTemp + ' </P> ' +
  62. // '<p> 水冷槽溫度1 = '+ obj2[i].tower_data.Fan.coldTempData1 + ' </P> ' +
  63. // '<p> 水冷槽溫度2 = '+ obj2[i].tower_data.Fan.coldTempData2 + ' </P><br> ' +
  64. // '<p> 馬達震動 </P> '+
  65. // '<p> ch001,通道1'+ obj2[i].tower_data.Moter.ch01.Vrms + ',' + obj2[i].tower_data.Moter.ch01.CV+' </P> ' +
  66. // '<p> ch002,通道2'+ obj2[i].tower_data.Moter.ch02.Vrms + ',' + obj2[i].tower_data.Moter.ch02.CV+' </P> '
  67. // ;
  68. inner =' <h1 class="ms-3"><i style=" color:#0174c7;" class="fas fa-file-signature me-1"></i>中控室DSC訊號</h1>\
  69. <div class="row px-0 mx-0">\
  70. <div class="card col-lg-2">\
  71. <p class="data-title fw-bold">'+ obj2[i].tower_data.DCS.hotTemp + '</p>\
  72. <div>\
  73. <h2 class="text-center">31.612</h2>\
  74. <P class="unit text-end">°C</P>\
  75. </div>\
  76. </div>\
  77. <div class="card col-lg-2">\
  78. <p class="data-title fw-bold">出水溫度</p>\
  79. <div>\
  80. <h2 class="text-center">'+ obj2[i].tower_data.DCS.coldTemp + '</h2>\
  81. <P class="unit text-end">°C</P>\
  82. </div>\
  83. </div>\
  84. <div class="card col-lg-2">\
  85. <p class="data-title fw-bold ">水流量</p>\
  86. <div>\
  87. <h2 class="text-center">'+ obj2[i].tower_data.DCS.waterFlow + '</h2>\
  88. <P class="unit text-end">M³/H</P>\
  89. </div>\
  90. </div>\
  91. <div class="card col-lg-2">\
  92. <p class="data-title fw-bold">風扇馬達電流</p>\
  93. <div>\
  94. <h2 class="text-center">'+ obj2[i].tower_data.DCS.fanMotorCur + '</h2>\
  95. <P class="unit text-end">A</P>\
  96. </div>\
  97. </div>\
  98. <div class="card col-lg-2">\
  99. <p class="data-title fw-bold ">風扇馬達轉速頻率</p>\
  100. <div>\
  101. <h2 class="text-center">'+ obj2[i].tower_data.DCS.fanMotorSpeedFreq + '&ensp;</h2>\
  102. <P class="unit text-end">Hz</P>\
  103. </div>\
  104. </div>\
  105. </div>\
  106. <div class="card mt-5">\
  107. <div class="row">\
  108. <div class="col-lg-6">\
  109. <h1><i style=" color:#0174c7;" class="fas fa-tachometer-alt me-2"></i>風扇震動</h1>\
  110. </div>\
  111. <div class="col-lg-6">\
  112. <h1><i style=" color:#0174c7;" class="fas fa-cogs me-2"></i>馬達震動</h1>\
  113. </div>\
  114. </div>\
  115. <div>\
  116. <div class="row px-0 mx-0">\
  117. <div class="col-lg-6">\
  118. <table class="table">\
  119. <thead>\
  120. <tr>\
  121. <th scope="col">數據名稱</th>\
  122. <th scope="col">值</th>\
  123. <th scope="col">單位</th>\
  124. </tr>\
  125. </thead>\
  126. <tbody>\
  127. <tr>\
  128. <td>馬達震動</td>\
  129. <td>'+ obj2[i].tower_data.Moter.ch01.Vrms + '</td>\
  130. <td>mm/s</td>\
  131. </tr>\
  132. <tr>\
  133. <td>減速機震動</td>\
  134. <td>'+ obj2[i].tower_data.Fan.reducer + '</td>\
  135. <td>mm/s</td>\
  136. </tr>\
  137. <tr>\
  138. <td>靜壓機</td>\
  139. <td>'+ obj2[i].tower_data.Fan.staticPressure + '</td>\
  140. <td>pa</td>\
  141. </tr>\
  142. <tr>\
  143. <td>水流量</td>\
  144. <td>'+ obj2[i].tower_data.Fan.waterFlow + '</td>\
  145. <td>M³/H</td>\
  146. </tr>\
  147. <tr>\
  148. <td>濕求溫度</td>\
  149. <td>'+ obj2[i].tower_data.Fan.wetTemp + '</td>\
  150. <td>°C</td>\
  151. </tr>\
  152. <tr>\
  153. <td>水冷槽溫度1</td>\
  154. <td>'+ obj2[i].tower_data.Fan.coldTempData1 + '</td>\
  155. <td>°C</td>\
  156. </tr>\
  157. <tr>\
  158. <td>水冷槽溫度2</td>\
  159. <td>'+ obj2[i].tower_data.Fan.coldTempData2 + '</td>\
  160. <td>°C</td>\
  161. </tr>\
  162. </tbody>\
  163. </table>\
  164. </div>\
  165. <div class="col-lg-6">\
  166. <div class="row px-0 mx-0">\
  167. <div class="card col-lg-5">\
  168. <p class="fw-bold ">ch001,通道1</p>\
  169. <div>\
  170. <p class="text-center">'+ obj2[i].tower_data.Moter.ch01.Vrms + ',' + obj2[i].tower_data.Moter.ch01.CV+'</p>\
  171. </div>\
  172. </div>\
  173. <div class="card col-lg-5">\
  174. <p class="fw-bold ">ch002,通道2</p>\
  175. <div>\
  176. <p class="text-center">'+ obj2[i].tower_data.Moter.ch02.Vrms + ',' + obj2[i].tower_data.Moter.ch02.CV+'</p>\
  177. </div>\
  178. </div>\
  179. <div class="card col-lg-5">\
  180. <p class="fw-bold ">ch002,通道3</p>\
  181. <div>\
  182. <p class="text-center">'+ obj2[i].tower_data.Moter.ch01.Vrms + ',' + obj2[i].tower_data.Moter.ch01.CV+'</p>\
  183. </div>\
  184. </div>\
  185. <div class="card col-lg-5">\
  186. <p class="fw-bold ">ch002,通道4</p>\
  187. <div>\
  188. <p class="text-center">'+ obj2[i].tower_data.Moter.ch02.Vrms + ',' + obj2[i].tower_data.Moter.ch02.CV+'</p>\
  189. </div>\
  190. </div>\
  191. </div>\
  192. </div>\
  193. </div>\
  194. </div>\
  195. </div>';
  196. }
  197. }
  198. document.getElementById("tower_info").innerHTML = inner;
  199. }
  200. //document就是這html文件。
  201. //getElementById是裡面的方法,參數給"college-list"抓到這id標籤列
  202. function start(){
  203. companySelect=document.getElementById("company-list");
  204. factorySelect=document.getElementById("factory-list");
  205. departmentSelect=document.getElementById("department-list");
  206. towerGroupSelect=document.getElementById("towerGroup-list");
  207. var inner='';
  208. var company_arr = new Array();
  209. for(var i=0;i<obj.length;i++){
  210. if(company_arr.indexOf(obj[i].company)==-1 && obj[i].able==1){
  211. inner=inner+'<option value="'+obj[i].company+'">公司'+obj[i].company+'</option>';
  212. company_arr.push(obj[i].company);
  213. }
  214. }
  215. //innerHTML 賦值inner給這element屬性
  216. companySelect.innerHTML=inner;
  217. }
  218. //製造一個字串,以html的語法填入院的陣列
  219. function onChangeColumn1() {
  220. companySelect=document.getElementById("company-list");
  221. factorySelect=document.getElementById("factory-list");
  222. departmentSelect=document.getElementById("department-list");
  223. towerGroupSelect=document.getElementById("towerGroup-list");
  224. factorySelect.innerHTML='';
  225. let factory_arr = new Array();
  226. let factory_inner = '';
  227. for(var i=0;i<obj.length;i++){
  228. if( companySelect.value == obj[i].company){
  229. if(factory_arr.indexOf(obj[i].factory)==-1 && obj[i].able==1){
  230. factory_inner=factory_inner+'<option value="'+obj[i].factory+'">工廠'+obj[i].factory+'</option>';
  231. factory_arr.push(obj[i].factory);
  232. }
  233. }
  234. //alert(companySelect.value);
  235. }
  236. factorySelect.innerHTML=factory_inner;
  237. }
  238. function onChangeColumn2() {
  239. companySelect=document.getElementById("company-list");
  240. factorySelect=document.getElementById("factory-list");
  241. departmentSelect=document.getElementById("department-list");
  242. towerGroupSelect=document.getElementById("towerGroup-list");
  243. departmentSelect.innerHTML='';
  244. let department_arr = new Array();
  245. let department_inner = '';
  246. for(var i=0;i<obj.length;i++){
  247. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory){
  248. if(department_arr.indexOf(obj[i].department)==-1 && obj[i].able==1){
  249. department_inner=department_inner+'<option value="'+obj[i].department+'">廠區'+obj[i].department+'</option>';
  250. department_arr.push(obj[i].department);
  251. }
  252. }
  253. }
  254. document.getElementById("department-list").innerHTML=department_inner;
  255. }
  256. function onChangeColumn3() {
  257. companySelect=document.getElementById("company-list");
  258. factorySelect=document.getElementById("factory-list");
  259. departmentSelect=document.getElementById("department-list");
  260. towerGroupSelect=document.getElementById("towerGroup-list");
  261. towerGroupSelect.innerHTML='';
  262. let towerGroup_inner = '';
  263. for(var i=0;i<obj.length;i++){
  264. if( companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department){
  265. if( obj[i].able==1){
  266. for(var ii=0;ii<obj[i].group.length;ii++){
  267. towerGroup_inner=towerGroup_inner+'<option value="'+obj[i].group[ii]+'">機組'+obj[i].group[ii]+'</option>';
  268. }
  269. }
  270. }
  271. }
  272. document.getElementById("towerGroup-list").innerHTML= towerGroup_inner;
  273. }