You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.2 KiB

3 weeks ago
<template>
3 weeks ago
<OpenLayerMap class="w-full map-container" v-if="inited" :markers="markers" :fences="fences" />
3 weeks ago
</template>
<script lang="ts" setup>
import OpenLayerMap from './components/OpenLayerMap.vue'
import { getLastestDetectorData } from '@/api/gas'
3 weeks ago
import { HandDetectorData } from '@/api/gas/handdetector'
import { MarkerData,FenceData } from './components/types/map.types'
3 weeks ago
import { Fence } from '@/api/gas/fence'
import { FenceApi } from '@/api/gas/fence'
import dayjs from 'dayjs'
3 weeks ago
const getDataTimer = ref<NodeJS.Timeout | null>(null)
const markers = ref<MarkerData[]>([])
3 weeks ago
const fences = ref<FenceData[]>([])
3 weeks ago
const inited = ref(false)
const getMarkers = async () => {
console.log('getMarkers')
3 weeks ago
return await getLastestDetectorData().then((res: HandDetectorData[]) => {
3 weeks ago
res = res.filter((i) => i.enableStatus === 1)
var res2 = res.map((i) => {
3 weeks ago
return {
...i,
coordinates: [i.longitude, i.latitude],
data: [],
time: i.time ? dayjs(i.time).format('YYYY-MM-DD HH:mm:ss') : '',
value: i.value,
3 weeks ago
unit: i.unit,
gasStatus: i.gasStatus, //气体报警状态
batteryStatus: i.batteryStatus, //电池报警状态
fenceStatus: i.fenceStatus, //电子围栏报警状态
onlineStatus: i.onlineStatus, //在线状态
enableStatus: i.enableStatus //启用状态
3 weeks ago
}
})
markers.value = res2 as unknown as any[]
3 weeks ago
inited.value = true
})
}
3 weeks ago
const getFences = async () => {
console.log('getFences')
return await FenceApi.getFencePage({
pageNo: 1,
pageSize: 100
}).then((res) => {
console.log('getFences', res)
let fencesData = res.list as Fence[]
fencesData = fencesData.map((i) => {
return {
...i,
fenceRange: JSON.parse(i.fenceRange)
}
})
3 weeks ago
fences.value = fencesData as unknown as FenceData[]
3 weeks ago
})
}
3 weeks ago
onMounted(() => {
getMarkers()
3 weeks ago
getFences()
3 weeks ago
console.log('定时器,暂时关掉,太烦了')
// getDataTimer.value = setInterval(() => {
// getMarkers()
// getFences()
// }, 5000)
3 weeks ago
})
onUnmounted(() => {
clearInterval(getDataTimer.value as NodeJS.Timeout)
})
</script>
3 weeks ago
<style scoped>
.map-container {
width: 100%;
height: calc(100vh - 140px);
}
</style>