refactor: 整体迁移控制面至MySQL + 替换UI框架为Element Plus

1. 移除naive-ui依赖,迁移前端至Element Plus
2. 重构后端数据库层,切换为MySQL替代SQLite
3. 调整项目部署架构,停止exe打包改为源码部署
4. 新增设备上报接口与相关数据库模型
5. 优化配置路径与SQL语法,替换为MySQL占位符格式
6. 调整站点名称与文案,统一为「37du 插件管理平台」
7. 新增SQLite到MySQL迁移脚本
This commit is contained in:
2026-09-16 15:58:45 +08:00
parent 813bee743b
commit 6d2dd93628
54 changed files with 5542 additions and 1890 deletions
+92 -91
View File
@@ -1,49 +1,56 @@
<template>
<n-config-provider :theme-overrides="themeOverrides" :locale="zhCN" :date-locale="dateZhCN">
<LoginPage v-if="!store.current" :app-name="store.appName" @ok="onLogin" />
<div class="console" v-else>
<header class="topbar">
<div class="brand">
<span class="logo">37</span>
<div class="brand-meta">
<strong>{{ store.appName }}</strong>
<span>中心机 · 控制面</span>
</div>
<LoginPage v-if="!store.current" :app-name="store.appName" @ok="onLogin" />
<div class="console" v-else>
<header class="topbar">
<div class="brand">
<span class="logo">37</span>
<div class="brand-meta">
<strong>{{ store.appName }}</strong>
<span>中心机 · 控制面</span>
</div>
<div class="spacer"></div>
<n-dropdown trigger="click" :options="acctOptions" @select="onCommand">
<div class="acct">
<span class="avatar">{{ initial }}</span>
<span class="acct-name">{{ store.nickname || store.current }}</span>
<n-tag v-if="store.isAdmin" size="small" round :bordered="false" type="primary" class="admin-tag">管理员</n-tag>
<n-icon class="caret" :size="13"><ArrowDown /></n-icon>
</div>
</n-dropdown>
</header>
<div class="body">
<aside class="aside">
<div class="aside-inner">
<n-menu class="menu" :value="activeKey" :options="menuOptions" :root-indent="0" @update:value="onMenu" />
</div>
<div class="aside-foot">
<span>37du 自动化</span>
<span class="ver">v0.1.0</span>
</div>
</aside>
<main class="main">
<component :is="viewComp" :key="route" />
</main>
</div>
<div class="spacer"></div>
<el-dropdown trigger="click" @command="onCommand">
<div class="acct">
<span class="avatar">{{ initial }}</span>
<span class="acct-name">{{ store.nickname || store.current }}</span>
<el-tag v-if="store.isAdmin" size="small" type="primary" round effect="light" class="admin-tag">管理员</el-tag>
<el-icon class="caret"><ArrowDown /></el-icon>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="pwd"><el-icon><Lock /></el-icon>修改密码</el-dropdown-item>
<el-dropdown-item divided command="logout"><el-icon><SwitchButton /></el-icon>退出登录</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</header>
<div class="body">
<aside class="aside">
<div class="aside-inner">
<el-menu :default-active="activeKey" @select="onMenu">
<el-menu-item v-for="m in menuOptions" :key="m.key" :index="m.key">
<el-icon><component :is="m.icon" /></el-icon>
<span>{{ m.label }}</span>
</el-menu-item>
</el-menu>
</div>
</aside>
<main class="main">
<transition name="view-fade" mode="out-in">
<component :is="viewComp" :key="route" />
</transition>
</main>
</div>
<PasswordDialog v-model="pwdOpen" />
</n-config-provider>
</div>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue'
import { ArrowDown } from '@element-plus/icons-vue'
import { themeOverrides, zhCN, dateZhCN, message } from './naive'
import { ArrowDown, Lock, SwitchButton, Odometer, TrendCharts, Box, User, Key, Document } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import LoginPage from './components/LoginPage.vue'
import PasswordDialog from './components/PasswordDialog.vue'
import OverviewView from './views/OverviewView.vue'
@@ -56,20 +63,15 @@ import { store, clearSession } from './store'
import { adminMe } from './api'
const menuOptions = [
{ label: '概览', key: 'overview' },
{ label: '数据看板', key: 'stats' },
{ label: '插件管理', key: 'plugins' },
{ label: '账号管理', key: 'accounts' },
{ label: '权限授权', key: 'grants' },
{ label: '审计报表', key: 'audit' },
]
const acctOptions = [
{ label: '修改密码', key: 'pwd' },
{ type: 'divider', key: 'd1' },
{ label: '退出登录', key: 'logout' },
{ label: '概览', key: 'overview', icon: Odometer },
{ label: '数据看板', key: 'stats', icon: TrendCharts },
{ label: '插件管理', key: 'plugins', icon: Box },
{ label: '账号管理', key: 'accounts', icon: User },
{ label: '权限授权', key: 'grants', icon: Key },
{ label: '审计报表', key: 'audit', icon: Document },
]
// 轻量 hash 路由:StaticFiles(html=True) 下刷新安全,零后端改动
// 轻量 hash 路由:静态站刷新安全,零后端改动
const KEY = {
'#/overview': 'overview',
'#/stats': 'stats',
@@ -129,71 +131,67 @@ onMounted(async () => {
<style scoped>
.console { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
/* ---------- 顶栏:磨砂玻璃 ---------- */
/* ---------- 顶栏:纸白面板 ---------- */
.topbar {
height: 64px; flex-shrink: 0;
display: flex; align-items: center; gap: 16px;
padding: 0 24px;
background: rgba(255, 255, 255, .72);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border-bottom: 1px solid var(--cp-border);
padding: 0 26px;
background: rgba(255, 253, 248, .86);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border-bottom: 1px solid var(--cp-line);
box-shadow: 0 6px 20px -18px rgba(35, 42, 58, .3);
position: relative; z-index: 20;
}
.topbar::after {
content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
background: linear-gradient(90deg, transparent, rgba(59, 108, 255, .35), rgba(34, 199, 232, .35), transparent);
background: linear-gradient(90deg, transparent, rgba(47, 92, 240, .4), rgba(15, 159, 155, .4), transparent);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
width: 38px; height: 38px; border-radius: 12px;
display: grid; place-items: center; position: relative;
background: linear-gradient(135deg, #3b6cff 0%, #22c7e8 130%);
background: linear-gradient(135deg, var(--cp-blue) 0%, var(--cp-teal) 140%);
color: #fff; font-size: 14px; font-weight: 800; letter-spacing: .5px;
box-shadow: 0 6px 16px -6px rgba(59, 108, 255, .6);
box-shadow: 0 8px 18px -8px rgba(47, 92, 240, .55);
}
.logo::after { content: ''; position: absolute; inset: 2px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .28); }
.logo::after { content: ''; position: absolute; inset: 2px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .3); }
.brand-meta { display: flex; flex-direction: column; line-height: 1.25; }
.brand-meta strong { font-size: 15px; color: var(--cp-ink); letter-spacing: .2px; }
.brand-meta strong { font-size: 15px; color: var(--cp-ink-1); letter-spacing: .2px; }
.brand-meta span { font-size: 11px; color: var(--cp-ink-3); letter-spacing: .4px; }
.spacer { flex: 1; }
.acct {
display: flex; align-items: center; gap: 9px; cursor: pointer;
padding: 6px 10px; border-radius: 12px; transition: background .18s;
padding: 6px 12px; border-radius: 12px; border: 1px solid transparent;
transition: background .18s, border-color .18s;
}
.acct:hover { background: rgba(59, 108, 255, .07); }
.acct:hover { background: rgba(47, 92, 240, .06); border-color: rgba(47, 92, 240, .16); }
.avatar {
width: 30px; height: 30px; border-radius: 50%;
display: grid; place-items: center;
background: linear-gradient(135deg, #3b6cff, #22c7e8);
background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal));
color: #fff; font-size: 13px; font-weight: 700;
}
.acct-name { font-size: 13px; font-weight: 600; color: var(--cp-ink); }
.acct-name { font-size: 13px; font-weight: 700; color: var(--cp-ink-1); }
.admin-tag { margin-left: 2px; }
.caret { color: var(--cp-ink-3); }
/* ---------- 主体:悬浮侧栏 + 内容区 ---------- */
.body { flex: 1; display: flex; gap: 18px; padding: 18px 24px 24px; min-height: 0; }
/* ---------- 主体:侧栏 + 内容区(紧凑间距,避免挤压表格) ---------- */
.body { flex: 1; display: flex; gap: 12px; padding: 14px 18px 22px; min-height: 0; }
.aside {
width: 208px; flex-shrink: 0;
width: 192px; flex-shrink: 0;
display: flex; flex-direction: column;
background: rgba(255, 255, 255, .78);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border: 1px solid var(--cp-border);
border-radius: 18px;
box-shadow: var(--cp-card-shadow);
padding: 14px 10px;
background: rgba(255, 253, 248, .8);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border: 1px solid var(--cp-line);
border-radius: 16px;
box-shadow: var(--cp-shadow);
padding: 12px 8px;
}
.aside-inner { flex: 1; }
.aside-foot {
display: flex; align-items: center; justify-content: space-between;
padding: 12px 12px 4px; margin-top: 8px;
border-top: 1px dashed var(--cp-border);
font-size: 11px; color: var(--cp-ink-3);
}
.main { flex: 1; min-width: 0; overflow: auto; padding: 4px 4px 8px; }
.main { flex: 1; min-width: 0; overflow: auto; padding: 0 2px 8px; }
/* 页面切换过渡:轻微上浮淡入 */
.view-fade-enter-active { transition: opacity .22s ease, transform .22s ease; }
@@ -201,15 +199,18 @@ onMounted(async () => {
.view-fade-enter-from { opacity: 0; transform: translateY(8px); }
.view-fade-leave-to { opacity: 0; }
/* ---------- 侧栏菜单:干净的标准导航,配色由 naive 主题统一控制 ---------- */
.menu { padding: 2px; }
.menu :deep(.n-menu-item) { margin-bottom: 4px; }
.menu :deep(.n-menu-item-content) {
/* 无图标时 naive 给 `padding-left:0` 的内联样式,需 !important 压过,
否则文字贴左边界、跑出圆角底色区域 */
padding-left: 16px !important;
padding-right: 16px !important;
border-radius: 10px;
box-sizing: border-box;
/* ---------- 侧栏菜单:纸面导航 ---------- */
.aside :deep(.el-menu-item) {
height: 44px; margin-bottom: 4px;
border-radius: 11px;
font-weight: 600; color: var(--cp-ink-2);
}
.aside :deep(.el-menu-item:hover) { background: rgba(47, 92, 240, .06); color: var(--cp-blue); }
.aside :deep(.el-menu-item.is-active) {
background: linear-gradient(90deg, rgba(47, 92, 240, .12), rgba(47, 92, 240, .04));
color: var(--cp-blue);
font-weight: 700;
box-shadow: inset 3px 0 0 var(--cp-blue);
}
.aside :deep(.el-menu-item .el-icon) { font-size: 17px; }
</style>
@@ -1,6 +1,6 @@
<template>
<div class="login">
<div class="card">
<div class="card cp-rise">
<div class="brand">
<span class="logo">37</span>
<div class="brand-meta">
@@ -9,35 +9,19 @@
</div>
</div>
<n-form class="form" label-placement="top" @keydown.enter.prevent="doLogin">
<n-form-item label="账号">
<n-input
v-model:value="account"
placeholder="请输入账号"
autocomplete="username"
size="large"
@keyup.enter="doLogin"
>
<template #prefix><n-icon><User /></n-icon></template>
</n-input>
</n-form-item>
<n-form-item label="密码">
<n-input
v-model:value="password"
type="password"
placeholder="请输入密码"
autocomplete="current-password"
size="large"
show-password-on="click"
@keyup.enter="doLogin"
>
<template #prefix><n-icon><Lock /></n-icon></template>
</n-input>
</n-form-item>
<n-button type="primary" size="large" block class="primary" :loading="busy" @click="doLogin">
<el-form class="form" label-position="top" @keyup.enter="doLogin">
<el-form-item label="账号">
<el-input v-model="account" placeholder="请输入账号" autocomplete="username" size="large"
:prefix-icon="User" @keyup.enter="doLogin" />
</el-form-item>
<el-form-item label="密码">
<el-input v-model="password" type="password" placeholder="请输入密码" autocomplete="current-password"
size="large" :prefix-icon="Lock" show-password @keyup.enter="doLogin" />
</el-form-item>
<el-button type="primary" size="large" class="primary" :loading="busy" @click="doLogin">
{{ busy ? '登录中…' : '登 录' }}
</n-button>
</n-form>
</el-button>
</el-form>
<div class="foot">内网管理面 · 请使用管理员账号登录</div>
</div>
@@ -47,9 +31,9 @@
<script setup>
import { ref } from 'vue'
import { User, Lock } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import { adminLogin } from '../api'
import { store } from '../store.js'
import { message } from '../naive'
const props = defineProps({ appName: { type: String, default: '37du 自动化工作台' } })
const emit = defineEmits(['ok'])
@@ -71,7 +55,7 @@ async function doLogin() {
store.token = r.token || ''
store.isAdmin = true
store.nickname = r.nickname || ''
try { localStorage.setItem('cp_account', acct); localStorage.setItem('cp_token', store.token) } catch (_) {}
try { localStorage.setItem('cp_account', acct); localStorage.setItem('cp_token', store.token) } catch (_) { }
message.success(`欢迎,${store.nickname || acct}`)
emit('ok', r)
} catch (e) {
@@ -90,37 +74,111 @@ async function doLogin() {
justify-content: center;
padding: 24px;
box-sizing: border-box;
background: linear-gradient(180deg, #f7f8fa 0%, #eef0f4 100%);
font-family: var(--font-body, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', sans-serif);
}
.card {
width: 380px;
width: 404px;
box-sizing: border-box;
background: #ffffff;
border: 1px solid var(--cp-border, #e5e7ec);
border-radius: 16px;
padding: 34px 32px 28px;
box-shadow: 0 16px 40px -24px rgba(30, 42, 76, .25);
position: relative;
background: var(--cp-panel);
border: 1px solid var(--cp-line);
border-radius: 22px;
padding: 40px 36px 28px;
box-shadow: 0 26px 64px -30px rgba(35, 42, 58, .45);
}
/* 顶部渐变描边 */
.card::before {
content: '';
position: absolute;
top: 0;
left: 30px;
right: 30px;
height: 2px;
background: linear-gradient(90deg, transparent, var(--cp-blue), var(--cp-teal), transparent);
border-radius: 2px;
}
/* 纸面噪点质感 */
.card::after {
content: '';
position: absolute;
inset: 0;
border-radius: 22px;
pointer-events: none;
opacity: .5;
background-image: radial-gradient(rgba(35, 42, 58, .08) 0.5px, transparent 0.5px);
background-size: 5px 5px;
}
.brand {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 30px;
position: relative;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 28px; }
.logo {
width: 42px; height: 42px; border-radius: 12px; flex: none;
display: grid; place-items: center;
background: linear-gradient(135deg, #3b6cff 0%, #22c7e8 130%);
color: #fff; font-size: 15px; font-weight: 800; letter-spacing: .4px;
box-shadow: 0 8px 18px -8px rgba(59, 108, 255, .55);
width: 46px;
height: 46px;
border-radius: 14px;
flex: none;
display: grid;
place-items: center;
position: relative;
background: linear-gradient(135deg, var(--cp-blue) 0%, var(--cp-teal) 140%);
color: #fff;
font-size: 15px;
font-weight: 800;
letter-spacing: .4px;
box-shadow: 0 10px 22px -10px rgba(47, 92, 240, .6);
}
.brand-meta h1 { margin: 0; font-size: 17px; font-weight: 700; color: var(--cp-ink, #1c2433); letter-spacing: .2px; }
.brand-meta p { margin: 3px 0 0; font-size: 12px; color: var(--cp-ink-3, #8a93a6); }
.form :deep(.n-form-item) { margin-bottom: 20px; }
.form :deep(.n-form-item-label) { font-size: 12.5px; font-weight: 600; color: var(--cp-ink-2, #4a5270); padding-bottom: 6px; }
.form :deep(.n-input) { border-radius: 8px; }
.form :deep(.n-input__inner) { font-size: 14px; }
.logo::after {
content: '';
position: absolute;
inset: 2px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, .3);
}
.primary.n-button--primary-type { height: 44px; border-radius: 8px; font-size: 14px; letter-spacing: .1em; }
.brand-meta h1 {
margin: 0;
font-size: 17px;
font-weight: 800;
color: var(--cp-ink-1);
letter-spacing: .2px;
}
.foot { margin-top: 20px; text-align: center; font-size: 11.5px; color: var(--cp-ink-3, #8a93a6); }
</style>
.brand-meta p {
margin: 4px 0 0;
font-size: 12px;
color: var(--cp-ink-3);
letter-spacing: .4px;
}
.form { position: relative; }
.form .el-form-item { margin-bottom: 20px; }
.form .el-form-item__label { font-size: 12.5px; font-weight: 700; padding-bottom: 6px; }
.form .el-input__wrapper { border-radius: 10px; }
.primary {
width: 100%;
height: 46px;
border-radius: 12px;
font-size: 14px;
font-weight: 700;
letter-spacing: .12em;
margin-top: 4px;
}
.foot {
margin-top: 24px;
text-align: center;
font-size: 11.5px;
color: var(--cp-ink-3);
letter-spacing: .4px;
position: relative;
}
</style>
@@ -1,31 +1,33 @@
<template>
<n-modal v-model:show="visible" preset="card" title="修改密码" :style="{ width: '420px' }" :bordered="false" @after-leave="reset">
<n-alert v-if="store.current" type="info" :bordered="false" class="acct-tip">当前账号:{{ store.current }}</n-alert>
<n-form ref="formRef" :model="form" :rules="rules" label-placement="top">
<n-form-item label="原密码" path="oldPwd">
<n-input v-model:value="form.oldPwd" type="password" show-password-on="click" placeholder="请输入原密码" />
</n-form-item>
<n-form-item label="新密码" path="newPwd">
<n-input v-model:value="form.newPwd" type="password" show-password-on="click" placeholder="至少 6 位,不与原密码相同" />
</n-form-item>
<n-form-item label="确认新密码" path="newPwd2">
<n-input v-model:value="form.newPwd2" type="password" show-password-on="click" placeholder="再次输入新密码" />
</n-form-item>
</n-form>
<el-dialog v-model="visible" title="修改密码" width="440px" align-center destroy-on-close @closed="reset">
<el-alert v-if="store.current" type="info" :closable="false" class="acct-tip" show-icon>
当前账号:<b class="mono">{{ store.current }}</b>
</el-alert>
<el-form ref="formRef" :model="form" :rules="rules" label-position="top">
<el-form-item label="原密码" prop="oldPwd">
<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-form-item>
<el-form-item label="确认新密码" prop="newPwd2">
<el-input v-model="form.newPwd2" type="password" placeholder="再次输入新密码" show-password @keyup.enter="submit" />
</el-form-item>
</el-form>
<template #footer>
<n-space justify="end">
<n-button @click="visible = false">取消</n-button>
<n-button type="primary" :loading="busy" @click="submit">保存</n-button>
</n-space>
<div class="modal-foot">
<el-button @click="visible = false">取消</el-button>
<el-button type="primary" :loading="busy" @click="submit">保存</el-button>
</div>
</template>
</n-modal>
</el-dialog>
</template>
<script setup>
import { reactive, ref } from 'vue'
import { ElMessage as message } from 'element-plus'
import { store } from '../store'
import { adminPassword } from '../api'
import { message } from '../naive'
const visible = defineModel({ type: Boolean, default: false })
const formRef = ref()
@@ -37,17 +39,17 @@ const rules = {
newPwd: [
{ required: true, message: '请输入新密码' },
{ min: 6, message: '新密码至少 6 位' },
{ validator: (_r, v) => (v && v === form.oldPwd ? new Error('新密码不能与原密码相同') : true), message: '新密码不能与原密码相同' },
{ validator: (_r, v, cb) => (v && v === form.oldPwd ? cb(new Error('新密码不能与原密码相同')) : cb()), message: '新密码不能与原密码相同' },
],
newPwd2: [
{ required: true, message: '请再次输入新密码' },
{ validator: (_r, v) => (v !== form.newPwd ? new Error('两次输入的密码不一致') : true), message: '两次输入的密码不一致' },
{ validator: (_r, v, cb) => (v !== form.newPwd ? cb(new Error('两次输入的密码不一致')) : cb()), message: '两次输入的密码不一致' },
],
}
function reset() {
form.oldPwd = form.newPwd = form.newPwd2 = ''
formRef.value?.restoreValidation()
formRef.value?.resetFields()
}
async function submit() {
@@ -66,5 +68,6 @@ async function submit() {
</script>
<style scoped>
.acct-tip { margin-bottom: 14px; }
.acct-tip { margin-bottom: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
</style>
@@ -0,0 +1,6 @@
// 时间展示格式化:统一去掉 ISO 的 T,隐藏秒,避免出现 "2026-09-16T12:34:40" 这类原始格式
export function fmtTime(iso) {
if (!iso) return '—'
if (!iso.includes('T')) return iso // 后端已是空格分隔格式,原样返回
return iso.replace('T', ' ').slice(0, 16) // ISO → YYYY-MM-DD HH:mm
}
+4 -3
View File
@@ -1,6 +1,7 @@
import { createApp } from 'vue'
import naive from 'naive-ui'
// 图标沿用 @element-plus/icons-vue(纯 SVG 组件,与 UI 框架解耦)
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 图标沿用 @element-plus/icons-vue(纯 SVG 组件)
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
import './style.css'
@@ -10,4 +11,4 @@ const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.use(naive).mount('#app')
app.use(ElementPlus).mount('#app')
@@ -1,62 +0,0 @@
// Naive UI 主题与离散式反馈(message/dialog 无需 Provider 包裹即可调用)
import { createDiscreteApi, zhCN, dateZhCN } from 'naive-ui'
export const themeOverrides = {
common: {
primaryColor: '#3b6cff',
primaryColorHover: '#5e84ff',
primaryColorPressed: '#2f56d6',
primaryColorSuppl: '#4c79ff',
infoColor: '#3b6cff',
successColor: '#22b07a',
warningColor: '#eab308',
errorColor: '#e5484d',
borderRadius: '10px',
borderRadiusSmall: '8px',
fontFamily:
'"HarmonyOS Sans SC","Microsoft YaHei UI","PingFang SC",-apple-system,"Segoe UI",sans-serif',
},
Card: {
borderRadius: '16px',
},
Button: {
borderRadiusMedium: '10px',
borderRadiusLarge: '12px',
},
Menu: {
itemHeight: '46px',
itemBorderRadius: '10px',
itemTextColor: '#3a4660',
itemTextColorHover: '#3b6cff',
itemTextColorActive: '#3b6cff',
itemTextColorActiveHover: '#2f56d6',
itemColorHover: 'rgba(31, 45, 80, .05)',
itemColorActive: 'rgba(59, 108, 255, .10)',
itemColorActiveHover: 'rgba(59, 108, 255, .15)',
iconColor: '#7b8aa8',
iconColorHover: '#3b6cff',
iconColorActive: '#3b6cff',
iconColorActiveHover: '#2f56d6',
},
DataTable: {
thColor: '#f5f8fe',
thTextColor: '#5b6b8c',
thFontWeight: '600',
tdColor: 'transparent',
tdColorHover: 'rgba(59,108,255,.06)',
borderColor: 'rgba(88,113,183,.10)',
borderRadius: '12px',
},
Dialog: {
borderRadius: '16px',
},
}
export const { message, dialog, notification } = createDiscreteApi(
['message', 'dialog', 'notification'],
{
configProviderProps: { themeOverrides, locale: zhCN, dateLocale: dateZhCN },
}
)
export { zhCN, dateZhCN }
+1 -1
View File
@@ -2,7 +2,7 @@ import { reactive, ref } from 'vue'
import { adminOverview } from './api'
export const store = reactive({
appName: '37du 内网插件控制面',
appName: '37du 插件管理平台',
isAdmin: false,
current: _get('cp_account'),
token: _get('cp_token'),
+256 -45
View File
@@ -1,16 +1,65 @@
/* ============ 37du 内网插件控制面 全局基础样式(组件由 Naive UI 提供) ============ */
/* ============================================================
37du 插件管理平台 · 全局样式(Element Plus)
设计语言:纸张 + 墨色 · 编辑部数据台
- 暖白纸感画布 + 细网格底纹
- 深墨色文字 + 钴蓝/琥珀强调色
- 数字/ID/时间用等宽字体,营造精密仪表感
============================================================ */
:root {
/* 设计令牌:文字 / 边框 / 表面 / 品牌色 / 投影 */
--cp-ink: #141c33;
--cp-ink-2: #5b6b8c;
--cp-ink-3: #94a3c4;
--cp-border: rgba(88, 113, 183, .14);
--cp-surface: rgba(255, 255, 255, .82);
--cp-blue: #3b6cff;
--cp-cyan: #22c7e8;
--cp-violet: #8b5cf6;
--cp-card-shadow: 0 10px 30px -14px rgba(43, 64, 132, .20);
--cp-card-shadow-hover: 0 18px 44px -18px rgba(59, 108, 255, .30);
/* ---------- Element Plus 主题变量 ---------- */
--el-color-primary: #2f5cf0;
--el-color-primary-light-3: #7a96f5;
--el-color-primary-light-5: #a5b9f9;
--el-color-primary-light-7: #cfdbfc;
--el-color-primary-light-8: #e3eafd;
--el-color-primary-light-9: #f1f5fe;
--el-color-primary-dark-2: #2246c0;
--el-color-success: #1d9d5c;
--el-color-warning: #d97706;
--el-color-danger: #d6453d;
--el-color-error: #d6453d;
--el-color-info: #7a8398;
--el-bg-color: #fffdf8;
--el-bg-color-overlay: #fffdf8;
--el-bg-color-page: #f3f0e8;
--el-fill-color-blank: #fffdf8;
--el-fill-color: rgba(35, 42, 58, .08);
--el-fill-color-light: rgba(35, 42, 58, .06);
--el-fill-color-lighter: rgba(35, 42, 58, .04);
--el-fill-color-extra-light: rgba(35, 42, 58, .03);
--el-text-color-primary: #232a3a;
--el-text-color-regular: #3b4358;
--el-text-color-secondary: #6b7488;
--el-text-color-placeholder: #9aa2b4;
--el-text-color-disabled: #b9bfcc;
--el-border-color: rgba(35, 42, 58, .16);
--el-border-color-light: rgba(35, 42, 58, .12);
--el-border-color-lighter: rgba(35, 42, 58, .10);
--el-border-color-extra-light: rgba(35, 42, 58, .07);
--el-border-radius-base: 10px;
--el-border-radius-small: 8px;
--el-box-shadow-light: 0 14px 34px -20px rgba(35, 42, 58, .28);
--el-mask-color: rgba(20, 26, 40, .45);
/* ---------- 设计令牌 ---------- */
--cp-bg: #f3f0e8; /* 纸感画布 */
--cp-ink-1: #232a3a; /* 主墨色(标题) */
--cp-ink: #3b4358; /* 正文 */
--cp-ink-2: #6b7488; /* 次要文字 */
--cp-ink-3: #9aa2b4; /* 弱化文字 */
--cp-line: rgba(35, 42, 58, .12);
--cp-line-strong: rgba(35, 42, 58, .22);
--cp-panel: #fffdf8; /* 纸白面板 */
--cp-panel-2: #faf7ee; /* 次级面板(轨道/底色) */
--cp-blue: #2f5cf0;
--cp-teal: #0f9f9b;
--cp-amber: #d97706;
--cp-success: #1d9d5c;
--cp-danger: #d6453d;
--cp-mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
--cp-shadow: 0 14px 34px -22px rgba(35, 42, 58, .28);
--cp-shadow-hover: 0 20px 44px -22px rgba(47, 92, 240, .30);
}
* { box-sizing: border-box; }
@@ -21,57 +70,219 @@ body {
font-size: 13px;
color: var(--cp-ink);
-webkit-font-smoothing: antialiased;
background-color: #eaf0fb;
/* 浅色极光画布:三层低透明光晕 + 渐变底 */
background-color: var(--cp-bg);
/* 纸感画布:暖白底 + 低透明细网格 + 两侧轻微墨晕 */
background-image:
radial-gradient(1100px 520px at 88% -10%, rgba(59, 108, 255, .14), transparent 60%),
radial-gradient(900px 480px at -8% 108%, rgba(34, 199, 232, .12), transparent 55%),
radial-gradient(760px 420px at 55% 118%, rgba(139, 92, 246, .10), transparent 60%),
linear-gradient(180deg, #f4f7fd 0%, #e9eefb 100%);
radial-gradient(900px 420px at 90% -8%, rgba(47, 92, 240, .07), transparent 62%),
radial-gradient(760px 400px at -6% 104%, rgba(15, 159, 155, .06), transparent 58%),
linear-gradient(rgba(35, 42, 58, .035) 1px, transparent 1px),
linear-gradient(90deg, rgba(35, 42, 58, .035) 1px, transparent 1px);
background-size: auto, auto, 44px 44px, 44px 44px;
background-attachment: fixed;
}
::selection { background: rgba(59, 108, 255, .18); }
::selection { background: rgba(47, 92, 240, .16); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c8d2e8; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b3c0de; background-clip: content-box; border: 2px solid transparent; }
::-webkit-scrollbar-thumb { background: rgba(35, 42, 58, .22); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(35, 42, 58, .34); background-clip: content-box; border: 2px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }
/* ---------- Naive 组件统一质感 ---------- */
.n-card {
--n-border-color: var(--cp-border);
--n-color: rgba(255, 255, 255, .82);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
box-shadow: var(--cp-card-shadow);
/* ============================================================
Element Plus 组件质感覆盖
============================================================ */
/* ---------- 按钮 ---------- */
.el-button {
--el-button-bg-color: #fffdf8;
--el-button-border-color: rgba(35, 42, 58, .20);
--el-button-text-color: var(--cp-ink);
--el-button-hover-bg-color: #fff;
--el-button-hover-border-color: var(--cp-blue);
--el-button-hover-text-color: var(--cp-blue);
--el-button-active-bg-color: #eef2fe;
--el-button-active-border-color: var(--cp-blue);
--el-button-active-text-color: var(--cp-blue);
font-weight: 600;
}
.n-data-table {
--n-border-color: rgba(88, 113, 183, .10);
.el-button--primary {
--el-button-bg-color: var(--cp-blue);
--el-button-border-color: var(--cp-blue);
--el-button-text-color: #fff;
--el-button-hover-bg-color: #5579f3;
--el-button-hover-border-color: #5579f3;
--el-button-hover-text-color: #fff;
--el-button-active-bg-color: #2246c0;
--el-button-active-border-color: #2246c0;
--el-button-active-text-color: #fff;
box-shadow: 0 8px 18px -10px rgba(47, 92, 240, .55);
}
.el-button--danger {
--el-button-bg-color: var(--cp-danger);
--el-button-border-color: var(--cp-danger);
--el-button-text-color: #fff;
--el-button-hover-bg-color: #e26860;
--el-button-hover-border-color: #e26860;
--el-button-hover-text-color: #fff;
--el-button-active-bg-color: #b33831;
--el-button-active-border-color: #b33831;
--el-button-active-text-color: #fff;
}
/* ---------- 共享页面工具类 ---------- */
.page { max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.page-head h3 { margin: 0 0 6px; font-size: 20px; font-weight: 700; letter-spacing: .2px; color: var(--cp-ink); display: flex; align-items: center; gap: 10px; }
/* ---------- 输入类 ---------- */
.el-input__wrapper,
.el-select__wrapper {
--el-input-border-color: rgba(35, 42, 58, .20);
--el-input-hover-border-color: var(--cp-blue);
--el-input-focus-border-color: var(--cp-blue);
box-shadow: 0 0 0 1px rgba(35, 42, 58, .18) inset;
background: #fffdf8;
}
.el-input__wrapper.is-focus,
.el-select__wrapper.is-focused { box-shadow: 0 0 0 1px var(--cp-blue) inset, 0 0 0 3px rgba(47, 92, 240, .12); }
.el-textarea__inner { background: #fffdf8; box-shadow: 0 0 0 1px rgba(35, 42, 58, .18) inset; }
.el-textarea__inner:focus { box-shadow: 0 0 0 1px var(--cp-blue) inset, 0 0 0 3px rgba(47, 92, 240, .12); }
/* ---------- 卡片 ---------- */
.el-card {
--el-card-bg-color: var(--cp-panel);
--el-card-border-color: var(--cp-line);
--el-card-border-radius: 16px;
border: 1px solid var(--cp-line);
box-shadow: var(--cp-shadow);
transition: box-shadow .22s ease, transform .22s ease;
}
.el-card:hover { box-shadow: var(--cp-shadow-hover); }
/* ---------- 表格 ---------- */
.el-table {
--el-table-border-color: rgba(35, 42, 58, .08);
--el-table-header-bg-color: #f6f2e7;
--el-table-header-text-color: var(--cp-ink-2);
--el-table-row-hover-bg-color: rgba(47, 92, 240, .05);
--el-table-bg-color: transparent;
--el-table-tr-bg-color: transparent;
--el-table-expanded-cell-bg-color: transparent;
background: transparent;
}
.el-table th.el-table__cell {
font-weight: 700;
font-size: 12px;
letter-spacing: .4px;
}
.el-table .el-table__cell { padding: 9px 0; }
.el-table__inner-wrapper::before { display: none; }
.el-table--border .el-table__inner-wrapper::after { display: none; }
/* ---------- 标签 ---------- */
.el-tag { font-weight: 600; }
.el-tag--primary { --el-tag-bg-color: rgba(47,92,240,.10); --el-tag-border-color: rgba(47,92,240,.22); --el-tag-text-color: var(--cp-blue); }
.el-tag--success { --el-tag-bg-color: rgba(29,157,92,.10); --el-tag-border-color: rgba(29,157,92,.24); --el-tag-text-color: #15803d; }
.el-tag--warning { --el-tag-bg-color: rgba(217,119,6,.10); --el-tag-border-color: rgba(217,119,6,.24); --el-tag-text-color: var(--cp-amber); }
.el-tag--danger { --el-tag-bg-color: rgba(214,69,61,.10); --el-tag-border-color: rgba(214,69,61,.24); --el-tag-text-color: var(--cp-danger); }
.el-tag--info { --el-tag-bg-color: rgba(35,42,58,.06); --el-tag-border-color: rgba(35,42,58,.14); --el-tag-text-color: var(--cp-ink-2); }
/* ---------- 弹窗 / 浮层 ---------- */
.el-dialog {
--el-dialog-bg-color: var(--cp-panel);
border: 1px solid var(--cp-line);
border-radius: 18px;
box-shadow: 0 24px 60px -24px rgba(35, 42, 58, .4);
}
.el-dialog__header { padding-bottom: 14px; border-bottom: 1px solid var(--cp-line); }
.el-dialog__title { font-weight: 800; color: var(--cp-ink-1); }
.el-popper.is-light { background: var(--cp-panel); border-color: var(--cp-line); }
.el-select-dropdown, .el-dropdown__popper { background: var(--cp-panel); }
.el-select-dropdown__item.is-hovering { background: rgba(47, 92, 240, .08); }
.el-select-dropdown__item.is-selected { color: var(--cp-blue); font-weight: 700; }
/* ---------- 开关 / 复选 / 单选 ---------- */
.el-switch { --el-switch-on-color: var(--cp-blue); }
.el-checkbox { --el-checkbox-checked-bg-color: var(--cp-blue); --el-checkbox-checked-input-border-color: var(--cp-blue); --el-checkbox-input-border-color: rgba(35,42,58,.3); --el-checkbox-text-color: var(--cp-ink); }
.el-checkbox__label { font-weight: 500; }
/* ---------- 表单 ---------- */
.el-form-item__label { font-weight: 600; color: var(--cp-ink-2); }
/* ---------- 标签页 ---------- */
.el-tabs__item { font-weight: 600; color: var(--cp-ink-2); }
.el-tabs__item.is-active { color: var(--cp-blue); }
.el-tabs__active-bar { background-color: var(--cp-blue); height: 3px; border-radius: 2px; }
/* ---------- 消息 / 提示 ---------- */
.el-message { background: var(--cp-panel); border-color: var(--cp-line); box-shadow: var(--cp-shadow); }
.el-message-box { background: var(--cp-panel); border: 1px solid var(--cp-line); border-radius: 16px; }
/* ---------- 空态 / 骨架 ---------- */
.el-empty__description p { color: var(--cp-ink-3); }
.el-skeleton { --el-skeleton-color: rgba(35,42,58,.06); --el-skeleton-to-color: rgba(35,42,58,.10); }
/* ---------- 菜单 ---------- */
.el-menu { border-right: none !important; background: transparent; }
/* ============================================================
共享页面工具类
============================================================ */
.page { max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head h3 {
margin: 0 0 6px; font-size: 22px; font-weight: 800; letter-spacing: .3px;
color: var(--cp-ink-1); display: flex; align-items: center; gap: 12px;
}
.page-head h3 .badge {
font-size: 11px; font-weight: 600; color: var(--cp-blue); letter-spacing: .6px;
background: rgba(59, 108, 255, .10); border: 1px solid rgba(59, 108, 255, .18);
padding: 2px 9px; border-radius: 20px;
font-size: 10.5px; font-weight: 700; color: var(--cp-blue); letter-spacing: 1px;
font-family: var(--cp-mono); text-transform: uppercase;
background: rgba(47, 92, 240, .08); border: 1px solid rgba(47, 92, 240, .2);
padding: 3px 10px; border-radius: 20px;
}
.page-head p { margin: 0; font-size: 12.5px; color: var(--cp-ink-3); }
.block { margin-bottom: 16px; }
.page-head p { margin: 0; font-size: 12.5px; color: var(--cp-ink-3); letter-spacing: .2px; }
.block { margin-bottom: 18px; }
.dim { color: var(--cp-ink-3); }
.who { color: var(--cp-blue); font-weight: 600; }
.who { color: var(--cp-blue); font-weight: 700; }
/* 卡片标题前的小渐变竖条 */
.card-title { font-size: 15px; font-weight: 700; color: var(--cp-ink); display: flex; align-items: center; gap: 8px; }
.card-title::before { content: ''; width: 4px; height: 14px; border-radius: 3px; background: linear-gradient(180deg, #3b6cff, #22c7e8); }
/* 面板卡片 */
.cp-card {
position: relative;
background: var(--cp-panel);
border: 1px solid var(--cp-line);
border-radius: 16px;
box-shadow: var(--cp-shadow);
transition: box-shadow .22s ease, transform .22s ease;
}
.cp-card:hover { box-shadow: var(--cp-shadow-hover); }
/* 卡片顶部渐变发丝线 */
.cp-card::before {
content: ''; position: absolute; top: 0; left: 22px; right: 22px; height: 1px;
background: linear-gradient(90deg, transparent, rgba(47, 92, 240, .45), rgba(15, 159, 155, .45), transparent);
border-radius: 1px;
}
/* 表格单元格通用 */
.cell-strong { font-weight: 700; color: var(--cp-ink); }
/* 小标题(带竖线标记) */
.card-title {
font-size: 14px; font-weight: 800; color: var(--cp-ink-1);
display: flex; align-items: center; gap: 9px;
}
.card-title::before {
content: ''; width: 4px; height: 14px; border-radius: 2px;
background: linear-gradient(180deg, var(--cp-blue), var(--cp-teal));
}
/* 等宽数字(ID / 时间 / 统计值) */
.mono { font-family: var(--cp-mono); font-variant-numeric: tabular-nums; }
/* 表格列通用 */
.cell-strong { font-weight: 700; color: var(--cp-ink-1); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
/* 表格列内 render 的动态节点(不继承 scoped,全局生效) */
.acct { line-height: 1.3; }
.acct .ann { font-size: 13px; font-weight: 600; color: var(--cp-ink-1); }
.acct .anick { font-size: 11px; color: var(--cp-ink-3); }
/* 状态圆点 */
.status-dot { display: inline-flex; align-items: center; gap: 6px; }
.status-dot i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
/* ---------- 动效 ---------- */
@keyframes cp-rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.cp-rise { animation: cp-rise .5s cubic-bezier(.22, .61, .36, 1) both; }
@@ -5,123 +5,149 @@
<h3>账号管理 <span class="badge">Accounts</span></h3>
<p>建号 · 部门 / 管理员维护 · 密码重置(不能操作自己的账号)</p>
</div>
<n-space :size="10">
<n-button :loading="overviewBusy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新
</n-button>
<n-button type="primary" @click="openCreate">
<template #icon><n-icon><Plus /></n-icon></template>新建账号
</n-button>
</n-space>
<div class="head-acts">
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
<el-button type="primary" :icon="Plus" @click="openCreate">新建账号</el-button>
</div>
</div>
<n-card class="cp-rise" :bordered="false">
<n-data-table
:columns="columns"
:data="accounts"
:loading="overviewBusy"
:row-key="r => r.account"
:single-line="false"
/>
</n-card>
<!-- 账号卡片 -->
<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' }">
<div class="acct-top">
<div class="avatar-wrap">
<img v-if="a.avatar" :src="`/api/avatar/${a.account}?v=${encodeURIComponent(a.avatar)}`" class="avatar"
@error="e => e.target.style.display = 'none'" />
<span v-else class="avatar avatar-fallback">{{ (a.nickname || a.account || '?')[0].toUpperCase() }}</span>
<el-tooltip content="上传头像" placement="top">
<span class="avatar-edit" @click="pickAvatar(a)"><el-icon><Camera /></el-icon></span>
</el-tooltip>
</div>
<div class="acct-id">
<div class="id-row">
<span class="acct-account mono">{{ a.account }}</span>
<el-tag v-if="a.is_admin" size="small" type="primary" round effect="light">管理员</el-tag>
</div>
<div class="acct-nick">{{ a.nickname || '未设置昵称' }}</div>
</div>
<div class="acct-actions">
<el-tooltip content="重置密码"><el-button link type="primary" :icon="EditPen" @click="resetPwd(a)" /></el-tooltip>
<el-tooltip content="编辑资料"><el-button link type="info" :icon="Edit" @click="openEdit(a)" /></el-tooltip>
<el-tooltip content="删除账号"><el-button link type="danger" :icon="Delete" :disabled="a.account === current" @click="delAccount(a)" /></el-tooltip>
</div>
</div>
<div class="acct-tags">
<span class="tag-label">状态</span>
<el-switch size="small" :model-value="!!a.status" :disabled="a.account === current"
:loading="busySwitch === a.account" @change="v => toggleStatus(a, v)" />
<el-tag v-if="a.dept" size="small" type="info" effect="plain" round>{{ a.dept }}</el-tag>
</div>
<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>
</div>
<div class="acct-tags" v-else>
<span class="tag-label">插件</span>
<span class="dim">未授权</span>
</div>
<div class="acct-tags" v-if="a.platforms?.length">
<span class="tag-label">平台</span>
<el-tag v-for="pf in a.platforms" :key="pf" size="small" type="success" effect="light" round>{{ pf }}</el-tag>
</div>
<div class="acct-foot">
<span class="mono created dim-sm">创建于 {{ fmtTime(a.created_at) }}</span>
<span class="mono uid dim-sm">ID {{ a.id ?? '—' }}</span>
</div>
</div>
</div>
<el-empty v-else-if="!overviewBusy" description="暂无账号,点击右上角「新建账号」" :image-size="90" class="cp-card" />
<!-- 新建账号 -->
<n-modal v-model:show="createOpen" preset="card" title="新建账号" :style="{ width: '420px' }" :bordered="false" @after-leave="resetCreate">
<n-form ref="formRef" :model="form" :rules="rules" label-placement="top">
<n-form-item label="账号" path="account">
<n-input v-model:value="form.account" placeholder="登录账号" />
</n-form-item>
<n-form-item label="昵称">
<n-input v-model:value="form.nickname" placeholder="真实姓名,方便识别(可填钉钉名)" />
</n-form-item>
<n-form-item label="初始密码" path="password">
<n-input v-model:value="form.password" type="password" show-password-on="click" placeholder="至少 6 位" />
</n-form-item>
<n-form-item label="部门">
<n-input v-model:value="form.dept" placeholder="如 财务部 / IT" />
</n-form-item>
<n-form-item label="管理员">
<n-switch v-model:value="form.is_admin" />
</n-form-item>
</n-form>
<el-dialog v-model="createOpen" title="新建账号" width="440px" align-center destroy-on-close @closed="resetCreate">
<el-form ref="createFormRef" :model="form" :rules="rules" label-position="top">
<el-form-item label="账号" prop="account">
<el-input v-model="form.account" placeholder="登录账号" />
</el-form-item>
<el-form-item label="昵称">
<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-form-item>
<el-form-item label="部门">
<el-input v-model="form.dept" placeholder="如 财务部 / IT" />
</el-form-item>
<el-form-item label="管理员">
<el-switch v-model="form.is_admin" />
</el-form-item>
</el-form>
<template #footer>
<n-space justify="end">
<n-button @click="createOpen = false">取消</n-button>
<n-button type="primary" :loading="creating" @click="createAccount">建号</n-button>
</n-space>
<div class="modal-foot">
<el-button @click="createOpen = false">取消</el-button>
<el-button type="primary" :loading="creating" @click="createAccount">建号</el-button>
</div>
</template>
</n-modal>
</el-dialog>
<!-- 编辑资料 -->
<el-dialog v-model="editOpen" title="编辑账号资料" width="420px" align-center destroy-on-close>
<el-form :model="editForm" label-position="top">
<el-form-item label="账号">
<el-input :model-value="editTarget" disabled class="mono" />
</el-form-item>
<el-form-item label="昵称">
<el-input v-model="editForm.nickname" placeholder="真实姓名" />
</el-form-item>
<el-form-item label="部门">
<el-input v-model="editForm.dept" placeholder="如 财务部 / IT" />
</el-form-item>
<el-form-item label="管理员">
<el-switch v-model="editForm.is_admin" :disabled="editTarget === current" />
</el-form-item>
</el-form>
<template #footer>
<div class="modal-foot">
<el-button @click="editOpen = false">取消</el-button>
<el-button type="primary" :loading="savingEdit" @click="saveEdit">保存</el-button>
</div>
</template>
</el-dialog>
<!-- 重置密码 -->
<n-modal v-model:show="resetOpen" preset="card" title="重置密码" :style="{ width: '400px' }" :bordered="false">
<n-alert v-if="resetTarget" type="info" :bordered="false" style="margin-bottom: 14px">
为账号 <b>{{ resetTarget }}</b> 设置新密码(至少 6 位)
</n-alert>
<n-input v-model:value="resetPwdVal" type="password" show-password-on="click" placeholder="新密码(至少 6 位)" @keydown.enter="confirmReset" />
<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 位)
</el-alert>
<el-input v-model="resetPwdVal" type="password" placeholder="新密码(至少 6 位)" show-password @keyup.enter="confirmReset" />
<template #footer>
<n-space justify="end">
<n-button @click="resetOpen = false">取消</n-button>
<n-button type="primary" :loading="resetting" @click="confirmReset">确认重置</n-button>
</n-space>
<div class="modal-foot">
<el-button @click="resetOpen = false">取消</el-button>
<el-button type="primary" :loading="resetting" @click="confirmReset">确认重置</el-button>
</div>
</template>
</n-modal>
</el-dialog>
</div>
</template>
<script setup>
import { computed, h, onMounted, reactive, ref } from 'vue'
import { NButton, NInput, NSwitch, NTag } from 'naive-ui'
import { Refresh, Plus } from '@element-plus/icons-vue'
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 { message, dialog } from '../naive'
import { fmtTime } from '../format'
const current = computed(() => store.current || '')
const accounts = computed(() => overview.value?.accounts || [])
const busySwitch = ref('')
// ---------- 部门 / 昵称 行内编辑 ----------
const editing = ref('') // 正在编辑的账号
const editField = ref('') // 'dept' | 'nickname'
const editDraft = ref('')
function startEdit(row, field) {
if (row.account === current.value) return
editing.value = row.account
editField.value = field
editDraft.value = row[field] || ''
}
async function saveEdit(row) {
if (editing.value !== row.account) return
const field = editField.value
editing.value = ''
const val = (editDraft.value || '').trim()
if (val === (row[field] || '')) return
try {
await adminAccountUpdate({ account: row.account, [field]: val })
message.success(`已更新 ${row.account} 的${field === 'nickname' ? '昵称' : '部门'}`)
} catch (e) { message.error(e.message || e) }
}
function inlineInput(row, field) {
if (row.account === editing.value && editField.value === field) {
return h(NInput, {
value: editDraft.value,
size: 'small',
style: 'width: 140px',
onUpdateValue: v => (editDraft.value = v),
onKeyup: (e) => { if (e.key === 'Enter') saveEdit(row) },
onBlur: () => saveEdit(row),
})
}
return h('span', { class: 'dept', onClick: () => startEdit(row, field) },
row[field] || '—')
}
async function toggleAdmin(row) {
try { await adminAccountUpdate({ account: row.account, is_admin: !row.is_admin }); await refresh() }
catch (e) { message.error(e.message || e) }
}
async function toggleStatus(row, v) {
if (row.account === current.value && !v) { message.warning('不能停用当前登录的账号'); return }
try { await adminAccountUpdate({ account: row.account, status: v }); await refresh() }
catch (e) { message.error(e.message || e) }
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
// ---------- 头像(显示 + 上传) ----------
@@ -131,83 +157,32 @@ const _fileInput = (() => {
el.accept = 'image/*'
return el
})()
function pickAvatar(row) {
function pickAvatar(a) {
_fileInput.onchange = async () => {
const f = _fileInput.files && _fileInput.files[0]
_fileInput.value = ''
if (!f) return
try {
await adminAvatarUpload(row.account, f)
message.success(`已更新 ${row.account} 的头像`)
await adminAvatarUpload(a.account, f)
message.success(`已更新 ${a.account} 的头像`)
await refresh()
} catch (e) { message.error(e.message || e) }
}
_fileInput.click()
}
function avatarCell(row) {
const img = row.avatar
? h('img', {
src: `/api/avatar/${row.account}?v=${encodeURIComponent(row.avatar)}`,
class: 'cell-avatar',
onError: (e) => { e.target.style.display = 'none' },
})
: h('span', { class: 'dim' }, '—')
return h('div', { class: 'cell-avatar-wrap' }, [
img,
h(NButton, { text: true, size: 'tiny', type: 'primary', onClick: () => pickAvatar(row) }, { default: () => '上传' }),
])
}
function renderTags(list, kind) {
if (!list || !list.length) return h('span', { class: 'dim' }, '—')
return h('div', { class: 'tags' }, list.map(t => h(NTag, {
size: 'small', round: true, bordered: false,
type: kind === 'platform' ? 'success' : 'primary',
}, { default: () => t })))
async function toggleStatus(a, v) {
if (a.account === current.value && !v) { message.warning('不能停用当前登录的账号'); return }
busySwitch.value = a.account
try { await adminAccountUpdate({ account: a.account, status: v }); await refresh() }
catch (e) { message.error(e.message || e) }
finally { busySwitch.value = '' }
}
const columns = computed(() => [
{ title: 'ID', key: 'id', width: 64, render: r => h('span', { class: 'dim' }, r.id ?? '—') },
{ title: '用户名(工号)', key: 'account', width: 130, render: r => h('b', { class: 'cell-strong' }, r.account) },
{ title: '昵称(姓名)', key: 'nickname', width: 130, render: r => inlineInput(r, 'nickname') },
{ title: '部门', key: 'dept', width: 130, render: (row) => inlineInput(row, 'dept') },
{ title: '头像', key: 'avatar', width: 120, render: r => avatarCell(r) },
{
title: '状态', key: 'status', width: 90,
render: (row) => h(NSwitch, {
value: !!row.status,
disabled: row.account === current.value,
onUpdateValue: (v) => toggleStatus(row, v),
}),
},
{ title: '创建时间', key: 'created_at', width: 150, render: r => h('span', { class: 'dim' }, r.created_at || '—') },
{
title: '管理员', key: 'is_admin', width: 90,
render: (row) => h(NSwitch, {
value: !!row.is_admin,
disabled: row.account === current.value,
onUpdateValue: () => toggleAdmin(row),
}),
},
{ title: '已授权插件', key: 'plugins', minWidth: 160, render: r => renderTags(r.plugins, 'plugin') },
{ title: '已授权平台', key: 'platforms', minWidth: 130, render: r => renderTags(r.platforms, 'platform') },
{
title: '操作', key: 'actions', width: 170,
render: (row) => h('div', { class: 'ops' }, [
h(NButton, { text: true, type: 'primary', onClick: () => resetPwd(row) }, { default: () => '重置密码' }),
h(NButton, {
text: true, type: 'error',
disabled: row.account === current.value,
onClick: () => delAccount(row),
}, { default: () => '删除' }),
]),
},
])
// ---------- 新建账号 ----------
const createOpen = ref(false)
const creating = ref(false)
const formRef = ref()
const createFormRef = ref()
const form = reactive({ account: '', password: '', dept: '', nickname: '', is_admin: false })
const rules = {
account: { required: true, message: '请输入账号' },
@@ -220,10 +195,10 @@ function openCreate() { createOpen.value = true }
function resetCreate() {
form.account = form.password = form.dept = form.nickname = ''
form.is_admin = false
formRef.value?.restoreValidation()
createFormRef.value?.resetFields()
}
async function createAccount() {
try { await formRef.value.validate() } catch (_) { return }
try { await createFormRef.value.validate() } catch (_) { return }
creating.value = true
try {
await adminAccountCreate({ ...form, account: form.account.trim() })
@@ -234,13 +209,36 @@ async function createAccount() {
finally { creating.value = false }
}
// ---------- 编辑资料 ----------
const editOpen = ref(false)
const savingEdit = ref(false)
const editTarget = ref('')
const editForm = reactive({ nickname: '', dept: '', is_admin: false })
function openEdit(a) {
editTarget.value = a.account
editForm.nickname = a.nickname || ''
editForm.dept = a.dept || ''
editForm.is_admin = !!a.is_admin
editOpen.value = true
}
async function saveEdit() {
savingEdit.value = true
try {
await adminAccountUpdate({ account: editTarget.value, nickname: editForm.nickname, dept: editForm.dept, is_admin: editForm.is_admin })
message.success(`已更新 ${editTarget.value}`)
editOpen.value = false
await refresh()
} catch (e) { message.error(e.message || e) }
finally { savingEdit.value = false }
}
// ---------- 重置密码 ----------
const resetOpen = ref(false)
const resetTarget = ref('')
const resetPwdVal = ref('')
const resetting = ref(false)
function resetPwd(row) {
resetTarget.value = row.account
function resetPwd(a) {
resetTarget.value = a.account
resetPwdVal.value = ''
resetOpen.value = true
}
@@ -256,34 +254,75 @@ async function confirmReset() {
finally { resetting.value = false }
}
function delAccount(row) {
dialog.warning({
title: '删除账号',
content: `确认删除账号 ${row.account}?其插件授权将一并清除`,
positiveText: '删除',
negativeText: '取消',
onPositiveClick: async () => {
try { await adminAccountDelete({ account: row.account }); message.success(`已删除 ${row.account}`); await refresh() }
catch (e) { message.error(e.message || e) }
},
})
function delAccount(a) {
dialog.confirm(`确认删除账号 ${a.account}?其插件授权将一并清除`, '删除账号', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消',
}).then(async () => {
try { await adminAccountDelete({ account: a.account }); message.success(`已删除 ${a.account}`); await refresh() }
catch (e) { message.error(e.message || e) }
}).catch(() => {})
}
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
onMounted(refresh)
</script>
<style scoped>
.dept { cursor: pointer; border-bottom: 1px dashed transparent; transition: border-color .15s; }
.dept:hover { color: var(--cp-blue); border-bottom-color: rgba(59, 108, 255, .4); }
</style>
.head-acts { display: flex; gap: 10px; }
<!-- 列 render 中由 naive-ui 动态渲染的节点不继承 scoped scopeId,须用全局样式 -->
<style>
.ops { display: flex; align-items: center; gap: 16px; }
.ops .n-button { padding: 0 4px; }
.cell-avatar-wrap { display: flex; align-items: center; gap: 8px; }
.cell-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #f2f3f7; flex: none; }
.acct-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
gap: 18px;
}
.acct-card {
padding: 20px;
display: flex; flex-direction: column; gap: 12px;
}
.acct-top { display: flex; align-items: center; gap: 14px; }
.avatar-wrap { position: relative; flex-shrink: 0; }
.avatar {
width: 52px; height: 52px; border-radius: 16px; object-fit: cover;
display: block; box-shadow: 0 6px 14px -8px rgba(35, 42, 58, .4);
}
.avatar-fallback {
display: grid; place-items: center;
background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal));
color: #fff; font-size: 20px; font-weight: 800;
}
.avatar-edit {
position: absolute; right: -6px; bottom: -6px;
width: 22px; height: 22px; border-radius: 8px;
display: grid; place-items: center;
background: var(--cp-panel); border: 1px solid var(--cp-line-strong);
color: var(--cp-ink-2); cursor: pointer;
transition: all .18s;
}
.avatar-edit:hover { color: var(--cp-blue); border-color: var(--cp-blue); background: rgba(47, 92, 240, .06); }
.acct-id { flex: 1; min-width: 0; }
.id-row { display: flex; align-items: center; gap: 8px; }
.acct-account { font-size: 16px; font-weight: 800; color: var(--cp-ink-1); }
.acct-nick { font-size: 12.5px; color: var(--cp-ink-3); margin-top: 4px; }
.acct-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.acct-actions .el-button { font-size: 16px; }
.acct-tags { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.tag-label {
font-size: 11px; font-weight: 700; color: var(--cp-ink-3);
letter-spacing: .5px; margin-right: 2px; flex-shrink: 0;
}
.more { font-size: 12px; color: var(--cp-ink-3); font-weight: 700; }
.acct-foot {
display: flex; justify-content: space-between; align-items: center;
margin-top: auto; padding-top: 12px;
border-top: 1px dashed var(--cp-line-strong);
}
.dim-sm { color: var(--cp-ink-3); font-size: 11px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
.reset-tip { margin-bottom: 16px; }
</style>
@@ -5,34 +5,115 @@
<h3>审计与运行报表 <span class="badge">Audit</span></h3>
<p>操作审计 · 部署端运行上报记录(最新在前)</p>
</div>
<n-button :loading="busy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新
</n-button>
<el-button :loading="busy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<n-tabs type="line" class="block cp-rise" :value="tab" @update:value="v => tab = v" justify-content="space-evenly">
<n-tab-pane name="audit" tab="操作审计">
<n-data-table :columns="auditCols" :data="audits" size="small" :loading="busy" :row-key="r => r.id" :single-line="false" />
</n-tab-pane>
<n-tab-pane name="report" tab="运行上报">
<n-data-table :columns="reportCols" :data="reports" size="small" :loading="busy" :row-key="r => r.id" :single-line="false" />
</n-tab-pane>
</n-tabs>
<!-- 顶部摘要 -->
<div class="kpis cp-rise" v-if="loaded">
<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="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>
</div>
</div>
</div>
<div class="cp-card panel cp-rise">
<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-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" />
</div>
<el-table :data="filteredAudits" size="small" :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="130">
<template #default="{ row }">
<el-tag size="small" round effect="light" :type="actType(row.action)">{{ DETAIL_LABEL[row.action] || row.action }}</el-tag>
</template>
</el-table-column>
<el-table-column label="账号" width="140">
<template #default="{ row }">
<div class="acct" v-if="row.nickname">
<div class="ann mono">{{ row.account }}</div>
<div class="anick">{{ row.nickname }}</div>
</div>
<span v-else class="mono">{{ row.account || '—' }}</span>
</template>
</el-table-column>
<el-table-column label="对象" width="160" show-overflow-tooltip>
<template #default="{ row }"><span class="mono">{{ row.target || '—' }}</span></template>
</el-table-column>
<el-table-column label="详情" min-width="220" show-overflow-tooltip>
<template #default="{ row }">
<span :class="{ dim: !row.detail }">{{ row.detail || '—' }}</span>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="运行上报" name="report">
<el-table :data="reports" size="small" :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>
</template>
</el-table-column>
<el-table-column label="账号" width="140">
<template #default="{ row }">
<div class="acct" v-if="row.nickname">
<div class="ann mono">{{ row.account }}</div>
<div class="anick">{{ row.nickname }}</div>
</div>
<span v-else class="mono">{{ row.account || '—' }}</span>
</template>
</el-table-column>
<el-table-column label="设备" width="130" show-overflow-tooltip>
<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>
</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>
</el-table-column>
<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>
</el-tab-pane>
</el-tabs>
</div>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue'
import { h } from 'vue'
import { NTag } from 'naive-ui'
import { Refresh } from '@element-plus/icons-vue'
import { computed, onMounted, ref } from 'vue'
import { Refresh, Search, Document, DataLine, CircleCloseFilled, WarningFilled } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import { adminAudit, adminReports } from '../api'
import { message } from '../naive'
import { fmtTime } from '../format'
const tab = ref('audit')
const busy = ref(false)
const loaded = ref(false)
const audits = ref([])
const reports = ref([])
const actionFilter = ref('')
const search = ref('')
const DETAIL_LABEL = {
grant: '授权', 'revoke-grant': '撤销授权', 'plugin-patch': '更新插件',
@@ -40,44 +121,13 @@ const DETAIL_LABEL = {
'account-update': '改号', 'account-reset': '重置密码', 'account-delete': '删除',
'platform-grant': '平台授权', login: '登录',
}
function actTag(a) {
const map = { grant: 'info', 'revoke-grant': 'error', 'plugin-patch': 'warning',
'download-ticket': 'success', 'upload-pkg': 'success', login: 'info', }
return h(NTag, { size: 'small', bordered: false, type: map[a] || 'default', round: true },
{ default: () => DETAIL_LABEL[a] || a })
function actType(a) {
return { grant: 'primary', 'revoke-grant': 'danger', 'plugin-patch': 'warning',
'download-ticket': 'success', 'upload-pkg': 'success', login: 'primary' }[a] || 'info'
}
function acctCell(r) {
const nn = r.nickname
if (!r.account && !nn) return h('span', { class: 'dim' }, '—')
if (!nn) return h('span', null, r.account || '—')
return h('div', { class: 'acct' }, [
h('div', { class: 'ann' }, r.account || '—'),
h('div', { class: 'anick' }, nn || ''),
])
function statusColor(s) {
return { start: '#2f5cf0', running: '#2f5cf0', done: '#1d9d5c', success: '#1d9d5c', error: '#d6453d', failed: '#d6453d' }[s] || '#9aa2b4'
}
function statusTag(s) {
const map = { start: 'info', running: 'info', done: 'success', error: 'error' }
return h(NTag, { size: 'small', bordered: false, type: map[s] || 'default', round: true },
{ default: () => s || '—' })
}
const auditCols = [
{ title: '时间', key: 'at', width: 170 },
{ title: '操作', key: 'action', width: 130, render: r => actTag(r.action) },
{ title: '账号', key: 'account', width: 130, render: r => acctCell(r) },
{ title: '对象', key: 'target', width: 140, ellipsis: { tooltip: true } },
{ title: '详情', key: 'detail', minWidth: 220, ellipsis: { tooltip: true } },
]
const reportCols = [
{ title: '时间', key: 'at', width: 170 },
{ title: '状态', key: 'status', width: 100, render: r => statusTag(r.status) },
{ title: '账号', key: 'account', width: 130, render: r => acctCell(r) },
{ title: '设备', key: 'device_id', width: 110, render: r => r.device_id || h('span', { class: 'dim' }, '—') },
{ title: '插件', key: 'plugin_id', width: 140, ellipsis: { tooltip: true } },
{ title: '版本', key: 'version', width: 90 },
{ title: '时长', key: 'duration_sec', width: 90, render: r => typeof r.duration_sec === 'number' ? fmtDur(r.duration_sec) : '—' },
{ title: '消息', key: 'msg', minWidth: 200, ellipsis: { tooltip: true } },
]
function fmtDur(sec) {
sec = +sec || 0
if (sec < 60) return sec + 's'
@@ -86,12 +136,35 @@ 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)' },
]
})
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
})
async function refresh() {
busy.value = true
try {
const [a, r] = await Promise.all([adminAudit(), adminReports()])
audits.value = a.auditlogs || []
reports.value = r.reports || []
loaded.value = true
} catch (e) { message.error('读取失败:' + (e.message || e)) }
finally { busy.value = false }
}
@@ -99,10 +172,15 @@ onMounted(refresh)
</script>
<style scoped>
.dim { color: var(--cp-ink-3); }
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 18px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi { display: flex; align-items: center; gap: 13px; padding: 16px; }
.kpi-ic { width: 40px; height: 40px; border-radius: 12px; 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: 22px; font-weight: 800; line-height: 1.1; }
.kpi-lab { font-size: 12px; color: var(--cp-ink-3); margin-top: 4px; }
.panel { padding: 8px 18px 18px; }
.toolbar { display: flex; gap: 10px; margin: 4px 0 14px; }
.dim-sm { color: var(--cp-ink-2); }
</style>
<style>
.acct { line-height: 1.25; }
.acct .ann { font-size: 13px; color: var(--cp-ink-1); }
.acct .anick { font-size: 11px; color: var(--cp-ink-3); }
</style>
@@ -5,88 +5,87 @@
<h3>权限授权 <span class="badge">Grants</span></h3>
<p>按账号勾选可用插件与可登录平台,保存时仅提交差异项</p>
</div>
<n-button :loading="overviewBusy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新
</n-button>
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<n-card class="block cp-rise" :bordered="false">
<n-form inline>
<n-form-item label="选择账号">
<n-select
v-model:value="account"
:options="accountOptions"
placeholder="选择账号…"
style="width: 240px"
filterable
clearable
/>
</n-form-item>
<n-form-item v-if="account">
<span class="sel-hint">{{ account }} · 已授权 {{ grantedIds.length }} 个插件 / {{ platChecked.length }} 个平台</span>
</n-form-item>
</n-form>
</n-card>
<div class="cp-card panel cp-rise">
<!-- 账号选择 -->
<div class="pick-row">
<div class="pick-label">选择账号</div>
<el-select v-model="account" filterable clearable placeholder="选择账号…" style="width: 260px" :prefix-icon="User">
<el-option v-for="a in accountOptions" :key="a.value" :label="a.label" :value="a.value" />
</el-select>
<div class="pick-hint" v-if="account">
已授权 <b class="mono">{{ grantedIds.length }}</b> 个插件 / <b class="mono">{{ platChecked.length }}</b> 个平台
</div>
</div>
<template v-if="account">
<n-card class="block cp-rise" :bordered="false">
<template #header>
<div class="card-head">
<b>插件授权</b>
<n-button type="primary" size="small" :loading="saving" @click="saveGrant">保存插件授权</n-button>
<template v-if="account">
<!-- 插件授权 -->
<div class="section">
<div class="section-head">
<div class="card-title">插件授权</div>
<el-checkbox :model-value="allChecked" :indeterminate="someChecked" @change="toggleAll">全选</el-checkbox>
</div>
</template>
<n-checkbox-group v-model:value="grantedIds" v-if="plugins.length">
<div class="ck-grid">
<n-checkbox v-for="p in plugins" :key="p.id" :value="p.id" class="ck">
<span class="ck-main">
<span>{{ p.id }}<span class="dim">({{ p.name }})</span></span>
<span class="ck-sub" v-if="grantState[p.id]?.granted">
<n-switch size="small" :value="grantState[p.id].canRun"
@update:value="v => setGrant(p.id, { canRun: v })">
<template #checked>可运行</template>
<template #unchecked>禁运行</template>
</n-switch>
<n-switch size="small" :value="grantState[p.id].canDownload"
@update:value="v => setGrant(p.id, { canDownload: v })">
<template #checked>可下载</template>
<template #unchecked>禁下载</template>
</n-switch>
</span>
</span>
</n-checkbox>
</div>
</n-checkbox-group>
<n-empty v-else description="暂无插件,请先在「插件管理」上传" size="small" />
</n-card>
<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 :value="p.id" class="pck">
<span class="pname mono">{{ p.id }}</span>
<span class="psub dim">{{ p.name }}</span>
</el-checkbox>
<div class="pswitches">
<div class="psw">
<span class="psw-label" :class="{ on: canRun(p.id) }">可运行</span>
<el-switch size="small" :model-value="canRun(p.id)" :disabled="!grantedIds.includes(p.id)" @change="v => setGrant(p.id, { canRun: v })" />
</div>
<div class="psw">
<span class="psw-label" :class="{ on: canDownload(p.id) }">可下载</span>
<el-switch size="small" :model-value="canDownload(p.id)" :disabled="!grantedIds.includes(p.id)" @change="v => setGrant(p.id, { canDownload: v })" />
</div>
</div>
</div>
</el-checkbox-group>
<el-empty v-if="!plugins.length" description="暂无插件,请先在「插件管理」上传" :image-size="60" />
</div>
<n-card class="block cp-rise" :bordered="false">
<template #header>
<div class="card-head">
<b>平台授权</b>
<n-button type="primary" size="small" :loading="savingPlat" @click="savePlat">保存平台授权</n-button>
<!-- 平台授权 -->
<div class="section">
<div class="section-head">
<div class="card-title">平台授权</div>
</div>
</template>
<n-checkbox-group v-model:value="platChecked">
<div class="ck-grid">
<n-checkbox v-for="pf in PLATFORM_OPTS" :key="pf.id" :value="pf.id" class="ck">
{{ pf.label }}<span class="dim">({{ pf.id }})</span>
</n-checkbox>
</div>
</n-checkbox-group>
</n-card>
</template>
<el-checkbox-group v-model="platChecked" class="pf-list">
<el-checkbox v-for="pf in PLATFORM_OPTS" :key="pf.id" :value="pf.id" class="pf-chip">
<span>{{ pf.label }}</span>
<span class="dim mono">({{ pf.id }})</span>
</el-checkbox>
</el-checkbox-group>
</div>
</template>
<n-empty v-else description="先在上方选择一个账号" class="no-acc cp-rise" />
<el-empty v-else description="先在上方选择一个账号" :image-size="80" class="no-acc" />
</div>
<!-- 底部保存栏 -->
<transition name="savebar">
<div class="savebar cp-card cp-rise" v-if="account">
<div class="save-hint">
<span class="dot" :class="{ dirty: dirtyCount > 0 }"></span>
{{ dirtyCount > 0 ? `有 ${dirtyCount} 项授权变更待保存` : '授权已是最新' }}
</div>
<el-button type="primary" :loading="saving" :disabled="dirtyCount === 0" :icon="Check" @click="saveAll">
保存授权
</el-button>
</div>
</transition>
</div>
</template>
<script setup>
import { computed, onMounted, ref, watch } from 'vue'
import { Refresh } from '@element-plus/icons-vue'
import { Refresh, 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 { message } from '../naive'
const PLATFORM_OPTS = ref([])
@@ -102,7 +101,6 @@ const grantedIds = ref([])
const grantState = ref({}) // plugin_id -> { granted, canRun, canDownload }
const platChecked = ref([])
const saving = ref(false)
const savingPlat = ref(false)
let heldGrantState = {} // 已保存快照,用于差异比对
let heldPlatforms = new Set()
@@ -110,6 +108,15 @@ function setGrant(pid, patch) {
grantState.value[pid] = { ...grantState.value[pid], ...patch }
grantState.value = { ...grantState.value }
}
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)
function toggleAll(v) {
grantedIds.value = v ? plugins.value.map(p => p.id) : []
}
// 选中账号即自动载入其现有授权
watch(account, (acc) => {
@@ -139,10 +146,27 @@ watch(grantedIds, (ids) => {
grantState.value = state
})
// 差异计算
const pluginDirty = computed(() => {
const want = {}
Object.entries(grantState.value).forEach(([pid, s]) => { if (s.granted) want[pid] = s })
const allPids = [...new Set([...Object.keys(want), ...Object.keys(heldGrantState)])]
return allPids.filter(pid => {
const w = want[pid]; const h = heldGrantState[pid]
if (!!w !== !!h) return true
if (w && h) return w.canRun !== h.canRun || w.canDownload !== h.canDownload
return false
})
})
const platDirty = computed(() => {
const want = new Set(platChecked.value)
return [...new Set([...want, ...heldPlatforms])].filter(pf => want.has(pf) !== heldPlatforms.has(pf))
})
const dirtyCount = computed(() => pluginDirty.value.length + platDirty.value.length)
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
// 拉取可授权平台列表(后端只读接口,替代写死 hr/oa)
async function loadPlatforms() {
try {
const r = await adminPlatforms()
@@ -150,78 +174,121 @@ async function loadPlatforms() {
} catch (e) { message.error('平台列表读取失败:' + (e.message || e)) }
}
async function saveGrant() {
async function savePluginDiff() {
const acc = account.value
const want = {}
Object.entries(grantState.value).forEach(([pid, s]) => { if (s.granted) want[pid] = s })
const diff = pluginDirty.value
const results = await Promise.allSettled(diff.map(pid => adminGrant({
account: acc, plugin_id: pid, granted: !!want[pid],
can_run: want[pid]?.canRun !== false, can_download: want[pid]?.canDownload !== false,
})))
const failed = results.filter(r => r.status === 'rejected')
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
if (failed.length) { message.warning(`插件授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return 0 }
heldGrantState = JSON.parse(JSON.stringify(grantState.value))
return diff.length
}
async function savePlatDiff() {
const acc = account.value
const want = new Set(platChecked.value)
const diff = platDirty.value
const results = await Promise.allSettled(diff.map(pf => adminPlatformGrant({
account: acc, platform_id: pf, granted: want.has(pf),
})))
const failed = results.filter(r => r.status === 'rejected')
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
if (failed.length) { message.warning(`平台授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return 0 }
heldPlatforms = new Set(platChecked.value)
return diff.length
}
async function saveAll() {
const acc = account.value; if (!acc) return
saving.value = true
try {
const want = {}
Object.entries(grantState.value).forEach(([pid, s]) => {
if (s.granted) want[pid] = s
})
const allPids = [...new Set([...Object.keys(want), ...Object.keys(heldGrantState)])]
const diff = allPids.filter(pid => {
const w = want[pid]; const h = heldGrantState[pid]
if (!!w !== !!h) return true
if (w && h) return w.canRun !== h.canRun || w.canDownload !== h.canDownload
return false
})
if (!diff.length) { message.info('插件授权无需变更'); return }
const results = await Promise.allSettled(diff.map(pid => adminGrant({
account: acc, plugin_id: pid, granted: !!want[pid],
can_run: want[pid]?.canRun !== false, can_download: want[pid]?.canDownload !== false,
})))
const failed = results.filter(r => r.status === 'rejected')
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
if (failed.length) { message.warning(`插件授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return }
message.success(`已更新 ${diff.length} 项插件授权`)
heldGrantState = JSON.parse(JSON.stringify(grantState.value))
let okP = 0, okPl = 0
if (pluginDirty.value.length) okP = await savePluginDiff()
if (platDirty.value.length) okPl = await savePlatDiff()
if (!pluginDirty.value.length && !platDirty.value.length) { message.info('授权无需变更'); return }
message.success(`已保存:插件 ${okP} 项,平台 ${okPl} 项`)
await refresh()
} finally { saving.value = false }
}
async function savePlat() {
const acc = account.value; if (!acc) return
savingPlat.value = true
try {
const want = new Set(platChecked.value)
const diff = [...new Set([...want, ...heldPlatforms])].filter(pf => want.has(pf) !== heldPlatforms.has(pf))
if (!diff.length) { message.info('平台授权无需变更'); return }
const results = await Promise.allSettled(diff.map(pf => adminPlatformGrant({
account: acc, platform_id: pf, granted: want.has(pf),
})))
const failed = results.filter(r => r.status === 'rejected')
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
if (failed.length) { message.warning(`平台授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return }
message.success(`已更新 ${diff.length} 项平台授权`)
heldPlatforms = new Set(platChecked.value)
await refresh()
} finally { savingPlat.value = false }
} catch (e) { message.error('保存失败:' + (e.message || e)) }
finally { saving.value = false }
}
onMounted(() => { refresh(); loadPlatforms() })
</script>
<style scoped>
.card-head { display: flex; justify-content: space-between; align-items: center; }
.sel-hint { font-size: 12px; color: var(--cp-ink-2); }
.no-acc { margin-top: 60px; }
.panel { padding: 22px 24px 26px; }
/* 授权项:卡片式勾选 */
.ck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ck-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; line-height: 1.2; }
.ck-sub { display: flex; align-items: center; gap: 10px; }
:deep(.n-checkbox) {
display: flex; align-items: center; margin: 0;
width: 100%;
padding: 12px 14px;
border: 1px solid var(--cp-border);
.pick-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-bottom: 20px; border-bottom: 1px dashed var(--cp-line-strong); }
.pick-label { font-size: 13px; font-weight: 700; color: var(--cp-ink-1); }
.pick-hint { font-size: 12.5px; color: var(--cp-ink-3); }
.pick-hint b { color: var(--cp-blue); font-size: 13px; }
.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; }
/* 插件授权行 */
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow {
display: flex; align-items: center; justify-content: space-between; gap: 16px;
padding: 12px 16px;
border: 1px solid var(--cp-line);
border-radius: 12px;
background: rgba(255, 255, 255, .65);
background: var(--cp-panel);
transition: border-color .18s, background .18s, box-shadow .18s;
}
:deep(.n-checkbox:hover) { border-color: rgba(59, 108, 255, .4); }
:deep(.n-checkbox.n-checkbox--checked) {
border-color: rgba(59, 108, 255, .45);
background: linear-gradient(135deg, rgba(59, 108, 255, .08), rgba(34, 199, 232, .06));
box-shadow: 0 8px 18px -10px rgba(59, 108, 255, .35);
.prow:hover { border-color: rgba(47, 92, 240, .35); }
.prow.on {
border-color: rgba(47, 92, 240, .4);
background: linear-gradient(90deg, rgba(47, 92, 240, .05), rgba(15, 159, 155, .03));
box-shadow: 0 8px 18px -12px rgba(47, 92, 240, .4);
}
:deep(.n-checkbox .n-checkbox__label) { padding-left: 4px; flex: 1; min-width: 0; }
.prow .pck { flex: 1; min-width: 0; }
.pname { font-weight: 700; color: var(--cp-ink-1); font-size: 13px; }
.psub { font-size: 12px; margin-left: 8px; }
.pswitches { display: flex; gap: 22px; flex-shrink: 0; }
.psw { display: flex; align-items: center; gap: 8px; }
.psw-label { font-size: 12px; color: var(--cp-ink-3); transition: color .18s; }
.psw-label.on { color: var(--cp-blue); font-weight: 600; }
/* 平台授权 chips */
.pf-list { display: flex; flex-wrap: wrap; gap: 10px; }
.pf-chip { margin: 0 !important; }
.pf-chip :deep(.el-checkbox__input) { display: none; }
.pf-chip :deep(.el-checkbox__label) {
display: inline-flex; align-items: center; gap: 6px;
padding: 8px 16px;
border: 1px solid var(--cp-line);
border-radius: 12px;
background: var(--cp-panel);
font-weight: 600;
transition: border-color .18s, background .18s, box-shadow .18s, color .18s;
}
.pf-chip:hover :deep(.el-checkbox__label) { border-color: rgba(47, 92, 240, .4); }
.pf-chip.is-checked :deep(.el-checkbox__label) {
border-color: rgba(47, 92, 240, .55);
background: linear-gradient(135deg, rgba(47, 92, 240, .10), rgba(15, 159, 155, .06));
color: var(--cp-blue);
box-shadow: 0 6px 14px -10px rgba(47, 92, 240, .5);
}
.no-acc { padding: 30px 0; }
/* 底部保存栏 */
.savebar {
position: sticky; bottom: 18px; z-index: 10;
display: flex; align-items: center; justify-content: space-between;
margin-top: 20px; padding: 14px 20px;
background: rgba(255, 253, 248, .92);
backdrop-filter: blur(12px);
}
.save-hint { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--cp-ink-2); font-weight: 600; }
.save-hint .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--cp-success); }
.save-hint .dot.dirty { background: var(--cp-amber); box-shadow: 0 0 0 4px rgba(217, 119, 6, .18); }
.savebar-enter-active, .savebar-leave-active { transition: opacity .25s ease, transform .25s ease; }
.savebar-enter-from, .savebar-leave-to { opacity: 0; transform: translateY(10px); }
</style>
@@ -5,27 +5,25 @@
<h3>概览 <span class="badge">Dashboard</span></h3>
<p>中心机 · 插件分发与账号权限 · 当前账号 <b class="who">{{ store.nickname || store.current }}</b></p>
</div>
<n-button :loading="overviewBusy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新
</n-button>
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<div class="stat-grid" v-if="ov">
<div class="stat-card" v-for="(s, i) in stats" :key="s.label" :style="{ animationDelay: i * 60 + 'ms' }">
<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 }">
<n-icon :size="20"><component :is="s.icon" /></n-icon>
<el-icon :size="20"><component :is="s.icon" /></el-icon>
</div>
<div class="stat-meta">
<div class="stat-num" :class="{ sm: s.small }">{{ s.value }}</div>
<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>
<n-skeleton v-else-if="overviewBusy" text :repeat="3" style="margin-top: 20px" />
<el-skeleton v-else-if="overviewBusy" animated :rows="3" style="margin-top: 20px" />
<div class="tip-card cp-rise">
<div class="tip-ic"><n-icon :size="18"><InfoFilled /></n-icon></div>
<div class="tip-card cp-card cp-rise">
<div class="tip-ic"><el-icon :size="18"><InfoFilled /></el-icon></div>
<div class="tip-body">
<b>使用说明</b>
<p>「插件管理」上传与发布插件包(每插件保留最近 3 个版本);「账号管理」建号与账号维护;「权限授权」按账号勾选可用的插件与平台。部署机(webhost)仅在启动与手动刷新时拉取插件,授权变更后需在部署机刷新生效。</p>
@@ -36,26 +34,26 @@
<script setup>
import { computed, onMounted } from 'vue'
import { Refresh, InfoFilled } from '@element-plus/icons-vue'
import { Refresh, InfoFilled, Box, Collection, User, UserFilled, UploadFilled } from '@element-plus/icons-vue'
import { ElMessage as message } from 'element-plus'
import { store, overview, overviewBusy, loadOverview } from '../store'
import { message } from '../naive'
import { fmtTime } from '../format'
const ov = computed(() => overview.value)
const stats = computed(() => {
const plugins = ov.value?.plugins || []
return [
{ label: '插件', value: plugins.length, icon: 'Box', color: '#3b6cff', bg: 'linear-gradient(135deg,#eef2ff,#dbe6ff)' },
{ label: '版本总数', value: plugins.reduce((n, p) => n + (p.versions?.length || 0), 0), icon: 'Collection', color: '#7c5cff', bg: 'linear-gradient(135deg,#f2edff,#e6dcff)' },
{ label: '账号', value: (ov.value?.accounts || []).length, icon: 'User', color: '#12a4d8', bg: 'linear-gradient(135deg,#e7f6fb,#d3effa)' },
{ label: '管理员', value: (ov.value?.admins || []).length, icon: 'UserFilled', color: '#22b07a', bg: 'linear-gradient(135deg,#e6f7f0,#d2f1e4)' },
{ label: '最近上传', value: latest(), icon: 'UploadFilled', color: '#d99a1b', bg: 'linear-gradient(135deg,#fbf3e2,#f6e8c8)', small: true },
{ label: '插件', value: plugins.length, icon: Box, color: '#2f5cf0', bg: 'linear-gradient(135deg,#e8edfe,#d7e1fd)' },
{ 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 '—'
// ISO 时间转友好格式:2026-09-10T12:51:33 → 2026-09-10 12:51
return all.sort().at(-1).replace('T', ' ').slice(0, 16)
return fmtTime(all.sort().at(-1))
}
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
@@ -66,47 +64,39 @@ onMounted(refresh)
<style scoped>
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
gap: 16px;
grid-template-columns: repeat(auto-fill, minmax(236px, 1fr));
gap: 18px;
}
.stat-card {
position: relative; overflow: hidden;
display: flex; align-items: center; gap: 14px;
background: var(--cp-surface);
border: 1px solid var(--cp-border);
border-radius: 18px;
padding: 18px;
box-shadow: var(--cp-card-shadow);
transition: transform .22s ease, box-shadow .22s ease;
animation: cp-rise .5s cubic-bezier(.22, .61, .36, 1) both;
display: flex; align-items: center; gap: 16px;
padding: 20px;
overflow: hidden;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--cp-card-shadow-hover); }
.stat-card.wide { grid-column: span 2; }
.stat-ic {
width: 46px; height: 46px; border-radius: 14px; flex-shrink: 0;
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, .6);
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .7);
}
.stat-meta { min-width: 0; }
.stat-num { font-size: 26px; font-weight: 800; letter-spacing: .3px; line-height: 1.15; color: var(--cp-ink); font-variant-numeric: tabular-nums; }
.stat-num.sm { font-size: 13px; font-weight: 600; word-break: break-all; line-height: 1.4; }
.stat-label { font-size: 12px; color: var(--cp-ink-3); margin-top: 3px; }
.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: 18px;
margin-top: 20px;
display: flex; gap: 14px;
background: linear-gradient(135deg, rgba(59, 108, 255, .06), rgba(34, 199, 232, .05)), rgba(255, 255, 255, .7);
border: 1px solid rgba(59, 108, 255, .16);
border-radius: 16px;
padding: 18px 20px;
padding: 20px 22px;
background: linear-gradient(135deg, rgba(47, 92, 240, .05), rgba(15, 159, 155, .04)), var(--cp-panel);
}
.tip-ic {
width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
display: grid; place-items: center;
background: linear-gradient(135deg, #3b6cff, #22c7e8);
background: linear-gradient(135deg, var(--cp-blue), var(--cp-teal));
color: #fff;
box-shadow: 0 6px 14px -6px rgba(59, 108, 255, .55);
box-shadow: 0 8px 16px -8px rgba(47, 92, 240, .6);
}
.tip-body b { display: block; font-size: 14px; color: var(--cp-ink); margin-bottom: 4px; }
.tip-body p { margin: 0; font-size: 12.5px; line-height: 1.7; color: var(--cp-ink-2); }
.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); }
</style>
@@ -5,125 +5,199 @@
<h3>插件管理 <span class="badge">Plugins</span></h3>
<p>上传发布插件包 · 每插件保留最近 3 个版本,超出自动清理</p>
</div>
<n-button :loading="overviewBusy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新
</n-button>
<el-button :loading="overviewBusy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<n-card class="block cp-rise" :bordered="false">
<template #header><span class="card-title">上传插件包</span></template>
<n-form inline>
<n-form-item label="插件 ID">
<n-input v-model:value="pid" placeholder="如 seal_check" style="width: 150px" />
</n-form-item>
<n-form-item label="名称">
<n-input v-model:value="pname" placeholder="插件显示名" style="width: 150px" />
</n-form-item>
<n-form-item label="版本">
<n-input v-model:value="pver" placeholder="如 1.1.0" style="width: 110px" />
</n-form-item>
<n-form-item label="包文件">
<n-space align="center" :size="8">
<n-upload :default-upload="false" :show-file-list="false" accept=".zip" @change="onFileChange">
<n-button :type="pfile ? 'info' : 'default'">
<template #icon><n-icon><UploadFilled /></n-icon></template>
<div class="cp-card block cp-rise up-card">
<div class="card-title">上传插件包</div>
<el-form inline class="up-form" @submit.prevent>
<el-form-item label="插件 ID">
<el-input v-model="pid" placeholder="如 seal_check" style="width: 160px" class="mono" />
</el-form-item>
<el-form-item label="名称">
<el-input v-model="pname" placeholder="插件显示名" style="width: 160px" />
</el-form-item>
<el-form-item label="版本">
<el-input v-model="pver" placeholder="如 1.1.0" style="width: 120px" class="mono" />
</el-form-item>
<el-form-item label="包文件">
<div class="file-row">
<el-upload :auto-upload="false" :show-file-list="false" accept=".zip" :on-change="onFileChange" ref="upRef">
<el-button :type="pfile ? 'primary' : 'default'" plain :icon="FolderOpened">
{{ pfile ? '重新选择' : '选择 ZIP 包' }}
</n-button>
</n-upload>
<n-tag v-if="pfile" size="small" round type="info" :bordered="false">{{ pfile.name }}</n-tag>
</n-space>
</n-form-item>
<n-form-item>
<n-button type="primary" :loading="uploading" @click="upload">
<template #icon v-if="!uploading"><n-icon><UploadFilled /></n-icon></template>上传发布
</n-button>
</n-form-item>
</n-form>
</el-button>
</el-upload>
<el-tag v-if="pfile" size="small" round effect="plain" type="primary" class="mono">{{ pfile.name }}</el-tag>
</div>
</el-form-item>
<el-form-item>
<el-button type="primary" :loading="uploading" :icon="UploadFilled" @click="upload">上传发布</el-button>
</el-form-item>
</el-form>
<div class="hint">包根目录需含 plugin.json / main.py / requirements.txt,ZIP 完整性校验通过才会发布。</div>
</n-card>
</div>
<n-card class="block cp-rise" :bordered="false">
<template #header><span class="card-title">插件列表</span></template>
<n-data-table
:columns="columns"
:data="plugins"
:loading="overviewBusy"
:row-key="r => r.id"
:single-line="false"
:row-props="rowProps"
/>
</n-card>
<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">
<el-table-column label="插件 ID" min-width="160">
<template #default="{ row }"><b class="cell-strong mono">{{ row.id }}</b></template>
</el-table-column>
<el-table-column label="名称" min-width="180" show-overflow-tooltip prop="name" />
<el-table-column label="分类" min-width="110">
<template #default="{ row }">
<el-tag v-if="row.category" size="small" effect="plain" type="info" round>{{ row.category }}</el-tag>
<span v-else class="dim">—</span>
</template>
</el-table-column>
<el-table-column label="状态" min-width="100">
<template #default="{ row }">
<el-tag size="small" round effect="light" :type="statusMeta[row.status]?.type || 'info'">
{{ statusMeta[row.status]?.label || row.status || '—' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="最新版" min-width="110">
<template #default="{ row }"><span class="mono">{{ row.latest_version || '—' }}</span></template>
</el-table-column>
<el-table-column label="操作" width="210" fixed="right">
<template #default="{ row }">
<div class="cell-ops">
<el-button link type="info" :icon="View" @click="openDetail(row)">详情</el-button>
<el-button link type="primary" :icon="Edit" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" :icon="Delete" @click="delPlugin(row)">删除</el-button>
</div>
</template>
</el-table-column>
</el-table>
</div>
<n-modal v-model:show="editShow" preset="card" :bordered="false" style="width: 560px" :title="`编辑插件 · ${edit.pid}`">
<n-form label-placement="top">
<n-form-item label="名称">
<n-input v-model:value="edit.name" placeholder="插件显示名" />
</n-form-item>
<n-form-item label="分类">
<n-input v-model:value="edit.category" placeholder="如 薪酬 / 考勤 / 社保" />
</n-form-item>
<n-form-item label="描述">
<n-input v-model:value="edit.description" type="textarea" :rows="2" placeholder="插件用途说明" />
</n-form-item>
<n-form-item label="状态">
<n-radio-group v-model:value="edit.status">
<n-radio-button value="published">正常发布</n-radio-button>
<n-radio-button value="disabled">禁用(停止分发)</n-radio-button>
<n-radio-button value="revoked">下架(禁止运行)</n-radio-button>
</n-radio-group>
</n-form-item>
<n-form-item label="强制更新(留空表示不强制)" :show-feedback="false">
<!-- 编辑插件 -->
<el-dialog v-model="editShow" :title="`编辑插件 · ${edit.pid}`" width="560px" align-center destroy-on-close>
<el-form label-position="top">
<el-form-item label="名称">
<el-input v-model="edit.name" placeholder="插件显示名" />
</el-form-item>
<el-form-item label="分类">
<el-input v-model="edit.category" placeholder="如 薪酬 / 考勤 / 社保" />
</el-form-item>
<el-form-item label="描述">
<el-input v-model="edit.description" type="textarea" :rows="2" placeholder="插件用途说明" />
</el-form-item>
<el-form-item label="状态">
<el-radio-group v-model="edit.status">
<el-radio-button value="published">正常发布</el-radio-button>
<el-radio-button value="disabled">禁用(停止分发)</el-radio-button>
<el-radio-button value="revoked">下架(禁止运行)</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="强制更新(留空表示不强制)">
<div class="force-row">
<n-input v-model:value="edit.force_min" placeholder="最低版本,如 1.2.0" style="width: 180px" />
<n-input v-model:value="edit.force_dl" type="datetime-local" placeholder="截止时间" style="width: 200px" />
<div class="force-line">
<el-input v-model="edit.force_min" placeholder="最低版本,如 1.2.0" style="width: 180px" class="mono" />
<el-input v-model="edit.force_dl" type="datetime-local" placeholder="截止时间" style="width: 200px" class="mono" />
</div>
<span class="hint">到达截止时间后,未升级到该版本的部署机会被禁止启动</span>
</div>
</n-form-item>
</n-form>
</el-form-item>
</el-form>
<template #footer>
<div class="modal-foot">
<n-button @click="editShow = false">取消</n-button>
<n-button type="primary" :loading="saving" @click="saveEdit">保存</n-button>
<el-button @click="editShow = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="saveEdit">保存</el-button>
</div>
</template>
</n-modal>
</el-dialog>
<!-- 插件详情 -->
<el-dialog v-model="detailShow" :title="`插件详情 · ${detail?.id || ''}`" width="640px" align-center destroy-on-close>
<div v-if="detail" class="plg-detail">
<div class="d-head">
<span class="d-id mono">{{ detail.id }}</span>
<span class="d-name">{{ detail.name }}</span>
<el-tag size="small" round effect="light" :type="statusMeta[detail.status]?.type || 'info'">
{{ statusMeta[detail.status]?.label || detail.status || '—' }}
</el-tag>
</div>
<div class="d-grid">
<div class="d-item"><label>分类</label><span>{{ detail.category || '—' }}</span></div>
<div class="d-item"><label>最新版本</label><span class="mono">{{ detail.latest_version || '—' }}</span></div>
<div class="d-item"><label>表单字段</label><span class="mono">{{ detail.field_count || 0 }}</span></div>
<div class="d-item"><label>强制更新</label><span>{{ forceText(detail) }}</span></div>
</div>
<div class="d-sec"><label>描述</label><p class="d-desc">{{ detail.description || '—' }}</p></div>
<div class="d-sec">
<label>能力</label>
<div class="tags" v-if="detail.capabilities?.length">
<el-tag v-for="c in detail.capabilities" :key="c" size="small" effect="plain" round>{{ c }}</el-tag>
</div>
<span v-else class="dim">—</span>
</div>
<div class="d-sec">
<label>版本历史</label>
<div class="vlist" v-if="detail.versions?.length">
<div class="vrow" v-for="v in detail.versions" :key="v.version">
<el-tag size="small" round effect="light" class="mono"
:type="v.version === detail.latest_version ? 'primary' : 'info'">{{ v.version }}</el-tag>
<span class="vtime mono dim-sm">{{ fmtTime(v.uploaded_at) }}</span>
</div>
</div>
<span v-else class="dim">暂无版本</span>
</div>
<div class="d-sec">
<label>授权账号</label>
<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>
</div>
<span v-else class="dim">未授权</span>
</div>
</div>
<template #footer>
<el-button @click="detailShow = false">关闭</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup>
import { computed, h, onMounted, reactive, ref } from 'vue'
import { NButton, NTag } from 'naive-ui'
import { Refresh, UploadFilled } from '@element-plus/icons-vue'
import { computed, onMounted, reactive, ref } from 'vue'
import { ElMessage as message, ElMessageBox as dialog } from 'element-plus'
import { Refresh, UploadFilled, FolderOpened, Edit, Delete, View } from '@element-plus/icons-vue'
import { overview, overviewBusy, loadOverview } from '../store'
import { adminUpload, adminPluginDelete, adminPluginPatch } from '../api'
import { message, dialog } from '../naive'
import { fmtTime } from '../format'
const plugins = computed(() => overview.value?.plugins || [])
const pid = ref(''); const pname = ref(''); const pver = ref(''); const pfile = ref(null)
const uploading = ref(false)
const upRef = ref()
// 状态徽标文案与配色
const STATUS_META = {
const statusMeta = {
published: { label: '正常', type: 'success' },
disabled: { label: '禁用', type: 'warning' },
revoked: { label: '已下架', type: 'error' },
}
function renderStatus(row) {
const s = STATUS_META[row.status] || { label: row.status || '—', type: 'default' }
return h(NTag, { size: 'small', round: true, bordered: false, type: s.type }, { default: () => s.label })
revoked: { label: '已下架', type: 'danger' },
}
function onFileChange(e) {
pfile.value = e?.file?.file || null
function onFileChange(uploadFile) {
pfile.value = uploadFile.raw || null
}
function renderVersions(row) {
const list = row.versions || []
if (!list.length) return h('span', { class: 'dim' }, '—')
return h('div', { class: 'tags' }, list.map(v => h(NTag, {
size: 'small', round: true, bordered: false,
type: v.version === row.latest_version ? 'primary' : 'default',
}, { default: () => v.version })))
// —— 详情弹窗 ——
const detailShow = ref(false)
const detail = ref(null)
function openDetail(row) {
detail.value = row
detailShow.value = true
}
function forceText(p) {
if (p.force_min_version && p.force_deadline) return `${p.force_min_version} 起 · 截止 ${fmtTime(p.force_deadline)}`
return '无'
}
// —— 编辑弹窗状态 ——
@@ -163,37 +237,6 @@ async function saveEdit() {
finally { saving.value = false }
}
const columns = computed(() => [
{ title: '插件 ID', key: 'id', width: 150, render: r => h('b', { class: 'cell-strong' }, r.id) },
{ title: '名称', key: 'name', width: 130, ellipsis: { tooltip: true } },
{ title: '分类', key: 'category', width: 90, render: r => r.category ? h(NTag, { size: 'small', bordered: false, type: 'info' }, { default: () => r.category }) : h('span', { class: 'dim' }, '—') },
{
title: '能力 / 表单', key: 'caps', minWidth: 130,
render: r => h('div', { class: 'tags' }, [
...(r.capabilities?.length ? r.capabilities.map(c => h(NTag, { size: 'small', bordered: false, type: 'default' }, { default: () => c })) : [h('span', { class: 'dim' }, '—')]),
h(NTag, { size: 'small', bordered: false, type: 'info', style: 'margin-left:2px' }, { default: () => `${r.field_count || 0} 字段` }),
]),
},
{ title: '状态', key: 'status', width: 80, render: renderStatus },
{ title: '最新版', key: 'latest_version', width: 90 },
{ title: '版本历史', key: 'versions', minWidth: 200, render: renderVersions },
{
title: '授权账号', key: 'accounts', minWidth: 130,
render: r => (r.accounts?.length ? r.accounts.join('、') : h('span', { class: 'dim' }, '—')),
ellipsis: { tooltip: true },
},
{
title: '操作', key: 'actions', width: 120,
render: r => h('div', { class: 'row-acts' }, [
h(NButton, { size: 'small', text: true, type: 'primary', onClick: () => openEdit(r) }, { default: () => '编辑' }),
h(NButton, { size: 'small', text: true, type: 'error', onClick: () => delPlugin(r) }, { default: () => '删除' }),
]),
},
])
function rowProps() {
return { style: 'cursor:default' }
}
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
@@ -204,38 +247,51 @@ async function upload() {
await adminUpload(pid.value, pname.value || pid.value, pver.value, pfile.value)
message.success(`已发布 ${pid.value}@${pver.value}`)
pid.value = ''; pname.value = ''; pver.value = ''; pfile.value = null
upRef.value?.clearFiles()
await refresh()
} catch (e) { message.error('上传失败:' + (e.message || e)) }
finally { uploading.value = false }
}
function delPlugin(p) {
dialog.warning({
title: '删除插件',
content: `确认删除插件 ${p.id}?其全部版本与授权将一并清除`,
positiveText: '删除',
negativeText: '取消',
onPositiveClick: async () => {
try { await adminPluginDelete({ plugin_id: p.id }); message.success(`已删除插件 ${p.id}`); await refresh() }
catch (e) { message.error(e.message || e) }
},
})
dialog.confirm(`确认删除插件 ${p.id}?其全部版本与授权将一并清除`, '删除插件', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消',
}).then(async () => {
try { await adminPluginDelete({ plugin_id: p.id }); message.success(`已删除插件 ${p.id}`); await refresh() }
catch (e) { message.error(e.message || e) }
}).catch(() => {})
}
onMounted(refresh)
</script>
<style scoped>
.hint { font-size: 12px; color: var(--cp-ink-3); margin-top: 4px; }
.up-card, .list-card { padding: 20px 22px; }
.up-card .card-title { margin-bottom: 16px; }
.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; }
.force-row { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.force-line { display: flex; gap: 10px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
</style>
.cell-ops { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.cell-ops .el-button { padding: 0 4px; }
.cell-ops .el-button + .el-button { margin-left: 0; }
<!-- 以下类用于 n-data-table 列 render 中由 naive-ui 作用域动态渲染的节点,
它们不继承本组件 scoped scopeId,必须用全局(非 scoped)样式才生效。 -->
<style>
.dim { color: var(--cp-ink-3); }
.cell-strong { font-weight: 600; color: var(--cp-ink-1); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.row-acts { display: flex; align-items: center; gap: 14px; white-space: nowrap; }
.row-acts .n-button { --n-padding: 0; }
.row-acts .n-button + .n-button { margin-left: 0; }
/* 插件详情 */
.plg-detail { display: flex; flex-direction: column; gap: 18px; }
.d-head { display: flex; align-items: center; gap: 10px; }
.d-id { font-size: 16px; font-weight: 800; color: var(--cp-ink-1); }
.d-name { font-size: 15px; color: var(--cp-ink-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.d-item { display: flex; flex-direction: column; gap: 5px; padding: 12px 14px; background: var(--cp-panel-2); border-radius: 12px; }
.d-item label { font-size: 11px; font-weight: 700; color: var(--cp-ink-3); letter-spacing: .4px; }
.d-item span { font-size: 13px; font-weight: 600; color: var(--cp-ink-1); }
.d-sec { display: flex; flex-direction: column; gap: 8px; }
.d-sec > label { font-size: 11px; font-weight: 700; color: var(--cp-ink-3); letter-spacing: .4px; }
.d-desc { margin: 0; font-size: 13px; line-height: 1.7; color: var(--cp-ink); background: var(--cp-panel-2); padding: 10px 14px; border-radius: 10px; }
.vlist { display: flex; flex-direction: column; gap: 6px; }
.vrow { display: flex; align-items: center; gap: 12px; }
.vtime { font-size: 12px; }
.dim-sm { color: var(--cp-ink-3); }
</style>
@@ -5,25 +5,26 @@
<h3>运行统计 <span class="badge">Stats</span></h3>
<p>账号 · 插件规模 · 执行次数/时长/成败 · 近 14 天趋势</p>
</div>
<n-button :loading="busy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新
</n-button>
<el-button :loading="busy" :icon="Refresh" @click="refresh">刷新</el-button>
</div>
<template v-if="st">
<!-- 指标卡 -->
<div class="kpis cp-rise">
<div class="kpi"><span class="num" style="color:var(--cp-blue)">{{ st.users.total }}</span><span class="lab">用户总数</span></div>
<div class="kpi"><span class="num">{{ st.plugins.total }}</span><span class="lab">插件总数</span></div>
<div class="kpi"><span class="num">{{ st.runs.total }}</span><span class="lab">累计执行</span></div>
<div class="kpi"><span class="num" style="color:#34a853">{{ st.runs.success }}</span><span class="lab">成功</span></div>
<div class="kpi"><span class="num" style="color:#e5484d">{{ st.runs.failed }}</span><span class="lab">失败</span></div>
<div class="kpi"><span class="num">{{ fmtDur(st.runs.durationSec) }}</span><span class="lab">总运行时长</span></div>
<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-meta">
<div class="kpi-num mono" :style="{ color: k.color }">{{ k.value }}</div>
<div class="kpi-lab">{{ k.label }}</div>
</div>
</div>
</div>
<div class="grid cp-rise">
<div class="grid">
<!-- 近 14 天趋势 -->
<div class="card">
<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})`">
@@ -31,33 +32,44 @@
<div class="tbar failed" :style="{ height: pct(d.failed, maxRuns) + '%' }"></div>
<div class="tbar success" :style="{ height: pct(d.success, maxRuns) + '%' }"></div>
</div>
<span class="tday">{{ d.day }}</span>
<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>
</div>
<!-- 插件 / 用户排行 -->
<div class="rank-wrap">
<div class="card">
<div class="card-title">插件排行(按运行次数)</div>
<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">{{ i + 1 }}</span>
<span class="rk mono" :class="{ top: i < 3 }">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead"><span class="rname">{{ p.name || p.pluginId }}</span><em>{{ p.runs }} 次</em></div>
<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>
</li>
<li v-if="!st.topPlugins.length" class="empty">暂无运行记录</li>
</ul>
</div>
<div class="card">
<div class="card-title">活跃用户</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">{{ i + 1 }}</span>
<span class="rk mono" :class="{ top: i < 3 }">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead"><span class="rname">{{ u.account }}</span><em>{{ u.runs }} 次</em></div>
<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>
@@ -70,39 +82,76 @@
<div class="page-head sub cp-rise">
<div><h4>最近运行</h4></div>
</div>
<n-card class="cp-rise" :bordered="false" size="small">
<n-data-table :columns="recentCols" :data="st.recent" size="small" :row-key="r => r.at + r.pluginId" :single-line="false" />
</n-card>
<div class="cp-card cp-rise recent-card">
<el-table :data="st.recent" size="small" :row-key="r => r.at + r.pluginId">
<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) }">{{ statusLabel(row.status) }}</span></span>
</template>
</el-table-column>
<el-table-column label="账号" width="140">
<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>
</template>
</el-table-column>
<el-table-column label="插件" width="160" show-overflow-tooltip>
<template #default="{ row }"><span class="mono">{{ row.pluginId }}</span></template>
</el-table-column>
<el-table-column label="版本" width="100">
<template #default="{ row }"><span class="mono">{{ row.version }}</span></template>
</el-table-column>
<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>
</el-table>
</div>
</template>
<n-skeleton v-else-if="busy" text :repeat="4" style="margin-top: 20px" />
<div v-else class="empty-tip cp-rise">加载失败或暂无数据</div>
<el-skeleton v-else-if="busy" animated :rows="5" style="margin-top: 20px" />
<div v-else class="empty-tip cp-card cp-rise">加载失败或暂无数据</div>
</div>
</template>
<script setup>
import { onMounted, ref } from 'vue'
import { h } from 'vue'
import { NTag } from 'naive-ui'
import { Refresh } from '@element-plus/icons-vue'
import { computed, onMounted, ref } 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'
import { message } from '../naive'
import { fmtTime } from '../format'
const busy = ref(false)
const st = ref(null)
function statusTag(s) {
const map = { done: 'success', success: 'success', error: 'error', failed: 'error', running: 'info', start: 'info' }
return h(NTag, { size: 'small', bordered: false, type: map[s] || 'default', round: true },
{ default: () => (s === 'done' || s === 'success' ? '成功' : s === 'error' || s === 'failed' ? '失败' : s) })
const kpis = computed(() => {
if (!st.value) return []
const r = st.value
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: 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)' },
]
})
function statusColor(s) {
return { done: '#1d9d5c', success: '#1d9d5c', error: '#d6453d', failed: '#d6453d', running: '#2f5cf0', start: '#2f5cf0' }[s] || '#9aa2b4'
}
function acctCell(r) {
const nn = r.nickname
if (!nn) return h('span', null, r.account || '—')
return h('div', { class: 'acct' }, [
h('div', { class: 'ann' }, r.account || '—'),
h('div', { class: 'anick' }, nn || ''),
])
function statusLabel(s) {
return (s === 'done' || s === 'success') ? '成功' : (s === 'error' || s === 'failed') ? '失败' : s
}
function fmtDur(sec) {
sec = +sec || 0
@@ -112,17 +161,8 @@ function fmtDur(sec) {
const hh = Math.floor(m / 60)
return `${hh}h${m % 60}m`
}
const recentCols = [
{ title: '时间', key: 'at', width: 165 },
{ title: '状态', key: 'status', width: 90, render: r => statusTag(r.status) },
{ title: '账号', key: 'account', width: 110, render: r => acctCell(r) },
{ title: '插件', key: 'pluginId', width: 150, ellipsis: { tooltip: true } },
{ title: '版本', key: 'version', width: 90 },
{ title: '时长', key: 'durationSec', width: 90, render: r => fmtDur(r.durationSec) },
{ title: '信息', key: 'msg', minWidth: 220, ellipsis: { tooltip: true }, render: r => r.msg || h('span', { class: 'dim' }, '—') },
]
const maxRuns = () => Math.max(1, ...(st.value?.trend || []).map(t => t.runs || 0))
const pct = (n, max) => Math.max(1, Math.round((n || 0) / (max || 1) * 100))
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))
async function refresh() {
@@ -141,36 +181,59 @@ onMounted(refresh)
</script>
<style scoped>
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; }
.kpi .num { font-size: 26px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi .lab { font-size: 12px; color: var(--cp-ink-3); }
.grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
.rank-wrap { display: flex; flex-direction: column; gap: 16px; }
.card { padding: 18px 20px; }
.card-title { font-size: 14px; font-weight: 600; color: var(--cp-ink-1); margin-bottom: 14px; }
.trend { display: flex; gap: 4px; height: 160px; align-items: stretch; }
.tcol { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.tstack { flex: 1; display: flex; align-items: flex-end; gap: 1px; width: 100%; }
.tbar { flex: 1; border-radius: 1px 1px 0 0; }
.tbar.success { background: #34a853; }
.tbar.failed { background: #e5484d; }
.tday { font-size: 10px; color: var(--cp-ink-3); }
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.rank .rk { width: 20px; height: 20px; flex: none; border-radius: 6px; background: var(--cp-bg-2); color: var(--cp-ink-3); font-size: 12px; display: flex; align-items: center; justify-content: center; }
.rank li:nth-child(1) .rk { background: rgba(59,108,255,.12); color: var(--cp-blue); }
.rank .rbody { flex: 1; min-width: 0; }
.rhead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 5px; }
.rname { font-size: 13px; color: var(--cp-ink-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rhead em { font-style: normal; font-size: 12px; color: var(--cp-ink-3); }
.rbar { height: 5px; border-radius: 3px; background: var(--cp-bg-2); overflow: hidden; }
.rbar i { display: block; height: 100%; background: var(--cp-blue); border-radius: 3px; }
.page-head.sub h4 { margin: 0; font-size: 15px; }
.empty { color: var(--cp-ink-3); font-size: 12px; justify-content: center; padding: 16px 0 !important; }
.empty-tip { padding: 30px; text-align: center; color: var(--cp-ink-3); }
</style>
.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-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; }
<style>
.dim { color: var(--cp-ink-3); }
</style>
.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; }
.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 .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; }
.rname { font-size: 13px; font-weight: 600; color: var(--cp-ink-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.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-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); }
</style>