feat: 新增多插件 UI 支持及运行日志集中回传功能
本次提交包含多项功能更新: 1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持 2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储 3. 新增插件分类字段支持,用于场景库分组管理 4. 优化 xq0034/0037/0048 等插件的功能及描述 5. 修复控制面响应兼容问题,支持新旧版本数据格式 6. 新增 xq0033 插件的状态存储模块,用于历史记录管理 7. 优化 CRM 登录窗口模式,支持全屏置顶
This commit is contained in:
@@ -37,6 +37,28 @@ export function patchPlugin(plugin_id: string, body: any) {
|
||||
return request.post<any>({ url: '/api/admin/plugin/patch', params: { plugin_id }, data: body })
|
||||
}
|
||||
|
||||
// ==================== 字典(可维护枚举,如场景分类 plugin_category) ====================
|
||||
|
||||
/** 字典项列表(sort,id 升序) */
|
||||
export function fetchDictItems(key: string) {
|
||||
return request.get<{ items: { id: number; label: string; sort: number }[] }>({ url: `/api/admin/dict/${key}/items` })
|
||||
}
|
||||
|
||||
/** 新增字典项 */
|
||||
export function addDictItem(key: string, label: string) {
|
||||
return request.post<any>({ url: `/api/admin/dict/${key}/items`, data: { label } })
|
||||
}
|
||||
|
||||
/** 改名 / 上移下移 */
|
||||
export function updateDictItem(key: string, id: number, body: { label?: string; move?: 'up' | 'down' }) {
|
||||
return request.put<any>({ url: `/api/admin/dict/${key}/items/${id}`, data: body })
|
||||
}
|
||||
|
||||
/** 删除字典项(不影响已引用该值的业务数据) */
|
||||
export function deleteDictItem(key: string, id: number) {
|
||||
return request.del<any>({ url: `/api/admin/dict/${key}/items/${id}` })
|
||||
}
|
||||
|
||||
/** 账号列表 */
|
||||
export function fetchAccounts(params: { page?: number; page_size?: number; q?: string }) {
|
||||
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/accounts', params })
|
||||
@@ -192,3 +214,53 @@ export function uploadAvatar(file: File, account: string) {
|
||||
fd.append('file', file)
|
||||
return request.post<any>({ url: '/api/admin/avatar', data: fd, params: { account }, timeout: 30000 })
|
||||
}
|
||||
|
||||
// ==================== 集中日志(运行日志 / 客户端壳日志) ====================
|
||||
|
||||
/** 运行日志列表(分页 + 账号/设备/插件/状态/关键字/近N天筛选) */
|
||||
export function fetchRunLogs(params: {
|
||||
page?: number; page_size?: number; account?: string; device?: string;
|
||||
plugin?: string; status?: string; q?: string; days?: number;
|
||||
}) {
|
||||
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/run-logs', params })
|
||||
}
|
||||
|
||||
/** 单次运行日志详情(含日志正文) */
|
||||
export function fetchRunLogDetail(runId: string) {
|
||||
return request.get<any>({ url: `/api/admin/run-logs/${encodeURIComponent(runId)}` })
|
||||
}
|
||||
|
||||
/** 客户端壳日志设备列表 */
|
||||
export function fetchDeviceLogs(params: { page?: number; page_size?: number; account?: string; q?: string }) {
|
||||
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/device-logs', params })
|
||||
}
|
||||
|
||||
/** 设备壳日志尾部内容 */
|
||||
export function fetchDeviceLogDetail(deviceId: string) {
|
||||
return request.get<any>({ url: `/api/admin/device-logs/${encodeURIComponent(deviceId)}` })
|
||||
}
|
||||
|
||||
/** 壳日志全文下载(需鉴权头,用 fetch 取 blob 触发浏览器下载) */
|
||||
export async function downloadDeviceLog(deviceId: string, filename?: string) {
|
||||
const { useUserStore } = await import('@/store/modules/user')
|
||||
const token = useUserStore().accessToken
|
||||
const base = (import.meta.env.VITE_API_URL as string) || ''
|
||||
const res = await fetch(`${base}/api/admin/device-logs/${encodeURIComponent(deviceId)}/download`, {
|
||||
headers: { 'X-Admin-Token': token || '' },
|
||||
})
|
||||
if (!res.ok) throw new Error(`下载失败 HTTP ${res.status}`)
|
||||
const blob = await res.blob()
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = filename || `shell-${deviceId}.log`
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
a.remove()
|
||||
setTimeout(() => URL.revokeObjectURL(url), 5000)
|
||||
}
|
||||
|
||||
/** 手动触发一次保留期清理 */
|
||||
export function cleanupLogs() {
|
||||
return request.post<any>({ url: '/api/admin/logs/cleanup' })
|
||||
}
|
||||
|
||||
@@ -115,6 +115,9 @@ export function sysMenuAdd(body: {
|
||||
icon?: string
|
||||
type: number
|
||||
orderNum?: number
|
||||
viewPath?: string
|
||||
keepAlive?: boolean
|
||||
isShow?: boolean
|
||||
}) {
|
||||
return request.post<any>({ url: '/api/admin/sys/menu/add', data: body })
|
||||
}
|
||||
@@ -129,6 +132,9 @@ export function sysMenuEdit(body: {
|
||||
icon?: string
|
||||
type?: number
|
||||
orderNum?: number
|
||||
viewPath?: string
|
||||
keepAlive?: boolean
|
||||
isShow?: boolean
|
||||
}) {
|
||||
return request.post<any>({ url: '/api/admin/sys/menu/edit', data: body })
|
||||
}
|
||||
|
||||
+111
-69
@@ -1,7 +1,7 @@
|
||||
<!-- 通知中心(37du:接真实 notifications 数据,与员工端壳子同源) -->
|
||||
<template>
|
||||
<div
|
||||
class="art-notification-panel art-card-sm !shadow-xl"
|
||||
class="art-notification-panel art-card-sm !shadow-xl flex flex-col"
|
||||
:style="{
|
||||
transform: show ? 'scaleY(1)' : 'scaleY(0.9)',
|
||||
opacity: show ? 1 : 0
|
||||
@@ -9,63 +9,94 @@
|
||||
v-show="visible"
|
||||
@click.stop
|
||||
>
|
||||
<div class="flex-cb px-3.5 mt-3.5">
|
||||
<span class="text-base font-medium text-g-800">通知中心</span>
|
||||
<span class="text-xs text-g-800 px-1.5 py-1 c-p select-none rounded hover:bg-g-200" @click="markAllRead">
|
||||
全部已读
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="px-3.5 mt-2 text-xs text-g-500 flex-cb">
|
||||
<span>有效通知(含定向),员工端执行机同步可见</span>
|
||||
<ArtSvgIcon icon="ri:refresh-line" class="c-p text-g-500 text-sm" @click="refresh" />
|
||||
</div>
|
||||
|
||||
<div class="w-full h-[calc(100%-95px)] mt-1">
|
||||
<div class="h-full overflow-y-scroll scrollbar-thin">
|
||||
<ul v-if="items.length">
|
||||
<li
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="box-border flex px-3.5 py-3 c-p last:border-b-0 border-b border-g-300/40 hover:bg-g-200/60"
|
||||
<!-- 头部:标题 + 操作(固定,不参与滚动) -->
|
||||
<div class="shrink-0 px-3.5 pt-3.5">
|
||||
<div class="flex-cb">
|
||||
<div class="flex-c gap-2">
|
||||
<span class="text-base font-medium text-g-800">通知中心</span>
|
||||
<span
|
||||
v-if="unreadCount > 0"
|
||||
class="text-[11px] leading-4 px-1.5 rounded-full text-white bg-[var(--el-color-danger)]"
|
||||
>
|
||||
<div class="size-9 leading-9 text-center rounded-lg flex-cc shrink-0" :class="styleOf(item.level).iconClass">
|
||||
<ArtSvgIcon class="text-lg !bg-transparent" :icon="styleOf(item.level).icon" />
|
||||
</div>
|
||||
<div class="w-[calc(100%-45px)] ml-3">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<h4 class="text-sm font-normal leading-5.5 text-g-900 m-0 truncate">{{ item.title }}</h4>
|
||||
<el-tag v-if="isNew(item)" size="small" type="danger" effect="light">新</el-tag>
|
||||
</div>
|
||||
<p class="mt-1 text-xs text-g-500 line-clamp-2 !mb-0">{{ item.content }}</p>
|
||||
<p class="mt-1 text-[11px] text-g-400 !mb-0">
|
||||
{{ fmtTime(item.created_at) }}
|
||||
<el-tag size="small" type="info" effect="plain" class="ml-1">
|
||||
{{ item.target === 'all' ? '全员' : `@${item.account}` }}
|
||||
</el-tag>
|
||||
<el-tag v-if="item.level !== 'info'" size="small" :type="styleOf(item.level).tagType" effect="plain" class="ml-1">
|
||||
{{ levelName(item.level) }}
|
||||
</el-tag>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else class="relative top-25 h-full text-g-500 text-center !bg-transparent">
|
||||
<ArtSvgIcon icon="system-uicons:inbox" class="text-5xl" />
|
||||
<p class="mt-3.5 text-xs !bg-transparent">暂无有效通知,可在「通知推送」页发布</p>
|
||||
{{ unreadCount }}
|
||||
</span>
|
||||
</div>
|
||||
<span
|
||||
class="text-xs text-g-800 px-1.5 py-1 c-p select-none rounded hover:bg-g-200"
|
||||
@click="markAllRead"
|
||||
>
|
||||
全部已读
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="relative box-border w-full px-3.5">
|
||||
<ElButton class="w-full mt-3" @click="goNotifyPage" v-ripple>前往通知推送管理</ElButton>
|
||||
<div class="mt-2 text-xs text-g-500 flex-cb">
|
||||
<span class="truncate">有效通知(含定向),员工端执行机同步可见</span>
|
||||
<ArtSvgIcon
|
||||
icon="ri:refresh-line"
|
||||
class="c-p text-g-500 text-sm ml-2 shrink-0"
|
||||
@click="refresh"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="h-10"></div>
|
||||
|
||||
<!-- 列表:自适应高度 + 独立滚动 -->
|
||||
<div class="flex-1 min-h-0 mt-1 overflow-y-auto scrollbar-thin">
|
||||
<ul v-if="items.length" class="m-0 p-0 list-none">
|
||||
<li
|
||||
v-for="item in items"
|
||||
:key="item.id"
|
||||
class="box-border flex px-3.5 py-3 c-p last:border-b-0 border-b border-g-300/40 hover:bg-g-200/60"
|
||||
>
|
||||
<div
|
||||
class="size-9 leading-9 text-center rounded-lg flex-cc shrink-0"
|
||||
:class="styleOf(item.level).iconClass"
|
||||
>
|
||||
<ArtSvgIcon class="text-lg !bg-transparent" :icon="styleOf(item.level).icon" />
|
||||
</div>
|
||||
<div class="flex-1 min-w-0 ml-3">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<h4 class="text-sm font-normal leading-5.5 text-g-900 m-0 truncate">
|
||||
{{ item.title }}
|
||||
</h4>
|
||||
<el-tag v-if="isNew(item)" size="small" type="danger" effect="light">新</el-tag>
|
||||
</div>
|
||||
<p class="mt-1 text-xs text-g-500 line-clamp-2 !mb-0">{{ item.content }}</p>
|
||||
<p class="mt-1 text-[11px] text-g-400 !mb-0">
|
||||
{{ fmtTime(item.created_at) }}
|
||||
<el-tag size="small" type="info" effect="plain" class="ml-1">
|
||||
{{ item.target === 'all' ? '全员' : `@${item.account}` }}
|
||||
</el-tag>
|
||||
<el-tag
|
||||
v-if="item.level !== 'info'"
|
||||
size="small"
|
||||
:type="styleOf(item.level).tagType"
|
||||
effect="plain"
|
||||
class="ml-1"
|
||||
>
|
||||
{{ levelName(item.level) }}
|
||||
</el-tag>
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-else class="h-full flex-cc flex-col text-g-500 py-10">
|
||||
<ArtSvgIcon icon="system-uicons:inbox" class="text-5xl" />
|
||||
<p class="mt-3.5 text-xs">暂无有效通知,可在「通知推送」页发布</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部操作:固定,不再被裁切 -->
|
||||
<div
|
||||
class="shrink-0 px-3.5 py-3 border-t border-g-300/40 bg-[var(--default-box-color)] rounded-b-[inherit]"
|
||||
>
|
||||
<ElButton class="w-full" @click="goNotifyPage" v-ripple>前往通知推送管理</ElButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch, onMounted, onUnmounted } from 'vue'
|
||||
import { ref, watch, nextTick, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useNotifyCenter } from '@/hooks/core/useNotifyCenter'
|
||||
|
||||
@@ -80,7 +111,7 @@
|
||||
}>()
|
||||
|
||||
const router = useRouter()
|
||||
const { items, unreadCount, refresh, markAllRead, lastRead } = useNotifyCenter()
|
||||
const { items, unreadCount, refresh, markAllRead, lastReadId } = useNotifyCenter()
|
||||
|
||||
// 显隐(对齐原模板:v-show + scaleY 过渡)
|
||||
const show = ref(false)
|
||||
@@ -118,14 +149,30 @@
|
||||
onUnmounted(() => document.removeEventListener('click', onDocClick))
|
||||
|
||||
// 级别样式:info=蓝 notice / warning=橙 / important=红
|
||||
function styleOf(level: string): { icon: string; iconClass: string; tagType: 'warning' | 'danger' } {
|
||||
function styleOf(level: string): {
|
||||
icon: string
|
||||
iconClass: string
|
||||
tagType: 'warning' | 'danger'
|
||||
} {
|
||||
if (level === 'warning') {
|
||||
return { icon: 'ri:alert-line', iconClass: 'bg-[var(--el-color-warning-light-8)] text-[var(--el-color-warning)]', tagType: 'warning' }
|
||||
return {
|
||||
icon: 'ri:alert-line',
|
||||
iconClass: 'bg-[var(--el-color-warning-light-8)] text-[var(--el-color-warning)]',
|
||||
tagType: 'warning'
|
||||
}
|
||||
}
|
||||
if (level === 'important') {
|
||||
return { icon: 'ri:error-warning-line', iconClass: 'bg-[var(--el-color-danger-light-8)] text-[var(--el-color-danger)]', tagType: 'danger' }
|
||||
return {
|
||||
icon: 'ri:error-warning-line',
|
||||
iconClass: 'bg-[var(--el-color-danger-light-8)] text-[var(--el-color-danger)]',
|
||||
tagType: 'danger'
|
||||
}
|
||||
}
|
||||
return {
|
||||
icon: 'ri:information-line',
|
||||
iconClass: 'bg-[var(--el-color-primary-light-8)] text-[var(--el-color-primary)]',
|
||||
tagType: 'warning'
|
||||
}
|
||||
return { icon: 'ri:information-line', iconClass: 'bg-[var(--el-color-primary-light-8)] text-[var(--el-color-primary)]', tagType: 'warning' }
|
||||
}
|
||||
|
||||
function levelName(level: string): string {
|
||||
@@ -133,8 +180,7 @@
|
||||
}
|
||||
|
||||
function isNew(item: any): boolean {
|
||||
const ts = new Date(String(item.created_at || '').replace(' ', 'T')).getTime()
|
||||
return ts > (lastRead.value || 0)
|
||||
return Number(item.id) > (lastReadId.value || 0)
|
||||
}
|
||||
|
||||
function fmtTime(s: string): string {
|
||||
@@ -151,20 +197,16 @@
|
||||
@reference '@styles/core/tailwind.css';
|
||||
|
||||
.art-notification-panel {
|
||||
@apply absolute
|
||||
top-14.5
|
||||
right-5
|
||||
w-90
|
||||
h-125
|
||||
overflow-hidden
|
||||
transition-all
|
||||
duration-300
|
||||
origin-top
|
||||
will-change-[top,left]
|
||||
max-[640px]:top-[65px]
|
||||
max-[640px]:right-0
|
||||
max-[640px]:w-full
|
||||
max-[640px]:h-[80vh];
|
||||
@apply absolute top-14.5 right-5 z-[1000] w-90 overflow-hidden transition-all duration-300 origin-top will-change-[top,left] max-[640px]:top-[65px] max-[640px]:right-0 max-[640px]:w-full;
|
||||
|
||||
/* 高度自适应:常规 500px,窗口较矮时收缩,保证底部按钮始终可见 */
|
||||
height: min(500px, calc(100vh - 120px));
|
||||
}
|
||||
|
||||
@media (width <= 640px) {
|
||||
.art-notification-panel {
|
||||
height: 80vh;
|
||||
}
|
||||
}
|
||||
|
||||
.scrollbar-thin::-webkit-scrollbar {
|
||||
|
||||
@@ -6,14 +6,15 @@ import { fetchLatestNotifications } from '@/api/business'
|
||||
*
|
||||
* - 数据源:GET /api/admin/notifications/latest(active 且未过期,管理员全量可见,
|
||||
* 与员工端壳子 notifier.js 消费的 /api/notifications 同源同语义)
|
||||
* - 已读跟踪:localStorage 存最近已读时间戳(服务端无逐用户已读模型,控制台本地判定足够;
|
||||
* 时间戳之前的视为已读,铃铛红点 = 存在更新的通知)
|
||||
* - 已读跟踪:localStorage 存最近已读通知 id(服务端无逐用户已读模型,控制台本地判定足够)。
|
||||
* 用 id 而非时间戳做水位:id 自增单调、零时钟依赖,避免浏览器时钟略慢于服务端时
|
||||
* 新通知 created_at「在未来」导致红点永远清不掉(「全部已读没效果」根因)
|
||||
* - 轮询:模块级单例 60s 轻量刷新,页眉与面板不重复请求
|
||||
*/
|
||||
|
||||
const LAST_READ_KEY = '37du-notify-last-read'
|
||||
const LAST_READ_KEY = '37du-notify-last-read-id'
|
||||
|
||||
function readLastRead(): number {
|
||||
function readLastReadId(): number {
|
||||
try {
|
||||
return Number(localStorage.getItem(LAST_READ_KEY) || 0)
|
||||
} catch (e) {
|
||||
@@ -22,19 +23,13 @@ function readLastRead(): number {
|
||||
}
|
||||
|
||||
const items = ref<any[]>([])
|
||||
const lastRead = ref<number>(readLastRead())
|
||||
const lastReadId = ref<number>(readLastReadId())
|
||||
const loading = ref(false)
|
||||
let started = false
|
||||
|
||||
/** created_at 'YYYY-MM-DD HH:mm:ss' → 时间戳(服务端与本机同区) */
|
||||
function toTs(s: string): number {
|
||||
if (!s) return 0
|
||||
return new Date(String(s).replace(' ', 'T')).getTime() || 0
|
||||
}
|
||||
|
||||
/** 存在比"最近已读"更新的通知 */
|
||||
/** 存在比"最近已读 id"更新的通知 */
|
||||
const unreadCount = computed(() => {
|
||||
return items.value.filter((i) => toTs(i.created_at) > lastRead.value).length
|
||||
return items.value.filter((i) => Number(i.id) > lastReadId.value).length
|
||||
})
|
||||
|
||||
async function refresh(): Promise<void> {
|
||||
@@ -50,13 +45,16 @@ async function refresh(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 全部标记已读:以当前时间作为已读水位 */
|
||||
/** 全部标记已读:以当前列表中最大的通知 id 作为已读水位 */
|
||||
function markAllRead(): void {
|
||||
lastRead.value = Date.now()
|
||||
try {
|
||||
localStorage.setItem(LAST_READ_KEY, String(lastRead.value))
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
const maxId = items.value.reduce((m, i) => Math.max(m, Number(i.id) || 0), 0)
|
||||
if (maxId > lastReadId.value) {
|
||||
lastReadId.value = maxId
|
||||
try {
|
||||
localStorage.setItem(LAST_READ_KEY, String(maxId))
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,5 +68,5 @@ function ensureStarted(): void {
|
||||
|
||||
export function useNotifyCenter() {
|
||||
ensureStarted()
|
||||
return { items, unreadCount, loading, lastRead, refresh, markAllRead }
|
||||
return { items, unreadCount, loading, lastReadId, refresh, markAllRead }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 运行日志(37du 控制台)
|
||||
* 集中留存排查:插件运行日志(整次,可看正文)+ 客户端壳日志(shell.log 增量)。
|
||||
* 对接 /api/admin/run-logs、/api/admin/device-logs 及详情/下载/清理。
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import ArtPageHeader from '@/components/core/base/art-page-header/index.vue'
|
||||
import {
|
||||
fetchRunLogs, fetchRunLogDetail, fetchDeviceLogs, fetchDeviceLogDetail,
|
||||
downloadDeviceLog, cleanupLogs,
|
||||
} from '@/api/business'
|
||||
|
||||
// ==================== 插件运行日志 ====================
|
||||
const runsLoading = ref(false)
|
||||
const runs = ref<any[]>([])
|
||||
const runsTotal = ref(0)
|
||||
const runQuery = reactive({ page: 1, page_size: 20, status: '', days: '', q: '' })
|
||||
|
||||
const statusMap: Record<string, { label: string; type: any }> = {
|
||||
done: { label: '成功', type: 'success' },
|
||||
success: { label: '成功', type: 'success' },
|
||||
error: { label: '失败', type: 'danger' },
|
||||
failed: { label: '失败', type: 'danger' },
|
||||
running: { label: '运行中', type: 'primary' },
|
||||
}
|
||||
|
||||
async function loadRuns() {
|
||||
runsLoading.value = true
|
||||
try {
|
||||
const params: any = { page: runQuery.page, page_size: runQuery.page_size }
|
||||
if (runQuery.status) params.status = runQuery.status
|
||||
if (runQuery.days) params.days = runQuery.days
|
||||
if (runQuery.q) params.q = runQuery.q
|
||||
const r = await fetchRunLogs(params)
|
||||
runs.value = r.items || []
|
||||
runsTotal.value = r.total || 0
|
||||
} finally {
|
||||
runsLoading.value = false
|
||||
}
|
||||
}
|
||||
function searchRuns() {
|
||||
runQuery.page = 1
|
||||
loadRuns()
|
||||
}
|
||||
|
||||
// ==================== 客户端壳日志 ====================
|
||||
const devsLoading = ref(false)
|
||||
const devs = ref<any[]>([])
|
||||
const devsTotal = ref(0)
|
||||
const devQuery = reactive({ page: 1, page_size: 20, q: '' })
|
||||
|
||||
const activeTab = ref('runs')
|
||||
|
||||
async function loadDevs() {
|
||||
devsLoading.value = true
|
||||
try {
|
||||
const params: any = { page: devQuery.page, page_size: devQuery.page_size }
|
||||
if (devQuery.q) params.q = devQuery.q
|
||||
const r = await fetchDeviceLogs(params)
|
||||
devs.value = r.items || []
|
||||
devsTotal.value = r.total || 0
|
||||
} finally {
|
||||
devsLoading.value = false
|
||||
}
|
||||
}
|
||||
function searchDevs() {
|
||||
devQuery.page = 1
|
||||
loadDevs()
|
||||
}
|
||||
|
||||
// ==================== 运行日志详情抽屉 ====================
|
||||
const runDrawer = ref(false)
|
||||
const runDetailLoading = ref(false)
|
||||
const runDetail = ref<any>(null)
|
||||
|
||||
async function openRunDetail(row: any) {
|
||||
runDrawer.value = true
|
||||
runDetail.value = null
|
||||
runDetailLoading.value = true
|
||||
try {
|
||||
runDetail.value = await fetchRunLogDetail(row.run_id)
|
||||
} catch (e) {
|
||||
ElMessage.error('读取运行日志详情失败')
|
||||
} finally {
|
||||
runDetailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function copyRunLog() {
|
||||
const text = (runDetail.value?.logs || [])
|
||||
.map((l: any) => `${l.t || ''} ${String(l.level || 'INFO').padEnd(7)} ${l.msg}`)
|
||||
.join('\n')
|
||||
navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => ElMessage.success('已复制日志'))
|
||||
.catch(() => ElMessage.warning('复制失败,请手动选择复制'))
|
||||
}
|
||||
|
||||
// ==================== 客户端壳日志详情抽屉 ====================
|
||||
const devDrawer = ref(false)
|
||||
const devDetailLoading = ref(false)
|
||||
const devDetail = ref<any>(null)
|
||||
|
||||
async function openDevDetail(row: any) {
|
||||
devDrawer.value = true
|
||||
devDetail.value = null
|
||||
devDetailLoading.value = true
|
||||
try {
|
||||
devDetail.value = await fetchDeviceLogDetail(row.device_id)
|
||||
} catch (e) {
|
||||
ElMessage.error('读取客户端日志失败')
|
||||
} finally {
|
||||
devDetailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadDevDetail() {
|
||||
if (!devDetail.value) return
|
||||
devDetailLoading.value = true
|
||||
try {
|
||||
devDetail.value = await fetchDeviceLogDetail(devDetail.value.device_id)
|
||||
} catch (e) {
|
||||
ElMessage.error('刷新失败')
|
||||
} finally {
|
||||
devDetailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function onDownloadDev(row: any) {
|
||||
try {
|
||||
await downloadDeviceLog(row.device_id, `shell-${row.device_id}.log`)
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '下载失败')
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 清理 + 刷新 ====================
|
||||
const cleaning = ref(false)
|
||||
async function onCleanup() {
|
||||
try {
|
||||
await ElMessageBox.confirm('将清理超过保留期(默认 30 天)的集中日志,确认继续?', '清理超期日志', {
|
||||
confirmButtonText: '清理', cancelButtonText: '取消', type: 'warning',
|
||||
})
|
||||
} catch (e) {
|
||||
return // 用户取消
|
||||
}
|
||||
cleaning.value = true
|
||||
try {
|
||||
const r: any = await cleanupLogs()
|
||||
ElMessage.success(`清理完成:运行日志 ${r.deleted_run_logs} 条、客户端日志 ${r.deleted_device_logs} 个`)
|
||||
loadRuns()
|
||||
loadDevs()
|
||||
} finally {
|
||||
cleaning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
loadRuns()
|
||||
loadDevs()
|
||||
}
|
||||
|
||||
// ==================== 展示辅助 ====================
|
||||
function fmtDur(sec: number) {
|
||||
sec = +sec || 0
|
||||
if (sec < 60) return `${sec}s`
|
||||
const m = Math.floor(sec / 60)
|
||||
const s = sec % 60
|
||||
if (m < 60) return `${m}m${s ? `${s}s` : ''}`
|
||||
return `${Math.floor(m / 60)}h${m % 60}m`
|
||||
}
|
||||
function fmtBytes(n: number) {
|
||||
n = +n || 0
|
||||
if (n < 1024) return `${n} B`
|
||||
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
||||
return `${(n / 1024 / 1024).toFixed(2)} MB`
|
||||
}
|
||||
function levelClass(level: string) {
|
||||
const l = String(level || 'INFO').toUpperCase()
|
||||
return { 'lv-debug': l === 'DEBUG', 'lv-info': l === 'INFO', 'lv-warning': l === 'WARN' || l === 'WARNING', 'lv-error': l === 'ERROR' }
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadRuns()
|
||||
loadDevs()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<ArtPageHeader title="运行日志" description="执行机集中回传 · 插件运行日志与客户端壳日志统一留存排查">
|
||||
<template #actions>
|
||||
<el-button plain :loading="cleaning" @click="onCleanup">清理超期日志</el-button>
|
||||
<el-button type="primary" @click="refresh">刷新</el-button>
|
||||
</template>
|
||||
</ArtPageHeader>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-tabs v-model="activeTab">
|
||||
<!-- ==================== 插件运行日志 ==================== -->
|
||||
<el-tab-pane label="插件运行日志" name="runs">
|
||||
<el-form inline class="mb-2" @submit.prevent="searchRuns">
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="runQuery.status" clearable placeholder="全部" style="width: 130px" @change="searchRuns">
|
||||
<el-option label="成功" value="done" />
|
||||
<el-option label="失败" value="error" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="近">
|
||||
<el-select v-model="runQuery.days" clearable placeholder="全部" style="width: 110px" @change="searchRuns">
|
||||
<el-option label="7 天" :value="7" />
|
||||
<el-option label="14 天" :value="14" />
|
||||
<el-option label="30 天" :value="30" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="runQuery.q" placeholder="账号 / 设备 / 插件 / 名称 / 错误摘要" clearable style="width: 260px" @keyup.enter="searchRuns" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="searchRuns">查询</el-button>
|
||||
<el-button @click="Object.assign(runQuery, { q: '', status: '', days: '' }); searchRuns()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-table v-loading="runsLoading" :data="runs" border stripe>
|
||||
<el-table-column prop="uploaded_at" label="时间" width="170" />
|
||||
<el-table-column label="状态" width="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="statusMap[row.status]?.type || 'info'" size="small">
|
||||
{{ statusMap[row.status]?.label || row.status }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="账号" width="120">
|
||||
<template #default="{ row }">{{ row.nickname || row.account || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="device_id" label="设备" min-width="130" show-overflow-tooltip />
|
||||
<el-table-column label="插件" min-width="150" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ row.name || row.plugin_id || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="version" label="版本" width="90" />
|
||||
<el-table-column label="触发" width="80">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="row.trigger === 'schedule' ? 'warning' : 'info'" size="small" effect="plain">
|
||||
{{ row.trigger === 'schedule' ? '定时' : '手动' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="时长" width="90">
|
||||
<template #default="{ row }">{{ fmtDur(row.duration_sec) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="日志" width="80" align="center">
|
||||
<template #default="{ row }">{{ row.log_count || 0 }} 条</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="摘要 / 错误" min-width="180" show-overflow-tooltip>
|
||||
<template #default="{ row }">
|
||||
<span :class="row.error ? 'text-red-600' : 'text-gray-400'">{{ row.error || row.summary || '-' }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="110" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openRunDetail(row)">查看日志</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination
|
||||
v-model:current-page="runQuery.page"
|
||||
v-model:page-size="runQuery.page_size"
|
||||
:total="runsTotal"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="loadRuns"
|
||||
/>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
|
||||
<!-- ==================== 客户端壳日志 ==================== -->
|
||||
<el-tab-pane label="客户端日志" name="devices">
|
||||
<el-form inline class="mb-2" @submit.prevent="searchDevs">
|
||||
<el-form-item label="关键字">
|
||||
<el-input v-model="devQuery.q" placeholder="设备ID / 主机名 / 账号" clearable style="width: 240px" @keyup.enter="searchDevs" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="searchDevs">查询</el-button>
|
||||
<el-button @click="Object.assign(devQuery, { q: '' }); searchDevs()">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-table v-loading="devsLoading" :data="devs" border stripe>
|
||||
<el-table-column prop="device_id" label="设备ID" min-width="170" show-overflow-tooltip />
|
||||
<el-table-column label="账号" width="120">
|
||||
<template #default="{ row }">{{ row.nickname || row.account || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="hostname" label="主机名" min-width="140" show-overflow-tooltip />
|
||||
<el-table-column prop="client_version" label="客户端版本" width="100" />
|
||||
<el-table-column label="日志体积" width="110">
|
||||
<template #default="{ row }">{{ fmtBytes(row.size_bytes) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="updated_at" label="最近回传" width="170" />
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="openDevDetail(row)">查看</el-button>
|
||||
<el-button link type="primary" size="small" @click="onDownloadDev(row)">下载</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div class="flex justify-end mt-4">
|
||||
<el-pagination
|
||||
v-model:current-page="devQuery.page"
|
||||
v-model:page-size="devQuery.page_size"
|
||||
:total="devsTotal"
|
||||
layout="total, prev, pager, next"
|
||||
@current-change="loadDevs"
|
||||
/>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
|
||||
<!-- ==================== 运行日志详情抽屉 ==================== -->
|
||||
<el-drawer v-model="runDrawer" size="62%" :title="`运行日志 · ${runDetail?.name || runDetail?.plugin_id || ''}`" destroy-on-close>
|
||||
<div v-loading="runDetailLoading" class="px-2">
|
||||
<template v-if="runDetail">
|
||||
<el-descriptions :column="4" border size="small" class="mb-4">
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="statusMap[runDetail.status]?.type || 'info'" size="small">{{ statusMap[runDetail.status]?.label || runDetail.status }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="插件">{{ runDetail.name || runDetail.plugin_id || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="版本">{{ runDetail.version || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="账号">{{ runDetail.account || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="设备">{{ runDetail.device_id || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="触发">{{ runDetail.trigger === 'schedule' ? '定时' : '手动' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="时长">{{ fmtDur(runDetail.duration_sec) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="日志条数">{{ runDetail.log_count || 0 }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div v-if="runDetail.summary || runDetail.error" class="mb-4">
|
||||
<div class="text-sm font-semibold text-gray-700 mb-1">结论</div>
|
||||
<div
|
||||
class="px-3 py-2 rounded-md text-sm break-all"
|
||||
:class="runDetail.error ? 'bg-red-50 text-red-600' : 'bg-emerald-50 text-emerald-700'"
|
||||
>{{ runDetail.error || runDetail.summary || '-' }}</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<span class="text-sm font-semibold text-gray-700">日志正文</span>
|
||||
<el-button link type="primary" size="small" @click="copyRunLog">复制日志</el-button>
|
||||
</div>
|
||||
<div class="log-view">
|
||||
<div
|
||||
v-for="(l, i) in (runDetail.logs || [])" :key="i"
|
||||
class="log-line"
|
||||
>
|
||||
<span class="lt">{{ l.t || '' }}</span>
|
||||
<span class="lvl" :class="levelClass(l.level)">{{ String(l.level || 'INFO').padEnd(7) }}</span>
|
||||
<span class="lmsg">{{ l.msg }}</span>
|
||||
</div>
|
||||
<div v-if="!(runDetail.logs || []).length" class="text-gray-500 py-4">(该次运行无日志记录)</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</el-drawer>
|
||||
|
||||
<!-- ==================== 客户端壳日志详情抽屉 ==================== -->
|
||||
<el-drawer v-model="devDrawer" size="70%" :title="`客户端日志 · ${devDetail?.hostname || devDetail?.device_id || ''}`" destroy-on-close>
|
||||
<div v-loading="devDetailLoading" class="px-2">
|
||||
<template v-if="devDetail">
|
||||
<el-descriptions :column="3" border size="small" class="mb-3">
|
||||
<el-descriptions-item label="设备ID">{{ devDetail.device_id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="主机名">{{ devDetail.hostname || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="账号">{{ devDetail.account || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="客户端版本">{{ devDetail.client_version || '-' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="日志体积">{{ fmtBytes(devDetail.size_bytes) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="最近回传">{{ devDetail.last_uploaded_at }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<span class="text-sm font-semibold text-gray-700">壳日志内容(尾部)</span>
|
||||
<div>
|
||||
<el-button link type="primary" size="small" @click="reloadDevDetail">刷新</el-button>
|
||||
<el-button link type="primary" size="small" @click="onDownloadDev(devDetail)">下载全文</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-alert v-if="devDetail.truncated" type="warning" :closable="false" class="mb-2" show-icon
|
||||
:title="`内容较长,仅展示最近部分(共 ${fmtBytes(devDetail.size_bytes)}),完整日志请「下载全文」`" />
|
||||
<pre class="shell-view">{{ devDetail.content || '(空)' }}</pre>
|
||||
</template>
|
||||
</div>
|
||||
</el-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
export default { name: 'Logs' }
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.log-view {
|
||||
max-height: 46vh;
|
||||
overflow: auto;
|
||||
background: #171c26;
|
||||
border-radius: 8px;
|
||||
padding: 12px 14px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
font-family: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
|
||||
}
|
||||
.log-line { display: flex; gap: 10px; white-space: pre-wrap; word-break: break-all; }
|
||||
.log-line .lt { color: #6b7488; flex-shrink: 0; }
|
||||
.log-line .lvl { flex-shrink: 0; font-weight: 700; }
|
||||
.log-line .lmsg { color: #cfd6e4; }
|
||||
.lv-debug { color: #8a93a6; }
|
||||
.lv-info { color: #7db0ff; }
|
||||
.lv-warning { color: #e8b64c; }
|
||||
.lv-error { color: #ff6b63; }
|
||||
.shell-view {
|
||||
max-height: 64vh;
|
||||
overflow: auto;
|
||||
margin: 0;
|
||||
background: #171c26;
|
||||
border-radius: 8px;
|
||||
padding: 12px 14px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.65;
|
||||
color: #cfd6e4;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
font-family: ui-monospace, "Cascadia Code", Consolas, "Courier New", monospace;
|
||||
}
|
||||
</style>
|
||||
@@ -5,7 +5,10 @@
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { fetchPlugins, uploadPlugin, patchPlugin, deletePlugin } from '@/api/business'
|
||||
import {
|
||||
fetchPlugins, uploadPlugin, patchPlugin, deletePlugin,
|
||||
fetchDictItems, addDictItem, updateDictItem, deleteDictItem
|
||||
} from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
@@ -71,6 +74,91 @@ async function setStatus(row: any, status: string) {
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 分类维护(字典 plugin_category:在「分类管理」弹窗中增删改/排序) ----
|
||||
const DICT_KEY = 'plugin_category'
|
||||
const categories = ref<{ id: number; label: string }[]>([])
|
||||
|
||||
async function loadDict() {
|
||||
try {
|
||||
const r = await fetchDictItems(DICT_KEY)
|
||||
categories.value = r.items || []
|
||||
} catch {
|
||||
categories.value = []
|
||||
}
|
||||
}
|
||||
|
||||
/** 下拉选项:字典 + 当前值兜底(避免历史分类值被隐藏) */
|
||||
function categoryOptions(row: any): string[] {
|
||||
const labels = categories.value.map((c) => c.label)
|
||||
const cur = String(row.category || '').trim()
|
||||
return cur && !labels.includes(cur) ? [...labels, cur] : labels
|
||||
}
|
||||
|
||||
// ---- 场景分类字典管理弹窗 ----
|
||||
const dictOpen = ref(false)
|
||||
const dictSaving = ref(false)
|
||||
const newLabel = ref('')
|
||||
|
||||
function openDict() {
|
||||
newLabel.value = ''
|
||||
dictOpen.value = true
|
||||
loadDict()
|
||||
}
|
||||
|
||||
async function submitAddDict() {
|
||||
const label = newLabel.value.trim()
|
||||
if (!label) {
|
||||
ElMessage.warning('请输入分类名称')
|
||||
return
|
||||
}
|
||||
dictSaving.value = true
|
||||
try {
|
||||
await addDictItem(DICT_KEY, label)
|
||||
newLabel.value = ''
|
||||
await loadDict()
|
||||
} finally {
|
||||
dictSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function renameDictItem(it: { id: number; label: string }) {
|
||||
const { value } = await ElMessageBox.prompt('修改分类名称(已设置旧分类的插件不会自动跟随,需重新选择)', '重命名分类', {
|
||||
inputValue: it.label,
|
||||
inputPattern: /\S+/,
|
||||
inputErrorMessage: '名称不能为空'
|
||||
})
|
||||
await updateDictItem(DICT_KEY, it.id, { label: String(value).trim() })
|
||||
ElMessage.success('已重命名')
|
||||
await loadDict()
|
||||
}
|
||||
|
||||
async function moveDictItem(it: { id: number; label: string }, move: 'up' | 'down') {
|
||||
await updateDictItem(DICT_KEY, it.id, { move })
|
||||
await loadDict()
|
||||
}
|
||||
|
||||
async function removeDictItem(it: { id: number; label: string }) {
|
||||
await ElMessageBox.confirm(`从字典移除分类「${it.label}」?已设置该分类的插件不受影响。`, '删除确认', {
|
||||
type: 'warning'
|
||||
})
|
||||
await deleteDictItem(DICT_KEY, it.id)
|
||||
ElMessage.success('已删除')
|
||||
await loadDict()
|
||||
}
|
||||
|
||||
async function setCategory(row: any, val: string) {
|
||||
const prev = row.category || ''
|
||||
const next = String(val || '').trim()
|
||||
if (next === prev) return
|
||||
row.category = next
|
||||
try {
|
||||
await patchPlugin(row.id, { category: next })
|
||||
ElMessage.success(next ? `分类已更新为「${next}」` : '已清空分类')
|
||||
} catch {
|
||||
row.category = prev
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 强制更新 ----
|
||||
const forceOpen = ref(false)
|
||||
const forceSaving = ref(false)
|
||||
@@ -125,13 +213,17 @@ async function remove(row: any) {
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
onMounted(() => {
|
||||
load()
|
||||
loadDict()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<ArtPageHeader title="插件管理" description="插件上传发布、版本管理与强制更新">
|
||||
<template #actions>
|
||||
<el-button @click="openDict"><ArtSvgIcon icon="ri:book-2-line" class="mr-1" />分类管理</el-button>
|
||||
<el-button type="primary" @click="openUpload"><ArtSvgIcon icon="ri:upload-2-line" class="mr-1" />上传发布</el-button>
|
||||
</template>
|
||||
</ArtPageHeader>
|
||||
@@ -155,7 +247,20 @@ onMounted(load)
|
||||
<el-table-column prop="id" label="插件ID" min-width="140" />
|
||||
<el-table-column prop="name" label="名称" min-width="160" />
|
||||
<el-table-column prop="latest_version" label="最新版本" width="110" />
|
||||
<el-table-column prop="category" label="分类" width="110" />
|
||||
<el-table-column prop="category" label="分类" width="150">
|
||||
<template #default="{ row }">
|
||||
<el-select
|
||||
:model-value="row.category || ''"
|
||||
size="small"
|
||||
clearable
|
||||
placeholder="未分类"
|
||||
style="width: 100%"
|
||||
@change="(v: string) => setCategory(row, v)"
|
||||
>
|
||||
<el-option v-for="c in categoryOptions(row)" :key="c" :label="c" :value="c" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="statusMap[row.status]?.type || 'info'" size="small">
|
||||
@@ -265,5 +370,34 @@ onMounted(load)
|
||||
<el-button type="primary" :loading="forceSaving" @click="submitForce">设置</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<!-- 场景分类字典管理弹窗 -->
|
||||
<el-dialog v-model="dictOpen" title="场景分类管理" width="460px">
|
||||
<div class="max-h-[320px] overflow-y-auto space-y-0.5">
|
||||
<div
|
||||
v-for="(it, i) in categories"
|
||||
:key="it.id"
|
||||
class="flex items-center gap-1 px-2 py-1.5 rounded-lg hover:bg-gray-50"
|
||||
>
|
||||
<span class="flex-1 text-sm">{{ it.label }}</span>
|
||||
<el-button link size="small" :disabled="i === 0" @click="moveDictItem(it, 'up')">上移</el-button>
|
||||
<el-button link size="small" :disabled="i === categories.length - 1" @click="moveDictItem(it, 'down')">下移</el-button>
|
||||
<el-button link size="small" type="primary" @click="renameDictItem(it)">重命名</el-button>
|
||||
<el-button link size="small" type="danger" @click="removeDictItem(it)">删除</el-button>
|
||||
</div>
|
||||
<div v-if="!categories.length" class="py-6 text-center text-sm text-gray-400">暂无分类,先在下方新增一个</div>
|
||||
</div>
|
||||
<div class="flex gap-2 mt-3">
|
||||
<el-input
|
||||
v-model="newLabel"
|
||||
placeholder="新分类名称(回车快速添加)"
|
||||
maxlength="64"
|
||||
@keyup.enter="submitAddDict"
|
||||
/>
|
||||
<el-button type="primary" :loading="dictSaving" @click="submitAddDict">新增</el-button>
|
||||
</div>
|
||||
<div class="px-1 mt-2 text-xs text-gray-400 leading-5">
|
||||
分类字典供插件列表下拉选择,执行机客户端场景库按分类分组展示;删除/重命名不影响已设置的插件。
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,57 +1,128 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 数据看板(37du 控制台)
|
||||
* 运行统计卡 + 近14天趋势折线 + 插件排行/活跃用户横向柱图 + 明细表
|
||||
* 数据:/api/admin/stats
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { fetchStats } from '@/api/business'
|
||||
import ArtPageHeader from '@/components/core/base/art-page-header/index.vue'
|
||||
/**
|
||||
* 数据看板(37du 控制台)
|
||||
* 总览 Hero + 关键指标 + 近14天趋势 + 运行构成 + 插件/用户排行榜
|
||||
* 数据:/api/admin/stats
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { fetchStats } from '@/api/business'
|
||||
import ArtPageHeader from '@/components/core/base/art-page-header/index.vue'
|
||||
|
||||
const loading = ref(false)
|
||||
const data = ref<any>({})
|
||||
const loading = ref(false)
|
||||
const data = ref<any>({})
|
||||
|
||||
const trendData = computed(() => {
|
||||
const trend = data.value.trend || []
|
||||
return [
|
||||
{ name: '触发', data: trend.map((t: any) => t.runs), showAreaColor: true },
|
||||
{ name: '成功', data: trend.map((t: any) => t.success) },
|
||||
{ name: '失败', data: trend.map((t: any) => t.failed) }
|
||||
]
|
||||
})
|
||||
const trendX = computed(() => (data.value.trend || []).map((t: any) => t.day))
|
||||
const trendData = computed(() => {
|
||||
const trend = data.value.trend || []
|
||||
return [
|
||||
{ name: '触发', data: trend.map((t: any) => t.runs), showAreaColor: true },
|
||||
{ name: '成功', data: trend.map((t: any) => t.success) },
|
||||
{ name: '失败', data: trend.map((t: any) => t.failed) }
|
||||
]
|
||||
})
|
||||
const trendX = computed(() => (data.value.trend || []).map((t: any) => t.day))
|
||||
|
||||
const pluginBarData = computed(() => (data.value.topPlugins || []).map((p: any) => p.runs))
|
||||
const pluginBarX = computed(() => (data.value.topPlugins || []).map((p: any) => p.name || p.pluginId))
|
||||
const userBarData = computed(() => (data.value.topUsers || []).map((u: any) => u.runs))
|
||||
const userBarX = computed(() => (data.value.topUsers || []).map((u: any) => u.nickname || u.account))
|
||||
const totalRuns = computed(() => data.value.runs?.total || 0)
|
||||
const successCount = computed(() => data.value.runs?.success || 0)
|
||||
const failedCount = computed(() => data.value.runs?.failed || 0)
|
||||
const finishedCount = computed(() => successCount.value + failedCount.value)
|
||||
|
||||
const successRate = computed(() => {
|
||||
const total = (data.value.runs?.success || 0) + (data.value.runs?.failed || 0)
|
||||
return total ? Math.round(((data.value.runs?.success || 0) / total) * 100) : 100
|
||||
})
|
||||
const successRate = computed(() => {
|
||||
return finishedCount.value ? Math.round((successCount.value / finishedCount.value) * 100) : 0
|
||||
})
|
||||
|
||||
const statCards = computed(() => [
|
||||
{ title: '运行总次数', count: data.value.runs?.total || 0, icon: 'ri:play-circle-line', iconStyle: 'bg-[#377dff]', desc: '全部触发' },
|
||||
{ title: '成功', count: data.value.runs?.success || 0, icon: 'ri:checkbox-circle-line', iconStyle: 'bg-[#00b42a]', desc: `成功率 ${successRate.value}%` },
|
||||
{ title: '失败', count: data.value.runs?.failed || 0, icon: 'ri:close-circle-line', iconStyle: 'bg-[#f53f3f]', desc: 'error / failed' },
|
||||
{ title: '总时长', count: data.value.runs?.durationSec || 0, icon: 'ri:timer-line', iconStyle: 'bg-[#7a7fff]', desc: '累计运行(秒)' },
|
||||
{ title: '活跃用户', count: data.value.runs?.activeUsers || 0, icon: 'ri:user-heart-line', iconStyle: 'bg-[#ff7d00]', desc: '有触发记录' },
|
||||
{ title: '活跃插件', count: data.value.runs?.activePlugins || 0, icon: 'ri:box-3-line', iconStyle: 'bg-[#f5319d]', desc: '被运行过' }
|
||||
])
|
||||
const today = computed(() => {
|
||||
const d = new Date()
|
||||
const p = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
|
||||
})
|
||||
|
||||
const statusTag = (s: string) => (s === 'published' ? 'success' : s === 'disabled' ? 'warning' : 'danger')
|
||||
const ringData = computed(() => [
|
||||
{ name: '成功', value: successCount.value },
|
||||
{ name: '失败', value: failedCount.value }
|
||||
])
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
data.value = await fetchStats()
|
||||
} finally {
|
||||
loading.value = false
|
||||
const avgDuration = computed(() => {
|
||||
const total = totalRuns.value
|
||||
return total ? fmtDuration((data.value.runs?.durationSec || 0) / total) : '—'
|
||||
})
|
||||
|
||||
const tiles = computed(() => [
|
||||
{
|
||||
title: '活跃用户',
|
||||
value: String(data.value.runs?.activeUsers || 0),
|
||||
unit: '人',
|
||||
icon: 'ri:user-heart-line',
|
||||
color: 'var(--el-color-warning)',
|
||||
bg: 'var(--el-color-warning-light-9)',
|
||||
desc: `账号总数 ${data.value.users?.total || 0}`
|
||||
},
|
||||
{
|
||||
title: '活跃插件',
|
||||
value: String(data.value.runs?.activePlugins || 0),
|
||||
unit: '个',
|
||||
icon: 'ri:box-3-line',
|
||||
color: 'var(--el-color-primary)',
|
||||
bg: 'var(--el-color-primary-light-9)',
|
||||
desc: `插件总数 ${data.value.plugins?.total || 0}`
|
||||
},
|
||||
{
|
||||
title: '累计运行时长',
|
||||
value: fmtDuration(data.value.runs?.durationSec || 0),
|
||||
unit: '',
|
||||
icon: 'ri:timer-line',
|
||||
color: 'var(--el-color-success)',
|
||||
bg: 'var(--el-color-success-light-9)',
|
||||
desc: `平均 ${avgDuration.value} / 次`
|
||||
},
|
||||
{
|
||||
title: '已发布插件',
|
||||
value: String(data.value.plugins?.published || 0),
|
||||
unit: '个',
|
||||
icon: 'ri:rocket-2-line',
|
||||
color: 'var(--el-color-danger)',
|
||||
bg: 'var(--el-color-danger-light-9)',
|
||||
desc: `停用 ${data.value.plugins?.disabled || 0} · 收回 ${data.value.plugins?.revoked || 0}`
|
||||
}
|
||||
])
|
||||
|
||||
const maxPluginRuns = computed(() =>
|
||||
Math.max(1, ...(data.value.topPlugins || []).map((p: any) => Number(p.runs) || 0))
|
||||
)
|
||||
const maxUserRuns = computed(() =>
|
||||
Math.max(1, ...(data.value.topUsers || []).map((u: any) => Number(u.runs) || 0))
|
||||
)
|
||||
|
||||
function fmtNum(n: number): string {
|
||||
return Number(n || 0).toLocaleString()
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
function fmtDuration(sec: number): string {
|
||||
const s = Math.round(Number(sec) || 0)
|
||||
if (!s) return '0 秒'
|
||||
if (s >= 3600) return `${(s / 3600).toFixed(1)} 小时`
|
||||
if (s >= 60) return `${Math.round(s / 60)} 分钟`
|
||||
return `${s} 秒`
|
||||
}
|
||||
|
||||
function pct(value: number, max: number): string {
|
||||
const v = Number(value) || 0
|
||||
return `${v ? Math.max(6, Math.round((v / Math.max(1, max)) * 100)) : 0}%`
|
||||
}
|
||||
|
||||
function rankClass(i: number): string {
|
||||
return i === 0 ? 'is-first' : i === 1 ? 'is-second' : i === 2 ? 'is-third' : ''
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
data.value = await fetchStats()
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -64,123 +135,346 @@ onMounted(load)
|
||||
</template>
|
||||
</ArtPageHeader>
|
||||
|
||||
<!-- 统计卡 -->
|
||||
<el-row :gutter="14" class="mb-3.5">
|
||||
<el-col :xs="12" :sm="8" :md="4" v-for="(c, i) in statCards" :key="i">
|
||||
<ArtStatsCard
|
||||
:title="c.title"
|
||||
:count="c.count"
|
||||
:icon="c.icon"
|
||||
:icon-style="c.iconStyle"
|
||||
:description="c.desc"
|
||||
class="rounded-xl mb-3.5"
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 趋势 -->
|
||||
<el-card shadow="never" class="rounded-xl mb-3.5">
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="font-semibold">近 14 天运行趋势</span>
|
||||
<span class="text-xs text-gray-400">触发 = start · 成功 = done/success · 失败 = error/failed</span>
|
||||
<!-- 总览 Hero -->
|
||||
<div class="stats-hero art-card mb-3.5">
|
||||
<div class="relative z-[1] flex flex-wrap items-center justify-between gap-5 px-6 py-5">
|
||||
<div class="min-w-0">
|
||||
<div class="flex-c gap-2 text-xs text-white/70">
|
||||
<ArtSvgIcon icon="ri:line-chart-line" />
|
||||
<span>运行总览 · {{ today }}</span>
|
||||
</div>
|
||||
<div class="mt-2 flex items-end gap-2">
|
||||
<span class="text-4xl leading-none font-semibold text-white">{{
|
||||
fmtNum(totalRuns)
|
||||
}}</span>
|
||||
<span class="mb-0.5 text-sm text-white/70">次运行</span>
|
||||
</div>
|
||||
<div class="mt-3 flex flex-wrap gap-2">
|
||||
<span class="hero-chip">
|
||||
<i class="dot bg-[#8ff0a4]"></i>成功 {{ fmtNum(successCount) }}
|
||||
</span>
|
||||
<span class="hero-chip">
|
||||
<i class="dot bg-[#ffb3b3]"></i>失败 {{ fmtNum(failedCount) }}
|
||||
</span>
|
||||
<span class="hero-chip">
|
||||
<i class="dot bg-white/60"></i>平均耗时 {{ avgDuration }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<ArtLineChart
|
||||
:data="trendData"
|
||||
:x-axis-data="trendX"
|
||||
:show-legend="true"
|
||||
:show-area-color="true"
|
||||
height="300px"
|
||||
:loading="loading"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 排行图 -->
|
||||
<div class="shrink-0">
|
||||
<el-progress
|
||||
type="circle"
|
||||
:percentage="successRate"
|
||||
:width="96"
|
||||
:stroke-width="8"
|
||||
color="#ffffff"
|
||||
trail-color="rgba(255,255,255,.28)"
|
||||
>
|
||||
<template #default>
|
||||
<div class="text-center leading-tight">
|
||||
<div class="text-xl font-semibold text-white">
|
||||
{{ finishedCount ? `${successRate}%` : '—' }}
|
||||
</div>
|
||||
<div class="text-[11px] text-white/70">成功率</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-progress>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 关键指标 -->
|
||||
<div class="mb-3.5 grid grid-cols-1 gap-3.5 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<div v-for="t in tiles" :key="t.title" class="art-card flex-c gap-3.5 px-5 py-4">
|
||||
<div
|
||||
class="size-11 flex-cc rounded-xl text-xl shrink-0"
|
||||
:style="{ color: t.color, background: t.bg }"
|
||||
>
|
||||
<ArtSvgIcon :icon="t.icon" />
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<p class="m-0 text-xs text-g-500">{{ t.title }}</p>
|
||||
<p class="mt-1 mb-0 text-2xl leading-none font-semibold text-g-900">
|
||||
{{ t.value
|
||||
}}<span v-if="t.unit" class="ml-1 text-xs font-normal text-g-500">{{ t.unit }}</span>
|
||||
</p>
|
||||
<p class="mt-1 mb-0 text-[11px] text-g-400 truncate">{{ t.desc }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 趋势 + 运行构成 -->
|
||||
<el-row :gutter="14" class="mb-3.5">
|
||||
<el-col :md="12" :xs="24">
|
||||
<el-col :md="16" :xs="24">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">插件排行 Top 8</span></template>
|
||||
<ArtHBarChart
|
||||
:data="pluginBarData"
|
||||
:x-axis-data="pluginBarX"
|
||||
height="260px"
|
||||
<template #header>
|
||||
<div class="flex-cb">
|
||||
<div>
|
||||
<span class="font-semibold">近 14 天运行趋势</span>
|
||||
<span class="ml-2 text-xs text-g-400"
|
||||
>触发 = start · 成功 = done/success · 失败 = error/failed</span
|
||||
>
|
||||
</div>
|
||||
<span class="text-xs text-g-400">近 14 天</span>
|
||||
</div>
|
||||
</template>
|
||||
<ArtLineChart
|
||||
:data="trendData"
|
||||
:x-axis-data="trendX"
|
||||
:show-legend="true"
|
||||
:show-area-color="true"
|
||||
height="280px"
|
||||
:loading="loading"
|
||||
/>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :md="12" :xs="24">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">活跃用户 Top 8</span></template>
|
||||
<ArtHBarChart
|
||||
:data="userBarData"
|
||||
:x-axis-data="userBarX"
|
||||
height="260px"
|
||||
:loading="loading"
|
||||
/>
|
||||
<el-col :md="8" :xs="24">
|
||||
<el-card shadow="never" class="rounded-xl h-full">
|
||||
<template #header><span class="font-semibold">运行构成</span></template>
|
||||
<div v-loading="loading">
|
||||
<div class="relative">
|
||||
<ArtRingChart
|
||||
:data="ringData"
|
||||
:colors="['#00b42a', '#f53f3f']"
|
||||
:radius="['56%', '80%']"
|
||||
:border-radius="8"
|
||||
height="180px"
|
||||
/>
|
||||
<div class="pointer-events-none absolute inset-0 flex-cc flex-col">
|
||||
<span class="text-2xl font-semibold text-g-900">
|
||||
{{ finishedCount ? `${successRate}%` : '—' }}
|
||||
</span>
|
||||
<span class="mt-0.5 text-xs text-g-500">成功率</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-3 space-y-2">
|
||||
<div class="flex-cb text-sm">
|
||||
<span class="flex-c gap-2 text-g-500"> <i class="dot bg-[#00b42a]"></i>成功 </span>
|
||||
<span class="font-medium text-g-900">
|
||||
{{ fmtNum(successCount) }}
|
||||
<span class="ml-1 text-xs font-normal text-g-400">
|
||||
{{ finishedCount ? Math.round((successCount / finishedCount) * 100) : 0 }}%
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex-cb text-sm">
|
||||
<span class="flex-c gap-2 text-g-500"> <i class="dot bg-[#f53f3f]"></i>失败 </span>
|
||||
<span class="font-medium text-g-900">
|
||||
{{ fmtNum(failedCount) }}
|
||||
<span class="ml-1 text-xs font-normal text-g-400">
|
||||
{{ finishedCount ? Math.round((failedCount / finishedCount) * 100) : 0 }}%
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex-cb border-t border-g-300/40 pt-2 text-sm">
|
||||
<span class="text-g-500">累计运行时长</span>
|
||||
<span class="font-medium text-g-900">{{
|
||||
fmtDuration(data.runs?.durationSec || 0)
|
||||
}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 明细 -->
|
||||
<!-- 排行榜 -->
|
||||
<el-row :gutter="14">
|
||||
<el-col :md="12" :xs="24">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">插件运行明细</span></template>
|
||||
<el-table :data="data.topPlugins || []" size="small" v-loading="loading">
|
||||
<el-table-column label="插件" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<div class="text-sm">{{ row.name }}</div>
|
||||
<div class="text-xs text-gray-400">{{ row.pluginId }}</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="runs" label="触发" width="70" align="center" />
|
||||
<el-table-column prop="success" label="成功" width="70" align="center">
|
||||
<template #default="{ row }"><span class="text-[#00b42a]">{{ row.success }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="failed" label="失败" width="70" align="center">
|
||||
<template #default="{ row }"><span :class="row.failed ? 'text-[#f53f3f]' : 'text-gray-300'">{{ row.failed }}</span></template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="90" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" :type="row.failed ? 'warning' : 'success'">
|
||||
{{ row.failed ? '有失败' : '正常' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :md="12" :xs="24">
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<template #header><span class="font-semibold">活跃用户明细</span></template>
|
||||
<el-table :data="data.topUsers || []" size="small" v-loading="loading">
|
||||
<el-table-column label="用户" min-width="180">
|
||||
<template #default="{ row }">
|
||||
<div class="flex items-center gap-2.5">
|
||||
<div class="size-7 rounded-full grid place-items-center bg-[var(--el-color-primary-light-9)] text-[var(--el-color-primary)] text-xs font-bold">
|
||||
{{ (row.nickname || row.account || '?').slice(0, 1) }}
|
||||
<el-card shadow="never" class="rounded-xl h-full">
|
||||
<template #header>
|
||||
<div class="flex-cb">
|
||||
<span class="font-semibold">插件排行 Top 8</span>
|
||||
<span class="text-xs text-g-400">按触发次数排序</span>
|
||||
</div>
|
||||
</template>
|
||||
<div v-loading="loading" class="min-h-40">
|
||||
<ul v-if="data.topPlugins?.length" class="m-0 p-0 list-none">
|
||||
<li
|
||||
v-for="(p, i) in data.topPlugins"
|
||||
:key="p.pluginId"
|
||||
class="flex items-center gap-3 border-b border-g-300/30 py-2.5 last:border-b-0"
|
||||
>
|
||||
<span class="rank-badge" :class="rankClass(Number(i))">{{ Number(i) + 1 }}</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex-cb gap-2">
|
||||
<span class="truncate text-sm text-g-900">{{ p.name }}</span>
|
||||
<span class="shrink-0 text-sm font-medium text-g-900"
|
||||
>{{ fmtNum(p.runs) }} 次</span
|
||||
>
|
||||
</div>
|
||||
<div>
|
||||
<div class="text-sm leading-tight">{{ row.nickname || row.account }}</div>
|
||||
<div class="text-xs text-gray-400">{{ row.account }}</div>
|
||||
<div class="mt-1 flex-cb gap-2 text-[11px] text-g-400">
|
||||
<span class="truncate">{{ p.pluginId }}</span>
|
||||
<span class="shrink-0">
|
||||
成功 <b class="text-[var(--el-color-success)]">{{ fmtNum(p.success) }}</b>
|
||||
· 失败
|
||||
<b :class="p.failed ? 'text-[var(--el-color-danger)]' : 'text-g-400'">
|
||||
{{ fmtNum(p.failed) }}
|
||||
</b>
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-[var(--el-fill-color)]">
|
||||
<div
|
||||
class="h-full rounded-full"
|
||||
:style="{
|
||||
width: pct(p.runs, maxPluginRuns),
|
||||
background:
|
||||
'linear-gradient(90deg, var(--el-color-primary), var(--el-color-primary-light-3))'
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="runs" label="运行次数" width="100" align="center" />
|
||||
<el-table-column label="占比" min-width="120">
|
||||
<template #default="{ row }">
|
||||
<el-progress
|
||||
:percentage="Math.round((row.runs / Math.max(1, data.topUsers?.[0]?.runs || 1)) * 100)"
|
||||
:stroke-width="8"
|
||||
:show-text="false"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else class="flex-cc flex-col py-10 text-g-400">
|
||||
<ArtSvgIcon icon="ri:bar-chart-box-line" class="mb-2 text-4xl" />
|
||||
<span class="text-xs">暂无运行记录</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
|
||||
<el-col :md="12" :xs="24">
|
||||
<el-card shadow="never" class="rounded-xl h-full">
|
||||
<template #header>
|
||||
<div class="flex-cb">
|
||||
<span class="font-semibold">活跃用户 Top 8</span>
|
||||
<span class="text-xs text-g-400">按触发次数排序</span>
|
||||
</div>
|
||||
</template>
|
||||
<div v-loading="loading" class="min-h-40">
|
||||
<ul v-if="data.topUsers?.length" class="m-0 p-0 list-none">
|
||||
<li
|
||||
v-for="(u, i) in data.topUsers"
|
||||
:key="u.account"
|
||||
class="flex items-center gap-3 border-b border-g-300/30 py-2.5 last:border-b-0"
|
||||
>
|
||||
<span class="rank-badge" :class="rankClass(Number(i))">{{ Number(i) + 1 }}</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex items-center gap-2.5">
|
||||
<span
|
||||
class="size-7 flex-cc shrink-0 rounded-full bg-[var(--el-color-primary-light-9)] text-xs font-bold text-[var(--el-color-primary)]"
|
||||
>
|
||||
{{ (u.nickname || u.account || '?').slice(0, 1) }}
|
||||
</span>
|
||||
<div class="min-w-0 flex-1">
|
||||
<div class="flex-cb gap-2">
|
||||
<span class="truncate text-sm text-g-900">{{
|
||||
u.nickname || u.account
|
||||
}}</span>
|
||||
<span class="shrink-0 text-sm font-medium text-g-900"
|
||||
>{{ fmtNum(u.runs) }} 次</span
|
||||
>
|
||||
</div>
|
||||
<div class="flex-cb gap-2 text-[11px] text-g-400">
|
||||
<span class="truncate">{{ u.account }}</span>
|
||||
<span class="shrink-0">
|
||||
占全部 {{ totalRuns ? Math.round((u.runs / totalRuns) * 100) : 0 }}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-1.5 h-1.5 overflow-hidden rounded-full bg-[var(--el-fill-color)]">
|
||||
<div
|
||||
class="h-full rounded-full"
|
||||
:style="{
|
||||
width: pct(u.runs, maxUserRuns),
|
||||
background: 'linear-gradient(90deg, var(--el-color-warning), #ffc078)'
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<div v-else class="flex-cc flex-col py-10 text-g-400">
|
||||
<ArtSvgIcon icon="ri:user-line" class="mb-2 text-4xl" />
|
||||
<span class="text-xs">暂无活跃用户</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.stats-hero {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
background: linear-gradient(120deg, var(--el-color-primary) 0%, #6d5efc 52%, #9b6bff 100%);
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* 右上装饰光斑,避免纯色渐变过于呆板 */
|
||||
.stats-hero::before {
|
||||
position: absolute;
|
||||
top: -70px;
|
||||
right: -40px;
|
||||
width: 260px;
|
||||
height: 260px;
|
||||
content: '';
|
||||
background: radial-gradient(circle, rgb(255 255 255 / 26%) 0%, transparent 68%);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.stats-hero::after {
|
||||
position: absolute;
|
||||
right: 180px;
|
||||
bottom: -110px;
|
||||
width: 220px;
|
||||
height: 220px;
|
||||
content: '';
|
||||
background: radial-gradient(circle, rgb(255 255 255 / 14%) 0%, transparent 70%);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.hero-chip {
|
||||
display: inline-flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
padding: 4px 10px;
|
||||
font-size: 12px;
|
||||
color: rgb(255 255 255 / 88%);
|
||||
background: rgb(255 255 255 / 16%);
|
||||
backdrop-filter: blur(4px);
|
||||
border: 1px solid rgb(255 255 255 / 20%);
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.dot {
|
||||
display: inline-block;
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.rank-badge {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--art-gray-600, #8a8f99);
|
||||
background: var(--el-fill-color);
|
||||
border-radius: 8px;
|
||||
|
||||
&.is-first {
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, #ffb400, #ff8f00);
|
||||
}
|
||||
|
||||
&.is-second {
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, #a8b3c4, #8896ab);
|
||||
}
|
||||
|
||||
&.is-third {
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, #e0a06a, #c97b3d);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -48,10 +48,13 @@ const form = reactive({
|
||||
parentId: null as number | null,
|
||||
name: '',
|
||||
router: '',
|
||||
viewPath: '',
|
||||
perms: '',
|
||||
icon: '',
|
||||
type: 1,
|
||||
orderNum: 0
|
||||
orderNum: 0,
|
||||
keepAlive: true,
|
||||
isShow: true
|
||||
})
|
||||
|
||||
const treeSelectData = computed(() => {
|
||||
@@ -92,10 +95,13 @@ watch(
|
||||
parentId: props.menuData.parentId ? Number(props.menuData.parentId) : null,
|
||||
name: props.menuData.name || '',
|
||||
router: props.menuData.router || '',
|
||||
viewPath: props.menuData.viewPath || '',
|
||||
perms: props.menuData.perms || '',
|
||||
icon: props.menuData.icon || '',
|
||||
type: Number(props.menuData.type ?? 1),
|
||||
orderNum: Number(props.menuData.orderNum ?? 0)
|
||||
orderNum: Number(props.menuData.orderNum ?? 0),
|
||||
keepAlive: Number(props.menuData.keepAlive ?? 1) !== 0,
|
||||
isShow: Number(props.menuData.isShow ?? 1) !== 0
|
||||
})
|
||||
} else {
|
||||
Object.assign(form, {
|
||||
@@ -103,10 +109,13 @@ watch(
|
||||
parentId: props.presetParentId,
|
||||
name: '',
|
||||
router: '',
|
||||
viewPath: '',
|
||||
perms: '',
|
||||
icon: '',
|
||||
type: 1,
|
||||
orderNum: 0
|
||||
orderNum: 0,
|
||||
keepAlive: true,
|
||||
isShow: true
|
||||
})
|
||||
}
|
||||
},
|
||||
@@ -124,10 +133,13 @@ async function handleSubmit() {
|
||||
parentId: form.parentId,
|
||||
name: form.name,
|
||||
router: form.router,
|
||||
viewPath: form.viewPath,
|
||||
perms: form.perms,
|
||||
icon: form.icon,
|
||||
type: form.type,
|
||||
orderNum: form.orderNum
|
||||
orderNum: form.orderNum,
|
||||
keepAlive: form.keepAlive,
|
||||
isShow: form.isShow
|
||||
})
|
||||
ElMessage.success('修改成功')
|
||||
} else {
|
||||
@@ -135,10 +147,13 @@ async function handleSubmit() {
|
||||
parentId: form.parentId,
|
||||
name: form.name,
|
||||
router: form.router,
|
||||
viewPath: form.viewPath,
|
||||
perms: form.perms,
|
||||
icon: form.icon,
|
||||
type: form.type,
|
||||
orderNum: form.orderNum
|
||||
orderNum: form.orderNum,
|
||||
keepAlive: form.keepAlive,
|
||||
isShow: form.isShow
|
||||
})
|
||||
ElMessage.success('新增成功')
|
||||
}
|
||||
@@ -181,6 +196,9 @@ async function handleSubmit() {
|
||||
<el-form-item v-if="form.type !== 2" label="路由" prop="router">
|
||||
<el-input v-model="form.router" placeholder="如 /system/user" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type !== 2" label="视图地址" prop="viewPath">
|
||||
<el-input v-model="form.viewPath" placeholder="如 /system/user(目录填 /index/index)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="权限标识" prop="perms">
|
||||
<el-input v-model="form.perms" placeholder="如 center:sys:user:list(按钮必填)" />
|
||||
</el-form-item>
|
||||
@@ -190,6 +208,12 @@ async function handleSubmit() {
|
||||
<el-form-item label="排序" prop="orderNum">
|
||||
<el-input-number v-model="form.orderNum" :min="0" :max="9999" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type !== 2" label="侧栏显示" prop="isShow">
|
||||
<el-switch v-model="form.isShow" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="form.type === 1" label="路由缓存" prop="keepAlive">
|
||||
<el-switch v-model="form.keepAlive" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
|
||||
Reference in New Issue
Block a user