fix: 修复几何数据类型转换及折叠问题
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
<template>
|
||||
<q-card class="shadow-2">
|
||||
<q-card-section class="bg-indigo-50 cursor-pointer" @click="toggleExpand">
|
||||
<q-card-section class="bg-indigo-50">
|
||||
<div class="text-h6 text-indigo-900 flex items-center gap-2">
|
||||
<q-icon name="architecture" />
|
||||
杆塔几何结构
|
||||
<q-space />
|
||||
<q-icon :name="expanded ? 'expand_less' : 'expand_more'" />
|
||||
</div>
|
||||
</q-card-section>
|
||||
|
||||
<q-slide-transition>
|
||||
<q-card-section v-show="expanded">
|
||||
<div class="geometry-container">
|
||||
<q-card-section>
|
||||
<div class="geometry-container">
|
||||
<canvas
|
||||
ref="canvasRef"
|
||||
:width="canvasWidth"
|
||||
@@ -37,7 +34,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-slide-transition>
|
||||
</q-card>
|
||||
</template>
|
||||
|
||||
@@ -57,8 +53,6 @@ const props = defineProps<{
|
||||
const canvasWidth = 600
|
||||
const canvasHeight = 500
|
||||
|
||||
// 展开/折叠状态
|
||||
const expanded = ref(true)
|
||||
const canvasRef = ref<HTMLCanvasElement | null>(null)
|
||||
let ctx: CanvasRenderingContext2D | null = null
|
||||
|
||||
@@ -67,23 +61,14 @@ const margin = { top: 40, right: 40, bottom: 60, left: 60 }
|
||||
const plotWidth = canvasWidth - margin.left - margin.right
|
||||
const plotHeight = canvasHeight - margin.top - margin.bottom
|
||||
|
||||
// 切换展开/折叠
|
||||
const toggleExpand = () => {
|
||||
expanded.value = !expanded.value
|
||||
if (expanded.value) {
|
||||
setTimeout(() => {
|
||||
if (canvasRef.value) {
|
||||
ctx = canvasRef.value.getContext('2d')
|
||||
draw()
|
||||
}
|
||||
}, 350)
|
||||
}
|
||||
}
|
||||
|
||||
// 计算坐标范围
|
||||
const calculateRange = () => {
|
||||
const allHeights = [...props.hArm, 0] // 包含地面
|
||||
const allX = [...props.gcX, -props.gcX[0] * 0.5, props.gcX[0] * 1.5] // 扩展水平范围
|
||||
// 确保将字符串转换为数字
|
||||
const hArmNums = props.hArm.map(v => Number(v))
|
||||
const gcXNums = props.gcX.map(v => Number(v))
|
||||
|
||||
const allHeights = [...hArmNums, 0] // 包含地面
|
||||
const allX = [...gcXNums, -gcXNums[0] * 0.5, gcXNums[0] * 1.5] // 扩展水平范围
|
||||
|
||||
const yMin = 0
|
||||
const yMax = Math.max(...allHeights) * 1.15
|
||||
@@ -105,7 +90,7 @@ const toCanvasY = (y: number, range: ReturnType<typeof calculateRange>): number
|
||||
|
||||
// 绘制函数
|
||||
const draw = () => {
|
||||
if (!ctx || !expanded.value) return
|
||||
if (!ctx) return
|
||||
|
||||
const range = calculateRange()
|
||||
|
||||
@@ -208,11 +193,13 @@ const drawWirePoints = (range: ReturnType<typeof calculateRange>) => {
|
||||
const c = ctx
|
||||
|
||||
props.hArm.forEach((height, index) => {
|
||||
const wireX = props.gcX[index] || 0
|
||||
// 确保将字符串转换为数字
|
||||
const heightNum = Number(height)
|
||||
const wireX = Number(props.gcX[index]) || 0
|
||||
const isGroundWire = index === 0
|
||||
|
||||
const canvasX = toCanvasX(wireX, range)
|
||||
const canvasY = toCanvasY(height, range)
|
||||
const canvasY = toCanvasY(heightNum, range)
|
||||
|
||||
// 绘制挂点标记
|
||||
c.fillStyle = isGroundWire ? '#4CAF50' : '#FF9800'
|
||||
@@ -229,7 +216,7 @@ const drawWirePoints = (range: ReturnType<typeof calculateRange>) => {
|
||||
const labelY = canvasY - 8
|
||||
|
||||
const wireName = isGroundWire ? '地线' : `导线${index}`
|
||||
const heightLabel = `H=${height}m`
|
||||
const heightLabel = `H=${heightNum}m`
|
||||
const xLabel = `X=${wireX}m`
|
||||
|
||||
c.fillText(wireName, labelX, labelY)
|
||||
@@ -244,7 +231,8 @@ const drawWirePoints = (range: ReturnType<typeof calculateRange>) => {
|
||||
const drawGround = (range: ReturnType<typeof calculateRange>) => {
|
||||
if (!ctx) return
|
||||
|
||||
const groundAngle = props.groundAngels[0] || 0
|
||||
// 确保将字符串转换为数字
|
||||
const groundAngle = Number(props.groundAngels[0]) || 0
|
||||
const angleRad = (groundAngle * Math.PI) / 180
|
||||
|
||||
ctx.strokeStyle = '#795548'
|
||||
|
||||
Reference in New Issue
Block a user