|
|
@ -9,7 +9,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts" name="Role">
|
|
|
|
<script setup lang="ts" name="Role">
|
|
|
|
import "leaflet/dist/leaflet.css";
|
|
|
|
import "leaflet/dist/leaflet.css";
|
|
|
|
import { LatLngBoundsExpression, Layer, LayerGroup, Map } from 'leaflet';
|
|
|
|
import { LatLngBoundsExpression, Layer, LayerGroup, Map, LeafletMouseEvent } from 'leaflet';
|
|
|
|
import { addMonitor, editMonitor, deleteMonitor } from '@/api/monitor';
|
|
|
|
import { addMonitor, editMonitor, deleteMonitor } from '@/api/monitor';
|
|
|
|
import { monitorType } from '../type'
|
|
|
|
import { monitorType } from '../type'
|
|
|
|
import * as L from 'leaflet'
|
|
|
|
import * as L from 'leaflet'
|
|
|
@ -17,6 +17,7 @@ import { filterTreeItem, onlyMessage } from '@/utils/comm'
|
|
|
|
import bg from '/images/bind/bdt.png'
|
|
|
|
import bg from '/images/bind/bdt.png'
|
|
|
|
import { deviceIcons, stateIcons } from '@/assets/diviceIcon'
|
|
|
|
import { deviceIcons, stateIcons } from '@/assets/diviceIcon'
|
|
|
|
import { pad } from "lodash-es";
|
|
|
|
import { pad } from "lodash-es";
|
|
|
|
|
|
|
|
const emit = defineEmits([ 'getMonitorList']);
|
|
|
|
interface MarkerType extends Layer {
|
|
|
|
interface MarkerType extends Layer {
|
|
|
|
markerId?: string | number
|
|
|
|
markerId?: string | number
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -32,7 +33,7 @@ const markers = ref<LayerGroup>()
|
|
|
|
const mapMonitorList = ref<monitorType[]>([])
|
|
|
|
const mapMonitorList = ref<monitorType[]>([])
|
|
|
|
|
|
|
|
|
|
|
|
const createMarkers = (info: monitorType): MarkerType => {
|
|
|
|
const createMarkers = (info: monitorType): MarkerType => {
|
|
|
|
let { id, name, monitorType, deviceNum, deviceIp, devicePort, positionX, positionY } = info
|
|
|
|
let { id, nodeName, positionX, positionY } = info
|
|
|
|
|
|
|
|
|
|
|
|
const x = parseFloat(positionX as string);
|
|
|
|
const x = parseFloat(positionX as string);
|
|
|
|
const y = parseFloat(positionY as string);
|
|
|
|
const y = parseFloat(positionY as string);
|
|
|
@ -45,14 +46,26 @@ const createMarkers = (info: monitorType): MarkerType => {
|
|
|
|
draggable: true,//开启拖拽
|
|
|
|
draggable: true,//开启拖拽
|
|
|
|
})
|
|
|
|
})
|
|
|
|
marker.markerId = id
|
|
|
|
marker.markerId = id
|
|
|
|
marker.bindTooltip('dsadas', {
|
|
|
|
marker.bindTooltip(nodeName, {
|
|
|
|
permanent: false, // 永久显示提示
|
|
|
|
permanent: true, // 永久显示提示
|
|
|
|
direction: 'top',// 提示显示的方向
|
|
|
|
direction: 'top',// 提示显示的方向
|
|
|
|
offset: L.point(0, -10)
|
|
|
|
offset: L.point(0, -10)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
console.log(marker)
|
|
|
|
// 添加拖拽结束事件
|
|
|
|
return marker
|
|
|
|
marker.on('dragend', async (event: LeafletMouseEvent) => {
|
|
|
|
|
|
|
|
const newMarkerPosition = event.target.getLatLng();
|
|
|
|
|
|
|
|
if (newMarkerPosition) {
|
|
|
|
|
|
|
|
const { lat, lng } = newMarkerPosition;
|
|
|
|
|
|
|
|
//存在则修改位置
|
|
|
|
|
|
|
|
const res = await editMonitor({ id: event.target.markerId, positionX: lng, positionY: lat });
|
|
|
|
|
|
|
|
if (res.result) {
|
|
|
|
|
|
|
|
onlyMessage('保存成功');
|
|
|
|
|
|
|
|
emit('getMonitorList');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return marker
|
|
|
|
|
|
|
|
};
|
|
|
|
//初始化画板
|
|
|
|
//初始化画板
|
|
|
|
const loadMap = () => {
|
|
|
|
const loadMap = () => {
|
|
|
|
const imageBounds: LatLngBoundsExpression = [[0, 0], [1080, 1980]];
|
|
|
|
const imageBounds: LatLngBoundsExpression = [[0, 0], [1080, 1980]];
|
|
|
@ -72,7 +85,8 @@ const loadMap = () => {
|
|
|
|
map.value = L.map('map')
|
|
|
|
map.value = L.map('map')
|
|
|
|
map.value.setView([30.58, 114.34,], 10);
|
|
|
|
map.value.setView([30.58, 114.34,], 10);
|
|
|
|
const stamenLayer = L.tileLayer('/static/map/{z}/{x}/{y}/tile.png', {
|
|
|
|
const stamenLayer = L.tileLayer('/static/map/{z}/{x}/{y}/tile.png', {
|
|
|
|
attribution: '垃圾程序员', // 图层属性信息※
|
|
|
|
attribution: '', // 图层属性信息※
|
|
|
|
|
|
|
|
|
|
|
|
minZoom: 10, // 最小缩放级别※
|
|
|
|
minZoom: 10, // 最小缩放级别※
|
|
|
|
maxZoom: 15 // 最大缩放级别※
|
|
|
|
maxZoom: 15 // 最大缩放级别※
|
|
|
|
}).addTo(map.value);
|
|
|
|
}).addTo(map.value);
|
|
|
@ -109,11 +123,11 @@ const drop = async (event: DragEvent) => {
|
|
|
|
const { lat, lng } = mouseEventLatLng;
|
|
|
|
const { lat, lng } = mouseEventLatLng;
|
|
|
|
//const dragEvent = event as DragEvent;
|
|
|
|
//const dragEvent = event as DragEvent;
|
|
|
|
let monitorData = JSON.parse(event.dataTransfer?.getData('monitorData') || '');
|
|
|
|
let monitorData = JSON.parse(event.dataTransfer?.getData('monitorData') || '');
|
|
|
|
console.log("🚀 monitorData:", monitorData, lat, lng)
|
|
|
|
|
|
|
|
//存在则修改位置
|
|
|
|
//存在则修改位置
|
|
|
|
const res = await editMonitor({ ...monitorData, positionX: lng, positionY: lat });
|
|
|
|
const res = await editMonitor({ ...monitorData, positionX: lng, positionY: lat });
|
|
|
|
if (res.result) {
|
|
|
|
if (res.result) {
|
|
|
|
onlyMessage('保存成功');
|
|
|
|
onlyMessage('保存成功');
|
|
|
|
|
|
|
|
emit('getMonitorList');
|
|
|
|
if (!monitorData.positionX) {
|
|
|
|
if (!monitorData.positionX) {
|
|
|
|
markers.value?.addLayer(createMarkers({ ...monitorData, positionX: lng, positionY: lat }))
|
|
|
|
markers.value?.addLayer(createMarkers({ ...monitorData, positionX: lng, positionY: lat }))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -132,13 +146,17 @@ const onDragLeave = (event: MouseEvent) => {
|
|
|
|
console.log('Drag leave');
|
|
|
|
console.log('Drag leave');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
watch(() => props.listData, (val) => {
|
|
|
|
loadMap()
|
|
|
|
console.log("🚀 val:", val)
|
|
|
|
mapMonitorList.value = filterTreeItem(props.listData, 'children', (i) => i.positionX)
|
|
|
|
markers.value?.clearLayers()
|
|
|
|
|
|
|
|
mapMonitorList.value = filterTreeItem(props.listData, 'children', i => i.positionX)
|
|
|
|
mapMonitorList.value.forEach((i: monitorType) => {
|
|
|
|
mapMonitorList.value.forEach((i: monitorType) => {
|
|
|
|
markers.value?.addLayer(createMarkers(i))
|
|
|
|
markers.value?.addLayer(createMarkers(i))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
|
|
loadMap();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|