<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>
|