优化后端构建方式,修改首页报表 bug

This commit is contained in:
eafonyang
2026-07-30 15:08:05 +08:00
parent f2bbaa6876
commit b1c88fc5e6
12 changed files with 56 additions and 54 deletions
+9 -8
View File
@@ -173,12 +173,7 @@ watch(deviceDays, () => {
// ===== 设备日活趋势 =====
const activeDays = ref(30);
const activeLoading = ref(false);
const activeLatest = ref({ date: '', total: 0 });
const activeLatestLabel = computed(() => {
if (activeDays.value === 1) return `${activeLatest.value.date} 总活跃`;
return `${activeLatest.value.date.slice(5)} 总日活`;
});
const activeTodayTotal = ref(0);
function buildActiveChartOptions(dates: string[], series: Array<{ name: string; data: number[] }>): ECOption {
const isHourly = activeDays.value === 1;
@@ -257,7 +252,13 @@ async function loadActiveDaily() {
activeLoading.value = true;
const { data, error } = await fetchGetActiveDaily(activeDays.value);
if (!error && data) {
activeLatest.value = data.latest;
// 今天模式(按小时):累加所有小时;多天模式:取末尾(今天)
const isHourly = activeDays.value === 1;
const lastIdx = (data.dates?.length || 1) - 1;
activeTodayTotal.value = (data.series || []).reduce((sum: number, s: { data: number[] }) => {
if (isHourly) return sum + s.data.reduce((a: number, b: number) => a + b, 0);
return sum + (s.data[lastIdx] || 0);
}, 0);
lastActiveData.value = { dates: data.dates, series: data.series };
await updateActiveChart(() => buildActiveChartOptions(data.dates, data.series));
}
@@ -359,7 +360,7 @@ onMounted(() => {
<template #header>活跃趋势</template>
<template #header-extra>
<NSpace align="center" :size="12">
<NTag type="success" size="small">{{ activeLatestLabel }} {{ activeLatest.total }}</NTag>
<NTag type="success" size="small">今日日活 {{ activeTodayTotal }}</NTag>
<NRadioGroup v-model:value="activeDays" size="small">
<NRadioButton :value="1">今天</NRadioButton>
<NRadioButton :value="7">近7天</NRadioButton>