Browse Source

不显示围栏弹窗

master
xh 1 day ago
parent
commit
f8b7a10687
  1. 2
      web/src/api/gas/handdetector/index.ts
  2. 4
      web/src/views/HandDevice/Home/components/OpenLayerMap.vue
  3. 18
      web/src/views/HandDevice/Home/components/composables/useMapEvents.ts
  4. 28
      web/src/views/HandDevice/Home/components/composables/useTrajectoryControls.ts
  5. 4
      web/src/views/HandDevice/Home/components/services/marker.service.ts
  6. 22
      web/src/views/HandDevice/Home/components/services/trajectory.service.ts
  7. 9
      web/src/views/HandDevice/Home/components/utils/map.utils.ts
  8. 29
      web/src/views/HandDevice/Home/index.vue

2
web/src/api/gas/handdetector/index.ts

@ -40,7 +40,7 @@ export interface HandDetectorData extends HandDetector {
statusStr?: string // 状态字符串 (normal, offline, gas_1,gas_2, battery_1, fence_1) statusStr?: string // 状态字符串 (normal, offline, gas_1,gas_2, battery_1, fence_1)
statusLabel?: string // 状态字符串 (正常, 离线, 气体报警, 电池报警, 围栏报警) statusLabel?: string // 状态字符串 (正常, 离线, 气体报警, 电池报警, 围栏报警)
statusColor?: string // 状态颜色 statusColor?: string // 状态颜色
statusPriority?: number // 状态优先级, 越小优先级越高
} }
// GAS手持探测器 API // GAS手持探测器 API

4
web/src/views/HandDevice/Home/components/OpenLayerMap.vue

