jihongshun
2025-08-07 afec9f1c12683a11845b277c62e0ca9b83e1a5ca
src/views/system/project/components/addPorjectDialog.vue
@@ -15,6 +15,7 @@
                  <el-table
                    :data="tableData"
                    max-height = '180'
                    :row-key="getRowKeys"
                    style="width: 100%">
                    <el-table-column
                      prop="deviceName"
@@ -45,6 +46,7 @@
                  <div class="fontJust">巡检点目录</div>
                  <el-tree
                    class="filter-tree"
                    node-key="id"
                    :data="treeData"
                    :props="defaultProps"
                    default-expand-all
@@ -72,6 +74,7 @@
import chooseModelDialog from './chooseModelDialog.vue';
import { obtainRealData ,buildKmz} from "@/api/system/template"
let rotationAngle = Cesium.Math.toRadians(0)
let lastConnectPolyline
export  default{
  components: {
    CesiumMap,
@@ -178,14 +181,60 @@
      }));
    },
    deleteData(row){
      console.log(row)
      // 找到 id 为 "1" 的元素索引
      const index = this.tableData.findIndex(item => item.id === row.id);
      // 如果找到了,删除该元素
      if (index !== -1) {
        this.tableData.splice(index, 1);
      }
      const dealTreeData = this.dealTee()
      this.treeData = dealTreeData
      const indexTree = this.treeData.findIndex(item => item.id === row.id);
      // 如果找到了,删除该元素
      if (index !== -1) {
        this.treeData.splice(indexTree, 1);
      }
      if(this.treeData?.length >=2 && this.treeData[0]?.children?.length > 0 && this.treeData[1]?.children?.length > 0 ) {
          this.dealAddHeight()
      } else if(this.treeData?.length ==1) {
        this.treeData.map((device,index) => {
          // 确保设备有children数组
          if(index == 0) {
            //第一个数据
            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
                // 获取最后一个空中点
                const lastChild = device.children[device.children.length - 1];
                const firstChild = device.children[0];
                // 深拷贝最后一个元素(包括嵌套的children)
                const newChildJson = JSON.parse(JSON.stringify(lastChild));
                // 深拷贝最一一个元素(包括嵌套的children)
                const firstChildJson = JSON.parse(JSON.stringify(firstChild));
                if(newChildJson && newChildJson.label.includes('加高')){
                  device.children?.pop(newChild);
                }else if(firstChildJson && firstChildJson.label.includes('加高')) {
                    device.children?.shift(firstChildJson);
                }
                // 添加到children数组末尾
            }
          }
        })
      }
      const entitiesToRemove = [];
      viewer.entities.values.forEach(entity => {
        if (entity.id && entity.id.includes(row.id)) {
          entitiesToRemove.push(entity.id);
        }
      });
      entitiesToRemove.forEach(id => {
        viewer.entities.removeById(id);
      });
      this.drawConnectionsWithLabels(this.treeData)
      // console.log(this.tableData)
      console.log(this.treeData)
      // const dealTreeData = this.dealTee()
      // console.log(dealTreeData)
      // this.treeData = dealTreeData
      // this.drawConnectionsWithLabels(this.treeData)
    },
    chooseModel(row){
      this.deviceId = row.id
@@ -203,14 +252,89 @@
      obtainRealData(flightTemplateId,deviceId).then(res=>{
        console.log(res)
        let treeDealData = this.transformFlightData(res.data?.coordinateSystemVoS || [])
        console.log(treeDealData)
        this.dealTreeMerge(obj,treeDealData)
        this.rotateAllPoints(this.treeData || [],res.data.longitude,res.data.latitude,res.data.height)
        console.log(this.treeData)
        if(this.treeData?.length >=2 && this.treeData[0]?.children?.length > 0 && this.treeData[1]?.children?.length > 0 ) {
            this.dealAddHeight()
        }
        console.log(this.treeData)
        this.drawConnectionsWithLabels(this.treeData)
      })
      // this.dealTreeMerge(obj)
    },
    dealAddHeight(){
      let currentLength = this.treeData.filter(item=>item.children)?.length || 0
      console.log(this.treeData)
      console.log(currentLength)
      this.treeData.map((device,index) => {
          // 确保设备有children数组
          if(index == 0) {
            //第一个数据
            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
                // 获取最后一个空中点
                const lastChild = device.children[device.children.length - 1];
                // 深拷贝最后一个元素(包括嵌套的children)
                const newChild = JSON.parse(JSON.stringify(lastChild));
                if(newChild.label.includes('加高')) {
                }else {
                  newChild.label = newChild.label + '-加高'
                  // 高度增加20
                  // newChild.height += 20;
                  //塔高 - 高度  + 往上飞多少米
                  newChild.height += (device.ardTowerModel?.modelHeight  - newChild.height +  20) ;
                  console.log('push11111111111111')
                  // 添加到children数组末尾
                  device.children.push(newChild);
                }
            }
          }
          else if(index == currentLength -1) {
            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
                // 获取最后一个空中点
                const lastChild = device.children[0];
                // 深拷贝最一一个元素(包括嵌套的children)
                const newChild = JSON.parse(JSON.stringify(lastChild));
                if(newChild.label.includes('加高')) {
                }else {
                  newChild.label = newChild.label + '-加高第一个点'
                  newChild.height += (device.ardTowerModel?.modelHeight  - newChild.height +  20) ;
                  // 添加到children数组末尾
                  device.children.unshift(newChild);
                }
            }
          } else {
            if (device.children && Array.isArray(device.children) && device.children.length > 0) {
                // 获取最后一个空中点
                const firstChild = device.children[0];
                const lastChild = device.children[device.children.length - 1];
                // 深拷贝最一一个元素(包括嵌套的children)
                const newFirstChild = JSON.parse(JSON.stringify(firstChild));
                const newLastChildChild = JSON.parse(JSON.stringify(lastChild));
                //高度增加20
                if(newFirstChild.label.includes('加高')) {
                }else {
                    newFirstChild.label = newFirstChild.label + '-加高'
                    newFirstChild.height += (device.ardTowerModel?.modelHeight  - newFirstChild.height +  20) ;
                    device.children.unshift(firstChild);
                }
                if(newLastChildChild.label.includes('加高')) {
                }else {
                    newLastChildChild.label = newLastChildChild.label + '-加高'
                    newLastChildChild.height += (device.ardTowerModel?.modelHeight  - newLastChildChild.height +  20) ;
                    device.children.push(newLastChildChild);
                }
            }
          }
      })
    },
    //返回数据转换树结构
    transformFlightData(data) {
      console.log(data)
      const result = [];
      data.forEach(item => {
@@ -257,8 +381,27 @@
        }
      });
    },
    generateId() {
      return 'id_' + Math.random().toString(36).substring(2, 10);
    },
    drawConnectionsWithLabels(devices) {
      if(lastConnectPolyline) {
        viewer.entities.remove(lastConnectPolyline)
        lastConnectPolyline = null
      }
        // 直接操作EntityCollection(推荐)
      const entitiesToRemove = [];
      viewer.entities.values.forEach(entity => {
        if (entity.id && entity.id.includes(this.deviceId)) {
          entitiesToRemove.push(entity.id);
        }
      });
      entitiesToRemove.forEach(id => {
        viewer.entities.removeById(id);
      });
      const airPoints = [];
      console.log(devices)
      devices.forEach(device => {
        if (!Array.isArray(device.children)) return;
        device.children.forEach(airPoint => {
@@ -272,6 +415,7 @@
          // ✅ 添加空中点实体和 label
          viewer.entities.add({
            position: airPos,
            id:device.id +'airpoint' + this.generateId(),
            point: {
              pixelSize: 6,
              color: Cesium.Color.YELLOW
@@ -301,6 +445,7 @@
              // ✅ 添加地面点实体和 label
              viewer.entities.add({
                id:device.id +'groundpoint' + this.generateId(),
                position: groundPos,
                point: {
                  pixelSize: 6,
@@ -320,6 +465,7 @@
              // ✅ 蓝色虚线连接:空中点 ➜ 地面点
              viewer.entities.add({
                id:device.id +'polyline' + this.generateId(),
                polyline: {
                  positions: [airPos, groundPos],
                  width: 2,
@@ -333,10 +479,10 @@
          }
        });
      });
      console.log(airPoints)
      // ✅ 黄色实线连接所有空中点
      if (airPoints.length > 1) {
        viewer.entities.add({
        lastConnectPolyline = viewer.entities.add({
          polyline: {
            positions: airPoints,
            width: 3,
@@ -375,6 +521,7 @@
              };
            });
          });
          console.log(newGround.children)
          return newGround;
        }
         
@@ -397,6 +544,10 @@
      // 将旋转后的局部坐标转换回世界坐标系
     return Cesium.Matrix4.multiplyByPoint(transformationMatrix, new Cesium.Cartesian3(rotatedX, rotatedY, rotatedZ), new Cesium.Cartesian3());
    },
    getRowKeys(row){
      console.log(row)
      return row.id +this.generateId()
    },
    submit(){
      console.log(this.treeData)