Files
NixMsg/web/src/views/OverviewView.vue
T

91 lines
2.6 KiB
Vue

<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { NCard, NGrid, NGridItem, NSpin, NStatistic } from "naive-ui";
import PageHeader from "@/components/PageHeader.vue";
import LoadFailed from "@/components/LoadFailed.vue";
import DailyChart from "@/components/DailyChart.vue";
import { fetchOverview, type Overview } from "@/api/admin";
import { formatUptime } from "@/utils/labels";
import { useAppTheme } from "@/theme";
const { isDark } = useAppTheme();
const loading = ref(true);
const loadError = ref("");
const data = ref<Overview | null>(null);
const daily = computed(() => data.value?.messages_daily ?? []);
async function load() {
loading.value = true;
loadError.value = "";
try {
data.value = await fetchOverview();
} catch (e) {
loadError.value = e instanceof Error ? e.message : "加载失败";
} finally {
loading.value = false;
}
}
onMounted(() => {
void load();
});
</script>
<template>
<div class="page">
<PageHeader title="概览" />
<div class="page-body overview-body">
<n-spin :show="loading">
<LoadFailed v-if="loadError && !data" :description="loadError" @retry="load" />
<template v-else-if="data">
<n-grid :cols="4" :x-gap="12" :y-gap="12" responsive="screen" item-responsive>
<n-grid-item span="4 m:2 l:1">
<n-card size="small">
<n-statistic label="在线设备" :value="data.endpoints_online">
<template #suffix>/ {{ data.endpoints_total }}</template>
</n-statistic>
</n-card>
</n-grid-item>
<n-grid-item span="4 m:2 l:1">
<n-card size="small">
<n-statistic label="群组" :value="data.groups_total" />
</n-card>
</n-grid-item>
<n-grid-item span="4 m:2 l:1">
<n-card size="small">
<n-statistic label="待送达" :value="data.messages_pending" />
</n-card>
</n-grid-item>
<n-grid-item span="4 m:2 l:1">
<n-card size="small">
<n-statistic label="已运行" :value="formatUptime(data.uptime_ms)" />
</n-card>
</n-grid-item>
</n-grid>
<n-card title="近两周消息量" size="small" class="chart-card">
<DailyChart :points="daily" :dark="isDark" />
</n-card>
</template>
</n-spin>
</div>
</div>
</template>
<style scoped>
.page {
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
}
.overview-body {
flex: 1;
overflow: auto;
padding: 16px;
}
.chart-card {
margin-top: 12px;
}
</style>