優化坐標數據解析邏輯,增加對 device_coordinate 的數值比對以避免精度問題
This commit is contained in:
parent
96fcd24546
commit
a0b5085a7c
@ -36,14 +36,25 @@ 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);
|
||||
} catch (e) {
|
||||
console.warn('解析 device_coordinate 失敗:', e);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
name: coordString,
|
||||
value: coordinate,
|
||||
itemStyle: {
|
||||
color:
|
||||
coordString === formState.value.device_coordinate
|
||||
? "#0000FF"
|
||||
: "#b02a02",
|
||||
color: isSelected ? "#0000FF" : "#b02a02",
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user