feat: 重构控制面安全机制与分页规范

本次提交包含多项安全加固和体验优化:
1. 分离管理密钥与传输凭证,避免持 API Token 者伪造管理员票据
2. 钉钉回调地址增加白名单校验,防止开放重定向钓鱼
3. 初始管理员密码改为随机生成并日志记录,移除硬编码 123456
4. 新增登录防爆破计数表,支持 MySQL 多 worker 共享
5. 统一分页规范,新增 usePagedList composable 和 PagerBar 组件
6. 控制面 CORS 收敛为白名单,避免公网环境下任意站点跨域
7. 插件管理、凭证管理等列表接口支持分页和搜索
8. 强制初始密码修改,未改密前禁止使用管理功能
9. 定时任务触发被拒日志节流,避免授权失效时刷屏
10. 健康检查接口移除环境信息泄露,返回固定响应
This commit is contained in:
2026-09-23 15:19:54 +08:00
parent a1cf59f09c
commit 8a196d6c87
80 changed files with 9029 additions and 493 deletions
+26
View File
@@ -9,6 +9,7 @@
"version": "0.1.0",
"dependencies": {
"@element-plus/icons-vue": "^2.3.2",
"echarts": "^6.1.0",
"element-plus": "^2.14.5",
"vue": "^3.5.13"
},
@@ -1170,6 +1171,16 @@
"integrity": "sha512-QDTCU0M0MxR3hQfnlDJfwekQiaanm1ubOD231u73WBckQ/fsamwRLiE2GBz6D3a/xF1NgfiDLJjXBa1hYOYTtQ==",
"license": "MIT"
},
"node_modules/echarts": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/echarts/-/echarts-6.1.0.tgz",
"integrity": "sha512-q0yaFPggC9FUdsWH4blavRWFmxdrIodbkoKNAjJudAI6CA9gNPxHtV2RcZNEepZVlk4yvBYkOkbk6HIVpIyHZA==",
"license": "Apache-2.0",
"dependencies": {
"tslib": "2.3.0",
"zrender": "6.1.0"
}
},
"node_modules/element-plus": {
"version": "2.14.5",
"resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.14.5.tgz",
@@ -1470,6 +1481,12 @@
"url": "https://github.com/sponsors/SuperchupuDev"
}
},
"node_modules/tslib": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==",
"license": "0BSD"
},
"node_modules/vite": {
"version": "6.4.3",
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.3.tgz",
@@ -1571,6 +1588,15 @@
"resolved": "https://registry.npmjs.org/vue-component-type-helpers/-/vue-component-type-helpers-3.3.11.tgz",
"integrity": "sha512-LwcxzeliO9fkQcpJG0PoX8X5kmAhKmH9wkpDLxNabwzkQ9Zeib2YVHwFV4pcWmMLfXVfjr/dSV+DaJ3cIPgSNA==",
"license": "MIT"
},
"node_modules/zrender": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/zrender/-/zrender-6.1.0.tgz",
"integrity": "sha512-oEGMDB6pOP2S6OwRR4PdVv610zrjnA3Bh+JnSG12fYJlBKjtNAoEb5fSUoCOOINlH96I2fU38/A2UpRKs67xYQ==",
"license": "BSD-3-Clause",
"dependencies": {
"tslib": "2.3.0"
}
}
}
}
@@ -10,6 +10,7 @@
},
"dependencies": {
"@element-plus/icons-vue": "^2.3.2",
"echarts": "^6.1.0",
"element-plus": "^2.14.5",
"vue": "^3.5.13"
},
+19 -4
View File
@@ -43,7 +43,7 @@
</transition>
</main>
</div>
<PasswordDialog v-model="pwdOpen" />
<PasswordDialog v-model="pwdOpen" :force="pwdForce" />
</div>
</template>
@@ -113,17 +113,24 @@ function onMenu(key) {
const initial = computed(() => (store.nickname || store.current || '')[0]?.toUpperCase() || '?')
const pwdOpen = ref(false)
const pwdForce = ref(false)
function onCommand(cmd) {
if (cmd === 'pwd') pwdOpen.value = true
if (cmd === 'pwd') { pwdForce.value = false; pwdOpen.value = true }
else if (cmd === 'logout') {
clearSession()
message.success('已退出登录')
}
}
function onLogin() {
function onLogin(r) {
route.value = '#/overview'
location.hash = '#/overview'
// 服务端强制:仍持初始密码(must_change_pwd=1)时拒绝一切管理操作,必须先改密
if (r && r.must_change_pwd) {
pwdForce.value = true
pwdOpen.value = true
message.warning('首次登录请先修改初始密码,修改成功后才能使用管理功能')
}
}
onMounted(async () => {
@@ -132,7 +139,15 @@ onMounted(async () => {
try {
const me = await adminMe()
if (!me.account || !me.is_admin) clearSession()
else { store.isAdmin = true; store.nickname = me.nickname || '' }
else {
store.isAdmin = true; store.nickname = me.nickname || ''
// 刷新后仍需先改初始密码(服务端拒绝一切管理操作)
if (me.must_change_pwd) {
pwdForce.value = true
pwdOpen.value = true
message.warning('请先修改初始密码,修改成功后才能使用管理功能')
}
}
} catch (_) { /* 后端 down:保持本地态 */ }
})
</script>
+45 -10
View File
@@ -26,6 +26,14 @@ function adminHeaders(extra = {}) {
return { 'X-Admin-Token': store.token || '', ...extra }
}
// 统一分页规范:所有列表接口 page(page≥1) + page_size,返回 {items, total}
function pagedQuery(params = {}) {
const qs = new URLSearchParams()
if (params.page) qs.set('page', params.page)
if (params.page_size) qs.set('page_size', params.page_size)
return qs.toString()
}
export async function adminLogin(account, password) {
return req('/api/admin/auth', {
method: 'POST',
@@ -46,6 +54,12 @@ export async function adminMe() {
export async function adminOverview() {
return req('/api/admin/overview', { headers: adminHeaders() })
}
export async function adminGrantData() {
return req('/api/admin/grant_data', { headers: adminHeaders() })
}
export async function adminAccountGrants(account) {
return req('/api/admin/account_grants?account=' + encodeURIComponent(account), { headers: adminHeaders() })
}
export async function adminPlatforms() {
return req('/api/admin/platforms', { headers: adminHeaders() })
}
@@ -63,8 +77,17 @@ export async function adminPlatformGrant(body) {
body: JSON.stringify(body)
})
}
export async function adminAccounts() {
return req('/api/admin/accounts', { headers: adminHeaders() })
export async function adminAccounts(page = 1, pageSize = 20, q = '') {
const qs = new URLSearchParams()
qs.set('page', page); qs.set('page_size', pageSize)
if (q) qs.set('q', q)
return req('/api/admin/accounts?' + qs.toString(), { headers: adminHeaders() })
}
export async function adminPlugins(page = 1, pageSize = 20, q = '') {
const qs = new URLSearchParams()
qs.set('page', page); qs.set('page_size', pageSize)
if (q) qs.set('q', q)
return req('/api/admin/plugins?' + qs.toString(), { headers: adminHeaders() })
}
export async function adminAccountCreate(body) {
return req('/api/admin/account', {
@@ -115,17 +138,25 @@ export async function adminPluginPatch(pluginId, body) {
body: JSON.stringify(body)
})
}
export async function adminAudit(limit = 300) {
return req('/api/admin/audit?limit=' + limit, { headers: adminHeaders() })
export async function adminAudit(page = 1, pageSize = 20, filters = {}) {
const qs = new URLSearchParams()
qs.set('page', page); qs.set('page_size', pageSize)
if (filters.action) qs.set('action', filters.action)
if (filters.q) qs.set('q', filters.q)
return req('/api/admin/audit?' + qs.toString(), { headers: adminHeaders() })
}
export async function adminReports(limit = 300) {
return req('/api/admin/reports?limit=' + limit, { headers: adminHeaders() })
export async function adminReports(page = 1, pageSize = 20, filters = {}) {
const qs = new URLSearchParams()
qs.set('page', page); qs.set('page_size', pageSize)
if (filters.status) qs.set('status', filters.status)
if (filters.q) qs.set('q', filters.q)
return req('/api/admin/reports?' + qs.toString(), { headers: adminHeaders() })
}
export async function adminStats() {
return req('/api/admin/stats', { headers: adminHeaders() })
}
export async function adminCredsList() {
return req('/api/admin/creds/manage', { headers: adminHeaders() })
export async function adminCredsList(page = 1, pageSize = 20) {
return req('/api/admin/creds/manage?' + pagedQuery({ page, page_size: pageSize }), { headers: adminHeaders() })
}
export async function adminCredsSeed(body) {
return req('/api/admin/creds/seed', {
@@ -134,8 +165,12 @@ export async function adminCredsSeed(body) {
body: JSON.stringify(body)
})
}
export async function adminFileSources(category = '') {
const qs = category ? '?category=' + encodeURIComponent(category) : ''
export async function adminFileSources(category = '', page = 1, pageSize = 20) {
const parts = []
if (category) parts.push('category=' + encodeURIComponent(category))
const pq = pagedQuery({ page, page_size: pageSize })
if (pq) parts.push(pq)
const qs = parts.length ? '?' + parts.join('&') : ''
return req('/api/admin/file-sources' + qs, { headers: adminHeaders() })
}
export async function adminFileSourceCreate(body) {
@@ -0,0 +1,21 @@
<template>
<div class="pager-bar" v-if="total > 0">
<el-pagination background layout="total, sizes, prev, pager, next"
:total="total" :current-page="page" :page-size="pageSize"
:page-sizes="[10, 20, 50, 100]"
@current-change="p => emit('change', p, pageSize)"
@size-change="s => emit('change', 1, s)" />
</div>
</template>
<script setup>
// 统一分页条:配合后端 page/page_size 分页接口({items,total})。
// 用法:<PagerBar :total="total" :page="page" :page-size="pageSize"
// @change="(p, s) => { page = p; pageSize = s; load() }" />
defineProps({ total: { type: Number, default: 0 }, page: { type: Number, default: 1 }, pageSize: { type: Number, default: 20 } })
const emit = defineEmits(['change'])
</script>
<style scoped>
.pager-bar { display: flex; justify-content: flex-end; padding: 12px 4px 2px; }
</style>
@@ -1,5 +1,10 @@
<template>
<el-dialog v-model="visible" title="修改密码" width="440px" align-center destroy-on-close @closed="reset">
<el-dialog v-model="visible" title="修改密码" width="440px" align-center destroy-on-close
:close-on-click-modal="!force" :close-on-press-escape="!force" :show-close="!force"
@closed="onClosed">
<el-alert v-if="force" type="warning" :closable="false" class="force-tip" show-icon>
首次登录请先修改初始密码,修改成功后才能使用管理功能。
</el-alert>
<el-alert v-if="store.current" type="info" :closable="false" class="acct-tip" show-icon>
当前账号:<b class="mono">{{ store.current }}</b>
</el-alert>
@@ -8,7 +13,7 @@
<el-input v-model="form.oldPwd" type="password" placeholder="请输入原密码" show-password @keyup.enter="submit" />
</el-form-item>
<el-form-item label="新密码" prop="newPwd">
<el-input v-model="form.newPwd" type="password" placeholder="至少 6 位,不与原密码相同" show-password @keyup.enter="submit" />
<el-input v-model="form.newPwd" type="password" placeholder="至少 8 位,不与原密码相同" show-password @keyup.enter="submit" />
</el-form-item>
<el-form-item label="确认新密码" prop="newPwd2">
<el-input v-model="form.newPwd2" type="password" placeholder="再次输入新密码" show-password @keyup.enter="submit" />
@@ -16,7 +21,7 @@
</el-form>
<template #footer>
<div class="modal-foot">
<el-button @click="visible = false">取消</el-button>
<el-button v-if="!force" @click="visible = false">取消</el-button>
<el-button type="primary" :loading="busy" @click="submit">保存</el-button>
</div>
</template>
@@ -29,16 +34,19 @@ import { ElMessage as message } from 'element-plus'
import { store } from '../store'
import { adminPassword } from '../api'
// force=true 强制改密模式(首次登录 must_change_pwd):不可取消/关闭,改密成功前不允许进入管理面
const props = defineProps({ force: { type: Boolean, default: false } })
const visible = defineModel({ type: Boolean, default: false })
const formRef = ref()
const busy = ref(false)
const changed = ref(false)
const form = reactive({ oldPwd: '', newPwd: '', newPwd2: '' })
const rules = {
oldPwd: { required: true, message: '请输入原密码' },
newPwd: [
{ required: true, message: '请输入新密码' },
{ min: 6, message: '新密码至少 6 位' },
{ min: 8, message: '新密码至少 8 位' },
{ validator: (_r, v, cb) => (v && v === form.oldPwd ? cb(new Error('新密码不能与原密码相同')) : cb()), message: '新密码不能与原密码相同' },
],
newPwd2: [
@@ -52,11 +60,17 @@ function reset() {
formRef.value?.resetFields()
}
function onClosed() {
// 强制模式下未改密成功不允许关闭:自动重新打开
if (props.force && !changed.value) visible.value = true
}
async function submit() {
try { await formRef.value.validate() } catch (_) { return }
busy.value = true
try {
await adminPassword({ account: store.current, old_password: form.oldPwd, new_password: form.newPwd })
changed.value = true
message.success('密码已修改,下次登录请使用新密码')
visible.value = false
} catch (e) {
@@ -68,6 +82,7 @@ async function submit() {
</script>
<style scoped>
.force-tip { margin-bottom: 14px; }
.acct-tip { margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
</style>
@@ -0,0 +1,66 @@
// 统一分页列表 composable:对接后端 page/page_size → {items,total} 契约。
//
// 统一管理:items/total/page/pageSize/busy 状态 + load/onPageChange/reset 行为;
// 自动处理越界回退(删除/筛选后当前页为空时回到最后一页);
// 请求竞态控制(快速翻页/切筛选时丢弃过期响应);
// 错误统一走 onError 回调(不向上抛),各页面不再各自 try/catch。
//
// 用法:
// const { items: accounts, total, page, size: pageSize, busy, load: refresh, onPageChange, reset } =
// usePagedList((p, s) => adminAccounts(p, s), {
// onError: e => message.error('读取失败:' + (e.message || e)),
// })
// 模板中直接使用解构出的 ref(自动解包),PagerBar 绑定 :total :page :page-size @change="onPageChange"。
import { ref } from 'vue'
export function usePagedList(fetcher, opts = {}) {
const onError = typeof opts.onError === 'function' ? opts.onError : () => {}
const items = ref([])
const total = ref(0)
const page = ref(1)
const size = ref(opts.pageSize || 20)
const busy = ref(false)
// 响应里除 items/total 外的附加字段(如 today/failed)透传到 meta
const meta = ref({})
// 请求序号:只接受最后一次发起的响应,丢弃过期响应
let seq = 0
async function load() {
const my = ++seq
busy.value = true
try {
const r = await fetcher(page.value, size.value)
if (my !== seq) return // 已过期(期间又发起了新请求)
items.value = r.items || []
total.value = r.total || 0
meta.value = r
// 越界回退:数据被删/筛选变化导致当前页为空,且总数>0 → 回到最后一页
if (!items.value.length && page.value > 1 && total.value > 0) {
const last = Math.max(1, Math.ceil(total.value / size.value))
if (last !== page.value) {
page.value = last
return load()
}
}
} catch (e) {
if (my === seq) onError(e)
} finally {
if (my === seq) busy.value = false
}
}
function onPageChange(p, s) {
if (p === page.value && s === size.value) return
page.value = p
size.value = s
load()
}
// 筛选条件/外部数据变化后回到第一页重新加载
function reset() {
page.value = 1
load()
}
return { items, total, page, size, busy, meta, load, onPageChange, reset }
}
@@ -6,11 +6,17 @@
<p>建号 · 部门 / 管理员维护 · 密码重置(不能操作自己的账号)</p>
</div>
<div class="head-acts">
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
<el-button :loading="busy" :icon="Refresh" @click="refresh">刷新</el-button>
<el-button type="primary" :icon="Plus" @click="openCreate">新建账号</el-button>
</div>
</div>
<!-- 账号搜索(服务端模糊:账号/昵称/部门) -->
<div class="search-bar cp-card cp-rise">
<el-input v-model="kw" placeholder="搜索账号 / 昵称 / 部门" clearable :prefix-icon="Search" style="width: 300px" @keyup.enter="onSearch" @clear="onSearch" />
<span v-if="kw" class="dim-sm">搜索中:{{ kw }}</span>
</div>
<!-- 账号卡片 -->
<div class="acct-grid" v-if="accounts.length">
<div class="acct-card cp-card cp-rise" v-for="(a, i) in accounts" :key="a.account" :style="{ animationDelay: i * 40 + 'ms' }">
@@ -46,8 +52,8 @@
<div class="acct-tags" v-if="a.plugins?.length">
<span class="tag-label">插件</span>
<el-tag v-for="p in a.plugins.slice(0, 3)" :key="p" size="small" type="primary" effect="light" round class="mono">{{ p }}</el-tag>
<span v-if="a.plugins.length > 3" class="more mono">+{{ a.plugins.length - 3 }}</span>
<el-tag v-for="p in a.plugins.slice(0, 2)" :key="p" size="small" type="primary" effect="light" round class="mono">{{ p }}</el-tag>
<span v-if="a.plugins.length > 2" class="more mono">+{{ a.plugins.length - 2 }}</span>
</div>
<div class="acct-tags" v-else>
<span class="tag-label">插件</span>
@@ -65,7 +71,8 @@
</div>
</div>
</div>
<el-empty v-else-if="!overviewBusy" description="暂无账号,点击右上角「新建账号」" :image-size="90" class="cp-card" />
<el-empty v-else-if="!busy" description="暂无账号,点击右上角「新建账号」" :image-size="90" class="cp-card" />
<PagerBar v-if="total > 0" :total="total" :page="page" :page-size="pageSize" @change="onPageChange" />
<!-- 新建账号 -->
<el-dialog v-model="createOpen" title="新建账号" width="440px" align-center destroy-on-close @closed="resetCreate">
@@ -77,7 +84,7 @@
<el-input v-model="form.nickname" placeholder="真实姓名,方便识别(可填钉钉名)" />
</el-form-item>
<el-form-item label="初始密码" prop="password">
<el-input v-model="form.password" type="password" placeholder="至少 6 位" show-password />
<el-input v-model="form.password" type="password" placeholder="至少 8 位" show-password />
</el-form-item>
<el-form-item label="部门">
<el-input v-model="form.dept" placeholder="如 财务部 / IT" />
@@ -121,9 +128,9 @@
<!-- 重置密码 -->
<el-dialog v-model="resetOpen" title="重置密码" width="420px" align-center destroy-on-close>
<el-alert type="info" :closable="false" class="reset-tip" show-icon>
为账号 <b class="mono">{{ resetTarget }}</b> 设置新密码(至少 6 位)
为账号 <b class="mono">{{ resetTarget }}</b> 设置新密码(至少 8 位)
</el-alert>
<el-input v-model="resetPwdVal" type="password" placeholder="新密码(至少 6 位)" show-password @keyup.enter="confirmReset" />
<el-input v-model="resetPwdVal" type="password" placeholder="新密码(至少 8 位)" show-password @keyup.enter="confirmReset" />
<template #footer>
<div class="modal-foot">
<el-button @click="resetOpen = false">取消</el-button>
@@ -137,18 +144,19 @@
<script setup>
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage as message, ElMessageBox as dialog } from 'element-plus'
import { Refresh, Plus, Camera, EditPen, Edit, Delete } from '@element-plus/icons-vue'
import { store, overview, overviewBusy, loadOverview } from '../store'
import { adminAccountCreate, adminAccountUpdate, adminAccountReset, adminAccountDelete, adminAvatarUpload } from '../api'
import { Refresh, Plus, Camera, EditPen, Edit, Delete, Search } from '@element-plus/icons-vue'
import { store } from '../store'
import { adminAccounts, adminAccountCreate, adminAccountUpdate, adminAccountReset, adminAccountDelete, adminAvatarUpload } from '../api'
import { fmtTime } from '../format'
import PagerBar from '../components/PagerBar.vue'
import { usePagedList } from '../composables/usePagedList'
const current = computed(() => store.current || '')
const accounts = computed(() => overview.value?.accounts || [])
const kw = ref('')
const list = usePagedList((p, s) => adminAccounts(p, s, kw.value), { onError: e => message.error('读取失败:' + (e.message || e)) })
const { items: accounts, total, page, size: pageSize, busy, load: refresh, onPageChange, reset } = list
const busySwitch = ref('')
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
function onSearch() { reset() }
// ---------- 头像(显示 + 上传) ----------
const _fileInput = (() => {
@@ -188,7 +196,7 @@ const rules = {
account: { required: true, message: '请输入账号' },
password: [
{ required: true, message: '请输入初始密码' },
{ min: 6, message: '密码至少 6 位' },
{ min: 8, message: '密码至少 8 位' },
],
}
function openCreate() { createOpen.value = true }
@@ -244,7 +252,7 @@ function resetPwd(a) {
}
async function confirmReset() {
const p = resetPwdVal.value
if (p.length < 6) { message.warning('密码至少 6 位'); return }
if (p.length < 8) { message.warning('密码至少 8 位'); return }
resetting.value = true
try {
await adminAccountReset({ account: resetTarget.value, new_password: p })
@@ -271,6 +279,7 @@ onMounted(refresh)
<style scoped>
.head-acts { display: flex; gap: 10px; }
.search-bar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; margin-bottom: 16px; }
.acct-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
@@ -23,12 +23,12 @@
<el-tabs v-model="tab">
<el-tab-pane label="操作审计" name="audit">
<div class="toolbar">
<el-select v-model="actionFilter" clearable placeholder="操作类型" style="width: 150px">
<el-select v-model="actionFilter" clearable placeholder="操作类型" style="width: 150px" @change="onAuditFilter">
<el-option v-for="(lb, key) in DETAIL_LABEL" :key="key" :label="lb" :value="key" />
</el-select>
<el-input v-model="search" placeholder="搜索账号 / 对象 / 详情" clearable :prefix-icon="Search" style="width: 240px" />
<el-input v-model="search" placeholder="搜索账号 / 对象 / 详情" clearable :prefix-icon="Search" style="width: 240px" @keyup.enter="onAuditFilter" @clear="onAuditFilter" />
</div>
<el-table :data="filteredAudits" size="small" :row-key="r => r.id">
<el-table :data="audits" size="small" v-loading="auditBusy" :row-key="r => r.id">
<el-table-column label="时间" width="170">
<template #default="{ row }"><span class="mono dim-sm">{{ fmtTime(row.at) }}</span></template>
</el-table-column>
@@ -55,16 +55,26 @@
</template>
</el-table-column>
</el-table>
<PagerBar :total="auditTotal" :page="auditPage" :page-size="auditPageSize" @change="onAuditPage" />
</el-tab-pane>
<el-tab-pane label="运行上报" name="report">
<el-table :data="reports" size="small" :row-key="r => r.id">
<div class="toolbar">
<el-select v-model="statusFilter" clearable placeholder="状态" style="width: 130px" @change="onReportFilter">
<el-option label="成功" value="done,success" />
<el-option label="失败" value="error,failed" />
<el-option label="运行中" value="running" />
<el-option label="已触发" value="start" />
</el-select>
<el-input v-model="reportSearch" placeholder="搜索账号 / 设备 / 插件 / 消息" clearable :prefix-icon="Search" style="width: 260px" @keyup.enter="onReportFilter" @clear="onReportFilter" />
</div>
<el-table :data="reports" size="small" v-loading="reportBusy" :row-key="r => r.id">
<el-table-column label="时间" width="170">
<template #default="{ row }"><span class="mono dim-sm">{{ fmtTime(row.at) }}</span></template>
</el-table-column>
<el-table-column label="状态" width="110">
<template #default="{ row }">
<span class="status-dot"><i :style="{ background: statusColor(row.status) }"></i><span :style="{ color: statusColor(row.status) }">{{ row.status || '—' }}</span></span>
<span class="status-dot"><i :style="{ background: statusColor(row.status) }"></i><span :style="{ color: statusColor(row.status) }">{{ statusLabel(row.status) }}</span></span>
</template>
</el-table-column>
<el-table-column label="账号" width="140">
@@ -80,13 +90,13 @@
<template #default="{ row }"><span class="mono dim-sm">{{ row.device_id || '—' }}</span></template>
</el-table-column>
<el-table-column label="插件" width="150" show-overflow-tooltip>
<template #default="{ row }"><span class="mono">{{ row.plugin_id || '—' }}</span></template>
<template #default="{ row }"><span class="mono">{{ row.pluginId || '—' }}</span></template>
</el-table-column>
<el-table-column label="版本" width="90">
<template #default="{ row }"><span class="mono">{{ row.version || '—' }}</span></template>
</el-table-column>
<el-table-column label="时长" width="90">
<template #default="{ row }"><span class="mono">{{ typeof row.duration_sec === 'number' ? fmtDur(row.duration_sec) : '—' }}</span></template>
<template #default="{ row }"><span class="mono">{{ typeof row.durationSec === 'number' ? fmtDur(row.durationSec) : '—' }}</span></template>
</el-table-column>
<el-table-column label="消息" min-width="200" show-overflow-tooltip>
<template #default="{ row }">
@@ -94,6 +104,7 @@
</template>
</el-table-column>
</el-table>
<PagerBar :total="reportTotal" :page="reportPage" :page-size="reportPageSize" @change="onReportPage" />
</el-tab-pane>
</el-tabs>
</div>
@@ -102,20 +113,36 @@
<script setup>
import { computed, onMounted, ref } from 'vue'
import { Refresh, Search, Document, DataLine, CircleCloseFilled, WarningFilled } from '@element-plus/icons-vue'
import { Refresh, Search, Document, DataLine, CircleCloseFilled } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import { adminAudit, adminReports } from '../api'
import { fmtTime } from '../format'
import PagerBar from '../components/PagerBar.vue'
import { usePagedList } from '../composables/usePagedList'
const tab = ref('audit')
const busy = ref(false)
const loaded = ref(false)
const audits = ref([])
const reports = ref([])
// 两个分页列表(服务端筛选:筛选/搜索条件作为闭包实时传给 fetcher)
const actionFilter = ref('')
const search = ref('')
const statusFilter = ref('')
const reportSearch = ref('')
const auditsList = usePagedList((p, s) => adminAudit(p, s, { action: actionFilter.value, q: search.value }), { onError: e => message.error('读取审计失败:' + (e.message || e)) })
const reportsList = usePagedList((p, s) => adminReports(p, s, { status: statusFilter.value, q: reportSearch.value }), { onError: e => message.error('读取上报失败:' + (e.message || e)) })
const { items: audits, total: auditTotal, page: auditPage, size: auditPageSize, busy: auditBusy, meta: auditMeta } = auditsList
const { items: reports, total: reportTotal, page: reportPage, size: reportPageSize, busy: reportBusy, meta: reportMeta } = reportsList
const DETAIL_LABEL = {
// 新命名(2026-09 服务端重构后)
'account-reset-pwd': '重置密码', 'grant-platform': '平台授权', 'revoke-platform': '撤销平台授权',
'plugin-publish': '上传发布', 'plugin-delete': '删除插件',
'creds-seed': '更新凭证',
'file-source-upsert': '登记文件源', 'file-source-patch': '更新文件源', 'file-source-delete': '删除文件源',
'shell-release': '发布壳子',
// 历史命名(旧版本审计记录兼容)
grant: '授权', 'revoke-grant': '撤销授权', 'plugin-patch': '更新插件',
'download-ticket': '下载', 'upload-pkg': '上传', 'account-create': '建号',
'account-update': '改号', 'account-reset': '重置密码', 'account-delete': '删除',
@@ -123,11 +150,18 @@ const DETAIL_LABEL = {
}
function actType(a) {
return { grant: 'primary', 'revoke-grant': 'danger', 'plugin-patch': 'warning',
'download-ticket': 'success', 'upload-pkg': 'success', login: 'primary' }[a] || 'info'
'download-ticket': 'success', 'upload-pkg': 'success', login: 'primary',
'plugin-publish': 'success', 'plugin-delete': 'danger',
'grant-platform': 'primary', 'revoke-platform': 'danger',
'account-reset-pwd': 'warning', 'creds-seed': 'warning',
'shell-release': 'success' }[a] || 'info'
}
function statusColor(s) {
return { start: '#2f5cf0', running: '#2f5cf0', done: '#1d9d5c', success: '#1d9d5c', error: '#d6453d', failed: '#d6453d' }[s] || '#9aa2b4'
}
function statusLabel(s) {
return ({ done: '成功', success: '成功', error: '失败', failed: '失败', running: '运行中', start: '已触发' })[s] || s
}
function fmtDur(sec) {
sec = +sec || 0
if (sec < 60) return sec + 's'
@@ -136,36 +170,27 @@ function fmtDur(sec) {
return `${Math.floor(m / 60)}h${m % 60}m`
}
const kpis = computed(() => {
const today = new Date().toISOString().slice(0, 10)
const tActs = audits.value.filter(a => (a.at || '').slice(0, 10) === today).length
const tReports = reports.value.filter(r => (r.at || '').slice(0, 10) === today).length
const fails = reports.value.filter(r => r.status === 'error' || r.status === 'failed').length
return [
{ label: '审计记录', value: audits.value.length, icon: Document, color: '#2f5cf0', bg: 'linear-gradient(135deg,#e8edfe,#d7e1fd)' },
{ label: '今日操作', value: tActs, icon: DataLine, color: '#0f9f9b', bg: 'linear-gradient(135deg,#e4f6f5,#d2efee)' },
{ label: '运行上报', value: reports.value.length, icon: DataLine, color: '#7c5cf6', bg: 'linear-gradient(135deg,#f0ebfe,#e4dcfd)' },
{ label: '今日上报', value: tReports, icon: DataLine, color: '#d97706', bg: 'linear-gradient(135deg,#fbf0df,#f6e4c8)' },
{ label: '上报失败', value: fails, icon: CircleCloseFilled, color: '#d6453d', bg: 'linear-gradient(135deg,#fbe9e8,#f6d8d6)' },
]
})
// KPI 全用后端统计值(total/today/failed),不依赖当前页 slice,保证分页后口径不变
const kpis = computed(() => [
{ label: '审计记录', value: auditTotal.value, icon: Document, color: '#2f5cf0', bg: 'linear-gradient(135deg,#e8edfe,#d7e1fd)' },
{ label: '今日操作', value: auditMeta.value.today || 0, icon: DataLine, color: '#0f9f9b', bg: 'linear-gradient(135deg,#e4f6f5,#d2efee)' },
{ label: '运行上报', value: reportTotal.value, icon: DataLine, color: '#7c5cf6', bg: 'linear-gradient(135deg,#f0ebfe,#e4dcfd)' },
{ label: '今日上报', value: reportMeta.value.today || 0, icon: DataLine, color: '#d97706', bg: 'linear-gradient(135deg,#fbf0df,#f6e4c8)' },
{ label: '上报失败', value: reportMeta.value.failed || 0, icon: CircleCloseFilled, color: '#d6453d', bg: 'linear-gradient(135deg,#fbe9e8,#f6d8d6)' },
])
const filteredAudits = computed(() => {
let list = audits.value
if (actionFilter.value) list = list.filter(a => a.action === actionFilter.value)
const kw = search.value.trim().toLowerCase()
if (kw) list = list.filter(a => [a.account, a.nickname, a.target, a.detail].join(' ').toLowerCase().includes(kw))
return list
})
// 筛选变化 → 回到第一页(服务端重新查询)
function onAuditFilter() { auditsList.reset() }
function onReportFilter() { reportsList.reset() }
function onAuditPage(p, s) { auditsList.onPageChange(p, s) }
function onReportPage(p, s) { reportsList.onPageChange(p, s) }
async function refresh() {
busy.value = true
try {
const [a, r] = await Promise.all([adminAudit(), adminReports()])
audits.value = a.auditlogs || []
reports.value = r.reports || []
await Promise.all([auditsList.load(), reportsList.load()])
loaded.value = true
} catch (e) { message.error('读取失败:' + (e.message || e)) }
} catch (_) { /* 子加载器已提示 */ }
finally { busy.value = false }
}
onMounted(refresh)
@@ -10,9 +10,9 @@
<div class="cp-card panel cp-rise">
<el-table :data="rows" v-loading="busy" size="default" style="width: 100%">
<el-table-column prop="account" label="执行机账号" width="150">
<el-table-column prop="account" label="执行机账号" width="180">
<template #default="{ row }">
<span class="mono">{{ row.account }}</span>
<span class="mono">{{ row.nickname ? `${row.nickname} · ${row.account}` : row.account }}</span>
</template>
</el-table-column>
<el-table-column label="公钥" width="90">
@@ -37,6 +37,7 @@
<el-empty description="暂无账号,客户端启动注册后自动出现" :image-size="80" />
</template>
</el-table>
<PagerBar :total="total" :page="page" :page-size="pageSize" @change="onPageChange" />
</div>
<el-dialog v-model="dlg" :title="`编辑凭证 · ${editing?.account || ''}`" width="540px">
@@ -61,6 +62,8 @@ import { onMounted, ref } from 'vue'
import { Refresh, EditPen } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import { adminCredsList, adminCredsSeed } from '../api'
import PagerBar from '../components/PagerBar.vue'
import { usePagedList } from '../composables/usePagedList'
const KEY_COLS = [
{ key: 'DINGTALK_APPKEY', label: 'AppKey' },
@@ -70,22 +73,13 @@ const KEY_COLS = [
]
const keyCols = KEY_COLS
const busy = ref(false)
const rows = ref([])
const list = usePagedList((p, s) => adminCredsList(p, s), { onError: e => message.error('读取失败:' + (e.message || e)) })
const { items: rows, total, page, size: pageSize, busy, load: refresh, onPageChange } = list
const dlg = ref(false)
const saving = ref(false)
const editing = ref(null)
const form = ref({})
async function refresh() {
busy.value = true
try {
const r = await adminCredsList()
rows.value = r.accounts || []
} catch (e) { message.error('读取失败:' + (e.message || e)) }
finally { busy.value = false }
}
function openEdit(row) {
editing.value = row
form.value = {}
@@ -6,7 +6,7 @@
<p>内网大文件(壳子/Chrome 等)直链登记。中心机只存链接,文件本身走内网文件服务器</p>
</div>
<div class="head-actions">
<el-select v-model="filter" placeholder="按分类过滤" style="width: 150px" clearable @change="refresh">
<el-select v-model="filter" placeholder="按分类过滤" style="width: 150px" clearable @change="onFilterChange">
<el-option v-for="c in categories" :key="c" :label="c" :value="c" />
</el-select>
<el-button :loading="busy" :icon="Refresh" @click="refresh">刷新</el-button>
@@ -57,6 +57,7 @@
<el-empty description="暂无登记的大文件源" :image-size="80" />
</template>
</el-table>
<PagerBar :total="total" :page="page" :page-size="pageSize" @change="onPageChange" />
</div>
<el-dialog v-model="dlg" title="登记内网直链" width="560px">
@@ -96,32 +97,30 @@
</template>
<script setup>
import { onMounted, ref } from 'vue'
import { onMounted, ref, watch } from 'vue'
import { Refresh, Plus, Delete } from '@element-plus/icons-vue'
import { ElMessage as message, ElMessageBox } from 'element-plus'
import { adminFileSources, adminFileSourceCreate, adminFileSourcePatch, adminFileSourceDelete } from '../api'
import PagerBar from '../components/PagerBar.vue'
import { usePagedList } from '../composables/usePagedList'
const CATS = ['shell', 'chrome']
const categories = CATS
const busy = ref(false)
const rows = ref([])
const filter = ref('')
const list = usePagedList((p, s) => adminFileSources(filter.value || '', p, s), { onError: e => message.error('读取失败:' + (e.message || e)) })
const { items: rows, total, page, size: pageSize, busy, load: refresh, onPageChange, reset } = list
const dlg = ref(false)
const saving = ref(false)
const form = ref({})
async function refresh() {
busy.value = true
try {
const r = await adminFileSources(filter.value || '')
rows.value = r.files || []
const seen = new Set(CATS)
;(r.files || []).forEach((f) => seen.add(f.category))
categories.length = 0
;[...seen].sort().forEach((c) => categories.push(c))
} catch (e) { message.error('读取失败:' + (e.message || e)) }
finally { busy.value = false }
}
function onFilterChange() { reset() }
// 分类下拉:由当前页数据补充实际出现的分类
watch(rows, () => {
const seen = new Set(CATS)
;(rows.value || []).forEach((f) => seen.add(f.category))
categories.length = 0
;[...seen].sort().forEach((c) => categories.push(c))
})
function catType(c) {
return { shell: 'success', chrome: 'warning' }[c] || 'info'
@@ -5,7 +5,7 @@
<h3>权限授权 <span class="badge">Grants</span></h3>
<p>按账号勾选可用插件与可登录平台,保存时仅提交差异项</p>
</div>
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
<el-button :loading="grantDataBusy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<div class="cp-card panel cp-rise">
@@ -25,10 +25,13 @@
<div class="section">
<div class="section-head">
<div class="card-title">插件授权</div>
<el-checkbox :model-value="allChecked" :indeterminate="someChecked" @change="toggleAll">全选</el-checkbox>
<div class="gh-sec-right">
<el-input v-model="pluginKw" placeholder="搜索插件 ID / 名称" clearable :prefix-icon="Search" size="small" style="width: 210px" />
<el-checkbox :model-value="allChecked" :indeterminate="someChecked" @change="toggleAll">全选</el-checkbox>
</div>
</div>
<el-checkbox-group v-model="grantedIds" class="plist">
<div class="prow" v-for="p in plugins" :key="p.id" :class="{ on: grantedIds.includes(p.id) }">
<el-checkbox-group v-model="grantedIds" class="plist" v-loading="grantsBusy">
<div class="prow" v-for="p in visiblePlugins" :key="p.id" :class="{ on: grantedIds.includes(p.id) }">
<el-checkbox :value="p.id" class="pck">
<span class="pname mono">{{ p.id }}</span>
<span class="psub dim">{{ p.name }}</span>
@@ -45,7 +48,7 @@
</div>
</div>
</el-checkbox-group>
<el-empty v-if="!plugins.length" description="暂无插件,请先在「插件管理」上传" :image-size="60" />
<el-empty v-if="!visiblePlugins.length" description="暂无插件,请先在「插件管理」上传" :image-size="60" />
</div>
<!-- 平台授权 -->
@@ -82,19 +85,28 @@
<script setup>
import { computed, onMounted, ref, watch } from 'vue'
import { Refresh, User, Check } from '@element-plus/icons-vue'
import { Refresh, Search, User, Check } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import { overview, overviewBusy, loadOverview } from '../store'
import { adminGrant, adminPlatformGrant, adminPlatforms } from '../api'
import { adminGrant, adminPlatformGrant, adminPlatforms, adminGrantData, adminAccountGrants } from '../api'
const PLATFORM_OPTS = ref([])
const grantDataBusy = ref(false)
const grantsBusy = ref(false)
const plugins = computed(() => overview.value?.plugins || [])
const accounts = computed(() => overview.value?.accounts || [])
// 轻量数据源(/grant_data 一次查询,不依赖 overview 全量聚合)
const plugins = ref([]) // {id,name,status}
const accounts = ref([]) // {account,nickname,dept,status}
const accountOptions = computed(() => accounts.value.map(a => ({
label: a.dept ? `${a.account} · ${a.dept}` : a.account,
label: [a.nickname, a.account, a.dept].filter(Boolean).join(' · '),
value: a.account,
})))
// 插件搜索(数据为全量,前端过滤安全)
const pluginKw = ref('')
const visiblePlugins = computed(() => {
const kw = pluginKw.value.trim().toLowerCase()
if (!kw) return plugins.value
return plugins.value.filter(p => [p.id, p.name].join(' ').toLowerCase().includes(kw))
})
const account = ref('')
const grantedIds = ref([])
@@ -111,26 +123,38 @@ function setGrant(pid, patch) {
function canRun(pid) { return grantState.value[pid]?.canRun !== false }
function canDownload(pid) { return grantState.value[pid]?.canDownload !== false }
// 全选 / 半选
const allChecked = computed(() => plugins.value.length > 0 && grantedIds.value.length === plugins.value.length)
const someChecked = computed(() => grantedIds.value.length > 0 && !allChecked.value)
// 全选 / 半选(基于当前可见插件:搜索后全选 = 全选搜索结果)
const allChecked = computed(() => visiblePlugins.value.length > 0 &&
visiblePlugins.value.every(p => grantedIds.value.includes(p.id)))
const someChecked = computed(() => visiblePlugins.value.some(p => grantedIds.value.includes(p.id)) && !allChecked.value)
function toggleAll(v) {
grantedIds.value = v ? plugins.value.map(p => p.id) : []
const visible = visiblePlugins.value.map(p => p.id)
grantedIds.value = v
? [...new Set([...grantedIds.value, ...visible])]
: grantedIds.value.filter(id => !visible.includes(id))
}
// 选中账号即自动载入其现有授权
watch(account, (acc) => {
const a = accounts.value.find(x => x.account === acc)
const state = {}
;(a?.plugins || []).forEach(pid => {
const g = a?.grants?.[pid] || {}
state[pid] = { granted: true, canRun: g.canRun !== false, canDownload: g.canDownload !== false }
})
heldGrantState = JSON.parse(JSON.stringify(state))
grantState.value = JSON.parse(JSON.stringify(state))
grantedIds.value = [...(a?.plugins || [])]
heldPlatforms = new Set(a?.platforms || [])
platChecked.value = [...heldPlatforms]
// 选中账号即拉取其现有授权(按账号 2 次查询,无 N+1)
watch(account, async (acc) => {
if (!acc) {
grantState.value = {}; grantedIds.value = []; platChecked.value = []
heldGrantState = {}; heldPlatforms = new Set()
return
}
grantsBusy.value = true
try {
const r = await adminAccountGrants(acc)
const state = {}
;(r.plugins || []).forEach(g => {
state[g.plugin_id] = { granted: true, canRun: g.canRun !== false, canDownload: g.canDownload !== false }
})
heldGrantState = JSON.parse(JSON.stringify(state))
grantState.value = JSON.parse(JSON.stringify(state))
grantedIds.value = [...(r.plugins || []).map(g => g.plugin_id)]
heldPlatforms = new Set(r.platforms || [])
platChecked.value = [...heldPlatforms]
} catch (e) { message.error('读取授权失败:' + (e.message || e)) }
finally { grantsBusy.value = false }
})
// 勾选/取消勾选插件时同步 granted 状态
@@ -165,13 +189,14 @@ const platDirty = computed(() => {
const dirtyCount = computed(() => pluginDirty.value.length + platDirty.value.length)
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
async function loadPlatforms() {
grantDataBusy.value = true
try {
const r = await adminPlatforms()
PLATFORM_OPTS.value = (r.platforms || []).map(p => ({ id: p.id, label: p.label }))
} catch (e) { message.error('平台列表读取失败:' + (e.message || e)) }
const [gd, pf] = await Promise.all([adminGrantData(), adminPlatforms()])
plugins.value = gd.plugins || []
accounts.value = gd.accounts || []
PLATFORM_OPTS.value = (pf.platforms || []).map(p => ({ id: p.id, label: p.label }))
} catch (e) { message.error('读取失败:' + (e.message || e)) }
finally { grantDataBusy.value = false }
}
async function savePluginDiff() {
@@ -216,7 +241,7 @@ async function saveAll() {
} catch (e) { message.error('保存失败:' + (e.message || e)) }
finally { saving.value = false }
}
onMounted(() => { refresh(); loadPlatforms() })
onMounted(refresh)
</script>
<style scoped>
@@ -230,6 +255,7 @@ onMounted(() => { refresh(); loadPlatforms() })
.section { margin-top: 24px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.section-head .card-title { margin-bottom: 0; }
.gh-sec-right { display: flex; align-items: center; gap: 14px; }
/* 插件授权行 */
.plist { display: flex; flex-direction: column; gap: 8px; }
@@ -8,18 +8,56 @@
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<div class="stat-grid" v-if="ov">
<div class="stat-card cp-card cp-rise" v-for="(s, i) in stats" :key="s.label" :class="{ wide: s.wide }" :style="{ animationDelay: i * 60 + 'ms' }">
<div class="stat-ic" :style="{ background: s.bg, color: s.color }">
<el-icon :size="20"><component :is="s.icon" /></el-icon>
<template v-if="ov">
<!-- 统计卡(4 列,与下方图表区对齐) -->
<div class="stat-grid">
<div class="stat-card cp-card cp-rise" v-for="(s, i) in stats" :key="s.label" :style="{ animationDelay: i * 60 + 'ms' }">
<div class="stat-ic" :style="{ background: s.bg, color: s.color }">
<el-icon :size="20"><component :is="s.icon" /></el-icon>
</div>
<div class="stat-meta">
<div class="stat-num mono">{{ s.value }}</div>
<div class="stat-label">{{ s.label }}</div>
</div>
<span class="stat-glow" :style="{ background: s.color }"></span>
</div>
<div class="stat-meta">
<div class="stat-num mono" :class="{ sm: s.small }">{{ s.value }}</div>
<div class="stat-label">{{ s.label }}</div>
</div>
<span class="stat-glow" :style="{ background: s.color }"></span>
</div>
</div>
<!-- 图表区(两列独立高度,不拉伸) -->
<div class="ov-grid">
<div class="cp-card cp-rise chart-card">
<div class="card-title">插件状态分布 <span class="sub">已发布 / 停用 / 已撤销</span></div>
<div ref="pieEl" class="pie-chart"></div>
<div class="pie-legend">
<span v-for="c in pieLegend" :key="c.name">
<i :style="{ background: c.color }"></i>{{ c.name }} <b class="mono">{{ c.value }}</b>
</span>
</div>
</div>
<div class="cp-card cp-rise chart-card">
<div class="card-title">授权覆盖 <span class="sub">已授权插件账号 / 账号总数</span></div>
<div ref="gaugeEl" class="gauge-chart"></div>
<div class="gauge-num mono">
<b>{{ authCount }}</b><span class="dim"> / {{ (ov.accounts || []).length }} 个账号已授权插件</span>
</div>
</div>
</div>
<!-- 最近动态 -->
<div class="page-head sub cp-rise">
<div><h4>最近动态</h4></div>
</div>
<div class="cp-card cp-rise feed-card">
<div class="feed-item" v-for="v in recentUploads" :key="v.key">
<span class="feed-dot"></span>
<span class="feed-text mono">{{ v.plugin }}</span>
<el-tag size="small" effect="plain" round type="primary" class="mono">v{{ v.version }}</el-tag>
<span class="feed-time mono dim-sm">{{ fmtTime(v.uploaded_at) }}</span>
</div>
<div v-if="!recentUploads.length" class="empty">暂无上传记录</div>
</div>
</template>
<el-skeleton v-else-if="overviewBusy" animated :rows="3" style="margin-top: 20px" />
<div class="tip-card cp-card cp-rise">
@@ -33,9 +71,16 @@
</template>
<script setup>
import { computed, onMounted } from 'vue'
import { Refresh, InfoFilled, Box, Collection, User, UserFilled, UploadFilled } from '@element-plus/icons-vue'
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { Refresh, InfoFilled, Box, Collection, User, UserFilled } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
// ECharts 按需引入(环图)
import * as echarts from 'echarts/core'
import { PieChart } from 'echarts/charts'
import { TooltipComponent, LegendComponent } from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'
echarts.use([PieChart, TooltipComponent, LegendComponent, CanvasRenderer])
import { store, overview, overviewBusy, loadOverview } from '../store'
import { fmtTime } from '../format'
@@ -47,56 +92,115 @@ const stats = computed(() => {
{ label: '版本总数', value: plugins.reduce((n, p) => n + (p.versions?.length || 0), 0), icon: Collection, color: '#7c5cf6', bg: 'linear-gradient(135deg,#f0ebfe,#e4dcfd)' },
{ label: '账号', value: (ov.value?.accounts || []).length, icon: User, color: '#0f9f9b', bg: 'linear-gradient(135deg,#e4f6f5,#d2efee)' },
{ label: '管理员', value: (ov.value?.admins || []).length, icon: UserFilled, color: '#1d9d5c', bg: 'linear-gradient(135deg,#e5f6ed,#d2efe0)' },
{ label: '最近上传', value: latest(), icon: UploadFilled, color: '#d97706', bg: 'linear-gradient(135deg,#fbf0df,#f6e4c8)', small: true, wide: true },
]
})
function latest() {
const all = (ov.value?.plugins || []).flatMap(p => p.versions || []).map(v => v.uploaded_at).filter(Boolean)
if (!all.length) return '—'
return fmtTime(all.sort().at(-1))
// 最近上传(按时间倒序取 6 条)
const recentUploads = computed(() => {
const items = []
for (const p of ov.value?.plugins || []) {
for (const v of p.versions || []) {
items.push({ key: p.id + v.version, plugin: p.id, version: v.version, uploaded_at: v.uploaded_at })
}
}
return items.filter(i => i.uploaded_at).sort((a, b) => (a.uploaded_at < b.uploaded_at ? 1 : -1)).slice(0, 6)
})
const authCount = computed(() => (ov.value?.accounts || []).filter(a => a.plugins?.length).length)
const pieLegend = computed(() => [
{ name: '已发布', color: '#1d9d5c', value: countStatus('published') },
{ name: '停用', color: '#d97706', value: countStatus('disabled') },
{ name: '已撤销', color: '#d6453d', value: countStatus('revoked') },
])
function countStatus(s) { return (ov.value?.plugins || []).filter(p => p.status === s).length }
// ---------- ECharts ----------
const pieEl = ref(null)
const gaugeEl = ref(null)
let pieChart = null
let gaugeChart = null
function renderCharts() {
if (!ov.value) return
const pieData = pieLegend.value.filter(c => c.value > 0)
if (pieEl.value) {
if (!pieChart) pieChart = echarts.init(pieEl.value)
pieChart.setOption({
tooltip: { trigger: 'item', formatter: '{b}: {c} ({d}%)' },
series: [{
type: 'pie', radius: ['58%', '78%'], center: ['50%', '50%'],
avoidLabelOverlap: true,
itemStyle: { borderRadius: 6, borderColor: '#fffdf8', borderWidth: 2 },
label: { show: false }, emphasis: { label: { show: false } },
data: pieData.map(c => ({ name: c.name, value: c.value, itemStyle: { color: c.color } })),
}],
})
}
const acc = (ov.value.accounts || []).length
const authed = authCount.value
const rate = acc ? Math.round(authed / acc * 100) : 0
if (gaugeEl.value) {
if (!gaugeChart) gaugeChart = echarts.init(gaugeEl.value)
gaugeChart.setOption({
series: [{
type: 'pie', radius: ['62%', '80%'], center: ['50%', '50%'],
silent: true,
label: { show: true, position: 'center', formatter: rate + '%', fontSize: 26, fontWeight: 800, color: '#232a3a' },
data: [
{ value: authed, itemStyle: { color: '#2f5cf0' } },
{ value: acc - authed, itemStyle: { color: 'rgba(35,42,58,.08)' } },
],
}],
})
}
}
// immediate:overview 有缓存(store 模块级)且 force 重拉失败时,ov 不变化也能渲染已有数据
watch(ov, () => nextTick(renderCharts), { immediate: true })
const onResize = () => { pieChart && pieChart.resize(); gaugeChart && gaugeChart.resize() }
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
onMounted(refresh)
onMounted(() => { refresh(); window.addEventListener('resize', onResize) })
onBeforeUnmount(() => { window.removeEventListener('resize', onResize); pieChart && pieChart.dispose(); gaugeChart && gaugeChart.dispose(); pieChart = gaugeChart = null })
</script>
<style scoped>
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
gap: 18px;
}
.stat-card {
display: flex; align-items: center; gap: 16px;
padding: 20px;
overflow: hidden;
}
.stat-card.wide { grid-column: span 2; }
.stat-ic {
width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
display: grid; place-items: center;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7);
}
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { display: flex; align-items: center; gap: 16px; padding: 20px; overflow: hidden; }
.stat-ic { width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0; display: grid; place-items: center; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7); }
.stat-meta { min-width: 0; }
.stat-num { font-size: 27px; font-weight: 800; letter-spacing: .3px; line-height: 1.15; color: var(--cp-ink-1); }
.stat-num.sm { font-size: 18px; font-weight: 700; white-space: nowrap; line-height: 1.4; }
.stat-label { font-size: 12px; color: var(--cp-ink-3); margin-top: 4px; letter-spacing: .3px; }
.stat-glow { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; border-radius: 0 6px 6px 0; opacity: .9; }
.tip-card {
margin-top: 20px;
display: flex; gap: 14px;
padding: 20px 22px;
background: linear-gradient(135deg, rgba(47, 92, 240, .05), rgba(15, 159, 155, .04)), var(--cp-panel);
}
.tip-ic {
width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
display: grid; place-items: center;
background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal));
color: #fff;
box-shadow: 0 8px 16px -8px rgba(47, 92, 240, .6);
}
/* 图表区两列独立高度 */
.ov-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 18px 0 0; align-items: start; }
@media (max-width: 1100px) { .ov-grid { grid-template-columns: 1fr; } }
.chart-card { padding: 20px; }
.card-title { margin-bottom: 10px; }
.card-title .sub { font-size: 11px; font-weight: 500; color: var(--cp-ink-3); margin-left: 4px; }
.pie-chart { height: 210px; }
.gauge-chart { height: 210px; }
.pie-legend { display: flex; justify-content: center; gap: 20px; margin-top: 4px; font-size: 12.5px; color: var(--cp-ink-2); }
.pie-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; }
.pie-legend b { margin-left: 3px; color: var(--cp-ink-1); }
.gauge-num { text-align: center; margin-top: 2px; font-size: 13px; color: var(--cp-ink-2); }
.gauge-num b { font-size: 20px; color: var(--cp-blue); }
.page-head.sub h4 { margin: 0; font-size: 15px; font-weight: 800; color: var(--cp-ink-1); }
.feed-card { padding: 8px 18px; }
.feed-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--cp-line); }
.feed-item:last-child { border-bottom: none; }
.feed-dot { width: 8px; height: 8px; border-radius: 50%; background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal)); flex: none; }
.feed-text { font-size: 13px; color: var(--cp-ink-1); min-width: 120px; }
.feed-time { margin-left: auto; }
.empty { color: var(--cp-ink-3); font-size: 12px; padding: 14px 0; text-align: center; }
.tip-card { margin-top: 20px; display: flex; gap: 14px; padding: 20px 22px; background: linear-gradient(135deg, rgba(47, 92, 240, .05), rgba(15, 159, 155, .04)), var(--cp-panel); }
.tip-ic { width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0; display: grid; place-items: center; background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal)); color: #fff; box-shadow: 0 8px 16px -8px rgba(47, 92, 240, .6); }
.tip-body b { display: block; font-size: 14px; color: var(--cp-ink-1); margin-bottom: 5px; }
.tip-body p { margin: 0; font-size: 12.5px; line-height: 1.8; color: var(--cp-ink-2); }
.dim-sm { color: var(--cp-ink-3); font-size: 12px; }
</style>
@@ -5,7 +5,7 @@
<h3>插件管理 <span class="badge">Plugins</span></h3>
<p>上传发布插件包 · 每插件保留最近 3 个版本,超出自动清理</p>
</div>
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
<el-button :loading="listBusy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<div class="cp-card block cp-rise up-card">
@@ -38,8 +38,11 @@
</div>
<div class="cp-card block cp-rise list-card">
<div class="card-title">插件列表</div>
<el-table :data="plugins" size="small" :loading="overviewBusy" :row-key="r => r.id">
<div class="list-head">
<div class="card-title">插件列表</div>
<el-input v-model="kw" placeholder="搜索插件 ID / 名称" clearable :prefix-icon="Search" size="small" style="width: 230px" @keyup.enter="onSearch" @clear="onSearch" />
</div>
<el-table :data="plugins" size="small" :loading="listBusy" :row-key="r => r.id">
<el-table-column label="插件 ID" min-width="160">
<template #default="{ row }"><b class="cell-strong mono">{{ row.id }}</b></template>
</el-table-column>
@@ -70,6 +73,7 @@
</template>
</el-table-column>
</el-table>
<PagerBar :total="total" :page="page" :page-size="pageSize" @change="onPageChange" />
</div>
<!-- 编辑插件 -->
@@ -199,7 +203,7 @@
<div class="dt-sec">
<div class="ed-sec-title">授权账号</div>
<div class="tags" v-if="detail.accounts?.length">
<el-tag v-for="a in detail.accounts" :key="a" size="small" effect="plain" type="success" round class="mono">{{ a }}</el-tag>
<el-tag v-for="a in detail.accounts" :key="a.account" size="small" effect="plain" type="success" round class="mono">{{ a.nickname ? `${a.nickname} · ${a.account}` : a.account }}</el-tag>
</div>
<span v-else class="dim">未授权任何账号,执行端不可见</span>
</div>
@@ -213,15 +217,19 @@
</template>
<script setup>
import { computed, onMounted, reactive, ref } from 'vue'
import { onMounted, reactive, ref } from 'vue'
import { ElMessage as message, ElMessageBox as dialog } from 'element-plus'
import { Refresh, UploadFilled, FolderOpened, Edit, Delete, View, Box, Files, User, Clock } from '@element-plus/icons-vue'
import { overview, overviewBusy, loadOverview } from '../store'
import { adminUpload, adminPluginDelete, adminPluginPatch } from '../api'
import { Refresh, UploadFilled, FolderOpened, Edit, Delete, View, Box, Files, User, Clock, Search } from '@element-plus/icons-vue'
import { adminPlugins, adminUpload, adminPluginDelete, adminPluginPatch } from '../api'
import { fmtTime } from '../format'
import PagerBar from '../components/PagerBar.vue'
import { usePagedList } from '../composables/usePagedList'
const plugins = computed(() => overview.value?.plugins || [])
const kw = ref('')
const list = usePagedList((p, s) => adminPlugins(p, s, kw.value), { onError: e => message.error('读取失败:' + (e.message || e)) })
const { items: plugins, total, page, size: pageSize, busy: listBusy, load: refresh, onPageChange, reset } = list
const pid = ref(''); const pname = ref(''); const pver = ref(''); const pfile = ref(null)
function onSearch() { reset() }
const uploading = ref(false)
const upRef = ref()
@@ -286,9 +294,6 @@ async function saveEdit() {
finally { saving.value = false }
}
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
async function upload() {
if (!pid.value || !pver.value || !pfile.value) { message.warning('请填写插件 ID / 版本并选择 ZIP 包'); return }
uploading.value = true
@@ -317,6 +322,8 @@ onMounted(refresh)
<style scoped>
.up-card, .list-card { padding: 20px 22px; }
.up-card .card-title { margin-bottom: 16px; }
.list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.list-head .card-title { margin-bottom: 0; }
.up-form :deep(.el-form-item) { margin-bottom: 16px; }
.file-row { display: flex; align-items: center; gap: 10px; }
.hint { font-size: 12px; color: var(--cp-ink-3); margin-top: 2px; line-height: 1.7; }
@@ -2,19 +2,17 @@
<div class="page">
<div class="page-head cp-rise">
<div>
<h3>运行统计 <span class="badge">Stats</span></h3>
<p>账号 · 插件规模 · 执行次数/时长/成败 · 近 14 天趋势</p>
<h3>数据看板 <span class="badge">Stats</span></h3>
<p>运行统计 · 近 14 天趋势曲线 · 插件/用户排行 · 最近运行记录(分页)</p>
</div>
<el-button :loading="busy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<template v-if="st">
<!-- 指标卡 -->
<!-- KPI -->
<div class="kpis cp-rise">
<div class="kpi cp-card" v-for="(k, i) in kpis" :key="k.label" :style="{ animationDelay: i * 50 + 'ms' }">
<div class="kpi-ic" :style="{ background: k.bg, color: k.color }">
<el-icon :size="18"><component :is="k.icon" /></el-icon>
</div>
<div class="kpi-ic" :style="{ background: k.bg, color: k.color }"><el-icon :size="17"><component :is="k.icon" /></el-icon></div>
<div class="kpi-meta">
<div class="kpi-num mono" :style="{ color: k.color }">{{ k.value }}</div>
<div class="kpi-lab">{{ k.label }}</div>
@@ -22,68 +20,55 @@
</div>
</div>
<div class="grid">
<!-- 近 14 天趋势 -->
<div class="cp-card trend-card cp-rise">
<div class="card-title">近 14 天运行趋势</div>
<div class="trend">
<div class="tcol" v-for="d in st.trend" :key="d.day" :title="`${d.day} · ${d.runs} 次(成功 ${d.success} / 失败 ${d.failed})`">
<div class="tstack">
<div class="tbar failed" :style="{ height: pct(d.failed, maxRuns) + '%' }"></div>
<div class="tbar success" :style="{ height: pct(d.success, maxRuns) + '%' }"></div>
<!-- 趋势曲线(全宽置顶) -->
<div class="cp-card cp-rise chart-card">
<div class="card-title">近 14 天运行趋势 <span class="sub">成功 / 失败 · 平滑曲线</span></div>
<div ref="trendEl" class="chart"></div>
</div>
<!-- 排行(两列左右分布) -->
<div class="rank-grid">
<div class="cp-card cp-rise rank-card">
<div class="card-title">插件排行 <span class="sub">按触发次数</span></div>
<ul class="rank" v-if="st.topPlugins.length">
<li v-for="(p, i) in st.topPlugins" :key="p.pluginId">
<span class="rk" :class="{ top: i < 3 }">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead">
<span class="rname">{{ p.name }}</span>
<em>{{ p.runs }} 次</em>
</div>
<div class="rbar"><i :style="{ width: Math.round(p.runs / rankMax(st.topPlugins) * 100) + '%' }"></i></div>
</div>
<span class="tday mono">{{ d.day }}</span>
</div>
</div>
<div class="trend-legend">
<span><i class="dot ok"></i>成功</span>
<span><i class="dot fail"></i>失败</span>
</div>
</li>
</ul>
<div v-else class="empty">暂无运行数据</div>
</div>
<!-- 插件 / 用户排行 -->
<div class="rank-wrap">
<div class="cp-card rank-card cp-rise">
<div class="card-title">插件排行 <span class="sub">按运行次数</span></div>
<ul class="rank">
<li v-for="(p, i) in st.topPlugins" :key="p.pluginId">
<span class="rk mono" :class="{ top: i < 3 }">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead">
<span class="rname mono">{{ p.name || p.pluginId }}</span>
<em class="mono">{{ p.runs }} 次</em>
</div>
<div class="rbar"><i :style="{ width: pct(p.runs, rankMax(st.topPlugins)) + '%' }"></i></div>
<div class="cp-card cp-rise rank-card">
<div class="card-title">活跃用户 <span class="sub">按执行次数</span></div>
<ul class="rank" v-if="st.topUsers.length">
<li v-for="(u, i) in st.topUsers" :key="u.account">
<span class="rk" :class="{ top: i < 3 }">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead">
<span class="rname mono">{{ u.nickname ? `${u.nickname} · ${u.account}` : u.account }}</span>
<em>{{ u.runs }} 次</em>
</div>
</li>
<li v-if="!st.topPlugins.length" class="empty">暂无运行记录</li>
</ul>
</div>
<div class="cp-card rank-card cp-rise">
<div class="card-title">活跃用户 <span class="sub">按运行次数</span></div>
<ul class="rank">
<li v-for="(u, i) in st.topUsers" :key="u.account">
<span class="rk mono" :class="{ top: i < 3 }">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead">
<span class="rname mono">{{ u.account }}</span>
<em class="mono">{{ u.runs }} 次</em>
</div>
<div class="rbar"><i :style="{ width: pct(u.runs, rankMax(st.topUsers)) + '%' }"></i></div>
</div>
</li>
<li v-if="!st.topUsers.length" class="empty">暂无运行记录</li>
</ul>
</div>
<div class="rbar"><i :style="{ width: Math.round(u.runs / rankMax(st.topUsers) * 100) + '%' }"></i></div>
</div>
</li>
</ul>
<div v-else class="empty">暂无执行记录</div>
</div>
</div>
<!-- 最近运行 -->
<!-- 最近运行(后端分页) -->
<div class="page-head sub cp-rise">
<div><h4>最近运行</h4></div>
</div>
<div class="cp-card cp-rise recent-card">
<el-table :data="st.recent" size="small" :row-key="r => r.at + r.pluginId">
<el-table :data="recent" size="small" v-loading="recentBusy" :row-key="r => r.id">
<el-table-column label="时间" width="170">
<template #default="{ row }"><span class="mono dim-sm">{{ fmtTime(row.at) }}</span></template>
</el-table-column>
@@ -92,13 +77,9 @@
<span class="status-dot"><i :style="{ background: statusColor(row.status) }"></i><span :style="{ color: statusColor(row.status) }">{{ statusLabel(row.status) }}</span></span>
</template>
</el-table-column>
<el-table-column label="账号" width="140">
<el-table-column label="账号" width="150">
<template #default="{ row }">
<div class="acct" v-if="row.nickname">
<div class="ann">{{ row.account }}</div>
<div class="anick">{{ row.nickname }}</div>
</div>
<span v-else>{{ row.account || '—' }}</span>
<span class="mono">{{ row.nickname ? `${row.nickname} · ${row.account}` : (row.account || '—') }}</span>
</template>
</el-table-column>
<el-table-column label="插件" width="160" show-overflow-tooltip>
@@ -110,12 +91,11 @@
<el-table-column label="时长" width="100">
<template #default="{ row }"><span class="mono">{{ fmtDur(row.durationSec) }}</span></template>
</el-table-column>
<el-table-column label="信息" min-width="220" show-overflow-tooltip>
<template #default="{ row }">
<span :class="{ dim: !row.msg }">{{ row.msg || '—' }}</span>
</template>
<el-table-column label="信息" min-width="200" show-overflow-tooltip>
<template #default="{ row }"><span :class="{ dim: !row.msg }">{{ row.msg || '—' }}</span></template>
</el-table-column>
</el-table>
<PagerBar :total="recentTotal" :page="page" :page-size="pageSize" @change="onPageChange" />
</div>
</template>
@@ -125,22 +105,37 @@
</template>
<script setup>
import { computed, onMounted, ref } from 'vue'
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
import { Refresh, User, Box, VideoPlay, CircleCheckFilled, CircleCloseFilled, Timer } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import { adminStats } from '../api'
// ECharts 按需引入(折线图),避免全量包
import * as echarts from 'echarts/core'
import { LineChart } from 'echarts/charts'
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
import { CanvasRenderer } from 'echarts/renderers'
echarts.use([LineChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer])
import { adminStats, adminReports } from '../api'
import { fmtTime } from '../format'
import PagerBar from '../components/PagerBar.vue'
const busy = ref(false)
const st = ref(null)
// 最近运行:独立走 /api/admin/reports 后端分页(数据增长无压力)
import { usePagedList } from '../composables/usePagedList'
const recentList = usePagedList((p, s) => adminReports(p, s), { onError: e => message.error('读取失败:' + (e.message || e)) })
const { items: recent, total: recentTotal, page, size: pageSize, busy: recentBusy, load: loadRecent, onPageChange } = recentList
const kpis = computed(() => {
if (!st.value) return []
const r = st.value
// 累计执行 = 成功 + 失败(已完成任务数,口径一致);触发数 start(含运行中/中断残留)不作为累计
const finished = (r.runs.success || 0) + (r.runs.failed || 0)
return [
{ label: '用户总数', value: r.users.total, icon: User, color: '#2f5cf0', bg: 'linear-gradient(135deg,#e8edfe,#d7e1fd)' },
{ label: '插件总数', value: r.plugins.total, icon: Box, color: '#7c5cf6', bg: 'linear-gradient(135deg,#f0ebfe,#e4dcfd)' },
{ label: '累计执行', value: r.runs.total, icon: VideoPlay, color: '#0f9f9b', bg: 'linear-gradient(135deg,#e4f6f5,#d2efee)' },
{ label: '累计执行', value: finished, icon: VideoPlay, color: '#0f9f9b', bg: 'linear-gradient(135deg,#e4f6f5,#d2efee)' },
{ label: '成功', value: r.runs.success, icon: CircleCheckFilled, color: '#1d9d5c', bg: 'linear-gradient(135deg,#e5f6ed,#d2efe0)' },
{ label: '失败', value: r.runs.failed, icon: CircleCloseFilled, color: '#d6453d', bg: 'linear-gradient(135deg,#fbe9e8,#f6d8d6)' },
{ label: '总运行时长', value: fmtDur(r.runs.durationSec), icon: Timer, color: '#d97706', bg: 'linear-gradient(135deg,#fbf0df,#f6e4c8)' },
@@ -151,7 +146,7 @@ function statusColor(s) {
return { done: '#1d9d5c', success: '#1d9d5c', error: '#d6453d', failed: '#d6453d', running: '#2f5cf0', start: '#2f5cf0' }[s] || '#9aa2b4'
}
function statusLabel(s) {
return (s === 'done' || s === 'success') ? '成功' : (s === 'error' || s === 'failed') ? '失败' : s
return ({ done: '成功', success: '成功', error: '失败', failed: '失败', running: '运行中', start: '已触发' })[s] || s
}
function fmtDur(sec) {
sec = +sec || 0
@@ -161,10 +156,40 @@ function fmtDur(sec) {
const hh = Math.floor(m / 60)
return `${hh}h${m % 60}m`
}
const maxRuns = () => Math.max(1, ...(st.value?.trend || []).map(t => t.runs || 0))
const pct = (n, max) => Math.max(2, Math.round((n || 0) / (max || 1) * 100))
const rankMax = list => Math.max(1, ...(list || []).map(x => x.runs || 1))
// ---------- ECharts 趋势曲线 ----------
const trendEl = ref(null)
let chart = null
function renderTrend() {
if (!st.value || !trendEl.value) return
if (!chart) chart = echarts.init(trendEl.value)
chart.setOption({
tooltip: { trigger: 'axis', backgroundColor: 'rgba(35,42,58,.92)', borderWidth: 0, textStyle: { color: '#fff', fontSize: 12 } },
legend: { data: ['成功', '失败'], right: 4, top: 0, icon: 'roundRect', itemWidth: 14, itemHeight: 5, textStyle: { color: '#6b7488', fontSize: 12 } },
grid: { left: 36, right: 16, top: 36, bottom: 24 },
xAxis: { type: 'category', boundaryGap: false, data: st.value.trend.map(t => t.day),
axisLine: { lineStyle: { color: 'rgba(35,42,58,.16)' } }, axisTick: { show: false },
axisLabel: { fontSize: 10.5, color: '#9aa2b4' } },
yAxis: { type: 'value', minInterval: 1, splitLine: { lineStyle: { color: 'rgba(35,42,58,.07)' } },
axisLabel: { fontSize: 10.5, color: '#9aa2b4' } },
series: [
{ name: '成功', type: 'line', smooth: true, symbolSize: 6, data: st.value.trend.map(t => t.success || 0),
lineStyle: { width: 2.6, color: '#1d9d5c' }, itemStyle: { color: '#1d9d5c' },
areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [
{ offset: 0, color: 'rgba(29,157,92,.20)' }, { offset: 1, color: 'rgba(29,157,92,.01)' }] } } },
{ name: '失败', type: 'line', smooth: true, symbolSize: 6, data: st.value.trend.map(t => t.failed || 0),
lineStyle: { width: 2.6, color: '#d6453d' }, itemStyle: { color: '#d6453d' },
areaStyle: { color: { type: 'linear', x: 0, y: 0, x2: 0, y2: 1, colorStops: [
{ offset: 0, color: 'rgba(214,69,61,.16)' }, { offset: 1, color: 'rgba(214,69,61,.01)' }] } } },
],
})
}
watch(st, () => nextTick(renderTrend))
const onResize = () => chart && chart.resize()
// ---------- 数据 ----------
async function refresh() {
busy.value = true
try {
@@ -172,57 +197,39 @@ async function refresh() {
st.value = {
users: r.users || {}, plugins: r.plugins || {}, runs: r.runs || {},
trend: r.trend || [], topPlugins: r.topPlugins || [], topUsers: r.topUsers || [],
recent: r.recent || [],
}
await loadRecent()
} catch (e) { message.error('读取失败:' + (e.message || e)) }
finally { busy.value = false }
}
onMounted(refresh)
onMounted(() => { refresh(); window.addEventListener('resize', onResize) })
onBeforeUnmount(() => { window.removeEventListener('resize', onResize); chart && chart.dispose(); chart = null })
</script>
<style scoped>
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi {
display: flex; align-items: center; gap: 14px;
padding: 18px;
}
.kpi-ic {
width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0;
display: grid; place-items: center;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7);
}
.kpi { display: flex; align-items: center; gap: 14px; padding: 18px; }
.kpi-ic { width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0; display: grid; place-items: center; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7); }
.kpi-meta { min-width: 0; }
.kpi-num { font-size: 24px; font-weight: 800; line-height: 1.1; }
.kpi-lab { font-size: 12px; color: var(--cp-ink-3); margin-top: 4px; letter-spacing: .3px; }
.grid { display: grid; grid-template-columns: 1.45fr 1fr; gap: 18px; margin-bottom: 20px; }
@media (max-width: 1100px) { .grid { grid-template-columns: 1fr; } }
.rank-wrap { display: flex; flex-direction: column; gap: 18px; }
.trend-card, .rank-card { padding: 20px; }
.card-title { margin-bottom: 16px; }
/* 趋势图全宽置顶 */
.chart-card { padding: 20px; margin-bottom: 18px; }
.chart { height: 320px; }
/* 排行两列左右分布 */
.rank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 20px; }
@media (max-width: 900px) { .rank-grid { grid-template-columns: 1fr; } }
.rank-card { padding: 20px; }
.card-title { margin-bottom: 14px; }
.card-title .sub { font-size: 11px; font-weight: 500; color: var(--cp-ink-3); margin-left: 4px; }
.trend { display: flex; gap: 5px; height: 176px; align-items: stretch; }
.tcol { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; }
.tstack { flex: 1; display: flex; align-items: flex-end; gap: 2px; width: 100%; }
.tbar { flex: 1; border-radius: 3px 3px 0 0; transition: filter .18s, transform .18s; }
.tbar.success { background: linear-gradient(180deg, #34b877, #1d9d5c); }
.tbar.failed { background: linear-gradient(180deg, #f07a72, #d6453d); }
.tcol:hover .tbar { filter: brightness(1.05); }
.tday { font-size: 10px; color: var(--cp-ink-3); }
.trend-legend { display: flex; gap: 18px; margin-top: 14px; font-size: 12px; color: var(--cp-ink-2); }
.trend-legend .dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; margin-right: 6px; }
.trend-legend .ok { background: #1d9d5c; }
.trend-legend .fail { background: #d6453d; }
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: flex; align-items: center; gap: 11px; padding: 8px 0; }
.rank .rk {
width: 24px; height: 24px; flex: none; border-radius: 8px;
background: var(--cp-panel-2); color: var(--cp-ink-3);
font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.rank li { display: flex; align-items: center; gap: 11px; padding: 7px 0; }
.rank .rk { width: 24px; height: 24px; flex: none; border-radius: 8px; background: var(--cp-panel-2); color: var(--cp-ink-3); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.rank .rk.top { background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal)); color: #fff; box-shadow: 0 4px 10px -4px rgba(47, 92, 240, .5); }
.rank .rbody { flex: 1; min-width: 0; }
.rhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 10px; }
@@ -230,10 +237,12 @@ onMounted(refresh)
.rhead em { font-style: normal; font-size: 11.5px; color: var(--cp-ink-3); flex: none; }
.rbar { height: 6px; border-radius: 4px; background: var(--cp-panel-2); overflow: hidden; }
.rbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cp-blue), var(--cp-teal)); border-radius: 4px; transition: width .6s cubic-bezier(.22, .61, .36, 1); }
.empty { color: var(--cp-ink-3); font-size: 12px; justify-content: center; padding: 18px 0 !important; }
.empty { color: var(--cp-ink-3); font-size: 12px; justify-content: center; padding: 18px 0 !important; display: flex; }
.empty-tip { padding: 40px; text-align: center; color: var(--cp-ink-3); }
.page-head.sub h4 { margin: 0; font-size: 15px; font-weight: 800; color: var(--cp-ink-1); }
.recent-card { padding: 12px 16px; }
.dim-sm { color: var(--cp-ink-2); }
.dim-sm { color: var(--cp-ink-2); font-size: 12px; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.status-dot i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
</style>