feat: localize course grade analytics

This commit is contained in:
biss committed 2026-10-31 11:13:41 +08:00
1 parent 9635c664c4
commit 00452e6965
3 files changed
+41 -40

No files matched your search

+35 -40
View File
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { ArrowLeft, Refresh } from '@element-plus/icons-vue'
import * as echarts from 'echarts/core'
import { BarChart, LineChart } from 'echarts/charts'
@@ -21,6 +22,7 @@ echarts.use([
const route = useRoute()
const router = useRouter()
const { t } = useI18n()
const loading = ref(false)
const report = ref<any | null>(null)
const activeScope = ref('class')
@@ -34,15 +36,15 @@ const rows = computed(() => {
? report.value.classes.map((item: any) => ({
key: `class-${item.classId}`,
label: item.className,
caption: '该行政班学生',
caption: t('courseStats.classStudents'),
value: item.statistics,
}))
: [{ key: 'class', label: '本班', caption: '同班同学', value: report.value?.class }]
: [{ key: 'class', label: t('courseStats.myClass'), caption: t('courseStats.classmates'), value: report.value?.class }]
return [
...classRows,
{ key: 'major', label: '本专业', caption: '专业学生', value: report.value?.major },
{ key: 'college', label: '本学院', caption: '学院学生', value: report.value?.college },
{ key: 'university', label: '本校', caption: '全校学生', value: report.value?.university },
{ key: 'major', label: t('courseStats.myMajor'), caption: t('courseStats.majorStudents'), value: report.value?.major },
{ key: 'college', label: t('courseStats.myCollege'), caption: t('courseStats.collegeStudents'), value: report.value?.college },
{ key: 'university', label: t('courseStats.university'), caption: t('courseStats.universityStudents'), value: report.value?.university },
].filter(item => item.value)
})
@@ -51,10 +53,10 @@ const selectedDistribution = computed(() => selectedRow.value?.value.distributio
const recommendation = computed(() => {
const value = selectedRow.value?.value
if (!value) return ''
if (Number(value.passRate) < 70) return `合格率为 ${score(value.passRate)}%,建议优先复核低分段学生的平时与期末分项,并安排针对性答疑。`
if (Number(value.averageScore) < 70) return `平均分为 ${score(value.averageScore)},建议检查易失分知识点与教学进度,结合分数段安排补强。`
if (Number(value.standardDeviation) > 20) return `成绩离散度较高,建议关注不同教学班或学生群体的学习差异,核对评价标准与教学支持。`
return `平均分 ${score(value.averageScore)}、合格率 ${score(value.passRate)}%,当前表现稳定;可重点关注低分段学生的持续跟进。`
if (Number(value.passRate) < 70) return t('courseStats.insights.lowPass', { rate: score(value.passRate) })
if (Number(value.averageScore) < 70) return t('courseStats.insights.lowAverage', { average: score(value.averageScore) })
if (Number(value.standardDeviation) > 20) return t('courseStats.insights.highDeviation')
return t('courseStats.insights.stable', { average: score(value.averageScore), rate: score(value.passRate) })
})
function score(value: unknown) {
@@ -91,32 +93,32 @@ function drawChart() {
formatter: (params: any) => {
const item = distribution[params[0]?.dataIndex ?? 0]
const rate = item ? Number(item.count) / total * 100 : 0
return `<b>${item?.range ?? ''} 分</b><br/>人数 ${item?.count ?? 0} 人<br/>占比 ${rate.toFixed(1)}%`
return t('courseStats.chart.distributionTooltip', { range: item?.range ?? '', count: item?.count ?? 0, rate: rate.toFixed(1) })
},
},
grid: { left: 42, right: 22, top: 44, bottom: 38 },
xAxis: {
type: 'category',
name: '分数段',
name: t('courseStats.scoreBand'),
data: distribution.map((item: any) => item.range),
axisTick: { show: false },
axisLine: { lineStyle: { color: '#cbd4e1' } },
axisLabel: { color: '#475467', fontWeight: 600 },
},
yAxis: {
type: 'value', min: 0, minInterval: 1, name: '人数',
type: 'value', min: 0, minInterval: 1, name: t('courseStats.people'),
splitLine: { lineStyle: { color: '#edf1f6' } },
},
series: [
{
name: `${selectedRow.value.label}人数`, type: 'bar', barMaxWidth: 62,
name: t('courseStats.scopePeople', { scope: selectedRow.value.label }), type: 'bar', barMaxWidth: 62,
data: distribution.map((item: any, index: number) => ({ value: item.count, itemStyle: { color: palette[index] } })),
itemStyle: { borderRadius: [5, 5, 0, 0] },
label: {
show: true, position: 'top', color: '#344054', fontWeight: 700,
formatter: (params: any) => {
const count = Number(params.value)
return `${count} 人\n${(count / total * 100).toFixed(1)}%`
return t('courseStats.chart.barLabel', { count, rate: (count / total * 100).toFixed(1) })
},
},
},
@@ -136,10 +138,10 @@ function drawComparisonChart() {
trigger: 'axis',
formatter: (params: any) => {
const item = rows.value[params[0]?.dataIndex ?? 0]
return `<b>${item.label}</b><br/>最高分 ${score(item.value.highestScore)}<br/>平均分 ${score(item.value.averageScore)}<br/>最低分 ${score(item.value.lowestScore)}<br/>合格率 ${score(item.value.passRate)}%`
return t('courseStats.chart.comparisonTooltip', { scope: item.label, highest: score(item.value.highestScore), average: score(item.value.averageScore), lowest: score(item.value.lowestScore), rate: score(item.value.passRate) })
},
},
legend: { top: 2, data: ['分数区间', '平均分', '合格率'] },
legend: { top: 2, data: [t('courseStats.scoreRange'), t('courseStats.average'), t('courseStats.passRate')] },
grid: { left: 42, right: 52, top: 56, bottom: 36 },
xAxis: {
type: 'category',
@@ -152,17 +154,17 @@ function drawComparisonChart() {
},
},
yAxis: [
{ type: 'value', min: 0, max: 100, name: '分数', splitLine: { lineStyle: { color: '#edf1f6' } } },
{ type: 'value', min: 0, max: 100, name: '合格率', axisLabel: { formatter: '{value}%' }, splitLine: { show: false } },
{ type: 'value', min: 0, max: 100, name: t('courseStats.score'), splitLine: { lineStyle: { color: '#edf1f6' } } },
{ type: 'value', min: 0, max: 100, name: t('courseStats.passRate'), axisLabel: { formatter: '{value}%' }, splitLine: { show: false } },
],
series: [
{
name: '区间起点', type: 'bar', stack: 'score-range', silent: true,
name: t('courseStats.rangeStart'), type: 'bar', stack: 'score-range', silent: true,
itemStyle: { color: 'transparent' }, emphasis: { disabled: true },
data: rows.value.map(item => item.value.lowestScore),
},
{
name: '分数区间', type: 'bar', stack: 'score-range', barWidth: 22,
name: t('courseStats.scoreRange'), type: 'bar', stack: 'score-range', barWidth: 22,
itemStyle: { borderRadius: 8 },
data: rows.value.map((item, index) => ({
value: item.value.highestScore - item.value.lowestScore,
@@ -170,13 +172,13 @@ function drawComparisonChart() {
})),
},
{
name: '平均分', type: 'line', smooth: true, symbol: 'circle', symbolSize: 10,
name: t('courseStats.average'), type: 'line', smooth: true, symbol: 'circle', symbolSize: 10,
lineStyle: { width: 3, color: '#d58b32' },
itemStyle: { color: '#d58b32', borderColor: '#fff', borderWidth: 2 },
data: rows.value.map(item => item.value.averageScore),
},
{
name: '合格率', type: 'line', yAxisIndex: 1, smooth: true, symbol: 'diamond', symbolSize: 9,
name: t('courseStats.passRate'), type: 'line', yAxisIndex: 1, smooth: true, symbol: 'diamond', symbolSize: 9,
lineStyle: { width: 2, type: 'dashed', color: '#25847a' },
itemStyle: { color: '#25847a' },
data: rows.value.map(item => item.value.passRate),
@@ -203,20 +205,18 @@ onBeforeUnmount(() => {
<section class="page-intro">
<div>
<span class="section-kicker">COURSE INSIGHT</span>
<h2>{{ report?.courseName ?? '课程成绩分析' }}</h2>
<p>{{ report?.courseCode }} · {{ report?.termName }} · 本页数据来自已正式发布成绩</p>
<h2>{{ report?.courseName ?? t('courseStats.title') }}</h2><p>{{ report?.courseCode }} · {{ report?.termName }} · {{ t('courseStats.publishedOnly') }}</p>
</div>
<div class="actions">
<el-button :icon="ArrowLeft" @click="router.back()">返回</el-button>
<el-button :icon="Refresh" @click="load">刷新</el-button>
<el-button :icon="ArrowLeft" @click="router.back()">{{ t('courseStats.back') }}</el-button><el-button :icon="Refresh" @click="load">{{ t('courseStats.refresh') }}</el-button>
</div>
</section>
<el-alert v-if="report?.isRefreshing" type="info" :closable="false"
title="统计数据正在生成,请稍后刷新。" />
:title="t('courseStats.generating')" />
<section v-if="rows.length && selectedRow" class="scope-panel">
<nav class="scope-tabs" aria-label="统计范围">
<nav class="scope-tabs" :aria-label="t('courseStats.scope')">
<button
v-for="item in rows"
:key="item.key"
@@ -225,38 +225,33 @@ onBeforeUnmount(() => {
@click="activeScope = item.key"
>
<span>{{ item.label }}</span>
<small>{{ item.value.studentCount }} 人</small>
<small>{{ t('courseStats.peopleCount', { count: item.value.studentCount }) }}</small>
</button>
</nav>
<article class="scope-summary">
<div class="average-score">
<span>{{ selectedRow.label }}平均分</span>
<span>{{ t('courseStats.scopeAverage', { scope: selectedRow.label }) }}</span>
<strong>{{ score(selectedRow.value.averageScore) }}</strong>
<small>统计对象:{{ selectedRow.caption }} · {{ selectedRow.value.studentCount }} 人</small>
<small>{{ t('courseStats.population', { caption: selectedRow.caption, count: selectedRow.value.studentCount }) }}</small>
</div>
<dl>
<div><dt>最高分</dt><dd>{{ score(selectedRow.value.highestScore) }}</dd></div>
<div><dt>最低分</dt><dd>{{ score(selectedRow.value.lowestScore) }}</dd></div>
<div><dt>合格人数</dt><dd>{{ selectedRow.value.passedCount }} / {{ selectedRow.value.studentCount }}</dd></div>
<div><dt>合格率</dt><dd>{{ score(selectedRow.value.passRate) }}%</dd></div>
<div><dt>{{ t('courseStats.highest') }}</dt><dd>{{ score(selectedRow.value.highestScore) }}</dd></div><div><dt>{{ t('courseStats.lowest') }}</dt><dd>{{ score(selectedRow.value.lowestScore) }}</dd></div><div><dt>{{ t('courseStats.passed') }}</dt><dd>{{ selectedRow.value.passedCount }} / {{ selectedRow.value.studentCount }}</dd></div><div><dt>{{ t('courseStats.passRate') }}</dt><dd>{{ score(selectedRow.value.passRate) }}%</dd></div>
</dl>
</article>
</section>
<section v-if="recommendation" class="action-advice"><span>ACTION ADVICE</span><p>{{ recommendation }}</p></section>
<el-empty v-else-if="!loading" description="暂无可展示的课程统计" />
<el-empty v-else-if="!loading" :description="t('courseStats.empty')" />
<section v-if="rows.length" class="chart-panel">
<div class="chart-heading">
<div><span class="section-kicker">SCORE DISTRIBUTION</span><h3>{{ selectedRow?.label }}分数段分布</h3></div>
<p>按当前标签页单独统计,共 {{ selectedRow?.value.studentCount }} 人;柱顶显示人数和占比。</p>
<div><span class="section-kicker">SCORE DISTRIBUTION</span><h3>{{ t('courseStats.distributionTitle', { scope: selectedRow?.label }) }}</h3></div><p>{{ t('courseStats.distributionDescription', { count: selectedRow?.value.studentCount }) }}</p>
</div>
<div ref="chartElement" class="score-chart" />
</section>
<section v-if="rows.length" class="chart-panel comparison-panel">
<div class="chart-heading">
<div><span class="section-kicker">LEVEL COMPARISON</span><h3>各层级整体分析</h3></div>
<p>同时比较四个层级的最低—最高分区间、平均分和合格率;当前标签对应层级高亮。</p>
<div><span class="section-kicker">LEVEL COMPARISON</span><h3>{{ t('courseStats.comparisonTitle') }}</h3></div><p>{{ t('courseStats.comparisonDescription') }}</p>
</div>
<div ref="comparisonChartElement" class="score-chart" />
</section>