<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.stop="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 { inject, onMounted } from 'vue';
|
const emit = defineEmits(['update:coverData', 'update:deitData']);
|
const coverData = ref();
|
const layerParams = inject('layerParams');
|
const checkedKeys = ref([]); // 存储勾选的节点key
|
const treeRef = ref(null); // 获取tree实例
|
const checkedNodes = 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;
|
|
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;
|
|
if (treeData.value && treeData.value.length > 0) {
|
const folderNode = treeData.value[0];
|
// 赋值给 layerParams
|
layerParams.value.total_count = folderNode.total_count ?folderNode.total_count :0;
|
layerParams.value.total_area = folderNode.total_area ? folderNode.total_area :0;
|
}
|
},
|
{ immediate: true }
|
);
|
};
|
const handleCheck = (checkedNodesData, checkedKeysData) => {
|
const filteredNodes = checkedKeysData.checkedNodes.filter(node => node.level === 3);
|
checkedNodes.value = checkedNodesData.checkedNodes;
|
checkedKeys.value = filteredNodes.map(node => node.id);
|
coverData.value = filteredNodes;
|
emit('update:coverData', coverData.value);
|
};
|
// 全选方法
|
const selectAll = () => {
|
if (treeRef.value) {
|
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 和数据
|
treeRef.value.setCheckedKeys([]);
|
checkedKeys.value = [];
|
checkedNodes.value = [];
|
coverData.value = [];
|
} else {
|
// 全选:仅设置 level 3 节点的 id
|
treeRef.value.setCheckedKeys(allFenceKeys);
|
checkedKeys.value = allFenceKeys; // 同步更新 checkedKeys
|
checkedNodes.value = allFenceNodes; // 存储 level 3 数据
|
coverData.value = allFenceNodes; // 同步 coverData
|
}
|
emit('update:coverData', coverData.value);
|
}
|
};
|
// 定位按钮事件
|
const handleLocation = node => {
|
console.log('定位操作,节点:', node);
|
};
|
|
// 编辑按钮事件
|
const handleEdit = node => {
|
checkedKeys.value = [];
|
checkedNodes.value = [];
|
coverData.value = [];
|
layerParams.value.editNest = true;
|
emit('update:deitData', node.data);
|
};
|
|
// 删除按钮事件
|
const handleDelete = node => {
|
console.log('删除操作,节点:', node.data);
|
};
|
// 新增围栏
|
const addFence = () => {
|
layerParams.value.addNest = true;
|
};
|
// 新增文件夹
|
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>
|