|
@@ -1,6 +1,5 @@
|
|
|
<template>
|
|
|
<div class="map-layout">
|
|
|
-
|
|
|
<Teleport to=".header" v-if="isMounted">
|
|
|
<div class="custom_bar">
|
|
|
<div class="back_container">
|
|
@@ -34,7 +33,8 @@
|
|
|
</div>
|
|
|
<div class="right-control">
|
|
|
<MapRight v-if="isCurrentTab(0)" @fly-point="flyScenePoint" @fly-scene="flyScene" @goto-point="gotoPointPage" />
|
|
|
- <MapRightPoly v-if="isCurrentTab(1)"></MapRightPoly>
|
|
|
+ <MapRightPoly @del="handlePolysDel" @edit="handlePolysEdit" :data="boardData" v-if="isCurrentTab(1)">
|
|
|
+ </MapRightPoly>
|
|
|
</div>
|
|
|
|
|
|
<Teleport to="body" v-if="isMounted">
|
|
@@ -61,7 +61,7 @@ import { onMounted, ref, watchEffect, watch, onUnmounted, computed } from "vue";
|
|
|
import { createBoard, scenePosTransform } from "./board";
|
|
|
import MapRightPoly from "./map-right-poly.vue";
|
|
|
import { Back } from "@element-plus/icons-vue";
|
|
|
-import { addOrUpdateDrawingFetch, getDrawingDetailFetch, DrawingParamsType, DrawingDataType } from '@/request/drawing.ts'
|
|
|
+import { addOrUpdateDrawingFetch, getDrawingDetailFetch, DrawingParamsType, DrawingDataType, PolyDataType } from '@/request/drawing.ts'
|
|
|
// import { relicsPolyginsFetch } from "@/request";
|
|
|
import {
|
|
|
Grid,
|
|
@@ -199,29 +199,23 @@ const mapContainer = ref<HTMLDivElement>();
|
|
|
const boardContainer = ref<HTMLDivElement>();
|
|
|
let mapManage: Manage;
|
|
|
let board: ReturnType<typeof createBoard>;
|
|
|
-
|
|
|
+const boardData = ref<DrawingDataType | null>(null);
|
|
|
+let endEdithandler;
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
mapManage = mapManageInit(mapContainer.value!);
|
|
|
board = (window as any).board = boardInit(boardContainer.value!, mapManage);
|
|
|
isMounted.value = true
|
|
|
- try {
|
|
|
- const res = await getDrawingDetailFetch(String(relicsId.value));
|
|
|
- console.log('res', res.data)
|
|
|
- setTimeout(() => { })
|
|
|
-
|
|
|
- // board.setData(res.data, String(relicsId.value))
|
|
|
- } catch (error) {
|
|
|
|
|
|
- }
|
|
|
const borardPolyData = computed(() => board.getData());
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
watch(borardPolyData, (updater) => {
|
|
|
if (updater) {
|
|
|
- // console.log('borardPolyData', updater);
|
|
|
- console.log('borardPolyData', JSON.stringify(updater));
|
|
|
+ boardData.value = updater as any as DrawingDataType
|
|
|
}
|
|
|
}, { immediate: true, deep: true })
|
|
|
});
|
|
@@ -231,7 +225,6 @@ onUnmounted(() => {
|
|
|
board.destory();
|
|
|
});
|
|
|
|
|
|
-
|
|
|
const handleTabs = (index: number) => {
|
|
|
currentTab.value = index
|
|
|
}
|
|
@@ -239,7 +232,7 @@ const handleTabs = (index: number) => {
|
|
|
const handleBoardDraw = () => {
|
|
|
console.log('开始start draw', String(relicsId.value), board.polygon())
|
|
|
try {
|
|
|
- board.polygon().editPolygon();
|
|
|
+ endEdithandler = board.polygon().editPolygon();
|
|
|
isEditDrawingMode.value = true;
|
|
|
board.polygon().bus.on('penEndHandler', handleSyncDataToServer)
|
|
|
|
|
@@ -247,19 +240,26 @@ const handleBoardDraw = () => {
|
|
|
console.error('error', error)
|
|
|
}
|
|
|
}
|
|
|
-const handleSyncDataToServer = async () => {
|
|
|
- console.log('handleSyncDataToServer')
|
|
|
- const data = board.getData() as any as DrawingDataType;
|
|
|
- const param: DrawingParamsType = {
|
|
|
- data: data,
|
|
|
- relicsId: String(relicsId.value),
|
|
|
- // drawingId: String(relicsId.value)
|
|
|
- }
|
|
|
- patchPolyName(data);
|
|
|
- await addOrUpdateDrawingFetch(param);
|
|
|
- isEditDrawingMode.value = false;
|
|
|
- board.polygon().bus.off('penEndHandler');
|
|
|
+const handleSyncDataToServer = () => {
|
|
|
+ setTimeout(async () => {
|
|
|
+ console.log('handleSyncDataToServer')
|
|
|
+ const data = board.getData() as any as DrawingDataType;
|
|
|
+ boardData.value = data;
|
|
|
+ const param: DrawingParamsType = {
|
|
|
+ data: data,
|
|
|
+ relicsId: String(relicsId.value),
|
|
|
+ }
|
|
|
+ patchPolyName(data);
|
|
|
+
|
|
|
+ await addOrUpdateDrawingFetch(param);
|
|
|
+ isEditDrawingMode.value = false;
|
|
|
|
|
|
+ board.polygon().bus.off('penEndHandler');
|
|
|
+ if (endEdithandler) {
|
|
|
+
|
|
|
+ console.log('end edit')
|
|
|
+ }
|
|
|
+ }, 1000)
|
|
|
}
|
|
|
|
|
|
const patchPolyName = (data: DrawingDataType) => {
|
|
@@ -269,7 +269,66 @@ const patchPolyName = (data: DrawingDataType) => {
|
|
|
item.name = ''
|
|
|
}
|
|
|
})
|
|
|
+}
|
|
|
+
|
|
|
+watch(currentTab, (tab) => {
|
|
|
+ console.log('tab', tab)
|
|
|
+ if (tab === 1) {
|
|
|
+ initPolyTabData();
|
|
|
+ }
|
|
|
+}, { deep: true })
|
|
|
+
|
|
|
+const initPolyTabData = async () => {
|
|
|
+ try {
|
|
|
+ setTimeout(async () => {
|
|
|
+ const res = await getDrawingDetailFetch(String(relicsId.value));
|
|
|
+ console.log('res', res.data)
|
|
|
+ if (res.data) {
|
|
|
+ boardData.value = res.data;
|
|
|
+ board.setData(boardData.value, String(relicsId.value))
|
|
|
+ };
|
|
|
+ }, 500)
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const handlePolysDel = (id: string) => {
|
|
|
+
|
|
|
+ const data = board.getData() as any as DrawingDataType;
|
|
|
+ const index = data.polygons.findIndex(i => id === i.id)
|
|
|
+ console.log('handlePolysDel', id, index)
|
|
|
+ if (index > -1) {
|
|
|
+ data.polygons[index].lineIds.forEach(id => {
|
|
|
+ const lIndex = data.lines.findIndex(l => l.id === id);
|
|
|
+ const line = data.lines.find(l => l.id === id);
|
|
|
+ line.pointIds.forEach(p => {
|
|
|
+ const pointIndex = data.points.findIndex(pp => pp.id === p);
|
|
|
+ pointIndex > -1 && data.points.splice(pointIndex, 1)
|
|
|
+ })
|
|
|
+ lIndex > -1 && data.lines.splice(lIndex, 1)
|
|
|
+ });
|
|
|
+ data.polygons.splice(index, 1);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+const handlePolysEdit = (item: PolyDataType) => {
|
|
|
+ console.log('handlePolysEdit', item)
|
|
|
+ const data = board.getData() as any as DrawingDataType;
|
|
|
+ const index = data.polygons.findIndex(i => item.id === i.id)
|
|
|
+ data.polygons[index] = item;
|
|
|
+ handleSyncDataToServer();
|
|
|
+}
|
|
|
+
|
|
|
+const clearPolys = async () => {
|
|
|
+ await addOrUpdateDrawingFetch({
|
|
|
+ relicsId: String(relicsId.value),
|
|
|
+ data: {
|
|
|
+ points: [],
|
|
|
+ polygons: [],
|
|
|
+ lines: []
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
</script>
|
|
@@ -441,8 +500,8 @@ const patchPolyName = (data: DrawingDataType) => {
|
|
|
border-radius: 50%;
|
|
|
position: fixed;
|
|
|
z-index: 1000;
|
|
|
- transform: translateX(-50%);
|
|
|
- left: 50%;
|
|
|
+ transform: translateX(calc(-1 * calc(50% - 300px)));
|
|
|
+ left: calc(50% - 300px);
|
|
|
top: 90%;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|