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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user