vibration.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. <td>' + obj2[i].tower_data.Moter[ii].channelName + '</td>\
  72. <td>' + obj2[i].tower_data.Moter[ii].DataValue + '</td>\
  73. <td style="color:#078b07" class="fw-bold">健康<i class="fas fa-check-circle ps-1"></i></td>\
  74. <td>' + obj2[i].tower_data.Moter[ii].CVIndex + '</td>\
  75. <td><a href="/channel" target="_blank" title="通道資訊">通道資訊</a></td>\
  76. </tr>\
  77. </tbody>'
  78. }
  79. }
  80. }
  81. document.getElementById("tower_info").innerHTML = inner;
  82. console.log(inner);
  83. }
  84. //document就是這html文件。
  85. //getElementById是裡面的方法,參數給"college-list"抓到這id標籤列
  86. function start() {
  87. companySelect = document.getElementById("company-list");
  88. factorySelect = document.getElementById("factory-list");
  89. departmentSelect = document.getElementById("department-list");
  90. towerGroupSelect = document.getElementById("towerGroup-list");
  91. var inner = '';
  92. var company_arr = new Array();
  93. for (var i = 0; i < obj.length; i++) {
  94. if (company_arr.indexOf(obj[i].company) == -1 && obj[i].able == 1) {
  95. inner = inner + '<option value="' + obj[i].company + '">公司' + obj[i].company + '</option>';
  96. company_arr.push(obj[i].company);
  97. }
  98. }
  99. //innerHTML 賦值inner給這element屬性
  100. companySelect.innerHTML = inner;
  101. }
  102. //製造一個字串,以html的語法填入院的陣列
  103. function onChangeColumn1() {
  104. companySelect = document.getElementById("company-list");
  105. factorySelect = document.getElementById("factory-list");
  106. departmentSelect = document.getElementById("department-list");
  107. towerGroupSelect = document.getElementById("towerGroup-list");
  108. factorySelect.innerHTML = '';
  109. let factory_arr = new Array();
  110. let factory_inner = '';
  111. for (var i = 0; i < obj.length; i++) {
  112. if (companySelect.value == obj[i].company) {
  113. if (factory_arr.indexOf(obj[i].factory) == -1 && obj[i].able == 1) {
  114. factory_inner = factory_inner + '<option value="' + obj[i].factory + '">廠區' + obj[i].factory + '</option>';
  115. factory_arr.push(obj[i].factory);
  116. }
  117. }
  118. //alert(companySelect.value);
  119. }
  120. factorySelect.innerHTML = factory_inner;
  121. }
  122. function onChangeColumn2() {
  123. companySelect = document.getElementById("company-list");
  124. factorySelect = document.getElementById("factory-list");
  125. departmentSelect = document.getElementById("department-list");
  126. towerGroupSelect = document.getElementById("towerGroup-list");
  127. departmentSelect.innerHTML = '';
  128. let department_arr = new Array();
  129. let department_inner = '';
  130. for (var i = 0; i < obj.length; i++) {
  131. if (companySelect.value == obj[i].company && factorySelect.value == obj[i].factory) {
  132. if (department_arr.indexOf(obj[i].department) == -1 && obj[i].able == 1) {
  133. department_inner = department_inner + '<option value="' + obj[i].department + '">課' + obj[i].department + '</option>';
  134. department_arr.push(obj[i].department);
  135. }
  136. }
  137. }
  138. document.getElementById("department-list").innerHTML = department_inner;
  139. }
  140. function onChangeColumn3() {
  141. companySelect = document.getElementById("company-list");
  142. factorySelect = document.getElementById("factory-list");
  143. departmentSelect = document.getElementById("department-list");
  144. towerGroupSelect = document.getElementById("towerGroup-list");
  145. towerGroupSelect.innerHTML = '';
  146. let towerGroup_inner = '';
  147. for (var i = 0; i < obj.length; i++) {
  148. if (companySelect.value == obj[i].company && factorySelect.value == obj[i].factory && departmentSelect.value == obj[i].department) {
  149. if (obj[i].able == 1) {
  150. for (var ii = 0; ii < obj[i].group.length; ii++) {
  151. towerGroup_inner = towerGroup_inner + '<option value="' + obj[i].group[ii] + '">機組' + obj[i].group[ii] + '</option>';
  152. }
  153. }
  154. }
  155. }
  156. document.getElementById("towerGroup-list").innerHTML = towerGroup_inner;
  157. }