132 lines
6.3 KiB
Vue
132 lines
6.3 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { DataAnalysis, Refresh } from '@element-plus/icons-vue'
|
|
import { ElMessage } from 'element-plus'
|
|
import http, { apiErrorMessage } from '../api/http'
|
|
|
|
interface Status {
|
|
enabled: boolean
|
|
syncIntervalSeconds: number
|
|
sourceLookbackDays: number
|
|
batchSize: number
|
|
database: string
|
|
}
|
|
|
|
const status = ref<Status>()
|
|
const attendance = ref<any[]>([])
|
|
const grades = ref<any[]>([])
|
|
const audit = ref<any[]>([])
|
|
const loading = ref(false)
|
|
const range = ref<[Date, Date]>([
|
|
new Date(Date.now() - 29 * 24 * 60 * 60 * 1000),
|
|
new Date(),
|
|
])
|
|
const { t } = useI18n()
|
|
|
|
const attendanceTotals = computed(() => attendance.value.reduce((total, row) => total + Number(row.total ?? 0), 0))
|
|
const absentTotals = computed(() => attendance.value.reduce((total, row) => total + Number(row.absent ?? 0), 0))
|
|
const auditTotals = computed(() => audit.value.reduce((total, row) => total + Number(row.total ?? 0), 0))
|
|
|
|
function dateOnly(value: Date) {
|
|
const offset = value.getTimezoneOffset() * 60_000
|
|
return new Date(value.getTime() - offset).toISOString().slice(0, 10)
|
|
}
|
|
|
|
async function load() {
|
|
loading.value = true
|
|
try {
|
|
const [statusResponse, overviewResponse] = await Promise.all([
|
|
http.get<Status>('/clickhouse-analytics/status'),
|
|
http.get('/clickhouse-analytics/overview', {
|
|
params: { from: dateOnly(range.value[0]), to: dateOnly(range.value[1]) },
|
|
}),
|
|
])
|
|
status.value = statusResponse.data
|
|
attendance.value = overviewResponse.data.attendance ?? []
|
|
grades.value = overviewResponse.data.grades ?? []
|
|
audit.value = overviewResponse.data.audit ?? []
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error) || t('eventAnalytics.loadFailed'))
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
onMounted(load)
|
|
</script>
|
|
|
|
<template>
|
|
<main v-loading="loading" class="event-analytics page-stack">
|
|
<section class="page-intro">
|
|
<div>
|
|
<span class="eyebrow">CLICKHOUSE READ MODEL</span>
|
|
<h2>{{ t('eventAnalytics.title') }}</h2>
|
|
<p>{{ t('eventAnalytics.description') }}</p>
|
|
</div>
|
|
<div class="actions">
|
|
<el-date-picker v-model="range" type="daterange" :range-separator="t('eventAnalytics.to')" :start-placeholder="t('eventAnalytics.startDate')" :end-placeholder="t('eventAnalytics.endDate')" :clearable="false" />
|
|
<el-button type="primary" :icon="Refresh" @click="load">{{ t('eventAnalytics.refresh') }}</el-button>
|
|
</div>
|
|
</section>
|
|
|
|
<el-alert v-if="status && !status.enabled" type="warning" :closable="false" show-icon :title="t('eventAnalytics.disabledTitle')">
|
|
{{ t('eventAnalytics.disabledDescription') }}
|
|
</el-alert>
|
|
|
|
<template v-else>
|
|
<section class="metrics">
|
|
<article><el-icon><DataAnalysis /></el-icon><span>{{ t('eventAnalytics.attendanceRecords') }}</span><b>{{ attendanceTotals.toLocaleString() }}</b></article>
|
|
<article><el-icon><DataAnalysis /></el-icon><span>{{ t('eventAnalytics.absenceRecords') }}</span><b>{{ absentTotals.toLocaleString() }}</b></article>
|
|
<article v-if="audit.length"><el-icon><DataAnalysis /></el-icon><span>{{ t('eventAnalytics.auditRecords') }}</span><b>{{ auditTotals.toLocaleString() }}</b></article>
|
|
</section>
|
|
|
|
<section class="analysis-grid">
|
|
<el-card shadow="never">
|
|
<template #header>{{ t('eventAnalytics.dailyAttendance') }}</template>
|
|
<el-table :data="attendance" size="small" :empty-text="t('eventAnalytics.noAttendance')">
|
|
<el-table-column prop="attendanceDate" :label="t('eventAnalytics.date')" min-width="110" />
|
|
<el-table-column prop="total" :label="t('eventAnalytics.total')" align="right" />
|
|
<el-table-column prop="present" :label="t('eventAnalytics.present')" align="right" />
|
|
<el-table-column prop="absent" :label="t('eventAnalytics.absent')" align="right" />
|
|
<el-table-column prop="late" :label="t('eventAnalytics.late')" align="right" />
|
|
</el-table>
|
|
</el-card>
|
|
<el-card shadow="never">
|
|
<template #header>{{ t('eventAnalytics.gradeTrend') }}</template>
|
|
<el-table :data="grades" size="small" :empty-text="t('eventAnalytics.noGrades')">
|
|
<el-table-column prop="academicTermName" :label="t('eventAnalytics.term')" min-width="130" />
|
|
<el-table-column prop="studentCount" :label="t('eventAnalytics.students')" align="right" />
|
|
<el-table-column prop="averageScore" :label="t('eventAnalytics.average')" align="right" />
|
|
<el-table-column prop="passRate" :label="t('eventAnalytics.passRate')" align="right">
|
|
<template #default="{ row }">{{ (Number(row.passRate) * 100).toFixed(1) }}%</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</el-card>
|
|
</section>
|
|
|
|
<el-card v-if="audit.length" shadow="never">
|
|
<template #header>{{ t('eventAnalytics.auditTitle') }}</template>
|
|
<el-table :data="audit" size="small">
|
|
<el-table-column prop="date" :label="t('eventAnalytics.date')" min-width="110" />
|
|
<el-table-column prop="total" :label="t('eventAnalytics.operations')" align="right" />
|
|
<el-table-column prop="failed" :label="t('eventAnalytics.failures')" align="right" />
|
|
</el-table>
|
|
</el-card>
|
|
</template>
|
|
</main>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.event-analytics { --ink: #18324f; --line: #dce3ec; }
|
|
.page-intro { display: flex; justify-content: space-between; align-items: end; gap: 18px; }
|
|
.eyebrow { color: #3d75aa; font-size: 12px; letter-spacing: .12em; font-weight: 700; }
|
|
h2 { margin: 5px 0; color: var(--ink); } p { margin: 0; color: #6b7b8d; }
|
|
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
|
|
.metrics, .analysis-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
|
|
.analysis-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
.metrics article { padding: 20px; border: 1px solid var(--line); background: #fff; border-radius: 8px; display: grid; grid-template-columns: 26px 1fr; gap: 4px 9px; }
|
|
.metrics .el-icon { color: #3574a8; grid-row: span 2; font-size: 21px; } .metrics span { color: #657689; font-size: 13px; } .metrics b { color: var(--ink); font-size: 24px; }
|
|
@media (max-width: 760px) { .page-intro { align-items: start; flex-direction: column; } .metrics, .analysis-grid { grid-template-columns: 1fr; } }
|
|
</style>
|