jihongshun
2025-07-08 e0683e37cdd7dc99adf2af6521962c3f29d0f9b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
  <div>
    <el-dialog
      title="新建项目"
      :visible="dialogVisible"
      append-to-body 
      fullscreen
      :before-close="handleClose">
       <el-row :gutter="6">
          <el-col :span=6>
              <el-card class="noScroll">
                <div class="chooseModel">
                  <!-- <el-button type="primary" @click='chooseModel'>添加设备</el-button> -->
                  <div class="fontJust">设备列表</div>
                   <el-button @click="addDevice"> 新增</el-button>
                  <el-table
                    :data="tableData"
                    max-height = '180'
                    style="width: 100%">
                    <el-table-column
                      prop="deviceName"
                      label="设备名称"
                      width="150">
                    </el-table-column>
                    <el-table-column
                      prop="muban"
                      label="模板"
                      width="150">
                    </el-table-column>
                    <el-table-column
                      fixed="right"
                      label="操作"
                      width="100">
                      <template slot-scope="scope">
                        <el-button type="text" size="small" @click="flyToLocal(scope.row)">定位</el-button>
                        <el-button type="text" size="small" @click="deleteData(scope.row)">移除</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </el-card>
              <el-card >
                <div class="chooseModelTree">
                  <!-- <el-button type="primary" @click='chooseModel'>添加设备</el-button> -->
                  <div class="fontJust">巡检点目录</div>
                  <el-tree
                    class="filter-tree"
                    :data="treeData"
                    :props="defaultProps"
                    draggable  
                    default-expand-all
                    ref="tree">
                  </el-tree>
                </div>
              </el-card>
          </el-col>
          <el-col :span=18>
              <CesiumMap ></CesiumMap>
          </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="submit()" >生成航线任务</el-button>
      </span>
    </el-dialog>
     <chooseDeviceDialog v-if="showModel" @cancel ='cancel' @dealChooseArr="dealChooseArr" ></chooseDeviceDialog>
  </div>
</template>
<script>
import CesiumMap from "../../../../utils/components/cesium-map.vue";
import chooseDeviceDialog from './chooseDeviceDialog.vue';
export  default{
  components: {
    CesiumMap,
    chooseDeviceDialog
  },
  data(){
    return{
       dialogVisible :true,
        tableData: [],
        treeData:[],
        defaultProps: {
          children: 'children',
          label: 'label'
        },
        showModel:false,
        multipleSelection: []
    }
  },
  methods:{
    handleClose(){
      console.log("close")
      this.dialogVisible = false
      this.$emit('close')
    },
    flyToLocal(row){
      console.log(row)
      console.log(viewer)
       const position = Cesium.Cartesian3.fromDegrees(row.longitude,row.latitude, row.altitude);
 
      // 设置模型方向(可选)
      const heading = Cesium.Math.toRadians(row.face); // 朝东南方向
      const pitch = 0;
      const roll = 0;
      const orientation = Cesium.Transforms.headingPitchRollQuaternion(
        position,
        new Cesium.HeadingPitchRoll(heading, pitch, roll)
      );
 
      // 加载 glTF 模型
      const entity = viewer.entities.add({
        name: row.id,
        position: position,
        orientation: orientation,
        model: {
          uri: "http://192.168.1.5:9000/tower/2025/07/01/tower_20250701145739A004.glb", // 替换成你的模型路径
          scale: 1000,
        },
      });
      console.log(entity)
      // 飞行到模型位置
      viewer.flyTo(entity)
    },
    addDevice(){
      this.showModel = true
    },
    cancel(){
      this.showModel = false
    },
    hasSameId(array1, array2) {
      const ids1 = new Set(array1.map(item => item.id));
      const ids2 = new Set(array2.map(item => item.id));
      return ids1.size !== [...ids1].filter(id => ids2.has(id)).length;
    },
    dealChooseArr(arr){
      if(this.tableData?.length == 0 ){
        this.tableData = arr
      }else {
        const hasSameId = arr.filter(obj1 =>
          this.tableData.some(obj2 => obj1.id === obj2.id)
        );
        if(hasSameId?.length != 0){
          return this.$message({
            message: '选择设备数据和已有数据重复',
            type: 'warning'
          })
        }
        this.tableData = this.tableData.concat(arr)
      }
      const dealTreeData =this.dealTee()
      this.treeData = dealTreeData
      console.log(this.treeData)
    },
    dealTee(){
     return  this.tableData.map(item => ({
        ...item,
        label: item.deviceName,
        children: []
      }));
    },
    deleteData(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
    }
  }
}
 
</script>
<style scoped>
.filter-tree{
  height: 365px;
  width: 100%;
  overflow: auto;
}
.fontJust{
  text-align: center;
}
.el-table {
  height: 180px;
}
</style>