diff --git a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools2.js b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools2.js index cafa3a10..ebb826b8 100644 --- a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools2.js +++ b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools2.js @@ -1,5 +1,11 @@ import { modelTreeAllChild } from "@/api/bim/bim"; -import { getModelTree, getTreeAllLeafChild, getModelFeatureInfo, getModelFeatureInfos, modelTreeAllLeafChildByGlids } from "@/api/bim/bimModel"; +import { + getModelTree, + getTreeAllLeafChild, + getModelFeatureInfo, + getModelFeatureInfos, + modelTreeAllLeafChildByGlids, +} from "@/api/bim/bimModel"; import { MergeArray, DelArray } from "@/utils/index"; import { ElMessage } from "element-plus"; function selectFeature(that, featureId) { @@ -123,56 +129,62 @@ function initBim(that) { let tmps = that.allBimData.filter((it) => it.id == that.plan.id); if (tmps.length > 0) { tmps[0].bim.forEach((it) => { - if (that.allFeatures.filter((f) => f.featureId == it.featureId).length == 0) { + if ( + that.allFeatures.filter((f) => f.featureId == it.featureId).length == 0 + ) { that.allFeatures.push(it); } selectFeature(that, it.featureId); }); } tmps = that.allBimData.filter((it) => it.id != that.plan.id); - tmps.forEach((it) => { - it.bim.forEach((it) => { - if (that.readlyParts.filter((f) => f.featureId == it.featureId).length == 0) { - that.readlyParts.push(it.featureId); - } - }); - }); + // 合并that.readlyParts和tmps中的featureId并去重 + const tmpsFeatureIds = tmps.flatMap((item) => + item.bim.map((b) => b.featureId) + ); + that.readlyParts = [...new Set([...that.readlyParts, ...tmpsFeatureIds])]; } function getSelectFeatureIds(that) { let tmps = that.allBimData.filter((it) => it.id == that.plan.id); if (tmps.length > 0) { - return tmps[0].bim || []; + return (tmps[0].bim || []).map((it) => it.featureId); } return []; } function addAllModels(that, cb) { let api = bimSelectionDlgApi; loadModels(that); - setTimeout(() => { - that.models.forEach(model => { - api.Model.setVisible(model.modelId, true); - api.Model.original(model.modelId); - that.$refs.tree.setChecked(model.modelId, true, true) + let func = () => { + if (that.loadedModelCount == that.models.length) { setTimeout(() => { - cb && cb(); - }, 400) - }); - }, 1000) - + that.models.forEach((model) => { + api.Model.setVisible(model.modelId, true); + api.Model.original(model.modelId); + that.$refs.tree.setChecked(model.modelId, true, true); + setTimeout(() => { + cb && cb(); + }, 400); + }); + }, 1000); + } else { + setTimeout(func, 100); + } + }; + func(); } // 加载部分模型(计划中绑定的模型) function partLoadModel(that) { - let featureIds = getSelectFeatureIds(that); let api = bimSelectionDlgApi; addAllModels(that, () => { + let featureIds = getSelectFeatureIds(that); if (featureIds.length > 0) { - let tmps=featureIds.map(it=>it); - let tmpsIds2 = tmps.splice(0, 1000); + let tmps = featureIds.map((it) => it); + let tmpsIds2 = tmps.splice(0, 500); api.Feature.showFeatures(tmpsIds2.join("#")); setFeatueVisible(tmps, true); - initBim(that) + initBim(that); api.Feature.setColor(featureIds.join("#"), "rgba(255,0,255,1)"); that.$message.info("模型加载完成"); that.bimLoaded = true; @@ -191,74 +203,7 @@ function partLoadModel(that) { }; func(); } - }) -} -// 加载部分模型(计划中绑定的模型) -function partLoadModelxxx(that) { - let featureInfos = getSelectFeatureIds(that); - let api = bimSelectionDlgApi; - let obj = {}; - for (let i = 0; i < featureInfos.length; i++) { - let it = featureInfos[i].featureId; - 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); - }, 3000); - 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) => { - setTimeout(() => { - if (that.viewPoint) { - api.Camera.setViewPort(that.viewPoint); - } else { - api.Camera.getViewPort((p) => { - that.viewPoint = p; - }); - } - }, 1000); - that.$message.info("模型加载完成"); - that.bimLoaded = true; - that.doMenu(2); - initBim(that); - }, - { - FlyTo: true, - } - ); - } - } - if (featureInfos.length == 0) { - setTimeout(() => { - that.$refs.tree.setChecked("root", true, true); - }, 3000); - - loadModels(that); - initBim(that); - let func = () => { - if (that.loadedModelCount == that.models.length) { - setTimeout(() => { - setFeatueShowOrHide(that, []); - }, 1000); - } else { - setTimeout(func, 100); - } - }; - func(); - } + }); } //构建树形数据 @@ -343,7 +288,10 @@ async function setTreeNodeChecked(that, node, event) { } } else { let isPartLoad = false; - if (!that.models.find((d) => d.modelId == node.modelId).visible && checked) { + if ( + !that.models.find((d) => d.modelId == node.modelId).visible && + checked + ) { isPartLoad = true; } let selFeatureIds = []; @@ -447,9 +395,12 @@ function loadModels(that) { that.loadedModelCount = 0; modelIds.forEach((modelId) => { if (!api.m_model.has(modelId)) { - cnt++; - that.addModel(modelId); + that.addModel(modelId, () => { + cnt++; + }); return; + } else { + that.loadedModelCount++; } }); return cnt; @@ -505,7 +456,9 @@ function loadNode(that, node, resolve) { resolve(nd); setTimeout(() => { - document.querySelectorAll(".bim-selection-dialog .model-tree .el-tree-node")[0].click(); + document + .querySelectorAll(".bim-selection-dialog .model-tree .el-tree-node")[0] + .click(); }, 1000); } else if (node.level == 1) { let nd = []; @@ -535,14 +488,20 @@ function getTreeChildren(that, node, resolve) { getModelTree(data.modelId, data.glid).then((d) => { let tmps = (d.data || []).map((it) => { let title = it.externalId == 0 ? it.name : it.externalId; - title = title.replaceAll('"', "").replaceAll("'", "").replaceAll("\\", ""); + title = title + .replaceAll('"', "") + .replaceAll("'", "") + .replaceAll("\\", ""); it.title = title; it.key = it.glid; it.modelId = data.modelId; it.type = "data"; it.leaf = +it.externalId != 0; let o = convertFeatureInfo(it, data.modelId); - if (that.allFeatures.filter((item) => item.featureId == it.featureId).length == 0) { + if ( + that.allFeatures.filter((item) => item.featureId == it.featureId) + .length == 0 + ) { that.allFeatures.push({ featureId: it.featureId, info: it.info, @@ -602,7 +561,11 @@ async function selectTreeData(that) { featureId: o.featureId, info: o.info, }); - if (!that.selectItems.find((it) => it.featureId == o.featureId) && !that.readlyParts.includes(o.featureId) && !that.hideParts.includes(o.featureId)) { + if ( + !that.selectItems.find((it) => it.featureId == o.featureId) && + !that.readlyParts.includes(o.featureId) && + !that.hideParts.includes(o.featureId) + ) { that.selectItems.push(o); api.Feature.setColor(o.featureId, "rgba(255,0,255,1)"); } diff --git a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools3.js b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools3.js index 170df31a..9440a431 100644 --- a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools3.js +++ b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectTools3.js @@ -136,15 +136,12 @@ function initBim(that) { }); } tmps = that.allBimData.filter((it) => it.id != that.plan.id); - tmps.forEach((it) => { - it.bim.forEach((it) => { - if ( - that.readlyParts.filter((f) => f.featureId == it.featureId).length == 0 - ) { - that.readlyParts.push(it.featureId); - } - }); - }); + + // 合并that.readlyParts和tmps中的featureId并去重 + const tmpsFeatureIds = tmps.flatMap((item) => + item.bim.map((b) => b.featureId) + ); + that.readlyParts = [...new Set([...that.readlyParts, ...tmpsFeatureIds])]; } //构建树形数据 @@ -536,13 +533,13 @@ function resetModel(that, cb) { that.readlyParts = []; that.hideFeatures = []; that.allBimData = that.planList.filter((d) => d.hasBim); - that.models.forEach(model => { + that.models.forEach((model) => { api.Model.setVisible(model.modelId, true); api.Model.original(model.modelId); - that.$refs.tree.setChecked(model.modelId, true, true) + that.$refs.tree.setChecked(model.modelId, true, true); setTimeout(() => { cb && cb(); - }, 1000) + }, 1000); }); } @@ -557,7 +554,7 @@ function showPlanFeatchure(that) { let tmpsIds2 = featureIds.splice(0, 1000); api.Feature.showFeatures(tmpsIds2.join("#")); setFeatueVisible(featureIds, true); - initBim(that) + initBim(that); //that.selectItems = that.plan.bim.map((it) => it); featureIds = that.plan.bim.map((it) => it.featureId); @@ -567,8 +564,8 @@ function showPlanFeatchure(that) { that.selectItems = []; //未绑定BIM模型 显示所有可以绑定的构件 - initBim(that) - setFeatueVisible(that.readlyParts, false) + initBim(that); + setFeatueVisible(that.readlyParts, false); } }); } @@ -577,7 +574,6 @@ export default { selectSingle, initBim, clearAllSelection, - partLoadModel, buildTreeData, onCheckTree, boxSelection, diff --git a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog2.vue b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog2.vue index aba10ff1..b63a499d 100644 --- a/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog2.vue +++ b/yanzhu-ui-vue3/src/views/manage/plan/bimSelectionDialog2.vue @@ -1,5 +1,12 @@