|
@@ -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>
|
|
|
|