diff --git a/src/views/dashboard/Dashboard.vue b/src/views/dashboard/Dashboard.vue index 45978fb..0cc75c5 100644 --- a/src/views/dashboard/Dashboard.vue +++ b/src/views/dashboard/Dashboard.vue @@ -15,19 +15,22 @@ import useBuildingStore from "@/stores/useBuildingStore"; import { getSystemDevices, getSystemRealTime } from "@/apis/system"; import DashboardRefrig from "./components/DashboardRefrig.vue"; const FILE_BASEURL = import.meta.env.VITE_FILE_API_BASEURL; -const buildingStore = useBuildingStore() +const buildingStore = useBuildingStore(); const subscribeData = ref([]); const systemData = ref({}); let intervalId = null; +const productVisible = ref(false); // 產品產量儀表是否顯示 +const productCompleteVisible = ref(false); // 今日達成率是否顯示 + // 開始定時器 const startInterval = () => { // 清除之前的定時器(如果存在) if (intervalId) { clearInterval(intervalId); } - + // 每5秒呼叫一次 getData intervalId = setInterval(() => { getData(); @@ -37,29 +40,32 @@ const startInterval = () => { const getData = async () => { const res = await getSystemDevices({ building_guid: buildingStore.selectedBuilding?.building_guid, - }) + }); + + subscribeData.value = res.data; + console.log("devices", subscribeData.value); - subscribeData.value = res.data - console.log("devices", subscribeData.value) - // 轉換資料格式 const transformedData = {}; - - subscribeData.value.forEach(floor => { + + subscribeData.value.forEach((floor) => { if (floor.device_list && floor.device_list.length > 0) { const fullUrl = floor.floor_map_name; const uuid = fullUrl ? fullUrl.replace(/\.svg$/, "") : ""; - transformedData[uuid] = floor.device_list.map(device => { + transformedData[uuid] = floor.device_list.map((device) => { // 解析座標 - const coordinates = JSON.parse(device.device_coordinate || '[0,0]'); + const coordinates = JSON.parse(device.device_coordinate || "[0,0]"); const x = coordinates[0]; const y = coordinates[1]; - + // 決定設備狀態和顏色 let state = "Online"; let bgColor = device.device_normal_color; - - if (device.device_status === "Offline" || device.device_status === null) { + + if ( + device.device_status === "Offline" || + device.device_status === null + ) { state = "Offline"; bgColor = device.device_close_color; } @@ -80,7 +86,9 @@ const getData = async () => { points: device.points || [], floor: floor.full_name, state: state, - icon: device.device_image ? `${FILE_BASEURL}/upload/device_icon/${device.device_image}` : '', + icon: device.device_image + ? `${FILE_BASEURL}/upload/device_icon/${device.device_image}` + : "", bgColor: bgColor, Online_color: device.device_normal_color, Offline_color: device.device_close_color, @@ -92,15 +100,15 @@ const getData = async () => { buying_date: device.buying_date, created_at: device.created_at, bgSize: 50, - } + }, ]; }); } }); - + console.log("transformedData", transformedData); systemData.value = transformedData; -} +}; watch( () => buildingStore.selectedBuilding, @@ -111,7 +119,7 @@ watch( } }, { - immediate: true + immediate: true, } ); @@ -126,29 +134,38 @@ onUnmounted(() => {