无人机管理后台前端(已迁走)
张含笑
2025-12-09 5808f76456ca0d40de5074f132b73a5a488e3e13
src/views/layerManagement/components/leftList.vue
@@ -58,7 +58,8 @@
        default-expand-all
        :expand-on-click-node="false"
         :check-on-click-node="false"
        :filter-node-method="filterNode"
        highlight-current
        @check="handleCheck"
        :props="{
          label: 'name',
@@ -69,7 +70,7 @@
        <template #default="{ node }">
          <div class="tree-node">
            <!-- 节点名称 -->
            <span class="nodeName"  :class="{ 'search-highlight': isNodeMatched(node.data.id) }">{{ node.label }}</span>
            <span class="nodeName">{{ node.label }}</span>
            <!-- 操作按钮组 -->
            <div class="tree-node-actions">
              <el-button
@@ -77,7 +78,7 @@
               icon="el-icon-location"
                @click.stop="handleLocation(node)"
                :disabled="node.data.level === 2 && (!node.data.children || node.data.children.length === 0)"
              class="location-btn"
              class="location-btn"
              ></el-button>
              <el-button icon="el-icon-edit" link @click.stop="handleEdit(node)"></el-button>
              <el-button icon="el-icon-delete" link @click.stop="handleDelete(node)"></el-button>
