vibration.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. var xhr = new XMLHttpRequest();
  2. var url = "tower/org";
  3. obj = "";
  4. obj2 = "";
  5. xhr.open("GET", url);
  6. xhr.onload = function () {
  7. obj = JSON.parse(xhr.responseText);
  8. //insertHTML();
  9. start();
  10. onChangeColumn1();
  11. onChangeColumn2();
  12. onChangeColumn3();
  13. click_button();
  14. };
  15. xhr.send();
  16. function insertHTML(data) {
  17. var tower_select = document.getElementById('tower');
  18. //aria.innerHTML=data[0].tower_name;
  19. var inner = '';
  20. for (var i = 0; i < data.length; i++) {
  21. inner += '<option value="' + data[i].tower_name + '">' + data[i].tower_name + '</option>';
  22. }
  23. document.getElementById("tower").innerHTML = inner;
  24. }
  25. function click_button() {
  26. //alert("click");
  27. companySelect = document.getElementById("company-list");
  28. factorySelect = document.getElementById("factory-list");
  29. departmentSelect = document.getElementById("department-list");
  30. towerGroupSelect = document.getElementById("towerGroup-list");
  31. if (companySelect.value != 0 && factorySelect.value != 0 && departmentSelect.value != 0 && towerGroupSelect.value != 0) {
  32. var url2 = "tower/?company=" + companySelect.value + "&factory=" + factorySelect.value + "&department=" + departmentSelect.value + "&towerGroup=" + towerGroupSelect.value;
  33. var xhr2 = new XMLHttpRequest();
  34. xhr2.open("GET", url2);
  35. xhr2.onload = function () {
  36. obj2 = JSON.parse(xhr2.responseText);
  37. insertHTML(obj2);
  38. console.log(obj2);
  39. show_tower_info();
  40. };
  41. xhr2.send();
  42. }
  43. }
  44. // function show_tower_info(){
  45. // tower =document.getElementById("tower").value;
  46. // console.log(tower);
  47. // inner = '';
  48. // for(var i=0;i<obj2.length;i++){
  49. // if(obj2[i].tower_name === tower){
  50. // for(var ii=0;ii<obj2[i].tower_data.Moter.length;ii++){
  51. // inner += '<p >編號' + obj2[i].tower_data.Moter[ii].channelName + ' Vrms:'+ obj2[i].tower_data.Moter[ii].DataValue + ',健康指標:健康 健康狀態' + obj2[i].tower_data.Moter[ii].CVIndex+'</p>';
  52. // inner += '<a href="/channel" target="_blank" title="通道資訊">通道資訊</a><br>';
  53. // }
  54. // }
  55. // }
  56. // document.getElementById("tower_info").innerHTML = inner;
  57. // console.log(inner);
  58. // }
  59. function show_tower_info() {
  60. tower = document.getElementById("tower").value;
  61. console.log(tower);
  62. inner = '';
  63. for (var i = 0; i < obj2.length; i++) {
  64. if (obj2[i].tower_name === tower) {
  65. for (var ii = 0; ii < obj2[i].tower_data.Moter.length; ii++) {
  66. // inner += '<p>編號' + obj2[i].tower_data.Moter[ii].channelName + ' Vrms:' + obj2[i].tower_data.Moter[ii].DataValue + ',健康指標:健康 健康狀態' + obj2[i].tower_data.Moter[ii].CVIndex + '</p>';
  67. // inner += '<a href="/channel" target="_blank" title="通道資訊">通道資訊</a><br>';
  68. inner += '\
  69. <tbody>\
  70. <tr>\
  71. <tr>\
  72. <td>' + obj2[i].tower_data.Moter[ii].channelName + '</td>\
  73. <td>' + obj2[i].tower_data.Moter[ii].DataValue + '</td>\
  74. <td style="color:#078b07" class="fw-bold">健康<i class="fas fa-check-circle ps-1"></i></td>\
  75. <td>' + obj2[i].tower_data.Moter[ii].CVIndex + '</td>\
  76. <td><a href="/channel" target="_blank" title="通道資訊">通道資訊</a></td>\
  77. </tr>\
  78. </tbody>'
  79. }
  80. }
  81. }
  82. document.getElementById("tower_info").innerHTML = inner;
  83. console.log(inner);
  84. }
  85. //document就是這html文件。
  86. //getElementById是裡面的方法,參數給"college-list"抓到這id標籤列
  87. function start() {
  88. companySelect = document.getElementById("company-list");
  89. factorySelect = document.getElementById("factory-list");
  90. departmentSelect = document.getElementById("department-list");
  91. towerGroupSelect = document.getElementById("towerGroup-list");
  92. var inner = '';
  93. var company_arr = new Array();
  94. for (var i = 0; i < obj.length; i++) {
  95. if (company_arr.indexOf(obj[i].company) == -1 && obj[i].able == 1) {
  96. inner = inner + '<option value="' + obj[i].company + '">公司' + obj[i].company + '</option>';
  97. company_arr.push(obj[i].company);
  98. }
  99. }
  100. //innerHTML 賦值inner給這element屬性
  101. companySelect.innerHTML = inner;
  102. }
  103. //製造一個字串,以html的語法填入院的陣列
  104. function onChangeColumn1() {
  105. companySelect = document.getElementById("company-list");
  106. factorySelect = document.getElementById("factory-list");
  107. departmentSelect = document.getElementById("department-list");
  108. towerGroupSelect = document.getElementById("towerGroup-list");
  109. factorySelect.innerHTML = '';
  110. let factory_arr = new Array();
  111. let factory_inner = '';
  112. for (var i = 0; i < obj.length; i++) {
  113. if (companySelect.value == obj[i].company) {
  114. if (factory_arr.indexOf(obj[i].factory) == -1 && obj[i].able == 1) {
  115. factory_inner = factory_inner + '<option value="' + obj[i].factory + '">廠區' + obj[i].factory + '</option>';
  116. factory_arr.push(obj[i].factory);
  117. }
  118. }
  119. //alert(companySelect.value);
  120. }
  121. factorySelect.innerHTML = factory_inner;
  122. }
  123. function onChangeColumn2() {
  124. companySelect = document.getElementById("company-list");
  125. factorySelect = document.getElementById("factory-list");
  126. departmentSelect = document.getElementById("department-list");
  127. towerGroupSelect = document.getElementById("towerGroup-list");
  128. departmentSelect.innerHTML = '';
  129. let department_arr = new Array();
  130. let department_inner = '';
  131. for (var i = 0; i < obj.length; i++) {
  132. if (companySelect.value == obj[i].company && factorySelect.value == obj[i].factory) {
  133. if (department_arr.indexOf(obj[i].department) == -1 && obj[i].able == 1) {
  134. department_inner = department_inner + '<option value="' + obj[i].department + '">課' + obj[i].department + '</option>';
  135. department_arr.push(obj[i].department);
  136. }
  137. }
  138. }
  139. document.getElementById("department-list").innerHTML = department_inner;
  140. }
  141. function onChangeColumn3() {
  142. companySelect = document.getElementById("company-list");
  143. factorySelect = document.getElementById("factory-list");
  144. departmentSelect = document.getElementById("department-list");
  145. towerGroupSelect = document.getElementById("towerGroup-list");
  146. towerGroupSelect.innerHTML = '';
  147. let towerGroup_inner = '';
  148. for (var i = 0; i < obj.length; i++) {
  149. if (companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department) {
  150. if (obj[i].able == 1) {
  151. for (var ii = 0; ii < obj[i].group.length; ii++) {
  152. towerGroup_inner = towerGroup_inner + '<option value="' + obj[i].group[ii] + '">機組' + obj[i].group[ii] + '</option>';
  153. }
  154. }
  155. }
  156. }
  157. document.getElementById("towerGroup-list").innerHTML = towerGroup_inner;
  158. }