
{
+ if (device.full_name === 'SmartSocket-AA001') return 'red';
+ if (device.full_name === 'SmartSocket-AA003' || device.full_name === 'SmartSocket-AA004') return 'gray';
+ const realtimeDevice = realtimeData.value?.find(
+ (item) => item.device_number === device.device_number
+ );
+ const state = realtimeDevice?.state || '';
+ if (state === 'offnormal' || state === '') return device.device_close_color || '#999';
+ return device.device_normal_color || '#009100';
+};
+
const defaultOption = (map, data = []) => {
return {
animation: false,
@@ -38,13 +51,7 @@ const defaultOption = (map, data = []) => {
...sameOption,
symbolSize: 10,
itemStyle: {
- color: (params) =>
- params.data[2].full_name === "SmartSocket-AA001"
- ? "red"
- : params.data[2].full_name === "SmartSocket-AA003" ||
- params.data[2].full_name === "SmartSocket-AA004"
- ? "gray"
- : params.data[2].device_normal_color || "#009100",
+ color: (params) => getDeviceRealtimeColor(params.data[2]),
},
data,
},
@@ -52,19 +59,33 @@ const defaultOption = (map, data = []) => {
...sameOption,
symbolSize: 20,
itemStyle: {
- color: (params) =>
- params.data[2].full_name === "SmartSocket-AA001"
- ? "red"
- : params.data[2].full_name === "SmartSocket-AA003" ||
- params.data[2].full_name === "SmartSocket-AA004"
- ? "gray"
- : params.data[2].device_normal_color || "#009100",
+ color: (params) => getDeviceRealtimeColor(params.data[2]),
},
data: [],
},
],
};
};
+// 監聽 realtimeData 變化,刷新地圖顏色
+watch(
+ realtimeData,
+ () => {
+ setTimeout(() => {
+ if (
+ selectedFloor.value &&
+ asset_floor_chart.value &&
+ asset_floor_chart.value.chart &&
+ asset_floor_chart.value.chart.isDisposed() === false
+ ) {
+ asset_floor_chart.value.chart.setOption(
+ defaultOption(selectedFloor.value?.title, selectedData.value),
+ true
+ );
+ }
+ }, 0);
+ },
+ { deep: true }
+);
const { selectedFloor } = useSelectedFloor();
@@ -130,18 +151,23 @@ watch(
if (
selectedFloor.value &&
asset_floor_chart.value &&
- asset_floor_chart.value.chart
+ asset_floor_chart.value.chart &&
+ asset_floor_chart.value.chart.isDisposed() === false
) {
const selected = allData.value.filter((d) => d[2].is2DActive);
const unSelected = allData.value.filter((d) => !d[2].is2DActive);
- asset_floor_chart.value.chart.setOption({
- series: [
- { data: unSelected },
- {
- data: selected,
- },
- ],
- });
+ setTimeout(() => {
+ if (asset_floor_chart.value?.chart && !asset_floor_chart.value.chart.isDisposed()) {
+ asset_floor_chart.value.chart.setOption({
+ series: [
+ { data: unSelected },
+ {
+ data: selected,
+ },
+ ],
+ });
+ }
+ }, 0);
}
},
{
@@ -168,14 +194,18 @@ watch(
const unSelected = selectedData.value.filter((d) => !d[2].is2DActive);
console.log("allData.value", allData.value, selected, unSelected);
- asset_floor_chart.value.chart.setOption({
- series: [
- { data: unSelected },
- {
- data: selected,
- },
- ],
- });
+ setTimeout(() => {
+ if (asset_floor_chart.value?.chart && !asset_floor_chart.value.chart.isDisposed()) {
+ asset_floor_chart.value.chart.setOption({
+ series: [
+ { data: unSelected },
+ {
+ data: selected,
+ },
+ ],
+ });
+ }
+ }, 0);
}
},
{
diff --git a/src/views/system/components/SystemCard.vue b/src/views/system/components/SystemCard.vue
index ceba84d..9893c2f 100644
--- a/src/views/system/components/SystemCard.vue
+++ b/src/views/system/components/SystemCard.vue
@@ -5,11 +5,40 @@ import useSystemShowData from "@/hooks/useSystemShowData";
const { getCurrentInfoModalData, selected_dbid } = inject(
"system_selectedDevice"
);
-const { subscribeData } = inject("system_deviceList");
+const { subscribeData, realtimeData } = inject("system_deviceList");
const { showData } = useSystemShowData();
+
const FILE_BASEURL = import.meta.env.VITE_FILE_API_BASEURL;
+
+// 根據設備編號取得即時狀態
+const getDeviceRealtimeState = (deviceNumber) => {
+ const realtimeDevice = realtimeData.value?.find(
+ (item) => item.device_number === deviceNumber
+ );
+ return realtimeDevice?.state || '';
+};
+
+// 狀態顏色
+const getDeviceStatusColor = (device) => {
+ if (device.full_name === 'SmartSocket-AA001') return 'red';
+ if (device.full_name === 'SmartSocket-AA003' || device.full_name === 'SmartSocket-AA004') return 'gray';
+ const state = getDeviceRealtimeState(device.device_number);
+ if (state === 'offnormal' || state === '') return device.device_close_color || 'gray';
+ return device.device_normal_color;
+};
+
+// 狀態文字
+const getDeviceStatusText = (device) => {
+ if (device.full_name === 'SmartSocket-AA001') return 'Error';
+ if (device.full_name === 'SmartSocket-AA003' || device.full_name === 'SmartSocket-AA004') return 'Offline';
+ const state = getDeviceRealtimeState(device.device_number);
+ if (state === 'offnormal' || state === '') return 'Offline';
+ if (state === 'normal') return 'Online';
+ return state || device.device_status || 'Online';
+};
+
const fitToView = (forge_dbid, spriteDbId) => {
selected_dbid.value = [forge_dbid, spriteDbId];
};
@@ -72,25 +101,10 @@ const cancelDialog = () => {
{{ $t("system.status") }}:
- {{
- device.full_name === "SmartSocket-AA001"
- ? "Error"
- : device.full_name === "SmartSocket-AA003" ||
- device.full_name === "SmartSocket-AA004"
- ? "Offline"
- : device.device_status || 'Online'
- }}
+ {{ getDeviceStatusText(device) }}