start(); user_role = ''; data = ''; obj = ''; // 之後透過 fetch 取得fastapi後端資料! function start(){ var xhr = new XMLHttpRequest(); var url = "home/show"; obj = ""; xhr.open("GET",url); xhr.onload = function(){ obj = JSON.parse(xhr.responseText); data = obj ; console.log(data); document.getElementById('company_text').innerHTML=data[1][0].company; document.getElementById('factory_text').innerHTML=data[1][0].factory; document.getElementById('department_text').innerHTML=data[1][0].department; if(data[0].user_role==1){ company_show(); } else if(data[0].user_role==2){ factory_show(data[1][0].company); } else if(data[0].user_role==3){ department_show(data[1][0].company,data[1][0].department); department_change(); } else{ towerGroup_show(); } //insertHTML(); }; xhr.send(); console.log('Start'); } function get_user_role(){ user_role = data[0].user_role } function clear(){ document.getElementById('company').innerHTML=''; document.getElementById('towergroup').innerHTML=''; document.getElementById('company_name').innerHTML=''; document.getElementById('factory_select').innerHTML=''; document.getElementById("map").style.display="none"; document.getElementById('department_show').innerHTML=""; document.getElementById("department_list").style.display="none"; } function company_show(){ //顯示company按鈕 var inner=''; var company_arr = new Array(); for(var i=0;i
"; company_arr.push(obj[1][i].company); console.log(obj[1][i].company); } } clear(); document.getElementById('company').innerHTML=inner; company_health(company_arr); } function company_health(company_arr){ //使公司按鈕變色 for(var i=0;i
"; factory_arr.push(obj[1][i].factory); } } //測試用 inner+=""; document.getElementById('factory_select').innerHTML=inner; factory_health(factory_arr); document.getElementById("map").style.display=""; } function factory_health(factory_arr){ //使工廠按鈕變色 for(var i=0;i課'+obj[1][i].department+''; department_arr.push(obj[1][i].department); } } document.getElementById('company_text').innerHTML=company; document.getElementById('factory_text').innerHTML=factory; document.getElementById('department_list').innerHTML=inner; console.log("click"); if(factory==='A'){ newLocation(25.0339031,121.5623212); } else if(factory==='B'){ newLocation(24.42,121.42); } else if(factory==='C'){ newLocation(24.12,121.42); } document.getElementById("department_list").style.display=""; department_change(); } function department_change(){ console.log("change"); var inner=''; var tower_group_arr = new Array(); for(var i=0;i' ; tower_group_arr.push(obj[1][i].group); } } inner += '
機組健康狀態查看
健康
' document.getElementById('department_text').innerHTML=document.getElementById("department_list").value; document.getElementById('department_show').innerHTML=inner; } function towerGroup_show(){ var inner= ''; var tower_group_arr = new Array(); for(var i=0;i
'; for(var i=0;i'; } } inner += '
設備馬達效能查看
健康更多
' return inner; } function newLocation(newLat,newLng) { map.setCenter({ lat : newLat, lng : newLng }); addmarker(newLat,newLng); } var map; function initMap() { var position = { lat: 25.0339031, lng: 121.5623212 }; map = new google.maps.Map(document.getElementById('map'), { center: position, zoom: 14 }); var marker = new google.maps.Marker({ position: position, map: map }); } function addmarker(lat,lng){ var myLatlng = new google.maps.LatLng(lat,lng); var marker = new google.maps.Marker({ position: myLatlng, }); console.log("yes"); // To add the marker to the map, call setMap(); marker.setMap(map); } function clearMarkers(lat,lng) { var myLatlng = new google.maps.LatLng(lat,lng); marker = google.maps.Marker({ position: myLatlng, title:"Hello World!" }); markers.setMap(null); } function hide(){ document.getElementById("map").style.display="none";//隱藏 }