无人机管理后台前端(已迁走)
张含笑
2025-11-11 d94a55f3358ed7ded4d5a5579968744ed047b6a4
src/views/layerManagement/components/leftList.vue
@@ -159,7 +159,6 @@
    const allFenceKeys = treeData.value.flatMap(
      folder => folder.children.map(fence => fence.id) // folder 是 level 2,children 是 level 3
    );
    const allFenceNodes = treeData.value.flatMap(folder => folder.children);
    if (checkedKeys.value.length === allFenceKeys.length) {
      // 取消全选:清空 keys 和数据
@@ -178,21 +177,63 @@
  }
};
// 定位按钮事件
// const handleLocation = node => {
//   // checkedKeys.value = [];
//   // checkedNodes.value = [];
//   // coverData.value = [];
//   if (node.data.level === 2) {
//     const folderChildren = node.data.children || [];
//     const childrenIds = folderChildren.map(child => child.id);
//     treeRef.value.setCheckedKeys(childrenIds);
//     checkedKeys.value = childrenIds;
//     checkedNodes.value = folderChildren;
//     coverData.value = folderChildren;
//     emit('update:coverData', coverData.value);
//   } else {
//     const currentNodeId = node.data.id;
//     treeRef.value.setCheckedKeys([currentNodeId]);
//     checkedKeys.value = [currentNodeId];
//     checkedNodes.value = [node.data];
//     coverData.value = [node.data];
//     emit('update:coverData', coverData.value);
//   }
// };
const handleLocation = node => {
  checkedKeys.value = [];
  checkedNodes.value = [];
  coverData.value = [];
  const currentCheckedKeys = Array.isArray(checkedKeys.value) ? [...checkedKeys.value] : [];
  const currentCheckedNodes = Array.isArray(checkedNodes.value) ? [...checkedNodes.value] : [];
  // 触发定位逻辑(通知父组件)
  EventBus.emit('focusOnNode', node.data);
  if (node.data.level === 2) {
    const folderChildren = node.data.children || [];
    // const childrenIds = folderChildren.map(child => child.id);
    // treeRef.value.setCheckedKeys(childrenIds);
    // checkedKeys.value = childrenIds;
    // checkedNodes.value = folderChildren;
    coverData.value = folderChildren;
    emit('update:coverData', coverData.value);
  } else {
    emit('update:coverData', [node.data]);
    const childrenIds = folderChildren.map(child => child.id);
    // 合并已选中的节点(去重)
    const newCheckedKeys = [...new Set([...currentCheckedKeys, ...childrenIds])];
    const newCheckedNodes = [...currentCheckedNodes, ...folderChildren];
    treeRef.value.setCheckedKeys(newCheckedKeys);
    checkedKeys.value = newCheckedKeys;
    checkedNodes.value = newCheckedNodes;
    coverData.value = newCheckedNodes;
  }
  else {
    const currentNodeId = node.data.id;
    if (!currentCheckedKeys.includes(currentNodeId)) {
      currentCheckedKeys.push(currentNodeId);
      currentCheckedNodes.push(node.data);
      console.log(' currentCheckedNodes', currentCheckedNodes);
    }
    treeRef.value.setCheckedKeys(currentCheckedKeys);
    checkedKeys.value = currentCheckedKeys;
    checkedNodes.value = currentCheckedNodes;
    coverData.value = currentCheckedNodes;
    console.log('currentCheckedNodes',currentCheckedNodes);
    console.log('coverData.value',node.data);
  }
  emit('update:coverData', coverData.value);
};
// 编辑按钮事件
const handleEdit = node => {