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'
|
||||
|
||||
@@ -316,12 +316,13 @@ class EGMWebApp:
|
||||
para.insulator_c_len = float(parameter_data.get('insulator_c_len', 7.02))
|
||||
para.string_c_len = float(parameter_data.get('string_c_len', 9.2))
|
||||
para.string_g_len = float(parameter_data.get('string_g_len', 0.5))
|
||||
para.gc_x = list(parameter_data.get('gc_x', [17.9, 17]))
|
||||
# 确保数组元素转换为数字类型
|
||||
para.gc_x = [float(x) for x in parameter_data.get('gc_x', [17.9, 17])]
|
||||
para.ground_angels = [
|
||||
angel / 180 * math.pi
|
||||
float(angel) / 180 * math.pi
|
||||
for angel in parameter_data.get('ground_angels', [0])
|
||||
]
|
||||
para.h_arm = list(parameter_data.get('h_arm', [150, 130]))
|
||||
para.h_arm = [float(h) for h in parameter_data.get('h_arm', [150, 130])]
|
||||
para.altitude = int(parameter_data.get('altitude', 1000))
|
||||
# 解析电压等级字符串,如 "500kV" -> 500
|
||||
rated_voltage_str = str(parameter_data.get('rated_voltage', '500kV'))
|
||||
|
||||
Reference in New Issue
Block a user