| | |
| | | const { records } = useTests() |
| | | const { records: todoRecords } = useTodos() |
| | | const currentOwner = computed(() => getCurrentUser()?.displayName || getCurrentUser()?.username || 'Admin') |
| | | const dashboardError = ref('') |
| | | const hongKongKey = (date: Date) => { |
| | | const parts = new Intl.DateTimeFormat('zh-CN', { timeZone: 'Asia/Hong_Kong', year: 'numeric', month: '2-digit', day: '2-digit' }).formatToParts(date) |
| | | const value = (type: string) => parts.find(item => item.type === type)?.value || '' |
| | | return `${value('year')}-${value('month')}-${value('day')}` |
| | | } |
| | | onMounted(async () => { |
| | | try { |
| | | const [tests, groups] = await Promise.all([ |
| | |
| | | // 首页的电池组总数来自后端列表,避免用页面种子推断业务事实。 |
| | | batteryGroupCount.value = groups.total |
| | | } catch { |
| | | // 页面保留当前已加载数据,错误提示由全局请求层处理。 |
| | | dashboardError.value = '首页数据加载失败,请刷新后重试' |
| | | records.value = [] |
| | | batteryGroupCount.value = 0 |
| | | } |
| | | }) |
| | | const batteryGroupCount = ref(0) |
| | |
| | | |
| | | const periodData = computed(() => { |
| | | const now = new Date() |
| | | const dayKey = (date: Date) => `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}` |
| | | const dayKey = (date: Date) => hongKongKey(date) |
| | | const count = (key: string) => records.value.filter(item => item.createdAt.slice(0, key.length) === key).length |
| | | const weekLabels: string[] = []; const weekValues: number[] = [] |
| | | for (let index = 6; index >= 0; index -= 1) { const date = new Date(now); date.setDate(now.getDate() - index); const key = dayKey(date); weekLabels.push(`${date.getMonth() + 1}/${date.getDate()}`); weekValues.push(count(key)) } |
| | |
| | | |
| | | <template> |
| | | <div class="dashboard"> |
| | | <el-alert v-if="dashboardError" :title="dashboardError" type="error" :closable="false" show-icon /> |
| | | <section class="welcome-row"> |
| | | <div> |
| | | <h2>欢迎回来,Admin</h2> |
| | |
| | | <div class="metrics"> |
| | | <article><span>总测试数</span><strong>{{ records.length }}</strong></article> |
| | | <article><span>总电池组数</span><strong>{{ batteryGroupCount }}</strong></article> |
| | | <article><span>日新增测试</span><strong>{{ records.filter(item => item.createdAt.slice(0, 10) === new Date().toISOString().slice(0, 10)).length }}</strong></article> |
| | | <article><span>月新增测试</span><strong>{{ records.filter(item => item.createdAt.slice(0, 7) === new Date().toISOString().slice(0, 7)).length }}</strong></article> |
| | | <article><span>日新增测试</span><strong>{{ records.filter(item => item.createdAt.slice(0, 10) === hongKongKey(new Date())).length }}</strong></article> |
| | | <article><span>月新增测试</span><strong>{{ records.filter(item => item.createdAt.slice(0, 7) === hongKongKey(new Date()).slice(0, 7)).length }}</strong></article> |
| | | </div> |
| | | |
| | | <section class="panel chart-panel"> |