feat(elevator): 实现楼层感知的电梯状态显示,非当前楼层电梯强制显示为关门状态以优化可视化效果

This commit is contained in:
xudan 2025-12-16 10:34:05 +08:00
parent eda308db14
commit b1d77ae3c8
3 changed files with 60 additions and 24 deletions

View File

@ -106,6 +106,17 @@ const client = shallowRef<WebSocket>();
//
const elevatorStore = useElevatorStore();
//
const currentFloor = computed(() => currentFloorIndex.value + 1);
// store
elevatorStore.setCurrentFloor(currentFloor.value);
// store
watch(currentFloor, (newFloor) => {
elevatorStore.setCurrentFloor(newFloor);
});
// WS使
let doorMockTimer: number | undefined;
let doorMockStatus: 0 | 1 = 0;
@ -533,7 +544,7 @@ onMounted(async () => {
elevatorStore.handleElevatorWebSocketData({
id: '1998661793706377218',
type: 102,
elevatorFloor: 5,
elevatorFloor: 1,
elevatorDirection: 2, //
elevatorFrontDoorStatus: 2, //
isConnected: true
@ -544,26 +555,26 @@ onMounted(async () => {
//
const elevatorStates = [
{ floor: 5, direction: 2, doorStatus: 2 }, // 5
{ floor: 5, direction: 2, doorStatus: 3 }, // 5
{ floor: 5, direction: 2, doorStatus: 1 }, // 5
{ floor: 5, direction: 2, doorStatus: 1 }, // 5
{ floor: 6, direction: 2, doorStatus: 1 }, // 6
{ floor: 6, direction: 2, doorStatus: 2 }, // 6
{ floor: 6, direction: 2, doorStatus: 3 }, // 6
{ floor: 6, direction: 2, doorStatus: 1 }, // 6
{ floor: 7, direction: 2, doorStatus: 1 }, // 7
{ floor: 7, direction: 2, doorStatus: 2 }, // 7
{ floor: 7, direction: 2, doorStatus: 3 }, // 7
{ floor: 7, direction: 2, doorStatus: 1 }, // 7
{ floor: 7, direction: 1, doorStatus: 1 }, // 7
{ floor: 7, direction: 3, doorStatus: 1 }, // 7
{ floor: 6, direction: 3, doorStatus: 1 }, // 6
{ floor: 6, direction: 3, doorStatus: 2 }, // 6
{ floor: 6, direction: 3, doorStatus: 3 }, // 6
{ floor: 6, direction: 3, doorStatus: 1 }, // 6
{ floor: 5, direction: 3, doorStatus: 1 }, // 5
{ floor: 5, direction: 1, doorStatus: 1 }, // 5
{ floor: 1, direction: 2, doorStatus: 2 }, // 1
{ floor: 1, direction: 2, doorStatus: 3 }, // 1
{ floor: 1, direction: 2, doorStatus: 1 }, // 1
{ floor: 1, direction: 2, doorStatus: 1 }, // 1
{ floor: 2, direction: 2, doorStatus: 1 }, // 2
{ floor: 2, direction: 2, doorStatus: 2 }, // 2
{ floor: 2, direction: 2, doorStatus: 3 }, // 2
{ floor: 2, direction: 2, doorStatus: 1 }, // 2
{ floor: 3, direction: 2, doorStatus: 1 }, // 3
{ floor: 3, direction: 2, doorStatus: 2 }, // 3
{ floor: 3, direction: 2, doorStatus: 3 }, // 3
{ floor: 3, direction: 2, doorStatus: 1 }, // 3
{ floor: 3, direction: 1, doorStatus: 1 }, // 3
{ floor: 3, direction: 3, doorStatus: 1 }, // 3
{ floor: 2, direction: 3, doorStatus: 1 }, // 2
{ floor: 2, direction: 3, doorStatus: 2 }, // 2
{ floor: 2, direction: 3, doorStatus: 3 }, // 2
{ floor: 2, direction: 3, doorStatus: 1 }, // 2
{ floor: 1, direction: 3, doorStatus: 1 }, // 1
{ floor: 1, direction: 1, doorStatus: 1 }, // 1
];
elevatorMockTimer = window.setInterval(() => {

View File

@ -391,8 +391,12 @@ function drawElevatorMinimal(
elevatorDirection,
elevatorFrontDoorStatus,
isConnected,
isCurrentFloor = true, // 默认为true兼容旧数据
} = elevatorData;
// 如果不是当前楼层,强制设为关门状态,但保留其他状态
const actualDoorStatus = isCurrentFloor ? elevatorFrontDoorStatus : 1;
const { x = 0, y = 0, width: w = 0, height: h = 0 } = pen.calculative?.worldRect ?? {};
// 基于pen元素尺寸的动态边框参数
@ -475,7 +479,7 @@ function drawElevatorMinimal(
y + h / 2,
Math.min(48, w * 0.8), // 根据pen大小调整电梯图标宽度最大48像素
Math.min(60, h * 0.8), // 根据pen大小调整电梯图标高度最大60像素
elevatorFrontDoorStatus,
actualDoorStatus, // 使用经过楼层过滤后的门状态
time,
elevatorDirection
);

View File

@ -47,6 +47,8 @@ export const useElevatorStore = defineStore('elevator', () => {
const elevators = ref<Map<string, ElevatorData>>(new Map());
const elevatorPoints = ref<Map<string, ElevatorPoint>>(new Map());
const editorService = ref<EditorService | null>(null);
// 当前楼层状态
const currentFloor = ref<number>(1);
// 动画相关状态
const movingElevators = ref<Set<string>>(new Set());
const animationFrameId = ref<number | null>(null);
@ -54,6 +56,15 @@ export const useElevatorStore = defineStore('elevator', () => {
// ========== 方法 ==========
/**
*
*/
const setCurrentFloor = (floor: number) => {
currentFloor.value = floor;
console.log(`🛗 当前楼层设置为: ${floor}`);
// 重新刷新所有电梯显示,以应用新的楼层过滤
refreshMapping();
};
/**
*
@ -240,6 +251,9 @@ export const useElevatorStore = defineStore('elevator', () => {
const penId = elevatorData.penId;
// 判断电梯当前楼层是否与场景楼层一致
const isCurrentFloor = elevatorData.elevatorFloor === currentFloor.value;
// 基础更新数据
const updateData: any = {
// 更新点位信息
@ -250,7 +264,8 @@ export const useElevatorStore = defineStore('elevator', () => {
lastUpdate: elevatorData.lastUpdate,
// 保存原始后端数据
elevatorDirection: elevatorData.elevatorDirection,
elevatorFrontDoorStatus: elevatorData.elevatorFrontDoorStatus
elevatorFrontDoorStatus: isCurrentFloor ? elevatorData.elevatorFrontDoorStatus : 1, // 非当前楼层强制设为关门状态
isCurrentFloor: isCurrentFloor // 添加标识,用于渲染层判断
}
};
@ -258,6 +273,10 @@ export const useElevatorStore = defineStore('elevator', () => {
// 更新电梯点
editorService.value.updatePen(penId, updateData, false);
// 调试信息
if (elevatorData.elevatorFloor !== currentFloor.value) {
console.log(`🛗 电梯 ${elevatorData.deviceId} 位于 ${elevatorData.elevatorFloor} 楼,当前场景为 ${currentFloor.value} 楼,隐藏开关门状态`);
}
} catch (error) {
console.error(`🛗 更新电梯点显示失败 (${elevatorData.deviceId}):`, error);
@ -286,8 +305,10 @@ export const useElevatorStore = defineStore('elevator', () => {
elevators,
elevatorPoints,
editorService,
currentFloor,
// 方法
setEditorService,
setCurrentFloor,
handleElevatorWebSocketData,
refreshMapping
};