预览初始化+切换隧道

This commit is contained in:
Hcat
2023-12-29 21:18:48 +08:00
parent a02ecff84f
commit e49c126351
4 changed files with 164 additions and 148 deletions

View File

@@ -47,15 +47,14 @@ import {
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader"; import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader"; import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader";
import { onMounted, reactive, ref } from "vue"; import { onMounted, reactive, ref, toRaw, getCurrentInstance } from "vue";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { useModelSceneStore } from "@/store/modelSceneStore"; import { deleteEquipment, initData } from "./request";
import { toRaw } from "vue"
// 获取html标签跟随组件dom // 获取html标签跟随组件dom
const content = ref(null); const content = ref(null);
const info = ref(null); const info = ref(null);
const edit = ref(null); const edit = ref(null);
const store = useModelSceneStore(); let modelList = ref(null);
let demo; //定义demo全局变量 let demo; //定义demo全局变量
// const loader = new OBJLoader(); // const loader = new OBJLoader();
const loader = new OBJLoader(); const loader = new OBJLoader();
@@ -69,6 +68,16 @@ const params = defineProps(["isedit", "tunnelId"]); //接收参数看是不是
let isedit = ref(params.isedit) let isedit = ref(params.isedit)
// watch(
// () => params.tunnelId,
// (now) => {
// params.tunnelId = now
// console.log(params.tunnelId);
// },
// { deep: true }
// )
onMounted(handleMounted); onMounted(handleMounted);
// 挂载后回调 // 挂载后回调
async function handleMounted() { async function handleMounted() {
@@ -89,7 +98,7 @@ async function handleMounted() {
watch( watch(
() => params.tunnelId, () => params.tunnelId,
async () => { async () => {
const text = await store.initData(params.tunnelId); const text = await initData(params.tunnelId);
} }
); );
// 初始化设备模型 // 初始化设备模型
@@ -100,14 +109,38 @@ async function handleMounted() {
map.set("equ_sensors", await loadModel("/devicesModel/sensors.obj")); map.set("equ_sensors", await loadModel("/devicesModel/sensors.obj"));
// 给对象初加载设备模型 // 给对象初加载设备模型
demo.initDevicesModel(map); demo.initDevicesModel(map);
const equipmentList = await store.getEquipmentList(); // const equipmentList = await store.getEquipmentList();
demo.previewtunnelModeInit(equipmentList); modelList.value = await initData(params.tunnelId);
// previewEquInfProcess(equipmentList) // console.log("init", params.tunnelId);
demo.previewtunnelModeInit(modelList.value);
watch(
() => params.tunnelId,
(now) => {
params.tunnelId = now
// console.log(params.tunnelId);
checkTunnelInit(modelList.value)
demo.previewtunnelModeInit(modelList.value);
},
{ deep: true }
)
// demo.previewtunnelModeInit(equipmentList);
// previewEquInfProcess(modelList.value, targetP.value)
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
} }
function checkTunnelInit(equipmentList) {
equipmentList.forEach((item) => {
let equipment = toRaw(item)
console.log("我要清理掉之前的设备!!!");
console.log(equipment);
console.log(demo.scene.getObjectByName(equipment.position));
demo.removeEquipment(demo.scene.getObjectByName(equipment.position));
});
}
// 每个模型加载回调 // 每个模型加载回调
function loadModel(path) { function loadModel(path) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -163,46 +196,31 @@ function lClickCallback(demo) {
} }
let pointNum = ref(0); let pointNum = ref(0);
let targetP; let targetP = ref({});
// 右键点击附着点后调函数 // 右键点击附着点后调函数
function rClickCallback(demo) { function rClickCallback(demo) {
function editDev(targetPoint = null) { function editDev(targetPoint = null) {
hasDevice = targetPoint.hasDevice; hasDevice.value = targetPoint.hasDevice;
targetP = targetPoint; targetP.value = targetPoint;
//点击之后马上调用这个函数变成回调然后进行处理处理在传给preview表单 const equipmentList = initData(params.tunnelId)
const equipmentList = store.getEquipmentList().then((result) => { equipmentList.then((result) => {
previewEquInfProcess(result, targetP) previewEquInfProcess(result, targetP.value)
}); })
pointNum.value = Number( pointNum.value = Number(
targetPoint.name.substring( targetPoint.name.substring(
targetPoint.name.indexOf("_") + 1, targetPoint.name.indexOf("_") + 1,
targetPoint.name.lastIndexOf("_") targetPoint.name.lastIndexOf("_")
) - 1 ) - 1
); );
if (!targetPoint.info) return; if (!targetPoint.info) return;
editDevInfo(targetPoint.info); editDevInfo(targetPoint.info);
} }
demo.addFunction("editDev", editDev); demo.addFunction("editDev", editDev);
} }
// 添加设备 // 添加设备
function handleAddEqu(formInfo) { function handleAddEqu(formInfo) {
if (!formInfo.equipmentType) { demo.addEquipment(targetP.value, formInfo);
ElMessage({
message: "请选择传感器!",
type: "warning",
});
return;
}
//表单信息
//这里利用处理请求
demo.addEquipment(targetP, formInfo);
ElMessage({
message: "添加成功!",
type: "success",
});
} }
const centerDialogVisible = ref(false); const centerDialogVisible = ref(false);
@@ -219,12 +237,22 @@ function handleRemoveEqu() {
} }
// 对话框确认删除 // 对话框确认删除
function handleConfirmAddEqu() { function handleConfirmAddEqu() {
demo.removeEquipment(targetP); console.log("target:", targetP.value.info);
deleteEquipment(targetP.value.info.equipmentId, pointGap)
.then((res) => {
demo.removeEquipment(targetP.value);
centerDialogVisible.value = false; centerDialogVisible.value = false;
ElMessage({ ElMessage({
message: "删除成功!", message: "删除成功!",
type: "success", type: "success",
}); });
})
.catch((res) => {
ElMessage({
message: "删除失败!",
type: "warning",
});
});
} }
// 处理取消关闭编辑框事件 // 处理取消关闭编辑框事件
function handleCancel() { function handleCancel() {
@@ -242,11 +270,10 @@ let equipmentValue = ref(0)
function previewEquInfProcess(equipmentList, targetP) { function previewEquInfProcess(equipmentList, targetP) {
for (const equipment of equipmentList) { for (const equipment of equipmentList) {
// console.log(equipment);
if (equipment.position == targetP.name) { if (equipment.position == targetP.name) {
equipmentType.value = equipment.equipmentType equipmentType.value = equipment.equipmentType
//需要将获取到的设备列表进行序列化 //需要将获取到的设备列表进行序列化
equipmentName.value = toRaw(equipment.chooseEquipment).label equipmentName.value = equipment.equipmentName
equipmentValue.value = equipment.threshold equipmentValue.value = equipment.threshold
if (equipmentType.value == 'frequency') { if (equipmentType.value == 'frequency') {
equipmentType.value = '风机' equipmentType.value = '风机'

View File

@@ -36,7 +36,7 @@ function addEquipment(targetPoint, formInfo) {
// function handleValveEqu(targetPoint, equipmentInfo) { // function handleValveEqu(targetPoint, equipmentInfo) {
// } // }
let allline = new Array
// 其他传感器 // 其他传感器
function handleOtherEqu(targetPoint, equipmentInfo) { function handleOtherEqu(targetPoint, equipmentInfo) {
const equMesh = this.equMap.get("equ_sensors").clone(); const equMesh = this.equMap.get("equ_sensors").clone();
@@ -67,41 +67,24 @@ function handleOtherEqu(targetPoint, equipmentInfo) {
targetPoint.scale.set(0.03, 0.06, 0.05); targetPoint.scale.set(0.03, 0.06, 0.05);
this.scene.add(equMesh); this.scene.add(equMesh);
targetPoint.visible = false; targetPoint.visible = false;
// targetPoint.hasWall = true; targetPoint.hasWall = true;
// //处理风压阀的代码片段 //处理风压阀的代码片段
// let lineIndex = targetPoint.name.slice(7, 9); let lineIndex = targetPoint.name.slice(7, 9)
// for (let line = Number(lineIndex); line <= 20; line++) { if (allline.includes(Number(lineIndex))) {
// if (line < 10) { allline.slice(array.indexOf(lineIndex), 1)
// let wall = "wall_" + "0" + line; console.log('dadad');
// this.scene.getObjectByName(wall).visible = true; } else {
// let point = "point_" + "00" + line + "_tc"; allline.push(Number(lineIndex))
// this.scene.getObjectByName(point).visible = false; }
// this.scene.getObjectByName(point).layers.set(-2); console.log(allline);
// if (this.scene.getObjectByName(point).hasDevice == true) { // console.log(allline);
// let EquID = this.scene.getObjectByName(point).info.id; // allline.forEach((item, index, array) => {
// this.scene.getObjectById(EquID).visible = false; // if (array.includes(item)) {
// array.slice(array.indexOf(item), 1)
// array.slice(array.indexOf(item), 1)
// console.log(array);
// } // }
// } else if (line >= 10) { // })
// let wall = "wall_" + line;
// this.scene.getObjectByName(wall).visible = true;
// let point = "point_" + "0" + line + "_tc";
// this.scene.getObjectByName(point).visible = false;
// this.scene.getObjectByName(point).layers.set(-2);
// if (this.scene.getObjectByName(point).hasDevice == true) {
// let EquID = this.scene.getObjectByName(point).info.id;
// this.scene.getObjectById(EquID).visible = false;
// }
// }
// //处理21行的设备和附着点
// let point = "point_" + "0" + 21 + "_tc";
// this.scene.getObjectByName(point).visible = false;
// this.scene.getObjectByName(point).layers.set(-2);
// if (this.scene.getObjectByName(point).hasDevice == true) {
// let EquID = this.scene.getObjectByName(point).info.id;
// this.scene.getObjectById(EquID).visible = false;
// }
// }
// this.scene.getObjectByName('wall_01').visible = true
// console.log(this.scene); // console.log(this.scene);
// 保存该设备模型id后期直接从附附着点进行删除 // 保存该设备模型id后期直接从附附着点进行删除
targetPoint.info = { targetPoint.info = {
@@ -154,43 +137,44 @@ function handleFanEqu(
function removeEquipment(targetPoint) { function removeEquipment(targetPoint) {
//删除设备这里需要再进行处理,就是根据附着点(附着点一定保存了当前添加设备的信息了)判断是不是分压阀,然后继续一样的隐藏 //删除设备这里需要再进行处理,就是根据附着点(附着点一定保存了当前添加设备的信息了)判断是不是分压阀,然后继续一样的隐藏
if (!targetPoint.hasDevice) return; if (!targetPoint.hasDevice) return;
if (targetPoint.hasWall == true) { // if (targetPoint.hasWall == true) {
let lineIndex = targetPoint.name.slice(7, 9); // let lineIndex = targetPoint.name.slice(7, 9);
for (let line = Number(lineIndex); line <= 20; line++) { // for (let line = Number(lineIndex); line <= 20; line++) {
if (line < 10) { // if (line < 10) {
let wall = "wall_" + "0" + line; // let wall = "wall_" + "0" + line;
this.scene.getObjectByName(wall).visible = false; // this.scene.getObjectByName(wall).visible = false;
let point = "point_" + "00" + line + "_tc"; // let point = "point_" + "00" + line + "_tc";
console.log(this.scene.getObjectByName(point)); // console.log(this.scene.getObjectByName(point));
this.scene.getObjectByName(point).visible = true; // this.scene.getObjectByName(point).visible = true;
this.scene.getObjectByName(point).layers.set(0); // this.scene.getObjectByName(point).layers.set(0);
if (this.scene.getObjectByName(point).hasDevice == true) { // if (this.scene.getObjectByName(point).hasDevice == true) {
this.scene.getObjectByName(point).visible = false; // this.scene.getObjectByName(point).visible = false;
let EquID = this.scene.getObjectByName(point).info.id; // let EquID = this.scene.getObjectByName(point).info.id;
this.scene.getObjectById(EquID).visible = true; // this.scene.getObjectById(EquID).visible = true;
} // }
} else if (line >= 10) { // } else if (line >= 10) {
let wall = "wall_" + line; // let wall = "wall_" + line;
this.scene.getObjectByName(wall).visible = false; // this.scene.getObjectByName(wall).visible = false;
let point = "point_" + "0" + line + "_tc"; // let point = "point_" + "0" + line + "_tc";
this.scene.getObjectByName(point).visible = true; // this.scene.getObjectByName(point).visible = true;
this.scene.getObjectByName(point).layers.set(0); // this.scene.getObjectByName(point).layers.set(0);
if (this.scene.getObjectByName(point).hasDevice == true) { // if (this.scene.getObjectByName(point).hasDevice == true) {
this.scene.getObjectByName(point).visible = false; // this.scene.getObjectByName(point).visible = false;
let EquID = this.scene.getObjectByName(point).info.id; // let EquID = this.scene.getObjectByName(point).info.id;
this.scene.getObjectById(EquID).visible = true; // this.scene.getObjectById(EquID).visible = true;
} // }
} // }
//处理21行的设备和附着点 // //处理21行的设备和附着点
let point = "point_" + "0" + 21 + "_tc"; // let point = "point_" + "0" + 21 + "_tc";
this.scene.getObjectByName(point).visible = true; // this.scene.getObjectByName(point).visible = true;
this.scene.getObjectByName(point).layers.set(0); // this.scene.getObjectByName(point).layers.set(0);
if (this.scene.getObjectByName(point).hasDevice == true) { // if (this.scene.getObjectByName(point).hasDevice == true) {
let EquID = this.scene.getObjectByName(point).info.id; // let EquID = this.scene.getObjectByName(point).info.id;
this.scene.getObjectById(EquID).visible = true; // this.scene.getObjectById(EquID).visible = true;
} // }
} // }
} // }
console.log("测试是不是删除了");
const mesh = this.scene.getObjectById(targetPoint.info.id); const mesh = this.scene.getObjectById(targetPoint.info.id);
this.scene.remove(mesh); this.scene.remove(mesh);
targetPoint.visible = true; targetPoint.visible = true;

View File

@@ -1,3 +1,4 @@
export default function previewtunnelModeInit(equipmentList) { export default function previewtunnelModeInit(equipmentList) {
//初始化将墙壁隐藏起来 //初始化将墙壁隐藏起来
// for (let line = 1; line <= 20; line++) { // for (let line = 1; line <= 20; line++) {
@@ -9,14 +10,8 @@ export default function previewtunnelModeInit(equipmentList) {
// this.scene.getObjectByName(wall).visible = false // this.scene.getObjectByName(wall).visible = false
// } // }
// } // }
equipmentList.forEach((item) => { equipmentList.forEach((item) => {
const formInfo = { this.addEquipment(this.scene.getObjectByName(item.position), item);
equipmentType: item.equipmentType, //设备类型
chooseEquipment: item.chooseEquipment, //设备选择(设备名称)
threshold: item.threshold,
};
this.addEquipment(this.scene.getObjectByName(item.position), formInfo);
}); });
//进行预览和编辑模式的一些操作 //进行预览和编辑模式的一些操作
if (this.isedit == false) { if (this.isedit == false) {

View File

@@ -32,7 +32,7 @@
</div> </div>
<!-- <tunnel-scene id="tunnel-box" :isedit="false" /> --> <!-- <tunnel-scene id="tunnel-box" :isedit="false" /> -->
<!-- 一进去的话应该是预览模式所以引入这个组件 --> <!-- 一进去的话应该是预览模式所以引入这个组件 -->
<preview-scene id="tunnel-box" :isedit="false" :tunnelId="tunnelId"></preview-scene> <preview-scene id="tunnel-box" :isedit="false" :tunnelId="tunnelId" :key="tunnelId"></preview-scene>
<div class="left"> <div class="left">
<el-drawer v-model="drawerLeft" direction="ltr" modal-class="modal-box" :modal="false" :show-close="false" <el-drawer v-model="drawerLeft" direction="ltr" modal-class="modal-box" :modal="false" :show-close="false"
:close-on-click-modal="false" :close-on-press-escape="false"> :close-on-click-modal="false" :close-on-press-escape="false">
@@ -84,6 +84,7 @@ import {ElMessageBox} from "element-plus";
import { getUserInfo } from "@/api/login"; import { getUserInfo } from "@/api/login";
import { initSceneData } from "@/api/tunnelScene"; import { initSceneData } from "@/api/tunnelScene";
import { getSiteDetail } from "../../api/site"; import { getSiteDetail } from "../../api/site";
import { nextTick, reactive } from "vue";
const authStore = useAuthStore(); const authStore = useAuthStore();
const router = useRouter(); const router = useRouter();
@@ -259,6 +260,15 @@ const closeSocket = () => {
socket.close(); socket.close();
}; };
initWebSocket(); initWebSocket();
watch(
() => tunnelId.value,
(now) => {
tunnelId.value = now
},
{ deep: true }
)
</script> </script>
<style lang="scss"> <style lang="scss">
.el-dropdown__popper.el-popper { .el-dropdown__popper.el-popper {