// 设置第一次点赋值,重新定义一个新数组,将设备号为对象名,索引值作为键值
const getListNEW = useCallback(
(params, reload, gps) => {
if (gps && markArrNew.current) {
openBus(markArrNew.current, reload, gps);
} else {
openBus(params, reload);
markArrNew.current = params;
let json = {};
if (params?.list?.length > 0) {
params.list.forEach((item, index) => {
json[item.coding] = index;
});
} else if (params?.flow_list?.length > 0) {
params.flow_list.forEach((item, index) => {
json[item.coding] = index;
});
}
console.log('json----', json);
markArrNew1.current = json;
}
},
[markArrNew.current],
);
// 判断数据是否存在于对象中,如果有必定大于-1,没有则为-1,将websocket的数组以相同的对象名放入新数组
let gps = dataNew; // websocket返回的数组
let carList = dealCarList(markArrNew.current); // 去重后的数组
let nowIndex =
markArrNew1.current[gps.device_name] > -1 ?
markArrNew1.current[gps.device_name] : -1;
console.log('nowIndex', nowIndex);
if (nowIndex >= 0 && carList[nowIndex]?.longitude) {
markArrNew2.current = markArrNew2.current || {};
markArrNew2.current[gps.device_name || gps.data.deviceNo] = dataNew;
// 每隔3秒执行一下,这个数组,不管里面有多少数据,都执行一遍,达到实时位置的效果
const throttleRef = useRef(
throttle(() => {
console.log('throttleRef', markArrNew2.current);
for (let i in markArrNew2.current) {
setGPS(i, markArrNew2.current[i]);
}
markArrNew2.current = {};
}, 3000),
).current;