forked from drone/command-center-dashboard

chenyao
2025-04-09 bdb66cf55723eab8ce633a2babea25d315cab0d5
feat: 新建航线
5 files modified
784 ■■■■ changed files
src/api/home/task.js 15 ●●●●● patch | view | raw | blame | history
src/views/Home/HomeLeft/MachineNestList.vue 1 ●●●● patch | view | raw | blame | history
src/views/TaskManage/TaskIntermediateContent/AddTask.vue 110 ●●●● patch | view | raw | blame | history
src/views/TaskManage/TaskIntermediateContent/TaskMap.vue 542 ●●●●● patch | view | raw | blame | history
src/views/TaskManage/TaskIntermediateContent/TaskTable.vue 116 ●●●● patch | view | raw | blame | history
src/api/home/task.js
@@ -92,7 +92,10 @@
        method: 'post',
        data: {
            wayline_id: data.wayline_id,
            type: data.type
            type: data.type,
            latitude: data.latitude,
            longitude: data.longitude,
            polygon: data.polygon
        },
    })
}
@@ -106,5 +109,15 @@
    })
}
// 面状航线
export const getWaylineByArea = (data) => {
    return request({
        url: `/drone-device-core/wayline/api/v1/workspaces/getWaylineByArea`,
        method: 'post',
        data,
    })
}
src/views/Home/HomeLeft/MachineNestList.vue
@@ -67,7 +67,6 @@
// 搜索数据
const handleSearch = (name) => {
  console.log(name, '哒哒哒');
  searchText.value = name;
  pageParams.value.current = 1;
  tableList.value = [];
src/views/TaskManage/TaskIntermediateContent/AddTask.vue
@@ -11,10 +11,10 @@
        <div class="task-contain">
            <div class="left">
                <div class="search">
                    <div class="item">任务名称:<el-input v-model="searchForm.name" placeholder="请输入任务名称"></el-input></div>
                    <div class="item"><span style="color: red;">*</span>任务日期:
                    <div class="item"><span class="required">*</span>任务名称:<el-input v-model="searchForm.name" placeholder="请输入任务名称"></el-input></div>
                    <div class="item"><span class="required">*</span>任务日期:
                        <el-date-picker
                            v-model="searchForm.begin_time"
                            v-model="taskData"
                            format="YYYY-MM-DD"
                            value-format="YYYY-MM-DD"
                        />
@@ -46,16 +46,28 @@
                </div>
                <div class="lines">
                    <div class="wayline-type">
                        <el-radio-group v-model="searchForm.wayline_type">
                            <el-radio label="1">单点航线</el-radio>
                            <el-radio label="2">智能规划选区</el-radio>
                        <el-radio-group v-model="waylineType" @change="radioChange">
                            <el-radio :value="1" label="单点航线"></el-radio>
                            <el-radio :value="2" label="智能规划选区"></el-radio>
                        </el-radio-group>
                    </div>
                    <TaskMap class="wayline-map" :wayLineFile="wayLineFile"/>
                    <TaskMap class="wayline-map"
                        :wayLineFile="wayLineFile"
                        :checkedTableData="checkedTableData"
                        :waylineTypeTest="waylineType"
                        @clickPosition="clickSignPosition"
                        @saveWayline="savePlanerWayline"
                    />
                </div>
            </div>
            <div class="right">
                <TaskTable :waylineId="waylineId" :waylineType="waylineType" @update:selected="handleSelected" />
                <TaskTable ref="taskTableRef"
                    :waylineId="waylineId"
                    :waylineType="waylineType"
                    :singlePoint="singlePoint"
                    :planarPoints="planarPoints"
                    @update:selected="handleSelected"
                />
                <div class="btn">
                    <el-button type="primary" @click="cancel">取消</el-button>
                    <el-button type="primary" @click="submitClick">发布</el-button>
@@ -73,14 +85,18 @@
import TaskMap from './TaskMap.vue';
import TaskTable from './TaskTable.vue';
const emit = defineEmits(['refresh']);
const rangDate = ref([]);
// 航线ID
let waylineId = ref('');
const waylineId = ref('');
// 航线文件
let wayLineFile = ref('');
const wayLineFile = ref('');
// 航线类型
let waylineType = ref(0);
const waylineType = ref(3);
// 添加子组件引用
const taskTableRef = ref(null);
const taskData = ref('');
const searchForm = reactive({
    name: '',
    ai_types: [],
@@ -91,6 +107,9 @@
    remark: '',
    type: waylineType.value,
    dock_sns: [],
    longitude: '',
    latitude: '',
    polygon: [],
});
const isShowAddTask = defineModel('show');
@@ -102,32 +121,78 @@
    routeOptions.value = res.data.data;
  }
};
// 关联算法
const algorithmChange = (val) => {
  searchForm.ai_types = val;
};
// 切换航线类型
const radioChange = (val) => {
    // 清空选中航线值
    searchForm.file_id = '';
    // 航线ID也清空
    waylineId.value = '';
    wayLineFile.value = '';
  waylineType.value = val;
    searchForm.type = val;
    // 清空列表数据
    nextTick(() => {
    if (taskTableRef.value) {
      taskTableRef.value.clearTableData();
    }
  });
};
// 获取航线文件
const getWayLineFile = async (val) => {
    searchForm.type = 0;
    waylineType.value = 0;
    waylineId.value = val;
    const currentRoute = routeOptions.value.find(item => item.wayline_id === val);
  wayLineFile.value = currentRoute.object_key;
};
// 获取选中机场列表数据,并且发布
let checkedTableData = ref([]);
const handleSelected = (val) => {
  searchForm.dock_sns = val.map(item => item.device_sn);
    checkedTableData.value = val;
};
const emit = defineEmits(['refresh']);
// 地图点击事件 表格重新刷新数据
let singlePoint = ref({});
const clickSignPosition = (val) => {
  singlePoint.value = val;
    searchForm.longitude = val.longitude;
    searchForm.latitude = val.latitude;
};
// 保存面状航线
let planarPoints = ref([]);
const savePlanerWayline = (val) => {
  planarPoints.value = val;
    const polygonArray = val.map(point => [point.longitude, point.latitude]);
    searchForm.polygon = polygonArray;
};
// 提交
const submitClick = () => {
    if (!searchForm.begin_time) {
    if (!taskData.value) {
    ElMessage({
      message: '请选择任务日期',
      type: 'warning'
    });
    return;
  }
    searchForm.end_time = `${searchForm.begin_time} 23:59:59`;
    searchForm.begin_time = `${searchForm.begin_time} 00:00:00`;
    if (!searchForm.name) {
    ElMessage({
      message: '请输入任务名称',
      type: 'warning'
    });
    return;
  }
    searchForm.begin_time = `${taskData.value} 00:00:00`;
  searchForm.end_time = `${taskData.value} 23:59:59`;
    
    createTask(searchForm).then((res) => {
        if (res.data.code === 0) {
@@ -153,6 +218,7 @@
  waylineId.value = '';
  wayLineFile.value = '';
};
onMounted(() => {
  getRouteList();
})
@@ -171,7 +237,7 @@
.task-contain {
    display: flex;
    .left {
        width: 70%;
        width: 68%;
        .search {
            display: grid;
      grid-template-columns: repeat(3, 1fr);
@@ -179,6 +245,7 @@
      gap: 30px; // 增加间距使布局更合理
      margin-bottom: 8px; // 添加底部间距
            .item {
                position: relative;
        display: flex;
        align-items: center;
        :deep(.el-input),
@@ -191,11 +258,18 @@
                :deep(.el-date-editor.el-input__wrapper) {
          width: 200px;  // 调整日期选择器宽度
        }
                .required {
                    color: #f56c6c;
                    margin-left: 4px;
                    position: absolute;
                    left: -10px;
                    top: 8px;
                }
      }
        }
    }
    .right {
        width: 30%;
        width: 32%;
        display: flex;
    flex-direction: column;
    justify-content: space-between;
src/views/TaskManage/TaskIntermediateContent/TaskMap.vue
@@ -1,5 +1,5 @@
<template>
    <div id="taskMap" />
    <div id="taskMap"></div>
</template>
<script setup>
import * as Cesium from 'cesium'
@@ -12,9 +12,29 @@
import EndPointicon from '@/assets/images/EndPointicon.png';
import uavImg from '@/assets/images/home/useUavHome/uavImg.png'
import { getCenterPoint } from '@/utils/cesium/mapUtil'
import { getWaylineByArea } from '@/api/home/task';
import { useStore } from 'vuex';
const props = defineProps(['wayLineFile'])
const store = useStore();
const userAreaPosition = computed(() => store.state.home.userAreaPosition);
// 声明事件
const emit = defineEmits(['clickPosition', 'saveWayline']);
const props = defineProps({
    wayLineFile: {
    type: String,
    default: ''
  },
  checkedTableData: {
    type: Array,
    default: () => []
  },
    waylineTypeTest: {
    type: Number,
    default: 3
  }
})
const imageryProvider_ammapSL = new Cesium.UrlTemplateImageryProvider({
    url: 'https://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
@@ -26,8 +46,18 @@
    maximumLevel: 18,
    tilingScheme: new AmapMercatorTilingScheme(),
    credit: 'amap_SL',
})
let viewer = null
});
let viewer = null;
let currentEntity = null;
let connectLines = []; // 存储连接线实体
let polygonPoints = []; // 存储多边形的点
let polygonEntity = null; // 存储多边形实体
let existingEntity = null; // 后端返回数据生成得面状线
// 添加变量跟踪当前菜单
let currentMenu = null;
const init = () => {
    viewer = new Viewer('taskMap', {
        terrain: Terrain.fromWorldTerrain(),
@@ -46,22 +76,214 @@
    })
    viewer.imageryLayers.addImageryProvider(imageryProvider_ammapSL)
    viewer.scene.morphTo2D(0);
    //设置默认点
    const { longitude = 115.763819, latitude = 28.787374, height = 10 } = userAreaPosition.value || {};
    viewer.camera.setView({
        destination: Cartesian3.fromDegrees(longitude, latitude, height),
    });
}
// 渲染线和点
// 单点左键点击事件
const singlePointLeftClick = () => {
  viewer.screenSpaceEventHandler.setInputAction((click) => {
        if (props.waylineTypeTest !== 1) return
    const cartesian = viewer.camera.pickEllipsoid(
      click.position,
      viewer.scene.globe.ellipsoid
    );
    if (cartesian) {
      // 清除之前的实体
      viewer.entities.removeAll();
      // 添加新点
      const point = viewer.entities.add({
        position: cartesian,
        point: {
          pixelSize: 10,
          color: Cesium.Color.WHITE
        }
      });
      // 转换坐标
      const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
      const longitude = Cesium.Math.toDegrees(cartographic.longitude);
      const latitude = Cesium.Math.toDegrees(cartographic.latitude);
      // 更新当前实体引用
      currentEntity = point;
      // 发送坐标
      emit('clickPosition', { longitude, latitude });
    }
  }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
};
// 智能规划航线
const intelligentPlanning = () => {
    // 添加点击事件监听
  viewer.screenSpaceEventHandler.setInputAction((click) => {
        if (props.waylineTypeTest !== 2) return
        const cartesian = viewer.camera.pickEllipsoid(
            click.position,
            viewer.scene.globe.ellipsoid
        );
        if (cartesian) {
            // 添加新点
            const point = viewer.entities.add({
                position: cartesian,
                point: {
                    pixelSize: 10,
                    color: Cesium.Color.WHITE
                }
            });
            // 存储点位
            polygonPoints.push(cartesian);
            // 当点击超过2个点时绘制多边形
            if (polygonPoints.length > 2) {
                // 移除旧的多边形
                if (polygonEntity) {
                    viewer.entities.remove(polygonEntity);
                }
                // 创建新的多边形
                polygonEntity = viewer.entities.add({
                    polygon: {
                        hierarchy: new Cesium.PolygonHierarchy(polygonPoints),
                        // material: new Cesium.Color.fromBytes(212, 46, 32, 100),
                        material: new Cesium.Color(0, 0.5, 1, 0.3), // 蓝色
                        outline: true,
                        // outlineColor: new Cesium.Color.fromBytes(212, 46, 32, 255),
                        outlineColor: new Cesium.Color(0, 0.5, 1, 1), // 蓝
                        outlineWidth: 2,
                        height: 0, // Set explicit height
                        heightReference: Cesium.HeightReference.NONE // Disable terrain clamping
                    }
                });
            }
            // 转换坐标并发送
            const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
            const longitude = Cesium.Math.toDegrees(cartographic.longitude);
            const latitude = Cesium.Math.toDegrees(cartographic.latitude);
            // emit('clickPosition', cartographic);
        }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
    // 修改右键点击事件,添加菜单
    viewer.screenSpaceEventHandler.setInputAction((movement) => {
        if (props.waylineTypeTest !== 2) return
        if (polygonPoints.length > 2) {
            // 清除之前的菜单
            if (currentMenu) {
                document.body.querySelectorAll('.context-menu').forEach(menu => menu.remove());
            }
            const menuContainer = document.createElement('div');
            menuContainer.className = 'context-menu';
            // 获取地图容器
            const mapContainer = document.getElementById('taskMap');
            // 使用鼠标右键点击的实际位置
            menuContainer.style.position = 'absolute';
            menuContainer.style.left = `${movement.position.x}px`;
            menuContainer.style.top = `${movement.position.y}px`;
            menuContainer.style.zIndex = '1000';
            menuContainer.innerHTML = `
                <div class="menu-item" id="saveWayline">保存航线</div>
                <div class="menu-item" id="cancelDraw">取消绘制</div>
            `;
            mapContainer.appendChild(menuContainer);
            currentMenu = menuContainer;
            // 添加全局点击事件监听
            const handleClickOutside = (e) => {
                if (!menuContainer) return;
                const isClickInside = menuContainer.contains(e.target);
                if (!isClickInside) {
                    menuContainer.remove();
                    document.removeEventListener('mousedown', handleClickOutside);
                }
            };
            // 延迟添加事件监听,避免右键点击立即触发
            setTimeout(() => {
                document.addEventListener('mousedown', handleClickOutside);
            }, 100);
            // 菜单按钮点击事件
            document.getElementById('saveWayline').onclick = () => {
                const coordinates = polygonPoints.map(point => {
                    const cartographic = Cesium.Cartographic.fromCartesian(point);
                    return {
                        longitude: Cesium.Math.toDegrees(cartographic.longitude),
                        latitude: Cesium.Math.toDegrees(cartographic.latitude)
                    };
                });
                emit('saveWayline', coordinates);
                saveWaylineByArea(coordinates);
                mapContainer.removeChild(menuContainer);
            };
            document.getElementById('cancelDraw').onclick = () => {
                polygonPoints = [];
                viewer.entities.removeAll();
                mapContainer.removeChild(menuContainer);
            };
        }
    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
};
// 保存航线并且获取线
const saveWaylineByArea = (dataValue) => {
    const polygonArray = dataValue.map(point => [point.longitude, point.latitude]);
    getWaylineByArea({ type: 2, polygon: polygonArray }).then(res => {
        if (res.data.code !== 0) retrun;
        drawResultWayline(res.data.data);
    });
}
// 绘制后端生成得面状线
const drawResultWayline = (dataValue) => {
    // 先检查并删除已存在的航线
  existingEntity = viewer.entities.getById('result_wayline');
  if (existingEntity) {
    viewer.entities.remove(existingEntity);
  }
    const cartesian3List = ref([]);
    dataValue.forEach((lnglat) => {
        const cartesian3 = Cesium.Cartesian3.fromDegrees(
            Number(lnglat.x),
            Number(lnglat.y),
            Number(100), // 默认100
        )
        cartesian3List.value.push(cartesian3)
    });
    const setting = {
        id: 'result_wayline',
        polyline: {
            width: 2,
            positions: cartesian3List.value,
            material: Cesium.Color.CHARTREUSE,
        },
    }
    existingEntity = viewer?.entities.add({
        polyline: setting.polyline,
        id: setting.id,
    })
};
// 选中航线时调用 渲染线和点 type = 0
const renderingLine = lineObj => {
    const positions = lineObj.Placemark.map(item => {
        const [lon, lat] = item.Point.coordinates.split(',')
        return Cartesian3.fromDegrees(Number(lon), Number(lat))
    })
    // viewer.entities.add({
    //     position: positions[0],
    //     billboard: {
    //         image: new Cesium.ConstantProperty(uavImg),
    //         width: 24,
    //         height: 24,
    //     },
    // });
    viewer.entities.add({
        polyline: {
            width: 4,
@@ -75,24 +297,26 @@
            clampToGround: false,
        },
    })
  console.log('positions',positions)
  positions.forEach((point, index) => {
    let setting = {};
    if (index === 0) {
      //TODO
    } else if (index === 1) {
      setting = {
        position: point,
        id: `point_${index}`,
        billboard: {
          image: Startingpointicon,
          outlineWidth: 0,
          width: 20,
          height: 20,
          scale: 1.0,
        },
      }
    } else if (index === positions.length - 1) {
    // if (index === 0) {
    //   //TODO
    // }
        // else if (index === 1) {
    //   setting = {
    //     position: point,
    //     id: `point_${index}`,
    //     billboard: {
    //       image: Startingpointicon,
    //       outlineWidth: 0,
    //       width: 20,
    //       height: 20,
    //       scale: 1.0,
    //     },
    //   }
    // } else
        if (index === positions.length - 1) {
      setting = {
        position: point,
        id: `point_${index}`,
@@ -109,7 +333,7 @@
        position: point,
        id: `point_${index}`,
        label: {
          text: `${index}`,
          text: `${index+1}`,
          font: 'bold 14px serif',
          style: Cesium.LabelStyle.FILL,
          verticalOrigin: Cesium.VerticalOrigin.CENTER, // 垂直居中
@@ -144,25 +368,11 @@
    })
}
// const drawLine = () => {
//   console.log('尽量么');
//     // props.wayLineFile.way_lines.forEach(item => {
//   // let prexUrl = ref(import.meta.env.VITE_APP_AIRLINE_URL+ props.wayLineFile);
//   let prexUrl2 = ref('https://wrj.shuixiongit.com/minio/cloud-bucket/wayline/20241224/wayline_1735032173222.kmz');
//         analyzeKmzFile(`${prexUrl2.value}?_t=${new Date().getTime()}`).then(async res => {
//             const templateXML = await res.fileInfoObj['wpmz/template.kml']
//             const templateXMLJSON = XMLToJSON(templateXML)?.['Document']
//             const templateXMLObj = removeTextKey(templateXMLJSON.Folder)
//             renderingLine(templateXMLObj)
//         })
//     // })
// }
// 异步解析kmz文件
const analysis = async url => {
    return new Promise(async resolve => {
        const res = await analyzeKmzFile(`${url}?_t=${new Date().getTime()}`)
        const res = await analyzeKmzFile(`${url}?_t=${new Date().getTime()}`);
        const templateXML = await res.fileInfoObj['wpmz/template.kml']
        const templateXMLJSON = XMLToJSON(templateXML)?.['Document']
        const templateXMLObj = removeTextKey(templateXMLJSON.Folder)
@@ -174,37 +384,239 @@
const drawLine = async () => {
  let prexUrl = ref(import.meta.env.VITE_APP_AIRLINE_URL+ props.wayLineFile);
    const res = await analysis(prexUrl.value);
    if (!res.Placemark.length) return
  renderingLine(res);
    const points = res.Placemark.map(item => item.Point.coordinates.split(','))
    flyToPoints(points)
}
watch(() => props.wayLineFile, async (newValue, oldValue) => {
    if(newValue){
    await removeMap();
    await init();
// 选择航线时,根据选择机巢连线
const selectLineFile = (newVal) => {
    // 清除之前的实体
    // viewer.entities.removeAll();
    // 重新绘制航线
    // if (props.wayLineFile) {
    //   drawLine();
    // }
    // 添加选中点和连接线
    const positions = newVal.map(item => {
        const position = Cartesian3.fromDegrees(Number(item.longitude), Number(item.latitude));
        // 添加机巢点
        viewer.entities.add({
            position: position,
            billboard: {
                image: new Cesium.ConstantProperty(uavImg),
                width: 24,
                height: 24,
            },
        });
        return position;
    });
    // 添加连接线
    if (positions.length > 1) {
        viewer.entities.add({
            polyline: {
                positions: positions,
                width: 2,
                material: new Cesium.PolylineDashMaterialProperty({
                    color: Cesium.Color.RED,
                    dashLength: 8.0
                })
            }
        });
    }
    // 飞到中心点
    const lngLatArr = newVal.map(item => [item.longitude, item.latitude]);
    flyToPoints(lngLatArr);
};
// 单个点生成选择多个机巢生成航线
const singlePointLines = (newVal) => {
    // 清除之前的连接线
    connectLines.forEach(line => viewer.entities.remove(line));
    connectLines = [];
    if (currentEntity) {
        // 获取当前点的位置
        const currentPosition = currentEntity.position.getValue();
        // 为每个选中的机巢创建点和连接线
        newVal.forEach(item => {
            // 创建机巢点
            const nestPosition = Cartesian3.fromDegrees(
                Number(item.longitude),
                Number(item.latitude)
            );
            viewer.entities.add({
                position: nestPosition,
                billboard: {
                    image: new Cesium.ConstantProperty(uavImg),
                    width: 24,
                    height: 24,
                },
            });
            // 创建连接线
            const line = viewer.entities.add({
                polyline: {
                    positions: [currentPosition, nestPosition],
                    width: 2,
                    material: new Cesium.PolylineDashMaterialProperty({
                        color: Cesium.Color.RED,
                        dashLength: 8.0
                    })
                }
            });
            connectLines.push(line);
        });
        // 飞到所有点的中心位置
        const lngLatArr = newVal.map(item => [item.longitude, item.latitude]);
        flyToPoints(lngLatArr);
    }
};
// 智慧规划航线-面状航线
const planarPointsLines = (newVal) => {
  // 如果存在面状航线
  if (existingEntity) {
    const waylinePositions = existingEntity.polyline.positions.getValue();
    newVal.forEach(item => {
      // 创建机巢点
      const nestPosition = Cartesian3.fromDegrees(
        Number(item.longitude),
        Number(item.latitude)
      );
      // 添加机巢图标
      viewer.entities.add({
        position: nestPosition,
        billboard: {
          image: new Cesium.ConstantProperty(uavImg),
          width: 24,
          height: 24,
        },
      });
      // 找到最近的航线点并连线
      let minDistance = Number.MAX_VALUE;
      let closestPosition = null;
      waylinePositions.forEach(waylinePos => {
        const distance = Cartesian3.distance(nestPosition, waylinePos);
        if (distance < minDistance) {
          minDistance = distance;
          closestPosition = waylinePos;
        }
      });
      // 创建连接线
      if (closestPosition) {
        const line = viewer.entities.add({
          polyline: {
            positions: [nestPosition, closestPosition],
            width: 2,
            material: new Cesium.PolylineDashMaterialProperty({
              color: Cesium.Color.CHARTREUSE,
              dashLength: 8.0
            })
          }
        });
        connectLines.push(line);
      }
    });
    // 飞到所有点的中心位置
    const lngLatArr = newVal.map(item => [item.longitude, item.latitude]);
    flyToPoints(lngLatArr);
  }
};
// 监听选择航线文件事件
watch(() => props.wayLineFile, async (newVal, oldValue) => {
    await removeMap();
    if(newVal){
        await drawLine();
    }
})
}, { deep: true });
// 监听表格选中数据变化
watch(() => props.checkedTableData, (newVal) => {
    if (newVal.length > 0 && props.waylineTypeTest === 0) {
        selectLineFile(newVal);
    } else if (newVal.length > 0 && props.waylineTypeTest === 1) {
        singlePointLines(newVal);
    } else if (newVal.length > 0 && props.waylineTypeTest === 2) {
        planarPointsLines(newVal);
    }
}, { deep: true });
// 监听航线类型
watch(() => props.waylineTypeTest, async (newVal) => {
    await removeMap();
    if (newVal === 1) {
        await singlePointLeftClick();
    } else if (newVal === 2) {
        await intelligentPlanning();
    }
}, { deep: true });
const removeEvent = () => {
    // 清除事件监听器
    viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
    viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
};
const removeMap = () => {
    viewer.entities.removeAll()
    viewer.destroy()
  // 清除所有实体
  if (viewer) {
    // 清除连接线
    connectLines.forEach(line => viewer.entities.remove(line));
    connectLines = [];
    // 清除多边形点和实体
    polygonPoints = [];
    if (polygonEntity) {
      viewer.entities.remove(polygonEntity);
    }
    // 清除当前实体和面状航线
    if (currentEntity) {
      viewer.entities.remove(currentEntity);
    }
    if (existingEntity) {
      viewer.entities.remove(existingEntity);
    }
        viewer.entities.removeAll();
    // 重置所有变量
    currentEntity = null;
    polygonEntity = null;
    existingEntity = null;
  }
}
onBeforeUnmount(() => {
    removeMap()
    removeMap();
    removeEvent();
    // 移除所有实体并销毁viewer
    viewer.destroy();
    viewer = null;
})
onMounted(() => {
    nextTick(() => {
        init()
    })
})
});
</script>
<style scoped lang="scss">
#taskMap {
    position: relative;
    height: 100%;
    :deep() {
@@ -232,5 +644,27 @@
            display: none;
        }
    }
:deep(.context-menu) {
    position: absolute;
    background: rgba(0, 21, 41, 0.9);;
    border-radius: 4px;
    padding: 8px 0;
    min-width: 120px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
        .menu-item {
            padding: 8px 16px;
            color: #fff;
            cursor: pointer;
            transition: all 0.3s;
            font-size: 14px;
            &:hover {
                background: rgba(255, 255, 255, 0.1);
            }
        }
    }
}
</style>
src/views/TaskManage/TaskIntermediateContent/TaskTable.vue
@@ -1,7 +1,9 @@
<template>
  <div class="table-container">
    <el-table :data="tableData" style="width: 100%" height="400" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
    <el-table :data="tableData" style="width: 100%" height="400"
      @selection-change="handleSelectionChange"
      @select="handleSelect">
      <el-table-column type="selection" width="55" :selectable="checkSelectable" />
      <el-table-column type="index" label="序号" width="60" />
      <el-table-column prop="nickname" label="机巢名称" />
      <el-table-column prop="estimated_arrival_time" label="预计到达时间" />
@@ -31,16 +33,27 @@
  },
  waylineType: {
    type: Number,
    default: 0
    default: 3
  },
  singlePoint: {
    type: Object,
    default: () => ({})
  },
  planarPoints: {
    type: Array,
    default: () => ([])
  }
});
// 选中的数据
const selectedRows = ref([]);
// 分页参数
let pageParams = reactive({
let pageParams = ref({
  wayline_id: props.waylineId, 
  type: props.waylineType,
  longitude: props.singlePoint.longitude,
  latitude: props.singlePoint.latitude,
  polygon: [],
  page: 1,
  limit: 10
});
@@ -49,41 +62,108 @@
const tableData = ref([]);
const getNestList = async () => {
    tableData.value = [];
  const res = await getFlyingNestBy(pageParams);
  // console.log(pageParams.value,'草草草草')
  const res = await getFlyingNestBy(pageParams.value);
  if (res.data.code === 0) {
    console.log(res.data.data, '哒哒哒');
    tableData.value = res.data.data;
  }
};
// 分页大小改变
const handleSizeChange = (val) => {
  pageParams.limit = val;
  pageParams.value.limit = val;
  getNestList();
};
// 页码改变
const handleCurrentChange = (val) => {
  pageParams.page = val;
  pageParams.value.page = val;
  getNestList();
};
// 刷新数据
const refreshData = () => {
  tableData.value = [];
  pageParams.value.page = 1;
  getNestList();
};
const emit = defineEmits(['update:selected']);
const handleSelectionChange = (val) => {
  selectedRows.value = val;
  // 可以通过emit将选中数据传给父组件
  emit('update:selected', val);
  // 如果不是智能规划选区模式,才更新所有选中数据
  if (props.waylineType !== 2) {
    selectedRows.value = val;
    emit('update:selected', val);
  }
};
// 控制表格行是否可选
const checkSelectable = (row) => {
  if (props.waylineType === 2) {
    // 如果已经有选中的行,且当前行未被选中,则不允许选择
    return selectedRows.value.length === 0 || selectedRows.value.some(selected => selected.device_sn === row.device_sn);
  }
  return true;
};
// 处理单行选择
const handleSelect = (selection, row) => {
  if (props.waylineType === 2) {
    // 如果是智能规划选区模式,确保只能选中一行
    if (selection.length > 1) {
      // 保留最后选中的那一行
      const lastSelected = selection[selection.length - 1];
      selectedRows.value = [lastSelected];
      // 触发更新事件
      emit('update:selected', selectedRows.value);
    }
  }
};
// 监听航线ID变化
watch(() => props.waylineId, (newVal) => {
  pageParams.wayline_id = newVal;
  pageParams.value.type = 0;
  if (newVal) {
    pageParams.page = 1;
    getNestList();
    pageParams.value.wayline_id = newVal;
    refreshData();
  } else {
    // 数据为空时,清除列表数据
    tableData.value = [];
  }
}, { immediate: true });
onMounted(() => {
  // getNestList();
}, { deep: true });
// 监听单点返回的数据
watch(() => props.singlePoint, (newVal) => {
  pageParams.value.wayline_id = '';
  pageParams.value.type = 1;
  if (newVal && newVal.latitude && newVal.longitude) {
    pageParams.value.latitude = newVal.latitude;
    pageParams.value.longitude = newVal.longitude;
    refreshData();
  }
}, { deep: true });
// 监听面状航线返回的数据
watch(() => props.planarPoints, (newVal) => {
  pageParams.value.wayline_id = '';
  pageParams.value.type = 2;
  if (newVal && newVal.length > 0) {
    const polygonArray = newVal.map(point => [point.longitude, point.latitude]);
    pageParams.value.polygon = polygonArray;
    refreshData();
  }
}, { deep: true });
// 暴露给父组件的方法
const clearTableData = () => {
  tableData.value = [];
};
defineExpose({
  clearTableData
});
onMounted(() => {});
</script>
<style lang="scss" scoped>