Files
pqs-9100_client/frontend/src/views/machine/testScript/components/testScriptVolCurTab.vue

132 lines
3.2 KiB
Vue
Raw Normal View History

2024-12-30 14:43:13 +08:00
<template>
2025-02-13 16:15:26 +08:00
<div class="editor-container">
<div class="left-editor">
<!-- 左侧编辑区域内容 -->
<canvas ref="canvas" width="700" height="165"></canvas>
</div>
<div class="right-editor">
<!-- 右侧编辑区域内容 -->
<el-form :inline="true" label-width="auto" :model="form" class="form-two" >
<el-form-item label="电压有效值(V)">
<el-input v-model="form.input1" />
</el-form-item>
<el-form-item label="电流有效值(A)">
<el-input v-model="form.input2" />
</el-form-item>
<el-form-item label="电压相角(°)">
<el-input v-model="form.input3" />
</el-form-item>
<el-form-item label="电流相角(°)">
<el-input v-model="form.input4" />
</el-form-item>
</el-form>
</div>
2024-12-30 14:43:13 +08:00
</div>
</template>
<script setup lang="ts">
2025-02-13 16:15:26 +08:00
import { onMounted, ref } from 'vue'
const form = ref({
input1: 220,
input2: 0,
input3: 0,
input4: 0
})
const canvas = ref<HTMLCanvasElement | null>(null)
2025-01-06 09:21:24 +08:00
onMounted(() => {
2025-02-13 16:15:26 +08:00
if (canvas.value) {
const ctx = canvas.value.getContext('2d')
if (ctx) {
drawSineWave(ctx)
}
2025-01-06 09:21:24 +08:00
}
2025-02-13 16:15:26 +08:00
})
2025-01-06 09:21:24 +08:00
function drawSineWave(ctx: CanvasRenderingContext2D) {
2025-02-13 16:15:26 +08:00
const width = canvas.value!.width
const height = canvas.value!.height
const amplitude = 50 // 振幅
const frequency = 0.02 // 频率
const offset = height / 2 // 偏移量
// 绘制横轴
ctx.beginPath()
ctx.moveTo(0, offset)
ctx.lineTo(width, offset)
ctx.strokeStyle = 'black'
ctx.stroke()
// 绘制纵轴
ctx.beginPath()
ctx.moveTo(0, 0)
ctx.lineTo(0, height)
ctx.stroke()
// 绘制横轴刻度
const xStep = width / 10
for (let x = 0; x <= width; x += xStep) {
ctx.beginPath()
ctx.moveTo(x, offset - 5)
ctx.lineTo(x, offset + 5)
ctx.stroke()
// 添加横轴刻度标签
ctx.font = '12px Arial'
ctx.fillStyle = 'black'
ctx.textAlign = 'center'
ctx.fillText((x / xStep).toFixed(0), x, offset + 20)
}
// 绘制纵轴刻度
const yStep = height / 10
for (let y = 0; y <= height; y += yStep) {
ctx.beginPath()
ctx.moveTo(-5, y)
ctx.lineTo(5, y)
ctx.stroke()
// 添加纵轴刻度标签
ctx.font = '12px Arial'
ctx.fillStyle = 'black'
ctx.textAlign = 'right'
ctx.fillText(((offset - y) / yStep - 5).toFixed(1), -10, y + 5)
}
// 绘制正弦波
ctx.beginPath()
ctx.moveTo(0, offset)
for (let x = 0; x < width; x++) {
const y = offset + amplitude * Math.sin(frequency * x)
ctx.lineTo(x, y)
}
ctx.strokeStyle = 'red'
ctx.lineWidth = 2
ctx.stroke()
2025-01-06 09:21:24 +08:00
}
2024-12-30 14:43:13 +08:00
</script>
<style scoped>
canvas {
2025-02-13 16:15:26 +08:00
border: 1px solid #ccc;
2024-12-30 14:43:13 +08:00
}
.editor-container {
2025-02-13 16:15:26 +08:00
display: flex;
height: 100%;
2024-12-30 14:43:13 +08:00
}
.left-editor {
2025-02-13 16:15:26 +08:00
flex: 1;
margin-left: 20px;
2024-12-30 14:43:13 +08:00
}
.right-editor {
2025-02-13 16:15:26 +08:00
width: 600px;
display: flex;
align-items: center;
2024-12-30 14:43:13 +08:00
}
2025-02-13 16:15:26 +08:00
</style>