@@ -117,7 +118,6 @@
  dkbh: '',
  patchesName: '',
});
const matchedNodeIds = ref([]);
const loading = ref(false);
const treeData = ref([]);
const treeAllData = ref([]);
@@ -125,9 +125,19 @@
const gettreeDataApi = async () => {
  try {
    loading.value = true;
    const res = await treeDataApi();
    const res = await treeDataApi({filterExpired:false});
    treeAllData.value = res.data.data;
    if(coverData.value.length===0){
       checkedKeys.value = [];
    checkedNodes.value = [];
    coverData.value = [];
     nextTick(() => {
      if (treeRef.value) {
        treeRef.value.setCheckedKeys([]);
      }
    });
    }
    setupWatch();
  } catch (error) {
    console.error('获取数据失败:', error);
@@ -168,29 +178,38 @@
  );
};
const selectAll = () => {
 layerParams.value.currentLocationFolderId = null;
layerParams.value.isSingleLocating = false
  if (treeRef.value) {
    const allFenceKeys = getAllFenceKeys();
    const allFenceNodes = treeData.value.flatMap(folder => folder.children);
    if (checkedKeys.value.length === allFenceKeys.length) {
      // 取消全选
      treeRef.value.setCheckedKeys([]);
      checkedKeys.value = [];
      checkedNodes.value = [];
      coverData.value = [];
      emit('update:coverData', coverData.value);
    } else {
      // 全选
      treeRef.value.setCheckedKeys(allFenceKeys);
      checkedKeys.value = allFenceKeys;
      checkedNodes.value = allFenceNodes;
      coverData.value = allFenceNodes;
      emit('update:coverData', coverData.value);
    }
    emit('update:coverData', coverData.value);
  }
};
// 定位按钮事件
const handleLocation = node => {
 const currentKey = treeRef.value.getCurrentKey();
      if (currentKey === node.data.id) {
        treeRef.value.setCurrentKey(null); // 取消高亮
      } else {
        treeRef.value.setCurrentKey(node.data.id); // 高亮当前节点
      }
  if (node.data.level === 2) {
    layerParams.value.isSingleLocating = false;
    // 新增:标记当前定位的文件夹ID
@@ -204,16 +223,15 @@
  const currentCheckedKeys = [...checkedKeys.value];
  const currentCheckedNodes = [...checkedNodes.value];
  EventBus.emit('focusOnNode', node.data);
  if (node.data.level === 2) {
    const folderChildren = node.data.children || [];
    const childrenIds = folderChildren.map(child => child.id);
    const newChildrenIds = childrenIds.filter(id => !currentCheckedKeys.includes(id));
    const newChildrenNodes = folderChildren.filter(child => newChildrenIds.includes(child.id));
    const newCheckedKeys = [...new Set([...currentCheckedKeys, ...newChildrenIds])];
    const newCheckedNodes = [...currentCheckedNodes, ...newChildrenNodes];
    treeRef.value.setCheckedKeys(newCheckedKeys);
    checkedKeys.value = newCheckedKeys;
    checkedNodes.value = newCheckedNodes;
@@ -239,7 +257,7 @@
      layerParams.value.fileType = 1;
    } else if (props.activeName === '自定义禁飞区') {
      layerParams.value.fileType = 2;
    }
    }
    emit('update:editFolder', node.data);
  } else if (node.data.level === 3) {
    checkedKeys.value = [];
@@ -247,10 +265,10 @@
    coverData.value = [];
    layerParams.value.editNest = true;
    layerParams.value.decideWhetherToAddOrEdit = 2;
    if (props.activeName === '自定义识别区') {
    if (props.activeName === '自定义识别区') {
      layerParams.value.fenceType = 1; // 电子围栏类型标识
    } else if (props.activeName === '自定义禁飞区') {
      layerParams.value.fenceType = 2; // 自定义禁飞区类型标识
      layerParams.value.fenceType = 2; // 自定义禁飞区类型标识
    }
    emit('update:deitData', node.data);
  }
@@ -258,6 +276,7 @@
// 删除按钮事件
const handleDelete = node => {
  let id = node.data.id;
  ElMessageBox.confirm('确定要删除该内容吗?', '提示', {
    confirmButtonText: '确定',
@@ -282,7 +301,7 @@
      }
    })
    .catch(() => {
      ElMessage.warning('已取消删除');
    });
};
// 新增围栏
@@ -326,35 +345,12 @@
}
function search() {
  const keyword = formData.value.dkbh.trim();
  matchedNodeIds.value = [];
  if (!keyword) return;
  // 递归查找匹配的节点
  const findMatches = (nodes) => {
    nodes.forEach(node => {
      if (node.name && node.name.includes(keyword)) {
        matchedNodeIds.value.push(node.id);
      }
      if (node.children && node.children.length) {
        findMatches(node.children);
      }
    });
  };
  findMatches(treeData.value);
  treeRef.value?.filter(formData.value.dkbh);
}
// 重置搜索
function reset() {
  formData.value.dkbh = '';
  matchedNodeIds.value = [];
  treeRef.value?.filter('');
}
// 判断节点是否匹配搜索关键词
const isNodeMatched = (nodeId) => {
  return matchedNodeIds.value.includes(nodeId);
};
function filterNode(value, data) {
  if (props.activeName === '国土空间规划') {
    if (!value) return data.level === 2 || data.level === 1;
@@ -401,10 +397,10 @@
  () => props.resetCheck,
  (newVal) => {
    if (newVal !== undefined) {
      checkedKeys.value = [];
      checkedNodes.value = [];
      coverData.value = [];
      treeRef.value?.setCheckedKeys([]);
      checkedKeys.value = [];
      checkedNodes.value = [];
      coverData.value = [];
      treeRef.value?.setCheckedKeys([]);
    }
  },
  { immediate: true }
@@ -426,7 +422,7 @@
  left: 0;
height: calc(100% - 32px);
  z-index: 99;
  width: 382px;
  width: 332px;
  overflow: hidden;
  background: rgba(0,0,0,0.51);
  backdrop-filter: blur(4px);
@@ -435,16 +431,13 @@
  display: flex;
  flex-direction: column;
}
.search-highlight {
  color: #409eff !important; // 蓝色高亮,可以根据需要修改
  font-weight: bold;
}
.searchBox {
  display: flex;
  margin-top: 10px;
padding-right: 12px;
  .inputName {
    width: 184px;
    width: 140px;
    height: 32px;
  }
  .searchAndReset {
@@ -453,34 +446,7 @@
    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 {
@@ -496,14 +462,17 @@
  overflow-y: scroll;
  height: 0;
  flex-grow: 1;
  padding-right: 12px;
  // padding-right: 12px;
  :deep(.el-tree-node__content) {
  height: 35px !important;
  line-height: 35px !important;
  padding-left: 0 !important;
  // border-bottom: 1px solid  rgba(0,0,0,0.51);
  height: 45px !important;
  line-height: 45px !important;
  // padding-left: 0 !important;
  border-bottom: 1px dotted  rgba(255,255,255,0.1);
  }
  // 定位选中节点的背景色样式
  ::v-deep(.el-tree-node.is-current > .el-tree-node__content) {
    background-color: rgba(64, 158, 255, 0.2) !important; // 浅蓝色半透明背景
  }
  .isTheTerritory {
    :deep() {
      .el-tree-node__expand-icon {
@@ -521,6 +490,7 @@
    display: flex;
    justify-content: space-between;
    align-items: center;
     padding-right: 12px;
    width: 100%;
       .nodeName {
    font-size: 12px !important;
@@ -530,20 +500,20 @@
  .tree-node-actions {
    display: flex;
    // gap: 8px;
    button {
      padding: 0;
      color: #fff;
      padding: 0;
      color: #fff;
      width: 17px;
      height: 17px;
      //  color: #409eff;
      // &:hover {
      //   color: #409eff;
      //   color: #409eff;
      // }
    }
  }
  ::v-deep(.location-btn.el-button.is-link.is-disabled) {
  color:  #999 !important;
  color:  #999 !important;
}
}
</style>