diff --git a/src/apis/alert/api.js b/src/apis/alert/api.js index b82e6f8..f8f2bab 100644 --- a/src/apis/alert/api.js +++ b/src/apis/alert/api.js @@ -1,6 +1,7 @@ export const POST_ACK_API = `/obix/alarm`; export const GET_ALERT_FORMID_API = `/Alert/AlertList`; export const GET_ALERT_LOG_API = `api/Alarm/GetAlarmLog`; +export const GET_ALERT_LOG_LIST_API = `api/Alarm/GetAlarmLogList`; export const POST_OPERATION_RECORD_API = `/operation/SavOpeRecord`; export const GET_ALERT_SUB_LIST_API = `api/Device/GetMainSub`; diff --git a/src/apis/alert/index.js b/src/apis/alert/index.js index 0d54384..d2f19e3 100644 --- a/src/apis/alert/index.js +++ b/src/apis/alert/index.js @@ -2,6 +2,7 @@ import { POST_ACK_API, GET_ALERT_FORMID_API, GET_ALERT_LOG_API, + GET_ALERT_LOG_LIST_API, POST_OPERATION_RECORD_API, GET_ALERT_SUB_LIST_API, GET_OUTLIERS_LIST_API, @@ -19,7 +20,7 @@ import { GET_ALERT_SCHEDULE_LIST_API, POST_ALERT_SCHEDULE, DELETE_ALERT_SCHEDULE, - POST_ALERT_MQTT_REFRESH + POST_ALERT_MQTT_REFRESH, } from "./api"; import instance from "@/util/request"; import apihandler from "@/util/apihandler"; @@ -50,6 +51,16 @@ export const getAlertLog = async ({ }); }; +export const getAlertLogList = async (building_guid) => { + const res = await instance.post(GET_ALERT_LOG_LIST_API, { + building_guid, + }); + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + }); +}; + export const postOperationRecord = async (formData) => { const res = await instance.post(POST_OPERATION_RECORD_API, formData); diff --git a/src/components/chart/EffectScatter.vue b/src/components/chart/EffectScatter.vue index 75b34b9..9f122f1 100644 --- a/src/components/chart/EffectScatter.vue +++ b/src/components/chart/EffectScatter.vue @@ -17,42 +17,63 @@ const props = defineProps({ let chart = ref(null); let dom = ref(null); let currentClickPosition = ref([]); +let currentMapName = ref(null); async function updateSvg(svg, option) { if (!chart.value && dom.value && svg) { init(); - } else { - clear(); } - axios.get(svg.path).then(({ data }) => { - echarts.registerMap(svg.full_name, { svg: data }); - chart.value.setOption(option); - if (props.getCoordinate) { - chart.value.getZr().on("click", function (params) { - var pixelPoint = [params.offsetX, params.offsetY]; - var dataPoint = chart.value.convertFromPixel( - { geoIndex: 0 }, - pixelPoint - ); - currentClickPosition.value = dataPoint; - props.getCoordinate(dataPoint); - const updatedData = option.series.data - .filter( - (point) => !(point.itemStyle && point.itemStyle.color === "#0000FF") - ) - .concat({ - value: dataPoint, // 當前座標值 - itemStyle: { color: "#0000FF" }, // 設為藍色 - }); - chart.value.setOption({ - series: { - data: updatedData, - }, - }); - }); + + // 檢查是否需要載入新的 SVG 地圖 + const needNewSvg = currentMapName.value !== svg.full_name; + + if (needNewSvg) { + // 載入新的 SVG 地圖 + console.log("Loading new SVG map:", svg.full_name); + currentMapName.value = svg.full_name; + + try { + const { data } = await axios.get(svg.path); + echarts.registerMap(svg.full_name, { svg: data }); + chart.value.setOption(option); + setupClickHandler(option); + } catch (error) { + console.error("Failed to load SVG:", error); } - }); - console.log("updateSvg", svg.path); + } else if (chart.value) { + // 只更新數據,不重新載入 SVG + console.log("Updating chart data only"); + chart.value.setOption({ + series: option.series + }, false, true); + } +} + +function setupClickHandler(option) { + if (props.getCoordinate && chart.value) { + chart.value.getZr().on("click", function (params) { + var pixelPoint = [params.offsetX, params.offsetY]; + var dataPoint = chart.value.convertFromPixel( + { geoIndex: 0 }, + pixelPoint + ); + currentClickPosition.value = dataPoint; + props.getCoordinate(dataPoint); + const updatedData = option.series[1].data + .filter( + (point) => !(point.itemStyle && point.itemStyle.color === "#0000FF") + ) + .concat({ + value: dataPoint, // 當前座標值 + itemStyle: { color: "#0000FF" }, // 設為藍色 + }); + chart.value.setOption({ + series: [{}, { + data: updatedData, + }] + }); + }); + } } function clear() { diff --git a/src/views/dashboard/Dashboard.vue b/src/views/dashboard/Dashboard.vue index 9383947..6c41b88 100644 --- a/src/views/dashboard/Dashboard.vue +++ b/src/views/dashboard/Dashboard.vue @@ -2,12 +2,13 @@ import DashboardFloorBar from "./components/DashboardFloorBar.vue"; import DashboardEffectScatter from "./components/DashboardEffectScatter.vue"; import DashboardSysCard from "./components/DashboardSysCard.vue"; +import DashboardTemp from "./components/DashboardTemp.vue"; import DashboardRefrigTemp from "./components/DashboardRefrigTemp.vue"; import DashboardIndoorTemp from "./components/DashboardIndoorTemp.vue"; import DashboardElectricity from "./components/DashboardElectricity.vue"; import DashboardEmission from "./components/DashboardEmission.vue"; import DashboardAlert from "./components/DashboardAlert.vue"; -import { computed, inject, ref, watch } from "vue"; +import { computed, inject, ref, watch, onMounted, onUnmounted } from "vue"; import useBuildingStore from "@/stores/useBuildingStore"; import { getSystemDevices, getSystemRealTime } from "@/apis/system"; const FILE_BASEURL = import.meta.env.VITE_FILE_API_BASEURL; @@ -15,6 +16,21 @@ const buildingStore = useBuildingStore() const subscribeData = ref([]); const systemData = ref({}); +let intervalId = null; + +// 開始定時器 +const startInterval = () => { + // 清除之前的定時器(如果存在) + if (intervalId) { + clearInterval(intervalId); + } + + // 每5秒呼叫一次 getData + intervalId = setInterval(() => { + getData(); + }, 5000); +}; + const getData = async () => { const res = await getSystemDevices({ building_guid: buildingStore.selectedBuilding?.building_guid, @@ -38,11 +54,15 @@ const getData = async () => { // 決定設備狀態和顏色 let state = "online"; - let bgColor = "rgba(255, 255, 255)"; + let bgColor = device.device_normal_color; - if (device.device_status === "offline" || device.device_status === null) { - state = "offline"; - bgColor = "rgba(34, 51, 85)"; + if (device.device_status === "Offline" || device.device_status === null) { + state = "Offline"; + bgColor = device.device_close_color; + } + if (device.device_status === "Error") { + state = "Error"; + bgColor = device.device_error_color; } return [ @@ -69,12 +89,20 @@ watch( (newBuilding) => { if (newBuilding) { getData(); + startInterval(); } }, { immediate: true } ); + +// 組件卸載時清除定時器 +onUnmounted(() => { + if (intervalId) { + clearInterval(intervalId); + } +});