diff --git a/yanzhu-ui-vue3/src/api/bim/bim.js b/yanzhu-ui-vue3/src/api/bim/bim.js index 00d6f891..06e212a5 100644 --- a/yanzhu-ui-vue3/src/api/bim/bim.js +++ b/yanzhu-ui-vue3/src/api/bim/bim.js @@ -92,4 +92,25 @@ export function updateBimInfo(data) { method: "post", data: data, }); -} \ No newline at end of file +} + +export function getPlanBimInfo(id){ + return request({ + url: `/manage/api/bim/plan/getBimInfo?id=${id}`, + method: "get" + }); +} + +export function getPlanAllBimInfo(prjId){ + return request({ + url: `/manage/api/bim/plan/getAllBimInfo?projectId=${prjId}`, + method: "get" + }); +} + +export function modelTreeAllChild (name, pid) { + return request({ + url: "/manage/bim/modelInfo/modelTreeAllChild/" + name + "?pid=" + pid, + method: "get", + }); +}; \ No newline at end of file diff --git a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools.js b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools.js index c558df80..f771a550 100644 --- a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools.js +++ b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools.js @@ -1,3 +1,32 @@ +import { modelTreeAllChild } from "@/api/bim/bim"; +function selectFeature(that, featureId) { + let api = bimSelectionDlgApi; + if (that.selectItems.includes(featureId)) { + api.Feature.setColor(featureId, "rgba(255,255,255,1)"); + let index = that.selectItems.indexOf(featureId); + if (index > -1) { + that.selectItems.splice(index, 1); + } + } else { + api.Feature.setColor(featureId, "rgba(255,0,255,1)"); + that.selectItems.push(featureId); + } +} +function hideFeatures(that) { + let tmps = that.allBimData.filter((it) => it.id != that.plan.id); + tmps.forEach((it) => { + console.log("hide-->", it.bim); + it.bim.forEach((it) => { + hideFeature(that, it); + }); + }); +} + +function hideFeature(that, featureId) { + let api = bimSelectionDlgApi; + api.Feature.setVisible(featureId, false); +} + function selectSingle(that) { let api = bimSelectionDlgApi; api.Public.clearHandler(); @@ -5,20 +34,164 @@ function selectSingle(that) { if (n && n["id"]) { let featureId = n.id; let modelId = featureId.split("^")[0]; - if(that.selectItems.includes(featureId)){ - api.Feature.setColor(featureId, "rgba(255,255,255,1)"); - let index = that.selectItems.indexOf(featureId); - if (index > -1) { - that.selectItems.splice(index, 1); - } - }else{ - api.Feature.setColor(featureId, "rgba(255,0,255,1)"); - that.selectItems.push(featureId); - } + selectFeature(that, featureId); } }); } +function clearAllSelection(that) { + let api = bimSelectionDlgApi; + api.Public.clearHandler(); + that.selectItems.forEach((it) => { + selectFeature(that, it); + }); +} + +function initBim(that) { + console.log("initBim"); + let tmps = that.allBimData.filter((it) => it.id == that.plan.id); + if (tmps.length > 0) { + console.log("selected-->", tmps[0].bim); + tmps[0].bim.forEach((it) => { + selectFeature(that, it); + }); + } +} + +function getSelectFeatureIds(that) { + let tmps = that.allBimData.filter((it) => it.id == that.plan.id); + if (tmps.length > 0) { + return tmps[0].bim || []; + } + return []; +} + +// 加载部分模型(计划中绑定的模型) +function partLoadModel(that) { + let featureIds = getSelectFeatureIds(that); + let api = bimSelectionDlgApi; + let obj = {}; + for (let i = 0; i < featureIds.length; i++) { + let it = featureIds[i]; + let tmps = it.split("^"); + let modelId = tmps[0]; + if (!obj[modelId]) { + obj[modelId] = []; + } + obj[modelId].push(it); + } + for (let modelId in obj) { + let tmps = that.models.filter((it) => it.modelId == modelId); + setTimeout(() => { + that.$refs.tree.setChecked(modelId, true, true); + }, 1000); + if (tmps.length > 0) { + let url = `${window.config.modelUrl}/Tools/output/model/${modelId}/root.glt`; + that.partLoad = true; + api.Model.addPart( + url, + modelId, + obj[modelId].join("#"), + (res) => {}, + (res) => { + console.log("load part success", res); + that.viewPoint = p; + that.$message.info("模型加载完成"); + that.doMenu(2); + initBim(that); + }, + { + FlyTo: true, + } + ); + } + } +} + +//构建树形数据 +function buildTreeData(that) { + that.modelTrees = [ + { + title: "项目模型", + level: 0, + type: "root", + key: "root", + children: [], + hadLoad: true, + }, + ]; + that.models.forEach((d) => { + let node = { + title: d.modelName, + level: 1, + type: "model", + hasLoad: false, + modelId: d.lightweightName, + key: d.lightweightName, + externalId: "0", + glid: "", + children: [], + data: d, + }; + that.modelTrees[0].children.push(node); + getModelFeatures(that, d.lightweightName, node); + }); + that.treeExpendedKeys.push("root"); +} + +//获取模型所有构件 +function getModelFeatures(that, modelId, node) { + let tmps = that.allBimData.filter((it) => it.id != that.plan.id); + tmps.forEach((it) => { + console.log("hide-->", it.bim); + it.bim.forEach((it) => { + if (!that.readlyParts.includes(it)) { + that.readlyParts.push(it); + } + }); + }); + //获取模型构件 + modelTreeAllChild(modelId, "").then((res) => { + let objs = res.data || [] + + objs.forEach((o) => { + o.modelId=modelId + o.featureId=o.modelId+"^"+o.externalId + o.name=o.name||''; + o.name=o.name.replaceAll('"',"").replaceAll("'","").replaceAll('\\',''); + o.info=`[${o.externalId}]${o.groupname}-${o.name}` + if(o.externalId == "0"){ + return; + } + let featureId=o.modelId+"^"+o.externalId; + if (!that.allParts.includes(featureId)) { + that.allParts.push(featureId); + } + }); + that.allFeatures = objs; + let makeTree = (tmps) => { + tmps.forEach((item) => { + item.children = objs.filter((it) => it.pglid == item.glid); + if (item.children.length > 0) { + makeTree(item.children); + } + item.hasLoad = true; + item.title = item.name; + item.key = item.glid; + item.modelId = node.modelId; + }); + return tmps; + }; + + node.children = makeTree(objs.filter((item) => item.level == 0)); + that.treeKey++; + }); + that.showParts = that.allParts.filter((it) => !that.hideParts.includes(it)); +} export default { selectSingle, + initBim, + clearAllSelection, + partLoadModel, + buildTreeData, }; diff --git a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog.vue b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog.vue index 955b16ce..2ca3b001 100644 --- a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog.vue +++ b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog.vue @@ -6,11 +6,28 @@
- + +
+ +
+
-
-
{{ it.split("^")[1] }}
+
+ +
{{ it.info }}
+
删除
@@ -63,13 +80,14 @@ import useUserStore from "@/store/modules/user"; import { listBimModel } from "@/api/bim/bimModel"; import bimTools from "./bimSelectTools"; -import { updateBimInfo } from "@/api/bim/bim"; +import { updateBimInfo, getPlanAllBimInfo } from "@/api/bim/bim"; import { ElMessage, ElMessageBox } from "element-plus"; export default { data() { return { title: "任务计划绑定BIM", show: false, + partLoad: false, //部分加载构件 plan: null, currentPrjId: null, currentComId: null, @@ -81,6 +99,14 @@ export default { activeMenu: 0, elId: 0, selectItems: [], + allBimData: [], + treeKey: 0, + modelTrees: [], + treeExpendedKeys: [], + allFeatures: [], //所有构件集合 + allParts: [], //所有构件ID集合 + showParts: [], //显示构件ID集合 + readlyParts: [], //隐藏构件ID集合 }; }, beforeDestroy() { @@ -92,17 +118,24 @@ export default { } }, methods: { + onCheckTree(node, event) {}, + getSelectItems() { + return this.selectItems.map((it) => { + return this.allFeatures.find((item) => item.featureId == it); + }); + }, doSave() { updateBimInfo({ id: this.plan.id, text: JSON.stringify(this.selectItems), }).then((res) => { console.log(res); - if(res.success){ - ElMessage.success('保存成功') - this.show = false; - }else{ - ElMessage.error('保存失败') + if (res.success) { + ElMessage.success("保存成功"); + this.show = false; + this.$emit("success"); + } else { + ElMessage.error("保存失败"); } }); }, @@ -113,6 +146,7 @@ export default { this.resetScene(); break; case 1: + bimTools.clearAllSelection(this); break; case 2: bimTools.selectSingle(this); @@ -124,12 +158,30 @@ export default { } }, showDialog(plan) { + window.bimDlg = this; this.plan = plan; this.show = true; this.activeTab = "a1"; this.userStore = useUserStore(); this.currentPrjId = this.userStore.currentPrjId; this.currentComId = this.userStore.currentComId; + this.selectItems = []; + this.allBimData = []; + this.treeKey = 0; + this.partLoad = false; + this.modelTrees = []; + this.treeExpendedKeys = []; + this.allParts = []; + this.hideParts = []; + this.readlyParts = []; + this.allFeatures = []; + + getPlanAllBimInfo(this.plan.projectId).then((res) => { + this.allBimData = (res.data || []).map((it) => { + it.bim = this.$tryToJson(it.bimId || "[]", []); + return it; + }); + }); this.initEngine(); }, initEngine() { @@ -198,13 +250,19 @@ export default { comId: this.currentComId, projectId: this.currentPrjId, }).then((d) => { - this.models = d.rows || []; + this.models = (d.rows || []).map((it) => { + it.modelId = it.lightweightName; + it.gis = this.$tryToJson(it.gisJson || "{}", {}); + return it; + }); if (this.models.length == 0) { this.$modal.msgError("暂无模型,请先关联模型"); } else { - this.models.forEach((item) => { - this.addModel(item.lightweightName); - }); + bimTools.buildTreeData(this); + bimTools.partLoadModel(this); + // this.models.forEach((item) => { + // this.addModel(item.lightweightName); + // }); } }); }, @@ -222,6 +280,8 @@ export default { bimSelectionDlgApi.Camera.getViewPort((p) => { this.viewPoint = p; this.$message.info("模型加载完成"); + bimTools.initBim(this); + this.doMenu(2); }); }, 1000); } @@ -359,6 +419,13 @@ export default { line-height: 30px; padding: 0px 10px; margin-top: 5px; + .sel-item-info { + width: calc(100% - 40px); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + cursor: pointer; + } .el-button { position: absolute; right: 10px; @@ -367,6 +434,31 @@ export default { } } } + + .model-tree { + height: calc(100% - 36px); + overflow-y: auto; + .el-tree { + background: transparent; + color: #eee; + .el-checkbox { + color: #45fdfe; + } + .el-tree-node { + &:focus { + & > .el-tree-node__content { + background: #3489d966; + &:hover { + background: #3489d966; + } + } + } + .el-tree-node__content:hover { + background: #3489d966; + } + } + } + } } } diff --git a/yanzhu-ui-vue3/src/views/manage/plan/index.vue b/yanzhu-ui-vue3/src/views/manage/plan/index.vue index cb9f05a5..ac505cd0 100644 --- a/yanzhu-ui-vue3/src/views/manage/plan/index.vue +++ b/yanzhu-ui-vue3/src/views/manage/plan/index.vue @@ -69,7 +69,7 @@ - " + "
@@ -141,6 +141,9 @@ const data = reactive({ const { queryParams, form, rules } = toRefs(data); +function doSelectSuccess(){ + handleQuery(); +} function buildTree(all, id) { let tmps = all.filter((d) => d.parentId == id); if (tmps.length > 0) {