fix : 隧道模拟功能初步完成

This commit is contained in:
dj
2025-01-03 20:39:42 +08:00
parent 16df648f2b
commit 472bc3cb83
3 changed files with 98 additions and 80 deletions

View File

@@ -34,9 +34,9 @@ import DevInfo from "./displayInfoComp/DevInfo.vue";
import EditDialog from "./editEquComp/editDialog.vue";
import PreDialog from "./preEquComp/preDialog.vue";
// 导入模模型加载器
import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader";
import {GLTFLoader} from "three/examples/jsm/loaders/GLTFLoader";
// import { DRACOLoader } from "three/examples/jsm/loaders/dracoloader";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import {OrbitControls} from "three/examples/jsm/controls/OrbitControls";
import * as TWEEN from "three/examples/jsm/libs/tween.module";
import {
CSS2DRenderer,
@@ -44,8 +44,8 @@ import {
} from "three/addons/renderers/CSS2DRenderer.js";
// 引入CSS2渲染器CSS2DRenderer和CSS2模型对象CSS2DObject
import { OBJLoader } from "three/examples/jsm/loaders/OBJLoader";
import { RGBELoader } from "three/examples/jsm/loaders/RGBELoader";
import {OBJLoader} from "three/examples/jsm/loaders/OBJLoader";
import {RGBELoader} from "three/examples/jsm/loaders/RGBELoader";
import {
onMounted,
reactive,
@@ -54,12 +54,13 @@ import {
defineProps,
defineExpose,
} from "vue";
import { ElMessage } from "element-plus";
import { getScreenSimulateTunnel } from "@/api/tunnelManage";
import {ElMessage} from "element-plus";
import {getScreenSimulateTunnel} from "@/api/tunnelManage";
// 获取html标签跟随组件dom
const content = ref(null);
const info = ref(null);
const edit = ref(null);
const realtimeData = ref([]);
let modelList = ref(null);
let demo; //定义demo对象
const loader = new OBJLoader();
@@ -79,6 +80,7 @@ const params = defineProps([
// hover到设备回显参数
let equipmentName = ref("");
let equipmentType = ref("");
let pointValue = ref({});
let devRealtimeDetail = ref({
equipmentType: "",
value: "",
@@ -91,7 +93,7 @@ watch(
params.tunnelLength = now;
pointGap = now / 20;
},
{ deep: true }
{deep: true}
);
let pointGap = reactive(params.tunnelLength);
@@ -149,20 +151,21 @@ async function handleMounted() {
];
// 初始化仿真參數
const { data } = await getScreenSimulateTunnel(params.tunnelId);
const {data} = await getScreenSimulateTunnel(params.tunnelId);
demo.enableLeftBtn = false; //关闭左键
demo.pointsVisible(false); //隐藏附着点
TunnelSceneSimulateRender(data);
// 初始化标牌信息
renderRoadPlane({ nickname: params.tunnelAlias, length: params.tunnelLength });
} catch (err) {}
renderRoadPlane({nickname: params.tunnelAlias, length: params.tunnelLength});
} catch (err) {
}
}
// 从新渲染数据
async function rerender() {
try {
// 初始化仿真參數
const { data } = await getScreenSimulateTunnel(params.tunnelId);
const {data} = await getScreenSimulateTunnel(params.tunnelId);
console.log(data);
const modeData = randomPosition([
...data.frequencyChangerList,
@@ -183,6 +186,7 @@ async function rerender() {
});
}
}
// 随机生成1-20的随机数
function randomNum(max = 20) {
const nums = new Set();
@@ -191,6 +195,7 @@ function randomNum(max = 20) {
}
return [...nums];
}
//随机定位
function randomPosition(simulateData) {
const mid = Math.floor(simulateData.length / 2);
@@ -223,7 +228,8 @@ function loadModel(path) {
(obj) => {
resolve(obj);
},
(xhr) => {},
(xhr) => {
},
(err) => {
reject(err);
}
@@ -265,6 +271,7 @@ function lClickCallback(demo) {
}
editDevInfo(targetPoint.info);
}
// 传给内部使用
demo.addFunction("displayDevInfo", displayDevInfo);
}
@@ -284,6 +291,7 @@ function rClickCallback(demo) {
) - 1
);
if (!targetPoint.info) return;
pointValue.value = targetPoint.info
hoverDevEquipmentCallback(targetPoint.info);
editDevInfo(targetPoint.info);
}
@@ -355,13 +363,13 @@ const ThreeConfig = {
},
msg: "dda",
};
//=============隧模型道数据仿真====================
/**
* @description: 隧道中的设备重新模拟渲染
* @param {Object} data 渲染数据格式 [{equipmentId,equipmentName,pointName,equipmentType,equipmentValue}]
*/
function TunnelSceneSimulateRender(data) {
console.log('TunnelSceneSimulateRender',data)
if (!demo) return;
const modeData = randomPosition([
...data.frequencyChangerList,
@@ -375,38 +383,46 @@ function TunnelSceneSimulateRender(data) {
}));
demo.editTunnelInit(modeData); //渲染设备数据
}
/**
* @description: 鼠标悬浮在设备上时回调函数
*/
function hoverDevEquipmentCallback(targetPointInfo) {
console.log(targetPointInfo); //当前附着点信息
const {
equipmentId,
equipmentName: eName,
equipmentType: eType,
typeKey,
unit: u,
value
} = targetPointInfo;
//请求到的实时数据进行渲染
//业务代码.... 获取设备实时数据(data) const value = ....
//业务代码....获取设备实时数据
equipmentType.value = eType;
equipmentName.value = eName;
devRealtimeDetail.value.equipmentType =typeKey;
devRealtimeDetail.value.equipmentType = typeKey;
devRealtimeDetail.value.unit = u;
devRealtimeDetail.value.value = 1000; //1000替换为value
devRealtimeDetail.value.value = value; //1000替换为value
}
/**
* @description: 渲染隧道入口提示板信息
* @param {Object} data 隧道信息 {nickname,length}
*/
function renderRoadPlane(data) {
if (!demo) return;
const { nickname, length } = data; //隧道名称,长度
const {nickname, length} = data; //隧道名称,长度
demo.SignsInf(nickname, length + "");
}
const changePointValue = (item) => {
if (item.equipmentId == pointValue.value.equipmentId) {
pointValue.value.value = item.value
}
hoverDevEquipmentCallback(pointValue.value)
}
defineExpose({
rerender,TunnelSceneSimulateRender
rerender, TunnelSceneSimulateRender, changePointValue
});
</script>

