<template>
|
<div class="table-overlay">
|
<div class="searchBox">
|
<el-input
|
class="ztzf-layer-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 v-if="activeName !== '国土空间规划'" class="ztzf-button" @click="addFence">{{
|
props.activeName === '自定义识别区' ? '新增识别区' : '新增禁飞区'
|
}}</el-button>
|
<el-button v-if="activeName !== '国土空间规划'" class="ztzf-button" @click="addFolder"
|
>新增文件夹</el-button
|
>
|
<el-upload
|
v-if="activeName === '国土空间规划'"
|
action="#"
|
:show-file-list="false"
|
:before-upload="e => uploadFlightFile(e, '1')"
|
accept=".zip"
|
>
|
<el-button class="ztzf-button"> 上传 </el-button>
|
</el-upload>
|
|
<!-- <template v-if="activeName === '自定义禁飞区'">
|
<template v-if="failuresInfo.length">
|
<el-button class="ztzf-button" @click="synchronize"> 继续同步 </el-button>
|
<el-button class="ztzf-button" @click="failuresDel"> 取消同步 </el-button>
|
</template>
|
<el-button v-else class="ztzf-button" @click="synchronize"> 同步 </el-button>
|
</template> -->
|
|
<!-- <el-button class="ztzf-button" @click="selectAll">全选</el-button> -->
|
<el-button class="ztzf-button" @click="selectAll">
|
{{ checkedKeys.length === getAllFenceKeys().length ? '取消全选' : '全选' }}
|
</el-button>
|
</div>
|
<div
|
class="tableListBox"
|
v-loading="loading"
|
element-loading-background="rgba(0, 0, 0, 0.5)"
|
element-loading-text="加载中..."
|
>
|
<el-tree
|
class="ztzf-el-tree"
|
:class="{ isTheTerritory: activeName === '国土空间规划' }"
|
ref="treeRef"
|
v-model="checkedKeys"
|
:data="treeData"
|
show-checkbox
|
node-key="id"
|
default-expand-all
|
:expand-on-click-node="false"
|
:check-on-click-node="false"
|
:filter-node-method="filterNode"
|
@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
|
link
|
|
@click.stop="handleLocation(node)"
|
>定位</el-button>
|
<el-button link @click.stop="handleEdit(node)">编辑</el-button>
|
<el-button link @click.stop="handleDelete(node)">删除</el-button>
|
</div>
|
</div>
|
</template>
|
</el-tree>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
import {
|
treeDataApi,
|
deleteFenceApi,
|
deleteFolderApi,
|
spatialPlanningApi,
|
failuresListApi,
|
failuresDelApi,
|
areasUpdateApi,
|
} from '@/api/layer/index';
|
import { inject, nextTick, onMounted, watch } from 'vue';
|
const emit = defineEmits(['update:coverData', 'update:deitData', 'newFencesMethods']);
|
import EventBus from '@/utils/eventBus';
|
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 = ref({
|
isPush: undefined,
|
page: 1,
|
isGenerated: undefined,
|
pageSize: 17,
|
dkbh: '',
|
patchesName: '',
|
});
|
const loading = ref(false);
|
const treeData = ref([]);
|
const treeAllData = ref([]);
|
// 获取数据
|
const gettreeDataApi = async () => {
|
try {
|
loading.value = true;
|
const res = await treeDataApi();
|
treeAllData.value = res.data.data;
|
|
setupWatch();
|
} catch (error) {
|
console.error('获取数据失败:', error);
|
} finally {
|
loading.value = false;
|
}
|
};
|
|
const setupWatch = () => {
|
watch(
|
() => props.activeName,
|
newVal => {
|
const matchedCategory = treeAllData.value.find(item => item.name === newVal);
|
treeData.value = matchedCategory.children;
|
nextTick(search);
|
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) => {
|
layerParams.value.isSingleLocating = false
|
const filteredNodes = checkedKeysData.checkedNodes.filter(node => node.level === 3);
|
checkedNodes.value = filteredNodes
|
checkedKeys.value = filteredNodes.map(node => node.id);
|
coverData.value = filteredNodes;
|
emit('update:coverData', coverData.value);
|
};
|
// 全选方法
|
const getAllFenceKeys = () => {
|
return treeData.value.flatMap(
|
folder => folder.children.map(fence => fence.id)
|
);
|
};
|
const selectAll = () => {
|
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 = [];
|
} else {
|
// 全选
|
treeRef.value.setCheckedKeys(allFenceKeys);
|
checkedKeys.value = allFenceKeys;
|
checkedNodes.value = allFenceNodes;
|
coverData.value = allFenceNodes;
|
}
|
emit('update:coverData', coverData.value);
|
}
|
};
|
// 定位按钮事件
|
const handleLocation = node => {
|
if (node.data.level === 2) {
|
layerParams.value.isSingleLocating = false;
|
} else if (node.data.level === 3) {
|
layerParams.value.isSingleLocating = true;
|
}
|
|
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 newCheckedKeys = [...new Set([...currentCheckedKeys, ...childrenIds])];
|
const newCheckedNodes = [...currentCheckedNodes, ...folderChildren];
|
treeRef.value.setCheckedKeys(newCheckedKeys);
|
checkedKeys.value = newCheckedKeys;
|
checkedNodes.value = newCheckedNodes;
|
coverData.value = newCheckedNodes;
|
}
|
// 如果是单个节点(level 3),仅添加到选中列表(如果未选中)
|
else if (!currentCheckedKeys.includes(node.data.id)) {
|
layerParams.value.isSingleLocating = true
|
currentCheckedKeys.push(node.data.id);
|
currentCheckedNodes.push(node.data);
|
treeRef.value.setCheckedKeys(currentCheckedKeys);
|
checkedKeys.value = currentCheckedKeys;
|
checkedNodes.value = currentCheckedNodes;
|
coverData.value = currentCheckedNodes;
|
}
|
emit('update:coverData', coverData.value);
|
};
|
// 编辑按钮事件
|
const handleEdit = node => {
|
if (node.data.level == 2) {
|
layerParams.value.editFolder = true;
|
layerParams.value.addAnEditingFolder = 2;
|
if (props.activeName === '自定义识别区') {
|
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 = [];
|
checkedNodes.value = [];
|
coverData.value = [];
|
layerParams.value.editNest = true;
|
layerParams.value.decideWhetherToAddOrEdit = 2;
|
if (props.activeName === '自定义识别区') {
|
layerParams.value.fenceType = 1; // 电子围栏类型标识
|
} else if (props.activeName === '自定义禁飞区') {
|
layerParams.value.fenceType = 2; // 自定义禁飞区类型标识
|
}
|
emit('update:deitData', node.data);
|
}
|
};
|
|
// 删除按钮事件
|
const handleDelete = node => {
|
let id = node.data.id;
|
ElMessageBox.confirm('确定要删除该内容吗?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning',
|
})
|
.then(() => {
|
if (node.data.level === 2) {
|
// 删除文件夹
|
deleteFolderApi(id).then(res => {
|
ElMessage.success('删除成功');
|
gettreeDataApi();
|
EventBus.emit('deleteMapEntitiesByFolderId', id);
|
});
|
} else if (node.data.level === 3) {
|
// 删除单个围栏/禁飞区
|
deleteFenceApi(id).then(res => {
|
ElMessage.success('删除成功');
|
gettreeDataApi();
|
EventBus.emit('deleteMapEntityById', id);
|
});
|
}
|
})
|
.catch(() => {
|
ElMessage.warning('已取消删除');
|
});
|
};
|
// 新增围栏
|
const addFence = () => {
|
layerParams.value.addNest = true;
|
layerParams.value.decideWhetherToAddOrEdit = 1;
|
if (props.activeName === '自定义识别区') {
|
layerParams.value.fenceType = 1; // 电子围栏类型标识
|
} else if (props.activeName === '自定义禁飞区') {
|
layerParams.value.fenceType = 2; // 自定义禁飞区类型标识
|
}
|
emit('newFencesMethods');
|
};
|
// 新增文件夹
|
const addFolder = () => {
|
layerParams.value.addFolder = true;
|
layerParams.value.addAnEditingFolder = 1;
|
if (props.activeName === '自定义识别区') {
|
layerParams.value.fileType = 1;
|
} else if (props.activeName === '自定义禁飞区') {
|
layerParams.value.fileType = 2;
|
}
|
};
|
function uploadFlightFile(file, t) {
|
const fileSuffix = file.name.substring(file.name.lastIndexOf('.') + 1);
|
if (!['zip'].includes(fileSuffix)) {
|
return ElMessage.error('请上传zip格式的文件');
|
}
|
let data = new FormData();
|
const params = {
|
file: file,
|
fileName: file.name,
|
};
|
Object.keys(params).forEach(key => {
|
data.append(key, params[key]);
|
});
|
spatialPlanningApi(data).then(res => {
|
ElMessage.success('上传成功');
|
gettreeDataApi();
|
});
|
}
|
|
function search() {
|
treeRef.value?.filter(formData.value.dkbh);
|
}
|
function reset() {
|
formData.value.dkbh = '';
|
treeRef.value?.filter('');
|
}
|
function filterNode(value, data) {
|
if (props.activeName === '国土空间规划') {
|
if (!value) return data.level === 2 || data.level === 1;
|
return (data.level === 2 || data.level === 1) && data.name.includes(value);
|
}
|
if (!value) return true;
|
return data.name.includes(value);
|
}
|
|
// 同步信息
|
const failuresInfo = ref([]);
|
function failuresList() {
|
failuresListApi().then(res => {
|
failuresInfo.value = res.data.data || [];
|
});
|
}
|
|
// 同步
|
function synchronize() {
|
const data = failuresInfo.value.map(item => item.device_sn);
|
areasUpdateApi(data).then(res => {
|
if (res.data.data.length) {
|
let stringVal = res.data.data.reduce((acc, cur) => {
|
return acc + cur.nickname + '(' + cur.reason + ')' + ',';
|
}, '');
|
stringVal = stringVal.slice(0, -1);
|
ElMessageBox.alert(stringVal, '同步失败', {
|
confirmButtonText: '确定',
|
});
|
} else {
|
ElMessage.success('同步成功');
|
}
|
});
|
}
|
|
// 取消同步
|
function failuresDel() {
|
failuresDelApi().then(res => {
|
ElMessage.success('取消同步成功');
|
});
|
}
|
|
onMounted(() => {
|
failuresList();
|
gettreeDataApi();
|
EventBus.on('gettreeDataApi', gettreeDataApi);
|
});
|
onBeforeUnmount(() => {
|
EventBus.off('gettreeDataApi', gettreeDataApi);
|
});
|
</script>
|
|
<style scoped lang="scss">
|
.table-overlay {
|
position: absolute;
|
top: 0;
|
left: 0;
|
height: calc(100% - 32px);
|
z-index: 99;
|
width: 382px;
|
overflow: hidden;
|
background: rgba(0,0,0,0.51);
|
backdrop-filter: blur(4px);
|
border-radius: 8px 8px 8px 8px;
|
padding: 16px 0 16px 12px;
|
display: flex;
|
flex-direction: column;
|
}
|
|
.searchBox {
|
display: flex;
|
margin-top: 10px;
|
padding-right: 12px;
|
.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;
|
gap: 0 10px;
|
padding-right: 12px;
|
.el-button {
|
margin: 0 !important;
|
}
|
}
|
.tableListBox {
|
overflow-y: scroll;
|
height: 0;
|
flex-grow: 1;
|
padding-right: 12px;
|
:deep(.el-tree-node__content) {
|
height: 38px !important;
|
line-height: 38px !important;
|
}
|
|
.isTheTerritory {
|
:deep() {
|
.el-tree-node__expand-icon {
|
visibility: hidden;
|
}
|
}
|
}
|
|
:deep() {
|
.el-checkbox {
|
--el-checkbox-bg-color: transparent !important;
|
}
|
}
|
.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; // 按钮图标颜色
|
color: #409eff;
|
&:hover {
|
color: #409eff; // hover 时的颜色
|
}
|
}
|
}
|
}
|
</style>
|