優化坐標數據解析邏輯,增加對 device_coordinate 的數值比對以避免精度問題

This commit is contained in:
koko 2025-09-23 17:22:16 +08:00
parent 96fcd24546
commit a0b5085a7c

View File

@ -36,14 +36,25 @@ const defaultOption = (map, data = []) => {
// //
const formattedData = data.map((coordinate) => { const formattedData = data.map((coordinate) => {
const coordString = JSON.stringify(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);
} catch (e) {
console.warn('解析 device_coordinate 失敗:', e);
}
}
return { return {
name: coordString, name: coordString,
value: coordinate, value: coordinate,
itemStyle: { itemStyle: {
color: color: isSelected ? "#0000FF" : "#b02a02",
coordString === formState.value.device_coordinate
? "#0000FF"
: "#b02a02",
}, },
}; };
}); });
@ -117,7 +128,7 @@ const getCoordinate = (position) => {
<template> <template>
<!-- 平面圖 --> <!-- 平面圖 -->
<div class="flex gap-4 mb-5"> <div class="flex gap-4 mb-5">
<Select <Select
:value="formState" :value="formState"