hiển thị thuyền thông tin tàu

This commit is contained in:
Tran Anh Tuan
2025-12-03 16:22:25 +07:00
parent 47e9bac0f9
commit 22a3b591c6
22 changed files with 2135 additions and 260 deletions

View File

@@ -4,12 +4,14 @@ import {
EVENT_BANZONE_DATA,
EVENT_ENTITY_DATA,
EVENT_GPS_DATA,
EVENT_SEARCH_THINGS,
EVENT_TRACK_POINTS_DATA,
} from "@/constants";
import {
queryAlarm,
queryEntities,
queryGpsData,
querySearchThings,
queryTrackPoints,
} from "@/controller/DeviceController";
import { queryBanzones } from "@/controller/MapController";
@@ -21,12 +23,14 @@ const intervals: {
entities: ReturnType<typeof setInterval> | null;
trackPoints: ReturnType<typeof setInterval> | null;
banzones: ReturnType<typeof setInterval> | null;
searchThings: ReturnType<typeof setInterval> | null;
} = {
gps: null,
alarm: null,
entities: null,
trackPoints: null,
banzones: null,
searchThings: null,
};
export function getGpsEventBus() {
@@ -153,6 +157,37 @@ export function getBanzonesEventBus() {
}, AUTO_REFRESH_INTERVAL * 60);
}
export function searchThingEventBus(body: Model.SearchThingBody) {
// Clear interval cũ nếu có
if (intervals.searchThings) {
clearInterval(intervals.searchThings);
intervals.searchThings = null;
}
const searchThingsData = async () => {
// console.log("call api with body:", body);
try {
const resp = await querySearchThings(body);
if (resp && resp.data) {
eventBus.emit(EVENT_SEARCH_THINGS, resp.data);
} else {
console.log("SearchThings: no data returned");
}
} catch (err) {
console.error("SearchThings: fetch error", err);
}
};
// Gọi ngay lần đầu
searchThingsData();
// Sau đó setup interval để gọi lại mỗi 30s
intervals.searchThings = setInterval(() => {
searchThingsData();
}, AUTO_REFRESH_INTERVAL * 6); // 30 seconds
}
export function stopEvents() {
Object.keys(intervals).forEach((k) => {
const key = k as keyof typeof intervals;