模型预览新增树状图的筛选功能

This commit is contained in:
LHD_HY 2025-12-30 18:30:33 +08:00
parent 7030ff9bd5
commit f4745a253c
1 changed files with 1290 additions and 1081 deletions

View File

@ -179,6 +179,8 @@
> >
<AddOrEditForm ref="addOrEditComponentRef" @closeAddOrEditFormDialog="closeAddOrEditFormDialog" /> <AddOrEditForm ref="addOrEditComponentRef" @closeAddOrEditFormDialog="closeAddOrEditFormDialog" />
</el-dialog> </el-dialog>
<!-- 模型预览弹窗区分模型预览显示树形和单独查看模型不显示树形 -->
<el-dialog <el-dialog
title="模型预览" title="模型预览"
width="90%" width="90%"
@ -186,9 +188,29 @@
@close="onCloseMapView" @close="onCloseMapView"
:visible.sync="modelPreviewVisible" :visible.sync="modelPreviewVisible"
> >
<!-- <dxf-viewer :entities="dxfPreviewUrl"></dxf-viewer> --> <!-- 仅当是模型预览isBatchPreview为true时显示左侧树形复选框 -->
<div class="model-preview-wrapper" v-if="isBatchPreview">
<!-- 左侧树形菜单带复选框 -->
<div class="model-tree-container">
<el-tree
ref="projectTree"
:data="projectTreeData"
:props="treeProps"
:show-checkbox="true"
:check-strictly="true"
@check-change="handleNodeCheckChange"
node-key="id"
default-expand-all
class="model-tree"
></el-tree>
</div>
<!-- 右侧地图容器 -->
<div id="map-container-batch" class="model-map-container"></div>
</div>
<!-- 单独查看模型时只显示地图容器不显示树形 -->
<div id="map-container-single" v-else style="min-height: 76vh;"></div>
<div id="map-container"></div> <!-- <dxf-viewer :entities="dxfPreviewUrl"></dxf-viewer> -->
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
@ -297,6 +319,16 @@ export default {
map: null, map: null,
modelPreviewVisible: false, modelPreviewVisible: false,
modelPreviewInfoList: [], modelPreviewInfoList: [],
//
isBatchPreview: false,
// 使
projectTreeData: [], //
treeProps: {
children: 'children',
label: 'nodeName',
isLeaf: 'isLeaf'
},
checkedNodeIds: [], // ID
} }
}, },
created() { created() {
@ -322,7 +354,7 @@ export default {
this.open = true // this.open = true //
this.title = '新增项目' // this.title = '新增项目' //
}, },
// //
handleViewModel(row) { handleViewModel(row) {
/* const modelUrl = row.modelUrl /* const modelUrl = row.modelUrl
if (!modelUrl || !modelUrl.endsWith('.dxf')) { if (!modelUrl || !modelUrl.endsWith('.dxf')) {
@ -339,6 +371,8 @@ if (!modelUrl || !modelUrl.endsWith('.dxf')) {
// // console.error(':', error) // // console.error(':', error)
// }) // })
//
this.isBatchPreview = false
openView({ id: row.id }) openView({ id: row.id })
.then((res) => { .then((res) => {
this.modelPreviewInfoList = res.data this.modelPreviewInfoList = res.data
@ -628,7 +662,6 @@ if (!modelUrl || !modelUrl.endsWith('.dxf')) {
}, },
// //
handleAddLevelTwo() { handleAddLevelTwo() {
this.addOrEditFormTitle = '新增' this.addOrEditFormTitle = '新增'
this.editForm = null this.editForm = null
@ -678,28 +711,150 @@ if (!modelUrl || !modelUrl.endsWith('.dxf')) {
return [] return []
}, },
// // 使
loadProjectTree(customData = []) {
if (customData.length > 0) {
this.projectTreeData = customData.map(node => ({
...node,
// isLeaf nodelevel === nodeCount
isLeaf: Number(node.nodelevel) === Number(node.nodeCount)
}))
} else {
//
this.projectTreeData = this.modelList.map(node => ({
...node,
// / isLeaf
isLeaf: Number(node.nodelevel) === Number(node.nodeCount)
}))
}
},
//
filterLeafNode(node) {
return node.isLeaf
},
// ID
getAllChildNodeIds(node) {
let nodeIds = []
// ID
//
nodeIds.push(node.id)
//
if (node.children && node.children.length > 0) {
node.children.forEach(child => {
nodeIds = nodeIds.concat(this.getAllChildNodeIds(child))
})
}
return nodeIds
},
//
handleNodeCheckChange(node, checked) {
//
// if (!node || !node.isLeaf || Number(node.nodelevel) !== Number(node.nodeCount)) {
// return
// }
// 1. ID
const allChildIds = this.getAllChildNodeIds(node);
// 2.
if (checked) {
allChildIds.forEach(id => {
if (!this.checkedNodeIds.includes(id)) {
this.checkedNodeIds.push(id);
}
});
} else {
this.checkedNodeIds = this.checkedNodeIds.filter(id => !allChildIds.includes(id));
}
const treeRef = this.$refs.projectTree;
if (treeRef) {
//
if (!checked) {
treeRef.setCheckedKeys([]);
}
// +
treeRef.setCheckedKeys(this.checkedNodeIds);
}
// 4.
this.loadBatchCadData();
},
// CAD
async loadBatchCadData() {
// 1.
this.modelPreviewInfoList = []
this.clearMapOverlays()
if (this.checkedNodeIds.length === 0) {
return
}
try {
//
const promises = this.checkedNodeIds.map(nodeId => openView({ id: nodeId }))
const results = await Promise.all(promises)
//
this.modelPreviewInfoList = results.reduce((total, res) => {
return [...total, ...res.data]
}, [])
//
this.drawModel(this.modelPreviewInfoList)
} catch (error) {
console.error('加载勾选节点模型失败:', error)
this.$message.error('加载模型图层失败')
}
},
//
clearMapOverlays() {
if (this.map) {
this.map.clearOverlays()
}
},
//
handleModelPreview() { handleModelPreview() {
//
this.isBatchPreview = true
// ID // ID
const selectedProjectId = this.queryParams.projectId const selectedProjectId = this.queryParams.projectId
// //
if (selectedProjectId != null && selectedProjectId !== '') { if (selectedProjectId == null || selectedProjectId === '') {
console.log('已选中项目 ID:', selectedProjectId)
//
} else {
this.$modal.msgError('请选择项目') this.$modal.msgError('请选择项目')
return
} }
openViewAll({ projectId: selectedProjectId })
.then((res) => { //
this.modelPreviewInfoList = res.data this.loadProjectTree()
//
this.checkedNodeIds = []
if (this.$refs.projectTree) {
this.$refs.projectTree.setCheckedKeys([])
}
this.modelPreviewInfoList = []
// 5.
this.modelPreviewVisible = true this.modelPreviewVisible = true
console.log('res', res.data)
this.initMap() this.initMap()
})
.catch((err) => { //
console.error('获取模型详情失败:', err) // openViewAll({ projectId: selectedProjectId })
}) // .then((res) => {
// this.modelPreviewInfoList = res.data
// this.modelPreviewVisible = true
// this.initMap()
// })
// .catch((err) => {
// console.error(':', err)
// })
// this.modelPreviewVisible = true // this.modelPreviewVisible = true
// //
// // // //
@ -710,17 +865,35 @@ if (!modelUrl || !modelUrl.endsWith('.dxf')) {
onCloseMapView() { onCloseMapView() {
// //
if (this.map) { if (this.map) {
this.map.clearOverlays()
this.map = null this.map = null
} }
//
this.checkedNodeIds = []
if (this.$refs.projectTree) {
this.$refs.projectTree.setCheckedKeys([])
}
//
this.isBatchPreview = false
}, },
// //
initMap() { initMap() {
//
const lon = this.projectSelectList.find((item) => item.id == this.queryParams.projectId).lon * 1
const lat = this.projectSelectList.find((item) => item.id == this.queryParams.projectId).lat * 1
this.$nextTick(() => { this.$nextTick(() => {
this.map = new BMapGL.Map('map-container') // //
if (this.map) {
this.map.clearOverlays()
this.map = null
}
//
const projectItem = this.projectSelectList.find((item) => item.id == this.queryParams.projectId)
const lon = projectItem?.lon * 1 || 116.404
const lat = projectItem?.lat * 1 || 39.915
//
const mapContainerId = this.isBatchPreview ? 'map-container-batch' : 'map-container-single'
this.map = new BMapGL.Map(mapContainerId) //
this.map.setMapType(BMAP_EARTH_MAP) // this.map.setMapType(BMAP_EARTH_MAP) //
this.map.setDisplayOptions({ this.map.setDisplayOptions({
poiText: false, // POI poiText: false, // POI
@ -1150,7 +1323,43 @@ if (!modelUrl || !modelUrl.endsWith('.dxf')) {
background-color: #f0f7ff; background-color: #f0f7ff;
} }
#map-container { #map-container-single {
min-height: 76vh; min-height: 76vh;
} }
/* 模型预览弹窗样式(仅批量预览时生效) */
.model-preview-wrapper {
display: flex;
height: 76vh;
gap: 10px;
}
.model-tree-container {
width: 280px;
height: 100%;
border: 1px solid #ebeef5;
border-radius: 4px;
overflow-y: auto;
padding: 10px;
}
.model-map-container {
flex: 1;
height: 100%;
border-radius: 4px;
}
/* 树形组件样式优化 */
::v-deep .model-tree {
--el-tree-node-content-hover-bg-color: #f5f7fa;
}
::v-deep .model-tree .el-tree-node__checkbox {
margin-right: 8px;
}
/* 隐藏非末级节点的复选框 */
::v-deep .model-tree .el-tree-node:not(.is-leaf) .el-tree-node__checkbox {
display: none !important;
}
</style> </style>