Browse Source

feat: fixing typo

gemercheung 1 year ago
parent
commit
2ebf3f7588
4 changed files with 65 additions and 32 deletions
  1. 1 0
      src/request/drawing.ts
  2. 41 24
      src/view/map/map-board.vue
  3. 19 2
      src/view/map/map-right-poly.vue
  4. 4 6
      src/view/map/map-right.vue

+ 1 - 0
src/request/drawing.ts

@@ -14,6 +14,7 @@ export type PolyDataType = {
 }
 
 export interface DrawingDataType extends PolygonsAttrib {
+    id?: string;
     polygons: PolyDataType[],
 }
 

+ 41 - 24
src/view/map/map-board.vue

@@ -294,22 +294,39 @@ const initPolyTabData = async () => {
 }
 
 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)
+  try {
+    const data = board.getData() as any as DrawingDataType;
+    const obj: DrawingDataType = JSON.parse(JSON.stringify(data))
+    const index = obj.polygons.findIndex(i => id === i.id)
+    console.log('handlePolysDel', id, index)
+    const points = [];
+    if (index > -1) {
+      data.polygons[index].lineIds.forEach(id => {
+        // 当前poly下线段与点都删除
+        const line = data.lines.find(l => l.id === id);
+        line && line.pointIds.forEach(p => points.push(p));
+
+        const lIndex = obj.lines.findIndex(l => l.id === id);
+        lIndex > -1 && obj.lines.splice(lIndex, 1)
+      });
+      new Set(points).forEach((_, i) => {
+        const pIndex = obj.points.findIndex(p => p.id === i);
+        console.log('pIndex', pIndex, obj.points)
+        obj.points.splice(pIndex, 1)
       })
-      lIndex > -1 && data.lines.splice(lIndex, 1)
-    });
-    data.polygons.splice(index, 1);
+      console.log('points', new Set(points))
+      obj.polygons.splice(index, 1);
+    }
+    board.setData({
+      points: obj.points,
+      lines: obj.lines,
+      polygons: obj.polygons,
+    }, obj.id)
+
+  } catch (error) {
+    console.error('handlePolysDel', error);
   }
+
 }
 
 const handlePolysEdit = (item: PolyDataType) => {
@@ -320,16 +337,16 @@ const handlePolysEdit = (item: PolyDataType) => {
   handleSyncDataToServer();
 }
 
-const clearPolys = async () => {
-  await addOrUpdateDrawingFetch({
-    relicsId: String(relicsId.value),
-    data: {
-      points: [],
-      polygons: [],
-      lines: []
-    }
-  });
-}
+// const clearPolys = async () => {
+//   await addOrUpdateDrawingFetch({
+//     relicsId: String(relicsId.value),
+//     data: {
+//       points: [],
+//       polygons: [],
+//       lines: []
+//     }
+//   });
+// }
 
 </script>
 

+ 19 - 2
src/view/map/map-right-poly.vue

@@ -17,7 +17,7 @@
                                     <Edit @click="handleShowEditModel(item)" />
                                 </el-icon>
                                 <el-icon class="icon">
-                                    <Download />
+                                    <Download @click="handleDownload" />
                                 </el-icon>
                             </div>
                         </div>
@@ -36,7 +36,7 @@
 </template>
 
 <script setup lang="ts">
-import { ref, watchEffect } from "vue";
+import { ref, unref, watchEffect } from "vue";
 import type { PolyDataType, DrawingDataType } from '@/request/drawing.ts'
 import {
     Delete,
@@ -87,6 +87,23 @@ const del = async (id: string) => {
         emit('del', id)
     }
 }
+const handleDownload = () => {
+    const points = []
+    props.data.polygons.forEach(poly => {
+        poly.lineIds.forEach(line => {
+            const targetLine = props.data.lines.find(l => l.id === line)
+            targetLine && targetLine.pointIds.forEach(point => {
+                const targetPoint = props.data.points.find(p => p.id === point)
+                targetPoint && points.push(targetPoint)
+            })
+
+        })
+    });
+    console.log('points', points)
+
+
+    console.log('handleDownload');
+} 
 </script>
 
 <style lang="scss" scoped>

+ 4 - 6
src/view/map/map-right.vue

@@ -209,8 +209,6 @@ const addSceneHandler = async (scenes: Pick<Scene, "sceneId" | "sceneCode">[]) =
     relicsId.value!,
     scenes.map((item) => ({ sceneCode: item.sceneCode, id: item.sceneId }))
   );
-
-
 </script>
 
 
@@ -218,10 +216,10 @@ const addSceneHandler = async (scenes: Pick<Scene, "sceneId" | "sceneCode">[]) =
 :deep(.el-tree) {
   --el-tree-node-content-height: 52px;
 
-  .el-tree-node__content>label.el-checkbox {
-    // padding-top: 10px;
-    // align-items: flex-start;
-  }
+  // .el-tree-node__content>label.el-checkbox {
+  //   // padding-top: 10px;
+  //   // align-items: flex-start;
+  // }
 }
 
 .tree-item {