用户访问数量
This commit is contained in:
@@ -201,3 +201,54 @@ export function pageLoginLogs(params: LoginLogQuery) {
|
||||
export function loginLogSummary() {
|
||||
return request.get<never, LoginLogSummary>('/admin/login-logs/summary')
|
||||
}
|
||||
|
||||
// ==================== 网络访问统计 ====================
|
||||
|
||||
export interface AccessOverview {
|
||||
/** 历史访问人次 */
|
||||
historyCount: number
|
||||
/** 历史访问人数(去重) */
|
||||
historyUsers: number
|
||||
/** 本月访问人次 */
|
||||
monthCount: number
|
||||
monthUsers: number
|
||||
/** 本周访问人次 */
|
||||
weekCount: number
|
||||
weekUsers: number
|
||||
/** 今日访问人次 */
|
||||
todayCount: number
|
||||
todayUsers: number
|
||||
}
|
||||
|
||||
export interface AccessTrendPoint {
|
||||
/** 时间桶,如 2026-11-04 08 / 2026-11 / 2026 */
|
||||
bucket: string
|
||||
/** 访问人次 */
|
||||
count: number
|
||||
/** 访问人数(去重) */
|
||||
users: number
|
||||
}
|
||||
|
||||
export interface AccessDimensionItem {
|
||||
/** 维度值(IP / 单位 / 账号 / 在线状态) */
|
||||
name: string
|
||||
/** 访问人次 */
|
||||
count: number
|
||||
/** 访问人数(去重) */
|
||||
users: number
|
||||
}
|
||||
|
||||
/** 网络访问概览:历史 / 本月 / 本周 / 今日 */
|
||||
export function accessOverview() {
|
||||
return request.get<never, AccessOverview>('/admin/login-logs/access-overview')
|
||||
}
|
||||
|
||||
/** 网络访问趋势:granularity = hour|day|week|month|year,可指定 start/end(yyyy-MM-dd) */
|
||||
export function accessTrend(params: { granularity: string; start?: string; end?: string }) {
|
||||
return request.get<never, AccessTrendPoint[]>('/admin/login-logs/access-trend', { params })
|
||||
}
|
||||
|
||||
/** 网络访问维度统计:dimension = ip|org|account|type */
|
||||
export function accessDimension(params: { dimension: string; start?: string; end?: string; limit?: number }) {
|
||||
return request.get<never, AccessDimensionItem[]>('/admin/login-logs/access-dimension', { params })
|
||||
}
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import * as echarts from 'echarts'
|
||||
import {
|
||||
accessDimension,
|
||||
accessOverview,
|
||||
accessTrend,
|
||||
type AccessDimensionItem,
|
||||
type AccessOverview,
|
||||
type AccessTrendPoint
|
||||
} from '@/api/admin'
|
||||
|
||||
const overview = ref<AccessOverview | null>(null)
|
||||
const granularity = ref<'hour' | 'day' | 'week' | 'month' | 'year'>('hour')
|
||||
const dateRange = ref<string[]>([])
|
||||
const dimension = ref<'ip' | 'org' | 'account' | 'type'>('ip')
|
||||
const trendData = ref<AccessTrendPoint[]>([])
|
||||
const dimData = ref<AccessDimensionItem[]>([])
|
||||
|
||||
const trendRef = ref<HTMLElement>()
|
||||
const dimRef = ref<HTMLElement>()
|
||||
const charts: echarts.ECharts[] = []
|
||||
|
||||
function todayStr(): string {
|
||||
const d = new Date()
|
||||
const p = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
|
||||
}
|
||||
|
||||
function rangeParams() {
|
||||
return {
|
||||
start: dateRange.value?.[0] || undefined,
|
||||
end: dateRange.value?.[1] || undefined
|
||||
}
|
||||
}
|
||||
|
||||
const overviewCards = computed(() =>
|
||||
overview.value
|
||||
? [
|
||||
{ label: '历史访问', count: overview.value.historyCount, users: overview.value.historyUsers },
|
||||
{ label: '本月访问', count: overview.value.monthCount, users: overview.value.monthUsers },
|
||||
{ label: '本周访问', count: overview.value.weekCount, users: overview.value.weekUsers },
|
||||
{ label: '今日访问', count: overview.value.todayCount, users: overview.value.todayUsers }
|
||||
]
|
||||
: []
|
||||
)
|
||||
|
||||
async function loadOverview() {
|
||||
overview.value = await accessOverview()
|
||||
}
|
||||
|
||||
async function loadTrend() {
|
||||
const data = await accessTrend({ granularity: granularity.value, ...rangeParams() })
|
||||
// 小时粒度补全 0-23,保证「今日各小时」视图完整
|
||||
let list = data
|
||||
if (granularity.value === 'hour') {
|
||||
const byKey = new Map<string, AccessTrendPoint>()
|
||||
data.forEach((d) => byKey.set(d.bucket.slice(-2), d))
|
||||
list = []
|
||||
for (let h = 0; h < 24; h++) {
|
||||
const key = String(h).padStart(2, '0')
|
||||
list.push(byKey.get(key) ?? { bucket: key, count: 0, users: 0 })
|
||||
}
|
||||
}
|
||||
trendData.value = list
|
||||
renderTrend(list)
|
||||
}
|
||||
|
||||
async function loadDimension() {
|
||||
dimData.value = await accessDimension({ dimension: dimension.value, limit: 20, ...rangeParams() })
|
||||
renderDim(dimData.value)
|
||||
}
|
||||
|
||||
async function searchAll() {
|
||||
await Promise.all([loadTrend(), loadDimension()])
|
||||
}
|
||||
|
||||
function reset() {
|
||||
granularity.value = 'hour'
|
||||
dateRange.value = [todayStr(), todayStr()]
|
||||
dimension.value = 'ip'
|
||||
searchAll()
|
||||
}
|
||||
|
||||
function renderTrend(list: AccessTrendPoint[]) {
|
||||
const el = trendRef.value
|
||||
if (!el) return
|
||||
let chart = charts[0]
|
||||
if (!chart) {
|
||||
chart = echarts.init(el)
|
||||
charts[0] = chart
|
||||
}
|
||||
const labels = list.map((d) => (granularity.value === 'hour' ? d.bucket.slice(-2) + '时' : d.bucket))
|
||||
chart.setOption({
|
||||
tooltip: { trigger: 'axis' },
|
||||
legend: { data: ['访问人次', '访问人数'], bottom: 0 },
|
||||
grid: { left: 50, right: 20, top: 30, bottom: 40 },
|
||||
xAxis: { type: 'category', data: labels, axisLabel: { color: '#23362c' } },
|
||||
yAxis: { type: 'value', axisLabel: { color: '#23362c' } },
|
||||
series: [
|
||||
{
|
||||
name: '访问人次',
|
||||
type: 'bar',
|
||||
data: list.map((d) => d.count),
|
||||
itemStyle: { color: '#b8862d' },
|
||||
barMaxWidth: 28
|
||||
},
|
||||
{
|
||||
name: '访问人数',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
data: list.map((d) => d.users),
|
||||
itemStyle: { color: '#2f5d47' },
|
||||
lineStyle: { width: 2 }
|
||||
}
|
||||
]
|
||||
})
|
||||
chart.resize()
|
||||
}
|
||||
|
||||
function renderDim(list: AccessDimensionItem[]) {
|
||||
const el = dimRef.value
|
||||
if (!el) return
|
||||
let chart = charts[1]
|
||||
if (!chart) {
|
||||
chart = echarts.init(el)
|
||||
charts[1] = chart
|
||||
}
|
||||
const top = list.slice(0, 10).reverse()
|
||||
chart.setOption({
|
||||
tooltip: { trigger: 'axis' },
|
||||
grid: { left: 10, right: 24, top: 10, bottom: 10, containLabel: true },
|
||||
xAxis: { type: 'value', axisLabel: { color: '#23362c' } },
|
||||
yAxis: { type: 'category', inverse: true, data: top.map((d) => d.name), axisLabel: { color: '#23362c' } },
|
||||
series: [
|
||||
{
|
||||
name: '访问人次',
|
||||
type: 'bar',
|
||||
data: top.map((d) => d.count),
|
||||
itemStyle: { color: '#5b9a78' },
|
||||
barMaxWidth: 22
|
||||
}
|
||||
]
|
||||
})
|
||||
chart.resize()
|
||||
}
|
||||
|
||||
function handleResize() {
|
||||
charts.forEach((c) => c.resize())
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
dateRange.value = [todayStr(), todayStr()]
|
||||
await Promise.all([loadOverview(), loadTrend(), loadDimension()])
|
||||
window.addEventListener('resize', handleResize)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('resize', handleResize)
|
||||
charts.forEach((c) => c.dispose())
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="access-stats">
|
||||
<!-- 概览卡片 -->
|
||||
<el-row :gutter="16" class="mb-16">
|
||||
<el-col v-for="c in overviewCards" :key="c.label" :xs="12" :sm="6">
|
||||
<div class="ov-card">
|
||||
<div class="ov-label">{{ c.label }}</div>
|
||||
<div class="ov-count">{{ c.count.toLocaleString() }}</div>
|
||||
<div class="ov-users">访问人数 {{ c.users.toLocaleString() }}</div>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 控制条 -->
|
||||
<div class="toolbar">
|
||||
<span class="tb-label">时间粒度</span>
|
||||
<el-radio-group v-model="granularity" size="small" @change="loadTrend">
|
||||
<el-radio-button value="hour">小时</el-radio-button>
|
||||
<el-radio-button value="day">日</el-radio-button>
|
||||
<el-radio-button value="week">周</el-radio-button>
|
||||
<el-radio-button value="month">月</el-radio-button>
|
||||
<el-radio-button value="year">年</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-date-picker
|
||||
v-model="dateRange"
|
||||
type="daterange"
|
||||
:editable="false"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
value-format="YYYY-MM-DD"
|
||||
style="width: 260px"
|
||||
@change="searchAll"
|
||||
/>
|
||||
<el-button type="primary" @click="searchAll">查询</el-button>
|
||||
<el-button @click="reset">重置</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 访问趋势 -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<span class="panel-title">访问趋势</span>
|
||||
<span class="panel-sub">人次 = 登录会话数,人数 = 去重用户数</span>
|
||||
</div>
|
||||
<div ref="trendRef" class="chart-lg"></div>
|
||||
</div>
|
||||
|
||||
<!-- 维度统计 -->
|
||||
<div class="panel">
|
||||
<div class="panel-head">
|
||||
<span class="panel-title">维度统计</span>
|
||||
<el-radio-group v-model="dimension" size="small" @change="loadDimension">
|
||||
<el-radio-button value="ip">按 IP</el-radio-button>
|
||||
<el-radio-button value="org">按单位</el-radio-button>
|
||||
<el-radio-button value="account">按账号</el-radio-button>
|
||||
<el-radio-button value="type">按类型</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<el-row :gutter="16">
|
||||
<el-col :md="14" :xs="24">
|
||||
<div ref="dimRef" class="chart-md"></div>
|
||||
</el-col>
|
||||
<el-col :md="10" :xs="24">
|
||||
<el-table :data="dimData" border stripe max-height="360" size="small">
|
||||
<el-table-column type="index" label="#" width="50" />
|
||||
<el-table-column prop="name" label="维度值" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="count" label="人次" width="90" align="right" />
|
||||
<el-table-column prop="users" label="人数" width="90" align="right" />
|
||||
</el-table>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.ov-card {
|
||||
position: relative;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
padding: 18px 12px;
|
||||
background: var(--bg-card, #fff);
|
||||
border: 1px solid var(--border-soft, #e7eee9);
|
||||
border-radius: 10px;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 3px;
|
||||
background: linear-gradient(180deg, var(--brand-gold-light, #e9c878), var(--brand-gold-deep, #8a6420));
|
||||
}
|
||||
|
||||
.ov-label {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted, #7a8a80);
|
||||
}
|
||||
|
||||
.ov-count {
|
||||
font-family: var(--font-serif, serif);
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: var(--brand-primary-deep, #2f5d47);
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.ov-users {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted, #7a8a80);
|
||||
margin-top: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.tb-label {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted, #7a8a80);
|
||||
}
|
||||
}
|
||||
|
||||
.panel {
|
||||
background: var(--bg-card, #fff);
|
||||
border: 1px solid var(--border-soft, #e7eee9);
|
||||
border-radius: 10px;
|
||||
padding: 16px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.panel-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.panel-title {
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--text-main, #23362c);
|
||||
}
|
||||
|
||||
.panel-sub {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted, #7a8a80);
|
||||
}
|
||||
}
|
||||
|
||||
.chart-lg {
|
||||
width: 100%;
|
||||
height: 340px;
|
||||
}
|
||||
|
||||
.chart-md {
|
||||
width: 100%;
|
||||
height: 360px;
|
||||
}
|
||||
</style>
|
||||
@@ -13,7 +13,8 @@ const menuTitle: Record<string, string> = {
|
||||
library: '院校资源库',
|
||||
fields: '列表字段配置',
|
||||
deposit: '呈缴管理',
|
||||
log: '日志管理'
|
||||
log: '日志管理',
|
||||
access: '网络访问统计'
|
||||
}
|
||||
const pageTitle = computed(() => menuTitle[activeMenu.value] || '后台管理')
|
||||
|
||||
@@ -44,6 +45,7 @@ import {
|
||||
type SensitiveWord,
|
||||
} from '@/api/admin'
|
||||
import OrgUserPanel from './OrgUserPanel.vue'
|
||||
import AccessStatsPanel from './AccessStatsPanel.vue'
|
||||
import {
|
||||
acceptDeposit,
|
||||
pageDeposit,
|
||||
@@ -547,6 +549,7 @@ onMounted(() => {
|
||||
<el-menu-item index="fields">列表字段配置</el-menu-item>
|
||||
<el-menu-item index="deposit">呈缴管理</el-menu-item>
|
||||
<el-menu-item index="log">日志管理</el-menu-item>
|
||||
<el-menu-item index="access">网络访问统计</el-menu-item>
|
||||
</el-menu>
|
||||
</aside>
|
||||
|
||||
@@ -940,6 +943,9 @@ onMounted(() => {
|
||||
@size-change="fetchLogs"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ==================== 网络访问统计 ==================== -->
|
||||
<AccessStatsPanel v-if="activeMenu === 'access'" />
|
||||
</section>
|
||||
|
||||
<!-- 敏感词 新增/编辑 弹窗 -->
|
||||
|
||||
Reference in New Issue
Block a user