View File

@@ -233,17 +233,17 @@ const changeNum = (item) => {
}
}
const setValueA = () => {
if (electricityConsumptionMonthly.value === 0 || length.value === null) {
if (electricityConsumptionMonthly.value === 0 || length.value === null||electricityConsumptionMonthly.value<0) {
valueA.value.style.height = `0px`;
}
let width = (electricityConsumptionMonthly.value * length.value?.offsetHeight) / 200000;
let width = (electricityConsumptionMonthly.value * length.value?.offsetHeight) / 1000000;
valueA.value.style.height = `${width}px`;
}
const setValueB = () => {
if (monthlySavings.value === 0 || length.value === null) {
if (monthlySavings.value === 0 || length.value === null||monthlySavings.value<0) {
valueB.value.style.height = `0px`;
}
let width = (monthlySavings.value * length.value?.offsetHeight) / 200000;
let width = (monthlySavings.value * length.value?.offsetHeight) / 1000000;
valueB.value.style.height = `${width}px`;
}
const getBasicData = (data) => {

View File

@@ -326,8 +326,8 @@ const handleLogout = () => {
const initWebSocket = () => {
// let wsUrl = `ws://frp.toomewhy.top:38000/wstunnel/websocket/simulate/${token}/123`;
// let wsUrl = `ws://192.168.31.175:9000/websocket/simulate/${token}/${serialNumber.value}`;
let wsUrl = `ws://tunnel.feashow.com/api/wstunnel/websocket/simulate/${token}/${serialNumber.value}`;
// let wsUrl = import.meta.env.VITE_BASE_WSURL+`/${token}/${serialNumber.value}`;
// let wsUrl = `ws://tunnel.feashow.com/api/wstunnel/websocket/simulate/${token}/${serialNumber.value}`;
let wsUrl = import.meta.env.VITE_BASE_WSURL+`/${token}/${serialNumber.value}`;
// let wsUrl = `ws://clay.frp.feashow.cn/wstunnel/websocket/equipment/${token}/${serialNumber.value}`;
// let wsUrl = `ws://frp.toomewhy.top:39000/websocket/simulate/${token}/${serialNumber.value}`;
socket = new WebSocket(wsUrl);
@@ -348,7 +348,6 @@ const initWebSocket = () => {
data.forEach((item) => {
if (item.typeKey === "frequency") {
socketData.leftData = data;
console.log(socketData.leftData);
} else if (item.typeKey === "windPressure") {
socketData.windPressure = data;
} else if (item.typeKey === "sensor") {
@@ -356,6 +355,9 @@ const initWebSocket = () => {
} else if (item.typeKey === "windSpeed") {
socketData.windSpeed = data;
}
nextTick(() => {
previewRef.value.changePointValue(item)
})
});
}
};