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.

137 lines
3.7 KiB

2 weeks ago
<template>
<div class="flex flex-row overflow-auto" style="height: calc(100vh - 160px)">
<div class="flex-1 h-full position-relative">
<OpenLayerMap
ref="mapRef"
class="map-container"
:showDrawFences="true"
:showTrajectories="true"
:markers="filterMarkers"
:fences="fences"
/>
<TopPanel
v-model="search"
:handDetectorCount="handDetectorCount"
:onlineCount="onlineCount"
/>
</div>
<div class="markerList">
<!--marker列表 -->
<div v-for="item in filterMarkers" :key="item.id" class="marker-item">
<div>{{ item.name }}{{ item.onlineStatus === 1 ? '在线' : '离线' }}</div>
</div>
</div>
</div>
2 weeks ago
</template>
<script lang="ts" setup>
import OpenLayerMap from './components/OpenLayerMap.vue'
import TopPanel from './components/TopPanel.vue'
1 week ago
import { getLastDetectorData } from '@/api/gas'
1 week ago
import { HandDetectorData } from '@/api/gas/handdetector'
import { MarkerData, FenceData } from './components/types/map.types'
import { useHandDetectorStore } from '@/store/modules/handDetector'
import dayjs from 'dayjs'
const handDetectorStore = useHandDetectorStore() // 手持探测器 store
2 weeks ago
const getDataTimer = ref<NodeJS.Timeout | null>(null)
const markers = ref<MarkerData[]>([])
1 week ago
const fences = ref<FenceData[]>([])
const mapRef = ref<typeof OpenLayerMap>()
const search = ref('')
watch(
() => search.value,
(newSearch, oldSearch) => {
if (newSearch !== oldSearch) {
mapRef.value?.fitToMarkers()
}
},
{ immediate: false }
)
// 手持设备数量
const handDetectorCount = computed(() => markers.value.length)
const onlineCount = computed(() => markers.value.filter((item) => item.onlineStatus === 1).length)
const filterMarkers = computed(() => {
if (search.value) {
return markers.value.filter((item) => {
var isName = item.name.includes(search.value)
var isSn = item.sn?.includes(search.value)
var isGasChemical = item.gasChemical?.includes(search.value)
return isName || isSn || isGasChemical
})
}
return markers.value
})
2 weeks ago
const getMarkers = async () => {
console.log('getMarkers')
1 week ago
return await getLastDetectorData().then((res: HandDetectorData[]) => {
2 weeks ago
res = res.filter((i) => i.enableStatus === 1)
var res2 = res.map((i) => {
1 week ago
console.log([i.longitude, i.latitude])
2 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,
1 week ago
unit: i.unit,
gasStatus: i.gasStatus, //气体报警状态
batteryStatus: i.batteryStatus, //电池报警状态
fenceStatus: i.fenceStatus, //电子围栏报警状态
onlineStatus: i.onlineStatus, //在线状态
enableStatus: i.enableStatus //启用状态
2 weeks ago
}
})
markers.value = res2 as unknown as any[]
2 weeks ago
})
}
2 weeks ago
const getFences = async () => {
return await handDetectorStore.getAllFences().then((res) => {
2 weeks ago
console.log('getFences', res)
let fencesData = res.map((i) => {
return {
...i,
fenceRange: JSON.parse(i.fenceRange)
}
})
1 week ago
fences.value = fencesData as unknown as FenceData[]
2 weeks ago
})
}
2 weeks ago
onMounted(() => {
getMarkers()
getFences()
1 week ago
// getFences()
1 week ago
console.log('定时器,暂时关掉,太烦了')
getDataTimer.value = setInterval(() => {
getMarkers()
getFences()
}, 5000)
2 weeks ago
})
onUnmounted(() => {
clearInterval(getDataTimer.value as NodeJS.Timeout)
})
</script>
<style scoped lang="scss">
2 weeks ago
.map-container {
width: 100%;
height: 100%;
2 weeks ago
}
.markerList {
width: 220px;
height: 100%;
background-color: white;
padding:0 10px;
margin-left: 10px;
}
2 weeks ago
</style>