From 9e1827316a1d3fc81c0eaddb4771606a67c3aaf7 Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 12 Dec 2025 10:32:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(elevator):=20=E5=9C=A8=E7=94=B5=E6=A2=AF?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E5=8F=B3=E4=BE=A7=E6=B7=BB=E5=8A=A0=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E6=A5=BC=E5=B1=82=E6=98=BE=E7=A4=BA=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dstore=E4=B8=AD=E6=A5=BC=E5=B1=82=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E5=90=8D=E4=BB=A5=E5=8C=B9=E9=85=8D=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/editor/editor-drawers.ts | 47 +++++++++++++++++++++++++++ src/stores/elevator.store.ts | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/services/editor/editor-drawers.ts b/src/services/editor/editor-drawers.ts index dc247e7..bb6b696 100644 --- a/src/services/editor/editor-drawers.ts +++ b/src/services/editor/editor-drawers.ts @@ -439,6 +439,53 @@ function drawElevatorMinimal( elevatorDirection ); + // 在电梯图标右侧显示当前楼层 + const { elevatorFloor } = elevatorData; + + if (elevatorFloor && elevatorFloor > 0) { + ctx.save(); + + // 计算电梯图标的实际尺寸(基于最大值48*60的比例) + const iconWidth = Math.min(48, w * 0.8); + const iconHeight = Math.min(60, h * 0.8); + + // 文字尺寸基于图标的较小边,保持比例 + const baseSize = Math.min(iconWidth, iconHeight); + const fontSize = baseSize * 0.45; // 字体大小为图标较小边的45% + + // 设置文字样式 + ctx.font = `bold ${fontSize}px Arial, sans-serif`; + ctx.textAlign = 'left'; + ctx.textBaseline = 'middle'; + + // 文字位置:电梯图标右侧,间距基于图标尺寸 + const textX = x + w/2 + iconWidth/2 + iconWidth * 0.15; // 从图标中心右侧开始,留15%图标宽度的间距 + const textY = y + h/2; // 垂直居中 + + // 绘制楼层文字背景 + const floorText = `${elevatorFloor}F`; + const textMetrics = ctx.measureText(floorText); + const textWidth = textMetrics.width; + const textHeight = fontSize * 1.2; // 文字高度 + + // 背景矩形尺寸基于字体大小 + const bgPadding = fontSize * 0.25; // 背景内边距为字体大小的25% + const bgX = textX - bgPadding; + const bgY = textY - textHeight / 2; + const bgWidth = textWidth + bgPadding * 2; + const bgHeight = textHeight; + + // 绘制半透明背景 + ctx.fillStyle = 'rgba(0, 0, 0, 0.75)'; + ctx.fillRect(bgX, bgY, bgWidth, bgHeight); + + // 绘制楼层文字 + ctx.fillStyle = '#ffffff'; // 白色文字 + ctx.fillText(floorText, textX, textY); + + ctx.restore(); + } + // 状态渲染逻辑 - 只有断连状态才显示边框 if (!isConnected) { // 离线状态 - 红色虚线(静态,不带动画) diff --git a/src/stores/elevator.store.ts b/src/stores/elevator.store.ts index ac5fe0a..31d9832 100644 --- a/src/stores/elevator.store.ts +++ b/src/stores/elevator.store.ts @@ -246,7 +246,7 @@ export const useElevatorStore = defineStore('elevator', () => { point: { ...((editorService.value.getPenById(penId) as any)?.point || {}), isConnected: elevatorData.isConnected, - currentFloor: elevatorData.elevatorFloor, + elevatorFloor: elevatorData.elevatorFloor, lastUpdate: elevatorData.lastUpdate, // 保存原始后端数据 elevatorDirection: elevatorData.elevatorDirection,