refactor: 完成项目目录重构与代码迁移

本次提交完成了整体项目的目录梳理与代码迁移:
1.  将根级controlplane、webhost等目录的代码迁移至desktop/对应子目录,统一桌面端架构
2.  移动并整理了插件目录结构,将插件统一放入根级plugins/
3.  调整了前端项目的路径与配置,统一前后端开发构建流程
4.  清理了废弃的旧版app/目录与冗余的构建中间文件
5.  更新了.gitignore与README.md,适配新的项目结构
This commit is contained in:
2026-09-14 17:46:09 +08:00
parent a1a06504a5
commit 0ab43d0ed8
131 changed files with 4071 additions and 38034 deletions
+215
View File
@@ -0,0 +1,215 @@
<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>
</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.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>
<PasswordDialog v-model="pwdOpen" />
</n-config-provider>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue'
import { ArrowDown } from '@element-plus/icons-vue'
import { themeOverrides, zhCN, dateZhCN, message } from './naive'
import LoginPage from './components/LoginPage.vue'
import PasswordDialog from './components/PasswordDialog.vue'
import OverviewView from './views/OverviewView.vue'
import PluginManageView from './views/PluginManageView.vue'
import AccountManageView from './views/AccountManageView.vue'
import GrantManageView from './views/GrantManageView.vue'
import StatsView from './views/StatsView.vue'
import AuditView from './views/AuditView.vue'
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' },
]
// 轻量 hash 路由:StaticFiles(html=True) 下刷新安全,零后端改动
const KEY = {
'#/overview': 'overview',
'#/stats': 'stats',
'#/plugins': 'plugins',
'#/accounts': 'accounts',
'#/grants': 'grants',
'#/audit': 'audit',
}
const VIEWS = {
'#/overview': OverviewView,
'#/stats': StatsView,
'#/plugins': PluginManageView,
'#/accounts': AccountManageView,
'#/grants': GrantManageView,
'#/audit': AuditView,
}
const route = ref(VIEWS[location.hash] ? location.hash : '#/overview')
window.addEventListener('hashchange', () => {
if (VIEWS[location.hash]) route.value = location.hash
})
const viewComp = computed(() => VIEWS[route.value] || OverviewView)
const activeKey = computed(() => KEY[route.value] || 'overview')
function onMenu(key) {
const h = '#/' + key
location.hash = h
route.value = h
}
const initial = computed(() => (store.current || '')[0]?.toUpperCase() || '?')
const pwdOpen = ref(false)
function onCommand(cmd) {
if (cmd === 'pwd') pwdOpen.value = true
else if (cmd === 'logout') {
clearSession()
message.success('已退出登录')
}
}
function onLogin() {
route.value = '#/overview'
location.hash = '#/overview'
}
onMounted(async () => {
// 已本地标记登录时,校验登录票据仍有效且为管理员(票据过期/权限变更后回登录页)
if (!store.current) return
try {
const me = await adminMe()
if (!me.account || !me.is_admin) clearSession()
else store.isAdmin = true
} catch (_) { /* 后端 down:保持本地态 */ }
})
</script>
<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);
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);
}
.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%);
color: #fff; font-size: 14px; font-weight: 800; letter-spacing: .5px;
box-shadow: 0 6px 16px -6px rgba(59, 108, 255, .6);
}
.logo::after { content: ''; position: absolute; inset: 2px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .28); }
.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 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;
}
.acct:hover { background: rgba(59, 108, 255, .07); }
.avatar {
width: 30px; height: 30px; border-radius: 50%;
display: grid; place-items: center;
background: linear-gradient(135deg, #3b6cff, #22c7e8);
color: #fff; font-size: 13px; font-weight: 700;
}
.acct-name { font-size: 13px; font-weight: 600; color: var(--cp-ink); }
.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; }
.aside {
width: 208px; 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;
}
.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; }
/* 页面切换过渡:轻微上浮淡入 */
.view-fade-enter-active { transition: opacity .22s ease, transform .22s ease; }
.view-fade-leave-active { transition: opacity .12s ease; }
.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;
}
</style>
+116
View File
@@ -0,0 +1,116 @@
// 与 FastAPI 后端交互,控制面前端直连 /api/*
import { store } from './store.js'
async function req(url, opts) {
const res = await fetch(url, opts)
if (!res.ok) {
let msg = `HTTP ${res.status}`
try { msg = (await res.json()).detail || msg } catch (_) {}
throw new Error(msg)
}
return res.json()
}
// 管理接口无状态鉴权:携带登录后签发的签名票据(X-Admin-Token),后端验票解得当前账号
function adminHeaders(extra = {}) {
return { 'X-Admin-Token': store.token || '', ...extra }
}
export async function adminLogin(account, password) {
return req('/api/admin/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ account, password })
})
}
export async function adminPassword(body) {
return req('/api/admin/password', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminMe() {
return req('/api/admin/me', { headers: adminHeaders() })
}
export async function adminOverview() {
return req('/api/admin/overview', { headers: adminHeaders() })
}
export async function adminPlatforms() {
return req('/api/admin/platforms', { headers: adminHeaders() })
}
export async function adminGrant(body) {
return req('/api/admin/account_plugins', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminPlatformGrant(body) {
return req('/api/admin/account_platforms', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminAccounts() {
return req('/api/admin/accounts', { headers: adminHeaders() })
}
export async function adminAccountCreate(body) {
return req('/api/admin/account', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminAccountUpdate(body) {
return req('/api/admin/account/update', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminAccountReset(body) {
return req('/api/admin/account/reset_pwd', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminAccountDelete(body) {
return req('/api/admin/account/delete', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminPluginDelete(body) {
return req('/api/admin/plugin/delete', {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminPluginPatch(pluginId, body) {
const qs = new URLSearchParams({ plugin_id: pluginId })
return req('/api/admin/plugin/patch?' + qs.toString(), {
method: 'POST',
headers: adminHeaders({ 'Content-Type': 'application/json' }),
body: JSON.stringify(body)
})
}
export async function adminAudit(limit = 300) {
return req('/api/admin/audit?limit=' + limit, { headers: adminHeaders() })
}
export async function adminReports(limit = 300) {
return req('/api/admin/reports?limit=' + limit, { headers: adminHeaders() })
}
export async function adminStats() {
return req('/api/admin/stats', { headers: adminHeaders() })
}
export async function adminUpload(pluginId, name, version, file) {
const fd = new FormData()
fd.append('upload', file)
const qs = new URLSearchParams({ plugin_id: pluginId, name, version })
return req('/api/admin/pkg?' + qs.toString(), { method: 'POST', headers: adminHeaders(), body: fd })
}
@@ -0,0 +1,125 @@
<template>
<div class="login">
<div class="card">
<div class="brand">
<span class="logo">37</span>
<div class="brand-meta">
<h1>{{ appName }}</h1>
<p>中心机统一账户登录</p>
</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">
{{ busy ? '登录中…' : '登 录' }}
</n-button>
</n-form>
<div class="foot">内网管理面 · 请使用管理员账号登录</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { User, Lock } from '@element-plus/icons-vue'
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'])
const account = ref('')
const password = ref('')
const busy = ref(false)
async function doLogin() {
if (busy.value) return
const acct = account.value.trim()
if (!acct || !password.value) { message.warning('请输入账号与密码'); return }
busy.value = true
try {
const r = await adminLogin(acct, password.value)
if (!r.ok) throw new Error('登录失败')
if (!r.is_admin) { throw new Error('该账号无管理权限') }
store.current = acct
store.token = r.token || ''
store.isAdmin = true
try { localStorage.setItem('cp_account', acct); localStorage.setItem('cp_token', store.token) } catch (_) {}
message.success(`欢迎,${acct}`)
emit('ok', r)
} catch (e) {
message.error(e.message || String(e))
} finally {
busy.value = false
}
}
</script>
<style scoped>
.login {
min-height: 100vh;
display: flex;
align-items: center;
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;
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);
}
.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);
}
.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; }
.primary.n-button--primary-type { height: 44px; border-radius: 8px; font-size: 14px; letter-spacing: .1em; }
.foot { margin-top: 20px; text-align: center; font-size: 11.5px; color: var(--cp-ink-3, #8a93a6); }
</style>
@@ -0,0 +1,70 @@
<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>
<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>
</template>
</n-modal>
</template>
<script setup>
import { reactive, ref } from 'vue'
import { store } from '../store'
import { adminPassword } from '../api'
import { message } from '../naive'
const visible = defineModel({ type: Boolean, default: false })
const formRef = ref()
const busy = ref(false)
const form = reactive({ oldPwd: '', newPwd: '', newPwd2: '' })
const rules = {
oldPwd: { required: true, message: '请输入原密码' },
newPwd: [
{ required: true, message: '请输入新密码' },
{ min: 6, message: '新密码至少 6 位' },
{ validator: (_r, v) => (v && v === form.oldPwd ? new Error('新密码不能与原密码相同') : true), message: '新密码不能与原密码相同' },
],
newPwd2: [
{ required: true, message: '请再次输入新密码' },
{ validator: (_r, v) => (v !== form.newPwd ? new Error('两次输入的密码不一致') : true), message: '两次输入的密码不一致' },
],
}
function reset() {
form.oldPwd = form.newPwd = form.newPwd2 = ''
formRef.value?.restoreValidation()
}
async function submit() {
try { await formRef.value.validate() } catch (_) { return }
busy.value = true
try {
await adminPassword({ account: store.current, old_password: form.oldPwd, new_password: form.newPwd })
message.success('密码已修改,下次登录请使用新密码')
visible.value = false
} catch (e) {
message.error('修改失败:' + (e.message || e))
} finally {
busy.value = false
}
}
</script>
<style scoped>
.acct-tip { margin-bottom: 14px; }
</style>
+13
View File
@@ -0,0 +1,13 @@
import { createApp } from 'vue'
import naive from 'naive-ui'
// 图标沿用 @element-plus/icons-vue(纯 SVG 组件,与 UI 框架解耦)
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
import './style.css'
const app = createApp(App)
// 全量注册图标,模板中可直接用图标名,概览页卡片动态渲染需要
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component)
}
app.use(naive).mount('#app')
@@ -0,0 +1,62 @@
// 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 }
@@ -0,0 +1,40 @@
import { reactive, ref } from 'vue'
import { adminOverview } from './api'
export const store = reactive({
appName: '37du 内网插件控制面',
isAdmin: false,
current: _get('cp_account'),
token: _get('cp_token'),
})
// 概览数据缓存:各管理页共用一份 adminOverview 结果,避免切页重复拉取
export const overview = ref(null)
export const overviewBusy = ref(false)
export async function loadOverview(force = false) {
if (overview.value && !force) return overview.value
overviewBusy.value = true
try {
overview.value = await adminOverview()
return overview.value
} finally {
overviewBusy.value = false
}
}
export function resetOverview() {
overview.value = null
}
function _get(key) {
try { return localStorage.getItem(key) || '' } catch (_) { return '' }
}
export function clearSession() {
store.current = ''
store.token = ''
store.isAdmin = false
resetOverview()
try { localStorage.removeItem('cp_account'); localStorage.removeItem('cp_token') } catch (_) {}
}
@@ -0,0 +1,77 @@
/* ============ 37du 内网插件控制面 全局基础样式(组件由 Naive UI 提供) ============ */
: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);
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
font-family: "HarmonyOS Sans SC", "Microsoft YaHei UI", "PingFang SC", -apple-system, "Segoe UI", sans-serif;
font-size: 13px;
color: var(--cp-ink);
-webkit-font-smoothing: antialiased;
background-color: #eaf0fb;
/* 浅色极光画布:三层低透明光晕 + 渐变底 */
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%);
background-attachment: fixed;
}
::selection { background: rgba(59, 108, 255, .18); }
::-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-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);
}
.n-data-table {
--n-border-color: rgba(88, 113, 183, .10);
}
/* ---------- 共享页面工具类 ---------- */
.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; }
.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;
}
.page-head p { margin: 0; font-size: 12.5px; color: var(--cp-ink-3); }
.block { margin-bottom: 16px; }
.dim { color: var(--cp-ink-3); }
.who { color: var(--cp-blue); font-weight: 600; }
/* 卡片标题前的小渐变竖条 */
.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); }
/* 表格单元格通用 */
.cell-strong { font-weight: 700; color: var(--cp-ink); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
/* ---------- 动效 ---------- */
@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; }
@@ -0,0 +1,240 @@
<template>
<div class="page">
<div class="page-head cp-rise">
<div>
<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>
<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>
<!-- 新建账号 -->
<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>
<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>
</template>
</n-modal>
<!-- 重置密码 -->
<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" />
<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>
</template>
</n-modal>
</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 { store, overview, overviewBusy, loadOverview } from '../store'
import { adminAccountCreate, adminAccountUpdate, adminAccountReset, adminAccountDelete } from '../api'
import { message, dialog } from '../naive'
const current = computed(() => store.current || '')
const accounts = computed(() => overview.value?.accounts || [])
// ---------- 部门 / 昵称 行内编辑 ----------
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) }
}
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 })))
}
const columns = computed(() => [
{ title: '账号', key: 'account', width: 140, render: r => h('b', { class: 'cell-strong' }, r.account) },
{ title: '昵称', key: 'nickname', width: 150, render: r => inlineInput(r, 'nickname') },
{
title: '部门', key: 'dept', width: 160,
render: (row) => inlineInput(row, 'dept'),
},
{
title: '管理员', key: 'is_admin', width: 100,
render: (row) => h(NSwitch, {
value: !!row.is_admin,
disabled: row.account === current.value,
onUpdateValue: () => toggleAdmin(row),
}),
},
{ title: '已授权插件', key: 'plugins', minWidth: 180, render: r => renderTags(r.plugins, 'plugin') },
{ title: '已授权平台', key: 'platforms', minWidth: 140, 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 form = reactive({ account: '', password: '', dept: '', nickname: '', is_admin: false })
const rules = {
account: { required: true, message: '请输入账号' },
password: [
{ required: true, message: '请输入初始密码' },
{ min: 6, message: '密码至少 6 位' },
],
}
function openCreate() { createOpen.value = true }
function resetCreate() {
form.account = form.password = form.dept = form.nickname = ''
form.is_admin = false
formRef.value?.restoreValidation()
}
async function createAccount() {
try { await formRef.value.validate() } catch (_) { return }
creating.value = true
try {
await adminAccountCreate({ ...form, account: form.account.trim() })
message.success(`已建号 ${form.account.trim()}`)
createOpen.value = false
await refresh()
} catch (e) { message.error('建号失败:' + (e.message || e)) }
finally { creating.value = false }
}
// ---------- 重置密码 ----------
const resetOpen = ref(false)
const resetTarget = ref('')
const resetPwdVal = ref('')
const resetting = ref(false)
function resetPwd(row) {
resetTarget.value = row.account
resetPwdVal.value = ''
resetOpen.value = true
}
async function confirmReset() {
const p = resetPwdVal.value
if (p.length < 6) { message.warning('密码至少 6 位'); return }
resetting.value = true
try {
await adminAccountReset({ account: resetTarget.value, new_password: p })
message.success(`已重置 ${resetTarget.value} 密码`)
resetOpen.value = false
} catch (e) { message.error(e.message || e) }
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) }
},
})
}
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>
<!-- 列 render 中由 naive-ui 动态渲染的节点不继承 scoped scopeId,须用全局样式 -->
<style>
.ops { display: flex; align-items: center; gap: 16px; }
.ops .n-button { padding: 0 4px; }
</style>
@@ -0,0 +1,108 @@
<template>
<div class="page">
<div class="page-head cp-rise">
<div>
<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>
</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>
</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 { adminAudit, adminReports } from '../api'
import { message } from '../naive'
const tab = ref('audit')
const busy = ref(false)
const audits = ref([])
const reports = ref([])
const DETAIL_LABEL = {
grant: '授权', 'revoke-grant': '撤销授权', 'plugin-patch': '更新插件',
'download-ticket': '下载', 'upload-pkg': '上传', 'account-create': '建号',
'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 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 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'
const m = Math.floor(sec / 60), s = sec % 60
if (m < 60) return `${m}m${s ? s + 's' : ''}`
return `${Math.floor(m / 60)}h${m % 60}m`
}
async function refresh() {
busy.value = true
try {
const [a, r] = await Promise.all([adminAudit(), adminReports()])
audits.value = a.auditlogs || []
reports.value = r.reports || []
} catch (e) { message.error('读取失败:' + (e.message || e)) }
finally { busy.value = false }
}
onMounted(refresh)
</script>
<style scoped>
.dim { color: var(--cp-ink-3); }
</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>
@@ -0,0 +1,227 @@
<template>
<div class="page">
<div class="page-head cp-rise">
<div>
<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>
</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>
<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>
</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>
<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>
</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>
<n-empty v-else description="先在上方选择一个账号" class="no-acc cp-rise" />
</div>
</template>
<script setup>
import { computed, onMounted, ref, watch } from 'vue'
import { Refresh } from '@element-plus/icons-vue'
import { overview, overviewBusy, loadOverview } from '../store'
import { adminGrant, adminPlatformGrant, adminPlatforms } from '../api'
import { message } from '../naive'
const PLATFORM_OPTS = ref([])
const plugins = computed(() => overview.value?.plugins || [])
const accounts = computed(() => overview.value?.accounts || [])
const accountOptions = computed(() => accounts.value.map(a => ({
label: a.dept ? `${a.account} · ${a.dept}` : a.account,
value: a.account,
})))
const account = ref('')
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()
function setGrant(pid, patch) {
grantState.value[pid] = { ...grantState.value[pid], ...patch }
grantState.value = { ...grantState.value }
}
// 选中账号即自动载入其现有授权
watch(account, (acc) => {
const a = accounts.value.find(x => x.account === acc)
const state = {}
;(a?.plugins || []).forEach(pid => {
const g = a?.grants?.[pid] || {}
state[pid] = { granted: true, canRun: g.canRun !== false, canDownload: g.canDownload !== false }
})
heldGrantState = JSON.parse(JSON.stringify(state))
grantState.value = JSON.parse(JSON.stringify(state))
grantedIds.value = [...(a?.plugins || [])]
heldPlatforms = new Set(a?.platforms || [])
platChecked.value = [...heldPlatforms]
})
// 勾选/取消勾选插件时同步 granted 状态
watch(grantedIds, (ids) => {
const state = { ...grantState.value }
ids.forEach(pid => {
if (!state[pid]) state[pid] = { granted: true, canRun: true, canDownload: true }
else state[pid].granted = true
})
Object.keys(state).forEach(pid => {
if (!ids.includes(pid)) state[pid].granted = false
})
grantState.value = state
})
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
// 拉取可授权平台列表(后端只读接口,替代写死 hr/oa)
async function loadPlatforms() {
try {
const r = await adminPlatforms()
PLATFORM_OPTS.value = (r.platforms || []).map(p => ({ id: p.id, label: p.label }))
} catch (e) { message.error('平台列表读取失败:' + (e.message || e)) }
}
async function saveGrant() {
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))
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 }
}
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; }
/* 授权项:卡片式勾选 */
.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);
border-radius: 12px;
background: rgba(255, 255, 255, .65);
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);
}
:deep(.n-checkbox .n-checkbox__label) { padding-left: 4px; flex: 1; min-width: 0; }
</style>
@@ -0,0 +1,112 @@
<template>
<div class="page">
<div class="page-head cp-rise">
<div>
<h3>概览 <span class="badge">Dashboard</span></h3>
<p>中心机 · 插件分发与账号权限 · 当前账号 <b class="who">{{ store.current }}</b></p>
</div>
<n-button :loading="overviewBusy" @click="refresh">
<template #icon><n-icon><Refresh /></n-icon></template>刷新
</n-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-ic" :style="{ background: s.bg, color: s.color }">
<n-icon :size="20"><component :is="s.icon" /></n-icon>
</div>
<div class="stat-meta">
<div class="stat-num" :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" />
<div class="tip-card cp-rise">
<div class="tip-ic"><n-icon :size="18"><InfoFilled /></n-icon></div>
<div class="tip-body">
<b>使用说明</b>
<p>「插件管理」上传与发布插件包(每插件保留最近 3 个版本);「账号管理」建号与账号维护;「权限授权」按账号勾选可用的插件与平台。部署机(webhost)仅在启动与手动刷新时拉取插件,授权变更后需在部署机刷新生效。</p>
</div>
</div>
</div>
</template>
<script setup>
import { computed, onMounted } from 'vue'
import { Refresh, InfoFilled } from '@element-plus/icons-vue'
import { store, overview, overviewBusy, loadOverview } from '../store'
import { message } from '../naive'
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 },
]
})
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)
}
async function refresh() {
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
}
onMounted(refresh)
</script>
<style scoped>
.stat-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
gap: 16px;
}
.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;
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--cp-card-shadow-hover); }
.stat-ic {
width: 46px; height: 46px; border-radius: 14px; flex-shrink: 0;
display: grid; place-items: center;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .6);
}
.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-glow { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; border-radius: 0 6px 6px 0; opacity: .9; }
.tip-card {
margin-top: 18px;
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;
}
.tip-ic {
width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
display: grid; place-items: center;
background: linear-gradient(135deg, #3b6cff, #22c7e8);
color: #fff;
box-shadow: 0 6px 14px -6px rgba(59, 108, 255, .55);
}
.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); }
</style>
@@ -0,0 +1,241 @@
<template>
<div class="page">
<div class="page-head cp-rise">
<div>
<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>
</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>
{{ 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>
<div class="hint">包根目录需含 plugin.json / main.py / requirements.txt,ZIP 完整性校验通过才会发布。</div>
</n-card>
<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>
<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">
<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" />
<span class="hint">到达截止时间后,未升级到该版本的部署机会被禁止启动</span>
</div>
</n-form-item>
</n-form>
<template #footer>
<div class="modal-foot">
<n-button @click="editShow = false">取消</n-button>
<n-button type="primary" :loading="saving" @click="saveEdit">保存</n-button>
</div>
</template>
</n-modal>
</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 { overview, overviewBusy, loadOverview } from '../store'
import { adminUpload, adminPluginDelete, adminPluginPatch } from '../api'
import { message, dialog } from '../naive'
const plugins = computed(() => overview.value?.plugins || [])
const pid = ref(''); const pname = ref(''); const pver = ref(''); const pfile = ref(null)
const uploading = ref(false)
// 状态徽标文案与配色
const STATUS_META = {
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 })
}
function onFileChange(e) {
pfile.value = e?.file?.file || 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 editShow = ref(false)
const saving = ref(false)
const edit = reactive({ pid: '', name: '', category: '', description: '', status: 'published', force_min: '', force_dl: '' })
function openEdit(row) {
edit.pid = row.id
edit.name = row.name || ''
edit.category = row.category || ''
edit.description = row.description || ''
edit.status = row.status || 'published'
edit.force_min = row.force_min_version || ''
edit.force_dl = toLocalInput(row.force_deadline)
editShow.value = true
}
// ISO 时间 → datetime-local 输入框可识别的本地格式
function toLocalInput(iso) {
if (!iso) return ''
const d = new Date(iso.endsWith('Z') ? iso : iso + 'Z')
return isNaN(d) ? '' : `${String(d.getFullYear()).padStart(4, '0')}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}T${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
}
async function saveEdit() {
if (!edit.pid) return
saving.value = true
try {
const body = { name: edit.name, category: edit.category, description: edit.description, status: edit.status }
// 强制更新:min 与 deadline 均填则成对下发;否则清除强制更新
body.force_min_version = edit.force_min || null
body.force_deadline = edit.force_dl ? new Date(edit.force_dl).toISOString() : null
body.clear_force = !(edit.force_min && edit.force_dl)
await adminPluginPatch(edit.pid, body)
message.success(`已更新插件 ${edit.pid}`)
editShow.value = false
await refresh()
} catch (e) { message.error('保存失败:' + (e.message || e)) }
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)) }
}
async function upload() {
if (!pid.value || !pver.value || !pfile.value) { message.warning('请填写插件 ID / 版本并选择 ZIP 包'); return }
uploading.value = true
try {
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
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) }
},
})
}
onMounted(refresh)
</script>
<style scoped>
.hint { font-size: 12px; color: var(--cp-ink-3); margin-top: 4px; }
.force-row { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
</style>
<!-- 以下类用于 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; }
</style>
@@ -0,0 +1,176 @@
<template>
<div class="page">
<div class="page-head cp-rise">
<div>
<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>
</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>
<div class="grid cp-rise">
<!-- 近 14 天趋势 -->
<div class="card">
<div class="card-title">近 14 天运行趋势</div>
<div class="trend">
<div class="tcol" v-for="d in st.trend" :key="d.day" :title="`${d.day} · ${d.runs} 次(成功 ${d.success} / 失败 ${d.failed})`">
<div class="tstack">
<div class="tbar failed" :style="{ height: pct(d.failed, maxRuns) + '%' }"></div>
<div class="tbar success" :style="{ height: pct(d.success, maxRuns) + '%' }"></div>
</div>
<span class="tday">{{ d.day }}</span>
</div>
</div>
</div>
<!-- 插件 / 用户排行 -->
<div class="rank-wrap">
<div class="card">
<div class="card-title">插件排行(按运行次数)</div>
<ul class="rank">
<li v-for="(p, i) in st.topPlugins" :key="p.pluginId">
<span class="rk">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead"><span class="rname">{{ p.name || p.pluginId }}</span><em>{{ 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>
<ul class="rank">
<li v-for="(u, i) in st.topUsers" :key="u.account">
<span class="rk">{{ i + 1 }}</span>
<div class="rbody">
<div class="rhead"><span class="rname">{{ u.account }}</span><em>{{ u.runs }} 次</em></div>
</div>
</li>
<li v-if="!st.topUsers.length" class="empty">暂无运行记录</li>
</ul>
</div>
</div>
</div>
<!-- 最近运行 -->
<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>
</template>
<n-skeleton v-else-if="busy" text :repeat="4" style="margin-top: 20px" />
<div v-else class="empty-tip 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 { adminStats } from '../api'
import { message } from '../naive'
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) })
}
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 fmtDur(sec) {
sec = +sec || 0
if (sec < 60) return sec + 's'
const m = Math.floor(sec / 60), s = sec % 60
if (m < 60) return `${m}m${s ? s + 's' : ''}`
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 rankMax = list => Math.max(1, ...(list || []).map(x => x.runs || 1))
async function refresh() {
busy.value = true
try {
const r = await adminStats()
st.value = {
users: r.users || {}, plugins: r.plugins || {}, runs: r.runs || {},
trend: r.trend || [], topPlugins: r.topPlugins || [], topUsers: r.topUsers || [],
recent: r.recent || [],
}
} catch (e) { message.error('读取失败:' + (e.message || e)) }
finally { busy.value = false }
}
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>
<style>
.dim { color: var(--cp-ink-3); }
</style>