From d822b3074a274bb1b31ec452ce6d77e443033b46 Mon Sep 17 00:00:00 2001 From: "MJM_2025_05\\polly" Date: Mon, 4 Aug 2025 17:02:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=A6=96=E9=A0=81=E5=9C=96=E8=A1=A8?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8F=8AMQTT=E4=B8=B2=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/system/api.js | 6 +- src/apis/system/index.js | 22 ++- src/config/cn.json | 3 +- src/config/tw.json | 5 +- src/config/us.json | 5 +- src/views/AssetManagement/AssetManagement.vue | 14 +- .../components/AssetTableAddModal.vue | 8 +- .../components/AssetTableModalLeftInfo.vue | 37 ++-- .../AssetTableModalLeftInfoMQTT.vue | 170 +++++++++++++--- .../components/AssetTableModalRightInfo.vue | 19 +- src/views/dashboard/Dashboard.vue | 6 +- .../DashboardEffectScatterModal.vue | 12 +- .../components/DashboardEmission.vue | 13 +- .../components/DashboardHumidity.vue | 97 ++------- .../dashboard/components/DashboardTemp.vue | 184 ++++++++++-------- .../history/components/HistoryDataCahrt.vue | 42 ++-- 16 files changed, 383 insertions(+), 260 deletions(-) diff --git a/src/apis/system/api.js b/src/apis/system/api.js index 10fe396..4f79543 100644 --- a/src/apis/system/api.js +++ b/src/apis/system/api.js @@ -2,4 +2,8 @@ export const GET_SYSTEM_FLOOR_LIST_API = `/api/Device/GetFloor`; export const GET_SYSTEM_DEVICE_LIST_API = `/api/Device/GetDeviceList`; export const GET_SYSTEM_REALTIME_API = `/api/Device/GetRealTimeData`; -export const GET_SYSTEM_CONFIG_API = `/api/GetSystemConfig`; \ No newline at end of file +export const GET_SYSTEM_CONFIG_API = `/api/GetSystemConfig`; + +export const POST_MQTT_TOPIC_API = `api/Device/MQTTTopicTest`; +export const POST_MQTT_TOPIC_STOP_API = `api/Device/MQTTTopicTestStop`; + diff --git a/src/apis/system/index.js b/src/apis/system/index.js index 8dd497a..9756bdc 100644 --- a/src/apis/system/index.js +++ b/src/apis/system/index.js @@ -2,7 +2,9 @@ import { GET_SYSTEM_FLOOR_LIST_API, GET_SYSTEM_DEVICE_LIST_API, GET_SYSTEM_REALTIME_API, - GET_SYSTEM_CONFIG_API + GET_SYSTEM_CONFIG_API, + POST_MQTT_TOPIC_API, + POST_MQTT_TOPIC_STOP_API, } from "./api"; import instance from "@/util/request"; import apihandler from "@/util/apihandler"; @@ -45,3 +47,21 @@ export const getSystemConfig = async (building_guid) => { code: res.code, }); }; + +export const postMqttTopic = async ({ iotTag, Topic }) => { + const res = await instance.post(POST_MQTT_TOPIC_API, { iotTag, Topic }); + + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + }); +}; + +export const postMqttTopicStop = async ({ iotTag, Topic }) => { + const res = await instance.post(POST_MQTT_TOPIC_STOP_API, { iotTag, Topic }); + + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + }); +}; diff --git a/src/config/cn.json b/src/config/cn.json index cb12296..afae1a9 100644 --- a/src/config/cn.json +++ b/src/config/cn.json @@ -48,9 +48,10 @@ "this_year": "今年", "last_year": "去年", "refrig_chart": "冷藏趨勢", - "indoor_chart": "室內趨勢", + "indoor_chart": "室內", "temperature": "温度", "humidity": "湿度", + "no_data":"无数据", "alerts_data": "异常资料" }, "history": { diff --git a/src/config/tw.json b/src/config/tw.json index dc8c178..a53d1c6 100644 --- a/src/config/tw.json +++ b/src/config/tw.json @@ -47,10 +47,11 @@ "last_month": "上月", "this_year": "今年", "last_year": "去年", - "refrig_chart": "冷藏趨勢", - "indoor_chart": "室內趨勢", + "refrig_chart": "冷藏", + "indoor_chart": "室內", "temperature": "溫度", "humidity": "濕度", + "no_data": "無資料", "alerts_data": "異常資料" }, "history": { diff --git a/src/config/us.json b/src/config/us.json index 59ea94f..99a19e9 100644 --- a/src/config/us.json +++ b/src/config/us.json @@ -47,10 +47,11 @@ "last_month": "Last month", "this_year": "This year", "last_year": "Last year", - "refrig_chart": "Refrigeration chart", - "indoor_chart": "Indoor chart", + "refrig_chart": "Refrigeration", + "indoor_chart": "Indoor", "temperature": "Temp.", "humidity": "Hum.", + "no_data":"No data", "alerts_data": "Abnormal data" }, "history": { diff --git a/src/views/AssetManagement/AssetManagement.vue b/src/views/AssetManagement/AssetManagement.vue index acf2863..0bcda6b 100644 --- a/src/views/AssetManagement/AssetManagement.vue +++ b/src/views/AssetManagement/AssetManagement.vue @@ -12,13 +12,24 @@ const { searchParams, changeParams } = useSearchParam(); const companyOptions = ref([]); const iotSchemaOptions = ref([]); const elecTypeOptions = ref([]); + +const iotSchemaTag = ref(""); const getCompany = async () => { const res = await getOperationCompanyList(); companyOptions.value = res.data.map((d) => ({ ...d, key: d.id })); }; const getIOTSchemaOptions = async (id) => { const res = await getIOTSchema(Number(id)); - iotSchemaOptions.value = res.data.map((d) => ({ ...d, key: d.id })); + const data = res.data || []; + + iotSchemaOptions.value = data.map((d) => ({ ...d, key: d.id })); + + // 取出第一筆的 tagIoT,提供給最深層元件使用 + if (data.length > 0 && data[0].tagIoT) { + iotSchemaTag.value = data[0].tagIoT; + } else { + iotSchemaTag.value = ""; + } }; const getElecType = async () => { const res = await getElecTypeList(); @@ -52,6 +63,7 @@ provide("asset_modal_options", { departmentList, floors, }); +provide("iotSchemaTag", iotSchemaTag); diff --git a/src/views/AssetManagement/components/AssetTableModalRightInfo.vue b/src/views/AssetManagement/components/AssetTableModalRightInfo.vue index a8ed3e7..6689a75 100644 --- a/src/views/AssetManagement/components/AssetTableModalRightInfo.vue +++ b/src/views/AssetManagement/components/AssetTableModalRightInfo.vue @@ -34,20 +34,23 @@ const defaultOption = (map, data = []) => { // 生成坐標數據,根據坐標值的不同設置不同顏色 const formattedData = data.map((coordinate) => { const coordString = JSON.stringify(coordinate); - + // 解析 device_coordinate 為數值陣列進行比對 let isSelected = false; if (formState.value.device_coordinate) { try { const deviceCoord = JSON.parse(formState.value.device_coordinate); // 比對數值而非字串,避免精度問題 - isSelected = coordinate.length === deviceCoord.length && - coordinate.every((val, index) => Math.abs(val - deviceCoord[index]) < 0.001); + isSelected = + coordinate.length === deviceCoord.length && + coordinate.every( + (val, index) => Math.abs(val - deviceCoord[index]) < 0.001 + ); } catch (e) { - console.warn('解析 device_coordinate 失敗:', e); + console.warn("解析 device_coordinate 失敗:", e); } } - + return { name: coordString, value: coordinate, @@ -121,15 +124,15 @@ watch( const getCoordinate = (position) => { formState.value.device_coordinate = JSON.stringify(position); }; - - \ No newline at end of file +