hejianhao
2026-04-02 0940d56748a73525790c350c393a5be960aab62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
  <div class="training-chart">
    <h3>训练进度</h3>
    <div class="chart-container">
      <canvas ref="chartCanvas"></canvas>
    </div>
    <div class="metrics">
      <div class="metric">
        <span class="label">损失值:</span>
        <span class="value">{{ loss.toFixed(4) }}</span>
      </div>
      <div class="metric">
        <span class="label">准确率:</span>
        <span class="value">{{ accuracy.toFixed(2) }}%</span>
      </div>
    </div>
  </div>
</template>
 
<script setup>
import { ref, onMounted } from 'vue'
 
const props = defineProps({
  loss: {
    type: Number,
    default: 0
  },
  accuracy: {
    type: Number,
    default: 0
  }
})
 
const chartCanvas = ref(null)
 
onMounted(() => {
  const canvas = chartCanvas.value
  const ctx = canvas.getContext('2d')
  
  // 设置画布尺寸
  canvas.width = canvas.offsetWidth
  canvas.height = canvas.offsetHeight
  
  // 绘制简单的图表
  drawChart(ctx)
})
 
function drawChart(ctx) {
  // 清空画布
  ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
  
  // 绘制坐标轴
  ctx.strokeStyle = '#ccc'
  ctx.lineWidth = 1
  ctx.beginPath()
  ctx.moveTo(50, 30)
  ctx.lineTo(50, ctx.canvas.height - 30)
  ctx.lineTo(ctx.canvas.width - 30, ctx.canvas.height - 30)
  ctx.stroke()
  
  // 绘制示例数据点
  ctx.strokeStyle = '#1677ff'
  ctx.lineWidth = 2
  ctx.beginPath()
  ctx.moveTo(50, ctx.canvas.height - 30 - (props.loss * 100))
  ctx.lineTo(100, ctx.canvas.height - 30 - (props.accuracy * 2))
  ctx.stroke()
}
</script>
 
<style scoped>
.training-chart {
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
}
 
.chart-container {
  margin: 20px 0;
  height: 200px;
}
 
canvas {
  width: 100%;
  height: 100%;
  border: 1px solid #eee;
}
 
.metrics {
  display: flex;
  gap: 20px;
}
 
.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
}
 
.label {
  font-size: 12px;
  color: #666;
}
 
.value {
  font-size: 18px;
  font-weight: bold;
  color: #1677ff;
}
</style>