@ -143,7 +143,7 @@ const toggleTrajectories = () => {
showTrajectoriesStatus.value = !showTrajectoriesStatus.value showTrajectoriesStatus.value = !showTrajectoriesStatus.value
// console.log(showTrajectoriesStatus.value, props.markers); // console.log(showTrajectoriesStatus.value, props.markers);
if (showTrajectoriesStatus.value) { if (showTrajectoriesStatus.value) {
setTrajectoriesVisible(showTrajectoriesStatus.value, props.markers)
setTrajectoriesVisible(showTrajectoriesStatus.value,[])
} }
} }
@ -208,7 +208,7 @@ const init = () => {
} }
) )
// //
setupTrajectoryWatcher(services.trajectoryService as any, showTrajectoriesStatus)
setupTrajectoryWatcher(services.trajectoryService, showTrajectoriesStatus)
// //
const { setupAllWatchers } = useMapWatchers({ const { setupAllWatchers } = useMapWatchers({

18
web/src/views/HandDevice/Home/components/composables/useMapEvents.ts

@ -112,8 +112,12 @@ export const useMapEvents = () => {
const feature = map.forEachFeatureAtPixel(event.pixel, (feature: FeatureLike) => feature) const feature = map.forEachFeatureAtPixel(event.pixel, (feature: FeatureLike) => feature)
if (feature) { if (feature) {
map.getTargetElement().style.cursor = 'pointer'
showPopup(event, feature, popupOverlay, popupGenerator)
const isPopupShown = showPopup(event, feature, popupOverlay, popupGenerator)
if (isPopupShown) {
map.getTargetElement().style.cursor = 'pointer'
} else {
hidePopup(popupOverlay)
}
} else { } else {
map.getTargetElement().style.cursor = '' map.getTargetElement().style.cursor = ''
hidePopup(popupOverlay) hidePopup(popupOverlay)
@ -167,11 +171,11 @@ export const useMapEvents = () => {
feature: FeatureLike, feature: FeatureLike,
popupOverlay: Overlay | null, popupOverlay: Overlay | null,
popupGenerator: PopupContentGenerator popupGenerator: PopupContentGenerator
) => {
if (!popupOverlay) return
): Boolean => {
if (!popupOverlay) return false
const popupElement = popupOverlay.getElement() const popupElement = popupOverlay.getElement()
if (!popupElement) return
if (!popupElement) return false
const featureType = feature.get('type') const featureType = feature.get('type')
let popupContent = '' let popupContent = ''
@ -185,7 +189,8 @@ export const useMapEvents = () => {
break break
case 'fence': case 'fence':
case 'fence-label': case 'fence-label':
popupContent = popupGenerator.handleFence(feature)
// popupContent = popupGenerator.handleFence(feature)
return false
break break
default: default:
popupContent = popupGenerator.handleMarker(feature) popupContent = popupGenerator.handleMarker(feature)
@ -194,6 +199,7 @@ export const useMapEvents = () => {
// if (!popupContent) return // if (!popupContent) return
popupElement.innerHTML = popupContent popupElement.innerHTML = popupContent
popupOverlay.setPosition(event.coordinate) popupOverlay.setPosition(event.coordinate)
return true
} }
/** /**

28
web/src/views/HandDevice/Home/components/composables/useTrajectoryControls.ts

@ -1,7 +1,7 @@
/** /**
* composable * composable
*/ */
import { ref, watch } from 'vue'
import { ref, watch, onBeforeMount, onActivated, onDeactivated } from 'vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import type { TrajectoryPlayState } from '../types/map.types' import type { TrajectoryPlayState } from '../types/map.types'
import { TrajectoryService } from '../services/trajectory.service' import { TrajectoryService } from '../services/trajectory.service'
@ -152,7 +152,14 @@ export const useTrajectoryControls = () => {
() => trajectoryPlayState.value, () => trajectoryPlayState.value,
(newState) => { (newState) => {
if (trajectoryService && showTrajectories.value) { if (trajectoryService && showTrajectories.value) {
// 打印计时
// console.time('updateByPlayState')
trajectoryService.updateByPlayState(newState) trajectoryService.updateByPlayState(newState)
// console.timeEnd('updateByPlayState')
} else {
cleanup()
} }
}, },
{ deep: true } { deep: true }
@ -167,15 +174,26 @@ export const useTrajectoryControls = () => {
* *
*/ */
const cleanup = () => { const cleanup = () => {
// if (trajectoryPlayTimer.value) {
// window.clearInterval(trajectoryPlayTimer.value)
// }
// trajectoryPlayTimer.value = null
trajectoryPlayState.value.isPlaying = false
if (animationId) { if (animationId) {
window.cancelAnimationFrame(animationId) window.cancelAnimationFrame(animationId)
} }
} }
onDeactivated(() => {
console.log('onDeactivated')
cleanup()
})
onBeforeMount(() => {
cleanup()
})
if (import.meta.hot) {
import.meta.hot.accept((newModule) => {
// 热更新时的自定义清理逻辑
console.log('热更新发生,执行清理')
cleanup()
})
}
return { return {
// 状态 // 状态
trajectoryPlayState, trajectoryPlayState,

4
web/src/views/HandDevice/Home/components/services/marker.service.ts

@ -104,7 +104,7 @@ export class MarkerService {
if (features.length === 1) { if (features.length === 1) {
// 单个marker // 单个marker
const markerData: MarkerData = features[0].get('markerData') const markerData: MarkerData = features[0].get('markerData')
const statusStr = getHighestPriorityStatus(markerData)
const statusStr = getHighestPriorityStatus(markerData)
return markerData ? createMarkerStyle(statusStr) : new Style() return markerData ? createMarkerStyle(statusStr) : new Style()
} else { } else {
// 聚合marker // 聚合marker
@ -126,7 +126,7 @@ export class MarkerService {
// console.log('renderOrder',a,b.get('markerData').time); // console.log('renderOrder',a,b.get('markerData').time);
// 按xxx属性降序排列 // 按xxx属性降序排列
return b.get('markerData').time - a.get('markerData').time
return a.get('markerData').statusPriority - b.get('markerData').statusPriority
} }
}) })
} }

22
web/src/views/HandDevice/Home/components/services/trajectory.service.ts

@ -21,7 +21,7 @@ export class TrajectoryService {
private trajectoryLayer: VectorLayer<VectorSource> | null = null private trajectoryLayer: VectorLayer<VectorSource> | null = null
private trajectoryData: TrajectoryData[] = [] private trajectoryData: TrajectoryData[] = []
private map: Map | null = null private map: Map | null = null
private animationTimer: number | null = null
// private animationTimer: number | null = null
// 当前移动的 marker 图层 // 当前移动的 marker 图层
private movingMarkerLayer: VectorLayer<VectorSource> | null = null private movingMarkerLayer: VectorLayer<VectorSource> | null = null
@ -115,6 +115,7 @@ export class TrajectoryService {
// 创建移动中的 marker 图层 // 创建移动中的 marker 图层
this.movingMarkerLayer = new VectorLayer({ this.movingMarkerLayer = new VectorLayer({
source: new VectorSource(), source: new VectorSource(),
zIndex: 2, // 确保移动中的 marker 在轨迹之上
style: (feature) => { style: (feature) => {
const color = feature.get('color') || '#ff4757' const color = feature.get('color') || '#ff4757'
return new Style({ return new Style({
@ -272,16 +273,16 @@ export class TrajectoryService {
if (point.data) { if (point.data) {
// 将点数据构造为MarkerData格式以使用现有的状态计算函数 // 将点数据构造为MarkerData格式以使用现有的状态计算函数
const markerData = {
id: -1,
coordinates: [0, 0] as [number, number],
name: '',
const markerStatusData = {
// id: -1,
// coordinates: [0, 0] as [number, number],
// name: '',
gasStatus: point.data.gasStatus || '0', gasStatus: point.data.gasStatus || '0',
batteryStatus: point.data.batteryStatus || '0', batteryStatus: point.data.batteryStatus || '0',
fenceStatus: point.data.fenceStatus || '0', fenceStatus: point.data.fenceStatus || '0',
onlineStatus: point.data.onlineStatus || '1' onlineStatus: point.data.onlineStatus || '1'
} }
const status = getHighestPriorityStatus(markerData)
const status = getHighestPriorityStatus(markerStatusData)
color = getStatusColor(status) color = getStatusColor(status)
} }
@ -459,6 +460,7 @@ export class TrajectoryService {
* *
*/ */
hide(): void { hide(): void {
if (this.trajectoryLayer) { if (this.trajectoryLayer) {
this.trajectoryLayer.setVisible(false) this.trajectoryLayer.setVisible(false)
} }
@ -499,10 +501,10 @@ export class TrajectoryService {
* *
*/ */
destroy(): void { destroy(): void {
if (this.animationTimer) {
clearTimeout(this.animationTimer)
this.animationTimer = null
}
// if (this.animationTimer) {
// clearTimeout(this.animationTimer)
// this.animationTimer = null
// }
this.trajectoryLayer = null this.trajectoryLayer = null
this.movingMarkerLayer = null this.movingMarkerLayer = null

9
web/src/views/HandDevice/Home/components/utils/map.utils.ts

@ -23,7 +23,10 @@ export const getStatusMapping = (type: keyof typeof STATUS_DICT, value: string):
const info = findStatusInfo(STATUS_DICT[type], value) const info = findStatusInfo(STATUS_DICT[type], value)
return info ? `${type}_${value}` : '' return info ? `${type}_${value}` : ''
} }
// 获取状态优先级,越小优先级越高
export const getStatusPriority = (statusStr: string | keyof typeof STATUS_PRIORITY): number => {
return STATUS_PRIORITY[statusStr] || 0
}
/** /**
* *
*/ */
@ -69,7 +72,7 @@ export const getHighestPriorityStatus = (markerData: {
/** /**
* *
*/ */
export const getStatusColor = (status: string|keyof typeof STATUS_PRIORITY): string => {
export const getStatusColor = (status: string | keyof typeof STATUS_PRIORITY): string => {
if (status === 'normal') return '#67c23a' if (status === 'normal') return '#67c23a'
if (status === 'offline') return STATUS_DICT.onlineStatus[0].cssClass if (status === 'offline') return STATUS_DICT.onlineStatus[0].cssClass
@ -81,7 +84,7 @@ export const getStatusColor = (status: string|keyof typeof STATUS_PRIORITY): str
/** /**
* *
*/ */
export const getStatusLabel = (status:string| keyof typeof STATUS_PRIORITY): string => {
export const getStatusLabel = (status: string | keyof typeof STATUS_PRIORITY): string => {
if (status === 'normal') return '正常' if (status === 'normal') return '正常'
if (status === 'offline') return STATUS_DICT.onlineStatus[0].label if (status === 'offline') return STATUS_DICT.onlineStatus[0].label

29
web/src/views/HandDevice/Home/index.vue

@ -47,9 +47,7 @@
><span>电池状态</span ><span>电池状态</span
>{{ getLabelWithTypeValue('batteryStatus', item.batteryStatus) }}</div >{{ getLabelWithTypeValue('batteryStatus', item.batteryStatus) }}</div
> >
<!-- <div><span>启用状态</span>{{ item.enableStatus === 1 ? '启用' : '备用' }}</div> -->
<!-- <hr /> -->
<div><span>电量</span>{{ item.battery }}</div> <div><span>电量</span>{{ item.battery }}</div>
<div><span>数值</span>{{ item.value }} {{ item.unit }}</div> <div><span>数值</span>{{ item.value }} {{ item.unit }}</div>
<div><span>时间</span>{{ item.timeStr }}</div> <div><span>时间</span>{{ item.timeStr }}</div>
@ -67,14 +65,11 @@
> >
</div> </div>
<!-- {{ item }} -->
</div> </div>
</el-collapse-item> </el-collapse-item>
</el-collapse> </el-collapse>
</el-scrollbar> </el-scrollbar>
<!-- <div v-for="item in filterMarkers" :key="item.id" class="marker-item">
<div>{{ item.name }}{{ item.onlineStatus === 1 ? '在线' : '离线' }}</div>
</div> -->
</div> </div>
</div> </div>
</template> </template>
@ -84,9 +79,9 @@ import TopPanel from './components/TopPanel.vue'
import { getLastDetectorData } from '@/api/gas' import { getLastDetectorData } from '@/api/gas'
import { HandDetectorData } from '@/api/gas/handdetector' import { HandDetectorData } from '@/api/gas/handdetector'
import { tdengineApi, tdStruct, tdQuery } from '@/api/gas/tdengine/index'
import { tdengineApi } from '@/api/gas/tdengine/index'
import { getLabelWithTypeValue, getHighestPriorityStatus,getStatusLabel,getStatusColor } from './components/utils/map.utils'
import { getLabelWithTypeValue, getHighestPriorityStatus,getStatusLabel,getStatusColor,getStatusPriority } from './components/utils/map.utils'
import { MarkerData, FenceData } from './components/types/map.types' import { MarkerData, FenceData } from './components/types/map.types'
@ -94,6 +89,7 @@ import { useHandDetectorStore } from '@/store/modules/handDetector'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { getDistance } from 'ol/sphere' import { getDistance } from 'ol/sphere'
const componentsIsActive = ref(false)
const handDetectorStore = useHandDetectorStore() // store const handDetectorStore = useHandDetectorStore() // store
@ -156,6 +152,7 @@ const getMarkers = async () => {
statusStr:statusStr, // statusStr:statusStr, //
statusColor: getStatusColor(statusStr), // statusColor: getStatusColor(statusStr), //
statusLabel: getStatusLabel(statusStr), // statusLabel: getStatusLabel(statusStr), //
statusPriority: getStatusPriority(statusStr), //,
} }
}) })
markers.value = res2 markers.value = res2
@ -182,7 +179,7 @@ function setCenter(item: MarkerData) {
mapRef.value?.setCenter([item.longitude || 0, item.latitude || 0]) mapRef.value?.setCenter([item.longitude || 0, item.latitude || 0])
} }
} }
//
let currentMarker: MarkerData | null = null let currentMarker: MarkerData | null = null
var trajectoryTimeRange = ref([dayjs().subtract(1, 'hour').valueOf(), dayjs().valueOf()]) var trajectoryTimeRange = ref([dayjs().subtract(1, 'hour').valueOf(), dayjs().valueOf()])
// //
@ -232,7 +229,7 @@ async function showTrajectory(item: MarkerData) {
if (index === 0) { if (index === 0) {
return true return true
} }
if (index == arr.length - 2) {
if (index == arr.length - 1) {
return true return true
} }
@ -300,10 +297,20 @@ onMounted(() => {
console.log('定时器,暂时关掉,太烦了') console.log('定时器,暂时关掉,太烦了')
getDataTimer.value = setInterval(() => { getDataTimer.value = setInterval(() => {
if (!componentsIsActive.value) {
return
}
getMarkers() getMarkers()
getFences() getFences()
}, 5000) }, 5000)
}) })
onActivated(() => {
componentsIsActive.value = true
})
onDeactivated(() => {
componentsIsActive.value = false
})
onUnmounted(() => { onUnmounted(() => {
clearInterval(getDataTimer.value as NodeJS.Timeout) clearInterval(getDataTimer.value as NodeJS.Timeout)
}) })

Loading…
Cancel
Save