无人机管理后台前端(已迁走)
张含笑
2025-10-28 0f16db42e4e331bfaf084c27ca602c275e87668d
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<template>
  <div class="table-overlay">
    <div class="searchBox">
      <el-input
        class="ztzf-input inputName"
        v-model="formData.dkbh"
        placeholder="输入名称模糊搜索"
      ></el-input>
      <div class="searchAndReset">
        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button class="ztzf-button" icon="el-icon-refresh" @click="reset">清空</el-button>
      </div>
    </div>
    <div class="btnGroups">
      <el-button class="ztzf-button" @click="addFence">新增围栏</el-button>
      <el-button class="ztzf-button" @click="addFolder">新增文件夹</el-button>
      <el-button class="ztzf-button" @click="selectAll">全选</el-button>
    </div>
    <div class="tableListBox">
     <el-tree
  class="ztzf-el-tree"
  ref="treeRef"
  v-model="checkedKeys"
  :data="treeData"
  show-checkbox
  node-key="id"
  default-expand-all
  @check="handleCheck"
  :props="{
    label: 'name',
    children: 'children',
  }"
>
  <!-- 自定义节点内容 -->
  <template #default="{ node }">
    <div class="tree-node">
      <!-- 节点名称 -->
      <span>{{ node.label }}</span>
      <!-- 操作按钮组 -->
      <div class="tree-node-actions">
        <el-button icon="el-icon-location" type="text" @click="handleLocation(node)"></el-button>
        <el-button icon="el-icon-edit" type="text" @click="handleEdit(node)"></el-button>
        <el-button icon="el-icon-delete" type="text" @click="handleDelete(node)"></el-button>
      </div>
    </div>
  </template>
</el-tree>
    </div>
  </div>
</template>
 
<script setup>
import { treeDataApi } from '@/api/layer/index';
import { onMounted } from 'vue';
const emit = defineEmits(['update:coverData']);
const coverData = ref();
const props = defineProps(['activeName']);
const formData = {
  isPush: undefined,
  page: 1,
  isGenerated: undefined,
  pageSize: 17,
  dkbh: '',
  patchesName: '',
};
const reset = () => {};
const search = () => {};
const treeData = ref([]);
const treeAllData = ref([]);
// 获取数据
const gettreeDataApi = async () => {
  try {
    const res = await treeDataApi();
    treeAllData.value = res.data.data;
    console.log('接口获取数据', treeAllData.value);
    setupWatch();
  } catch (error) {
    console.error('获取数据失败:', error);
  }
};
const setupWatch = () => {
  watch(
    () => props.activeName,
    newVal => {
      const matchedCategory = treeAllData.value.find(item => item.name === newVal);
      treeData.value = matchedCategory.children;
    },
    { immediate: true }
  );
};
const checkedKeys = ref([]); // 存储勾选的节点key
const treeRef = ref(null); // 获取tree实例
 
const checkedNodes = ref([]); // 存储勾选的节点数据
 
const handleCheck = (checkedNodesData, checkedKeysData) => {
  checkedNodes.value = checkedNodesData.checkedNodes;
 
  coverData.value = checkedKeysData.checkedNodes;
 
  emit('update:coverData', coverData.value);
  // console.log('选中的节点数据:', checkedKeysData);
};
// 全选方法
const selectAll = () => {
  if (treeRef.value) {
    // 获取所有节点的key
    const allKeys = treeData.value.flatMap(item => [
      item.id,
      ...item.children.map(child => child.id),
    ]);
 
    if (checkedKeys.value.length === allKeys.length) {
      // 如果已经全选,则取消全选
      treeRef.value.setCheckedKeys([]);
      checkedNodes.value = [];
    } else {
      // 否则全选
      treeRef.value.setCheckedKeys(allKeys);
      // 获取所有节点数据
      checkedNodes.value = treeData.value.flatMap(item => [ ...item.children]);
      console.log('所有数据', checkedNodes.value);
    }
  }
};
// 定位按钮事件
const handleLocation = (node) => {
  console.log('定位操作,节点:', node);
  
 
};
 
// 编辑按钮事件
const handleEdit = (node) => {
  console.log('编辑操作,节点:', node.data);
   emit('update:coverData', [node.data]);
 
};
 
// 删除按钮事件
const handleDelete = (node) => {
  console.log('删除操作,节点:', node.data);
 
};
// 新增围栏
const addFence =()=>{
 
}
// 新增文件夹
const addFolder =()=>{
 
}
onMounted(() => {
  gettreeDataApi();
});
const changeClick = val => {};
</script>
 
<style scoped lang="scss">
.table-overlay {
  position: absolute;
  top: 0;
  left: 0;
  height: 95%;
  z-index: 99;
  width: 392px;
 
  overflow: hidden;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 8px 8px 8px 8px;
  padding: 16px 12px;
}
 
.searchBox {
  display: flex;
  margin-top: 10px;
  .inputName {
    width: 184px;
    height: 32px;
  }
  .searchAndReset {
    width: 182px;
    display: flex;
    justify-content: right;
    align-items: center;
    margin-right: 10px;
    .reset,
    .search {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 46px;
      height: 32px;
      cursor: pointer;
    }
 
    .reset {
      margin-left: 12px;
      background: #0d2b38;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #84cbd3;
      font-weight: 400;
      font-size: 14px;
      color: #ffffff;
    }
 
    .search {
      background: #1e2d51;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #c5d6ff;
      font-weight: 400;
      font-size: 14px;
      color: #ffffff;
    }
  }
}
.btnGroups {
  margin: 12px 0 14px 0;
  display: flex;
}
.tableListBox {
.tree-node {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}
 
.tree-node-actions {
  display: flex;
  gap: 8px; // 按钮之间的间距
  button {
    padding: 0; // 清除默认内边距
    color: #fff; // 按钮图标颜色
    &:hover {
      color: #409eff; //  hover 时的颜色
    }
  }
}
}
 
</style>