mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-08 11:47:28 +08:00
Merge pull request #207 from nagisa77/codex/add-site-statistics-page-for-dau-chart
Add admin stats page with DAU chart
This commit is contained in:
@@ -17,6 +17,15 @@
|
||||
<i class="menu-item-icon fas fa-info-circle"></i>
|
||||
<span class="menu-item-text">关于</span>
|
||||
</router-link>
|
||||
<router-link
|
||||
v-if="authState.role === 'ADMIN'"
|
||||
class="menu-item"
|
||||
exact-active-class="selected"
|
||||
to="/about/stats"
|
||||
>
|
||||
<i class="menu-item-icon fas fa-chart-line"></i>
|
||||
<span class="menu-item-text">站点统计</span>
|
||||
</router-link>
|
||||
<router-link class="menu-item" exact-active-class="selected" to="/new-post">
|
||||
<i class="menu-item-icon fas fa-edit"></i>
|
||||
<span class="menu-item-text">发帖</span>
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'
|
||||
import HomePageView from '../views/HomePageView.vue'
|
||||
import MessagePageView from '../views/MessagePageView.vue'
|
||||
import AboutPageView from '../views/AboutPageView.vue'
|
||||
import SiteStatsPageView from '../views/SiteStatsPageView.vue'
|
||||
import PostPageView from '../views/PostPageView.vue'
|
||||
import LoginPageView from '../views/LoginPageView.vue'
|
||||
import SignupPageView from '../views/SignupPageView.vue'
|
||||
@@ -26,6 +27,11 @@ const routes = [
|
||||
name: 'about',
|
||||
component: AboutPageView
|
||||
},
|
||||
{
|
||||
path: '/about/stats',
|
||||
name: 'site-stats',
|
||||
component: SiteStatsPageView
|
||||
},
|
||||
{
|
||||
path: '/new-post',
|
||||
name: 'new-post',
|
||||
|
||||
51
open-isle-cli/src/views/SiteStatsPageView.vue
Normal file
51
open-isle-cli/src/views/SiteStatsPageView.vue
Normal file
@@ -0,0 +1,51 @@
|
||||
<template>
|
||||
<div class="site-stats-page">
|
||||
<VChart v-if="option" :option="option" :autoresize="true" style="height:400px" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import VChart from 'vue-echarts'
|
||||
import { use } from 'echarts/core'
|
||||
import { LineChart } from 'echarts/charts'
|
||||
import { TitleComponent, TooltipComponent, GridComponent, DataZoomComponent } from 'echarts/components'
|
||||
import { CanvasRenderer } from 'echarts/renderers'
|
||||
import { API_BASE_URL } from '../main'
|
||||
import { getToken } from '../utils/auth'
|
||||
|
||||
use([LineChart, TitleComponent, TooltipComponent, GridComponent, DataZoomComponent, CanvasRenderer])
|
||||
|
||||
const option = ref(null)
|
||||
|
||||
async function loadData() {
|
||||
const token = getToken()
|
||||
const res = await fetch(`${API_BASE_URL}/api/stats/dau-range?days=30`, {
|
||||
headers: { Authorization: `Bearer ${token}` }
|
||||
})
|
||||
if (res.ok) {
|
||||
const data = await res.json()
|
||||
const dates = data.map(d => d.date)
|
||||
const values = data.map(d => d.value)
|
||||
option.value = {
|
||||
title: { text: '站点 DAU' },
|
||||
tooltip: { trigger: 'axis' },
|
||||
xAxis: { type: 'category', data: dates },
|
||||
yAxis: { type: 'value' },
|
||||
dataZoom: [{ type: 'slider', start: 80 }, { type: 'inside' }],
|
||||
series: [{ type: 'line', areaStyle: {}, smooth: true, data: values }]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadData)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.site-stats-page {
|
||||
padding: 20px;
|
||||
max-width: var(--page-max-width);
|
||||
margin: 0 auto;
|
||||
height: calc(100vh - var(--header-height) - 40px);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user