日志
This commit is contained in:
@@ -146,3 +146,58 @@ export function saveListFields(scene: string, items: ListFieldConfig[]) {
|
||||
export function resetListFields(scene: string) {
|
||||
return request.post<never, ListFieldConfig[]>(`/admin/list-fields/${scene}/reset`)
|
||||
}
|
||||
|
||||
// ==================== 登录日志 ====================
|
||||
|
||||
export interface LoginLog {
|
||||
id?: number
|
||||
userId?: number
|
||||
/** 登录账号 */
|
||||
username?: string
|
||||
/** 姓名 */
|
||||
realName?: string
|
||||
/** 所属单位 */
|
||||
orgName?: string
|
||||
/** 登录IP */
|
||||
ip?: string
|
||||
/** 浏览器/客户端标识 */
|
||||
userAgent?: string
|
||||
/** 登录时间 */
|
||||
loginTime?: string
|
||||
/** 退出时间,未退出为 null */
|
||||
logoutTime?: string | null
|
||||
/** 是否在线:1在线 0离线 */
|
||||
online?: number
|
||||
createTime?: string
|
||||
}
|
||||
|
||||
export interface LoginLogQuery {
|
||||
current: number
|
||||
size: number
|
||||
keyword?: string
|
||||
/** ONLINE 在线 / OFFLINE 离线 / 不传 全部 */
|
||||
status?: string
|
||||
/** 登录时间起(yyyy-MM-dd) */
|
||||
loginStart?: string
|
||||
/** 登录时间止(yyyy-MM-dd) */
|
||||
loginEnd?: string
|
||||
}
|
||||
|
||||
export interface LoginLogSummary {
|
||||
/** 会话总数 */
|
||||
total: number
|
||||
/** 当前在线人数 */
|
||||
online: number
|
||||
/** 今日登录次数 */
|
||||
today: number
|
||||
}
|
||||
|
||||
/** 登录日志分页 */
|
||||
export function pageLoginLogs(params: LoginLogQuery) {
|
||||
return request.get<never, PageResult<LoginLog>>('/admin/login-logs/page', { params })
|
||||
}
|
||||
|
||||
/** 登录日志概览统计 */
|
||||
export function loginLogSummary() {
|
||||
return request.get<never, LoginLogSummary>('/admin/login-logs/summary')
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@ const menuTitle: Record<string, string> = {
|
||||
hits: '敏感词命中处置',
|
||||
library: '院校资源库',
|
||||
fields: '列表字段配置',
|
||||
deposit: '呈缴管理'
|
||||
deposit: '呈缴管理',
|
||||
log: '日志管理'
|
||||
}
|
||||
const pageTitle = computed(() => menuTitle[activeMenu.value] || '后台管理')
|
||||
|
||||
@@ -50,6 +51,13 @@ import {
|
||||
type DepositQuery,
|
||||
type DepositRecord
|
||||
} from '@/api/deposit'
|
||||
import {
|
||||
loginLogSummary,
|
||||
pageLoginLogs,
|
||||
type LoginLog,
|
||||
type LoginLogQuery,
|
||||
type LoginLogSummary
|
||||
} from '@/api/admin'
|
||||
|
||||
// ==================== 敏感词库 ====================
|
||||
const wordQuery = reactive({ current: 1, size: 10, keyword: '' })
|
||||
@@ -438,6 +446,66 @@ function depositStatusText(status?: string) {
|
||||
return '待审核'
|
||||
}
|
||||
|
||||
// ==================== 日志管理 ====================
|
||||
const logQuery = reactive<LoginLogQuery>({ current: 1, size: 20, keyword: '', status: '', loginStart: '', loginEnd: '' })
|
||||
const logList = ref<LoginLog[]>([])
|
||||
const logTotal = ref(0)
|
||||
const logLoading = ref(false)
|
||||
const logDateRange = ref<string[]>([])
|
||||
const logSummary = ref<LoginLogSummary>({ total: 0, online: 0, today: 0 })
|
||||
|
||||
async function fetchLogs() {
|
||||
logLoading.value = true
|
||||
try {
|
||||
const page = await pageLoginLogs({
|
||||
current: logQuery.current,
|
||||
size: logQuery.size,
|
||||
keyword: logQuery.keyword || undefined,
|
||||
status: logQuery.status || undefined,
|
||||
loginStart: logDateRange.value?.[0] || undefined,
|
||||
loginEnd: logDateRange.value?.[1] || undefined,
|
||||
})
|
||||
logList.value = page.records || []
|
||||
logTotal.value = page.total || 0
|
||||
} finally {
|
||||
logLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchLogSummary() {
|
||||
try {
|
||||
logSummary.value = await loginLogSummary()
|
||||
} catch {
|
||||
logSummary.value = { total: 0, online: 0, today: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
function searchLogs() {
|
||||
logQuery.current = 1
|
||||
fetchLogs()
|
||||
}
|
||||
|
||||
function resetLogFilters() {
|
||||
logQuery.keyword = ''
|
||||
logQuery.status = ''
|
||||
logDateRange.value = []
|
||||
searchLogs()
|
||||
}
|
||||
|
||||
/** 在线时长:未退出按当前时间算,已退出按退出时间算 */
|
||||
function onlineDuration(row: LoginLog): string {
|
||||
const start = row.loginTime ? new Date(row.loginTime).getTime() : 0
|
||||
if (!start) return '-'
|
||||
const end = row.logoutTime ? new Date(row.logoutTime).getTime() : Date.now()
|
||||
const mins = Math.max(0, Math.floor((end - start) / 60000))
|
||||
if (mins < 60) return `${mins} 分钟`
|
||||
const hours = Math.floor(mins / 60)
|
||||
const rem = mins % 60
|
||||
if (hours < 24) return `${hours} 小时${rem ? ' ' + rem + ' 分' : ''}`
|
||||
const days = Math.floor(hours / 24)
|
||||
return `${days} 天 ${hours % 24} 小时`
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchWords()
|
||||
fetchHits()
|
||||
@@ -445,6 +513,8 @@ onMounted(() => {
|
||||
fetchStats()
|
||||
fetchFields()
|
||||
fetchDeposits()
|
||||
fetchLogs()
|
||||
fetchLogSummary()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -468,6 +538,7 @@ onMounted(() => {
|
||||
<el-menu-item index="library">院校资源库</el-menu-item>
|
||||
<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>
|
||||
</aside>
|
||||
|
||||
@@ -780,6 +851,86 @@ onMounted(() => {
|
||||
@current-change="fetchDeposits"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- ==================== 日志管理 ==================== -->
|
||||
<div v-show="activeMenu === 'log'">
|
||||
<div class="log-summary">
|
||||
<div class="log-card">
|
||||
<div class="log-card__num">{{ logSummary.total }}</div>
|
||||
<div class="log-card__label">会话总数</div>
|
||||
</div>
|
||||
<div class="log-card log-card--online">
|
||||
<div class="log-card__num">{{ logSummary.online }}</div>
|
||||
<div class="log-card__label">当前在线</div>
|
||||
</div>
|
||||
<div class="log-card log-card--today">
|
||||
<div class="log-card__num">{{ logSummary.today }}</div>
|
||||
<div class="log-card__label">今日登录</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="toolbar">
|
||||
<el-input
|
||||
v-model="logQuery.keyword"
|
||||
placeholder="账号 / 姓名 / 单位"
|
||||
clearable
|
||||
style="width: 220px"
|
||||
@keyup.enter="searchLogs"
|
||||
@clear="searchLogs"
|
||||
/>
|
||||
<el-select v-model="logQuery.status" placeholder="全部状态" clearable style="width: 130px" @change="searchLogs">
|
||||
<el-option label="在线" value="ONLINE" />
|
||||
<el-option label="离线" value="OFFLINE" />
|
||||
</el-select>
|
||||
<el-date-picker
|
||||
v-model="logDateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="登录起"
|
||||
end-placeholder="登录止"
|
||||
value-format="YYYY-MM-DD"
|
||||
style="width: 260px"
|
||||
@change="searchLogs"
|
||||
/>
|
||||
<el-button type="primary" @click="searchLogs">查询</el-button>
|
||||
<el-button @click="resetLogFilters">重置</el-button>
|
||||
<el-button @click="fetchLogSummary">刷新概览</el-button>
|
||||
</div>
|
||||
|
||||
<el-table v-loading="logLoading" :data="logList" border stripe>
|
||||
<el-table-column type="index" label="#" width="50" />
|
||||
<el-table-column prop="username" label="账号" width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="realName" label="姓名" width="120" show-overflow-tooltip />
|
||||
<el-table-column prop="orgName" label="单位" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column prop="ip" label="登录IP" width="140" />
|
||||
<el-table-column prop="loginTime" label="登录时间" width="180" />
|
||||
<el-table-column label="退出时间" width="180">
|
||||
<template #default="{ row }">{{ row.logoutTime || '—' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="在线时长" width="140">
|
||||
<template #default="{ row }">{{ onlineDuration(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="row.logoutTime ? 'info' : 'success'">
|
||||
{{ row.logoutTime ? '离线' : '在线' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
class="pager"
|
||||
background
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="logTotal"
|
||||
v-model:current-page="logQuery.current"
|
||||
v-model:page-size="logQuery.size"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@current-change="fetchLogs"
|
||||
@size-change="fetchLogs"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 敏感词 新增/编辑 弹窗 -->
|
||||
@@ -974,4 +1125,51 @@ onMounted(() => {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.log-summary {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
margin-bottom: 16px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.log-card {
|
||||
min-width: 150px;
|
||||
padding: 16px 20px;
|
||||
border: 1px solid var(--card-gold-border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--brand-light);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.log-card__num {
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
color: var(--text-main);
|
||||
font-family: var(--font-serif);
|
||||
}
|
||||
|
||||
.log-card__label {
|
||||
margin-top: 4px;
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.log-card--online {
|
||||
background: #e8f5e9;
|
||||
border-color: #b7dfc1;
|
||||
}
|
||||
|
||||
.log-card--online .log-card__num {
|
||||
color: #2e7d32;
|
||||
}
|
||||
|
||||
.log-card--today {
|
||||
background: #eaf2fb;
|
||||
border-color: #bcd4ef;
|
||||
}
|
||||
|
||||
.log-card--today .log-card__num {
|
||||
color: #1565c0;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user