feat: 重构控制台为37du自动化平台,新增权限授权与通知中心功能

- 更新系统名称、登录页宣传文案为37du平台相关内容
- 移除聊天功能相关代码与配置
- 新增客户端版本上报字段与设备统计接口
- 新增通知中心功能(60s轮询、localStorage已读标记)
- 新增权限授权工作台相关接口与页面
- 新增统一页头组件ArtPageHeader
- 调整快速入口配置指向真实功能页面
- 修复控制面地址为内网生产库
This commit is contained in:
2026-10-15 18:01:29 +08:00
parent f0a94bf523
commit a7dbc5a77e
49 changed files with 4925 additions and 2904 deletions
@@ -72,7 +72,7 @@ export function fetchAccountGrants(account: string) {
return request.get<any>({ url: '/api/admin/account_grants', params: { account } })
}
/** 授予/撤销插件 */
/** 授予/撤销插件(granted=false 即撤销整行) */
export function grantPlugin(body: any) {
return request.post<any>({ url: '/api/admin/account_plugins', data: body })
}
@@ -82,6 +82,28 @@ export function grantPlatform(body: any) {
return request.post<any>({ url: '/api/admin/account_platforms', data: body })
}
// ==================== 双向批量授权(新授权工作台) ====================
/** 授权矩阵总览(账号 × 插件 + 平台白名单,一次拉全量) */
export function fetchGrantsMatrix() {
return request.get<any>({ url: '/api/admin/grants/matrix' })
}
/** 插件维度:该插件已授权账号列表 */
export function fetchPluginGrants(pluginId: string) {
return request.get<any>({ url: '/api/admin/plugin_grants', params: { plugin_id: pluginId } })
}
/** 批量授权/更新(事务 upsert) */
export function batchPluginGrants(body: { plugin_id: string; items: { account: string; can_download: boolean; can_run: boolean }[] }) {
return request.post<any>({ url: '/api/admin/plugin_grants/batch', data: body, timeout: 60000 })
}
/** 批量撤销 */
export function revokePluginGrants(body: { plugin_id: string; accounts: string[] }) {
return request.post<any>({ url: '/api/admin/plugin_grants/revoke', data: body, timeout: 60000 })
}
/** 审计日志 */
export function fetchAudit(params: { page?: number; page_size?: number; action?: string; q?: string }) {
return request.get<{ items: any[]; total: number; today: number }>({ url: '/api/admin/audit', params })
@@ -102,11 +124,16 @@ export function fetchDevicesSummary() {
return request.get<any>({ url: '/api/admin/devices/summary' })
}
/** 通知列表 */
/** 通知列表(管理) */
export function fetchNotifications(params: { page?: number; page_size?: number; q?: string }) {
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/notifications', params })
}
/** 最新有效通知(页眉通知中心,active 且未过期) */
export function fetchLatestNotifications(limit: number = 30) {
return request.get<{ items: any[] }>({ url: '/api/admin/notifications/latest', params: { limit } })
}
/** 创建通知 */
export function createNotification(body: any) {
return request.post<any>({ url: '/api/admin/notifications', data: body })
@@ -151,3 +178,17 @@ export function patchFileSource(id: number, body: any) {
export function deleteFileSource(id: number) {
return request.del<any>({ url: `/api/admin/file-sources/${id}` })
}
// ==================== 个人中心(自助) ====================
/** 自助修改密码(旧密码校验,新密码≥8位,成功后 must_change_pwd 清零) */
export function changePassword(body: { account: string; old_password: string; new_password: string }) {
return request.post<any>({ url: '/api/admin/password', data: body })
}
/** 上传头像(multipart,file 字段) */
export function uploadAvatar(file: File, account: string) {
const fd = new FormData()
fd.append('file', file)
return request.post<any>({ url: '/api/admin/avatar', data: fd, params: { account }, timeout: 30000 })
}
@@ -0,0 +1,28 @@
<!-- 统一页头:标题 + 描述 + 右侧操作区 -->
<template>
<div class="flex items-end justify-between flex-wrap gap-3 mb-4">
<div class="flex items-center gap-3">
<div class="w-1 h-8 rounded-full bg-theme"></div>
<div>
<h2 class="m-0 text-xl font-bold text-g-800 leading-tight">{{ title }}</h2>
<p v-if="description" class="m-0 mt-1 text-xs text-g-500">{{ description }}</p>
</div>
</div>
<div class="flex items-center gap-2">
<slot name="actions"></slot>
</div>
</div>
</template>
<script setup lang="ts">
defineOptions({ name: 'ArtPageHeader' })
interface Props {
/** 页面标题 */
title: string
/** 页面描述(可选) */
description?: string
}
defineProps<Props>()
</script>
@@ -1,262 +0,0 @@
<!-- 系统聊天窗口 -->
<template>
<div>
<ElDrawer v-model="isDrawerVisible" :size="isMobile ? '100%' : '480px'" :with-header="false">
<div class="mb-5 flex-cb">
<div>
<span class="text-base font-medium">Art Bot</span>
<div class="mt-1.5 flex-c gap-1">
<div
class="h-2 w-2 rounded-full"
:class="isOnline ? 'bg-success/100' : 'bg-danger/100'"
></div>
<span class="text-xs text-g-600">{{ isOnline ? '在线' : '离线' }}</span>
</div>
</div>
<div>
<ElIcon class="c-p" :size="20" @click="closeChat">
<Close />
</ElIcon>
</div>
</div>
<div class="flex h-[calc(100%-70px)] flex-col">
<!-- 聊天消息区域 -->
<div
class="flex-1 overflow-y-auto border-t-d px-4 py-7.5 [&::-webkit-scrollbar]:!w-1"
ref="messageContainer"
>
<template v-for="(message, index) in messages" :key="index">
<div
:class="[
'mb-7.5 flex w-full items-start gap-2',
message.isMe ? 'flex-row-reverse' : 'flex-row'
]"
>
<ElAvatar :size="32" :src="message.avatar" class="shrink-0" />
<div
:class="['flex max-w-[70%] flex-col', message.isMe ? 'items-end' : 'items-start']"
>
<div
:class="[
'mb-1 flex gap-2 text-xs',
message.isMe ? 'flex-row-reverse' : 'flex-row'
]"
>
<span class="font-medium">{{ message.sender }}</span>
<span class="text-g-600">{{ message.time }}</span>
</div>
<div
:class="[
'rounded-md px-3.5 py-2.5 text-sm leading-[1.4] text-g-900',
message.isMe ? 'message-right bg-theme/15' : 'message-left bg-g-300/50'
]"
>{{ message.content }}</div
>
</div>
</div>
</template>
</div>
<!-- 聊天输入区域 -->
<div class="px-4 pt-4">
<ElInput
v-model="messageText"
type="textarea"
:rows="3"
placeholder="输入消息"
resize="none"
@keyup.enter.prevent="sendMessage"
>
<template #append>
<div class="flex gap-2 py-2">
<ElButton :icon="Paperclip" circle plain />
<ElButton :icon="Picture" circle plain />
<ElButton type="primary" @click="sendMessage" v-ripple>发送</ElButton>
</div>
</template>
</ElInput>
<div class="mt-3 flex-cb">
<div class="flex-c">
<ArtSvgIcon icon="ri:image-line" class="mr-5 c-p text-g-600 text-lg" />
<ArtSvgIcon icon="ri:emotion-happy-line" class="mr-5 c-p text-g-600 text-lg" />
</div>
<ElButton type="primary" @click="sendMessage" v-ripple class="min-w-20">发送</ElButton>
</div>
</div>
</div>
</ElDrawer>
</div>
</template>
<script setup lang="ts">
import { Picture, Paperclip, Close } from '@element-plus/icons-vue'
import { mittBus } from '@/utils/sys'
import meAvatar from '@/assets/images/avatar/avatar5.webp'
import aiAvatar from '@/assets/images/avatar/avatar10.webp'
defineOptions({ name: 'ArtChatWindow' })
// 类型定义
interface ChatMessage {
id: number
sender: string
content: string
time: string
isMe: boolean
avatar: string
}
// 常量定义
const MOBILE_BREAKPOINT = 640
const SCROLL_DELAY = 100
const BOT_NAME = 'Art Bot'
const USER_NAME = 'Ricky'
// 响应式布局
const { width } = useWindowSize()
const isMobile = computed(() => width.value < MOBILE_BREAKPOINT)
// 组件状态
const isDrawerVisible = ref(false)
const isOnline = ref(true)
// 消息相关状态
const messageText = ref('')
const messageId = ref(10)
const messageContainer = ref<HTMLElement | null>(null)
// 初始化聊天消息数据
const initializeMessages = (): ChatMessage[] => [
{
id: 1,
sender: BOT_NAME,
content: '你好!我是你的AI助手,有什么我可以帮你的吗?',
time: '10:00',
isMe: false,
avatar: aiAvatar
},
{
id: 2,
sender: USER_NAME,
content: '我想了解一下系统的使用方法。',
time: '10:01',
isMe: true,
avatar: meAvatar
},
{
id: 3,
sender: BOT_NAME,
content: '好的,我来为您介绍系统的主要功能。首先,您可以通过左侧菜单访问不同的功能模块...',
time: '10:02',
isMe: false,
avatar: aiAvatar
},
{
id: 4,
sender: USER_NAME,
content: '听起来很不错,能具体讲讲数据分析部分吗?',
time: '10:05',
isMe: true,
avatar: meAvatar
},
{
id: 5,
sender: BOT_NAME,
content: '当然可以。数据分析模块可以帮助您实时监控关键指标,并生成详细的报表...',
time: '10:06',
isMe: false,
avatar: aiAvatar
},
{
id: 6,
sender: USER_NAME,
content: '太好了,那我如何开始使用呢?',
time: '10:08',
isMe: true,
avatar: meAvatar
},
{
id: 7,
sender: BOT_NAME,
content: '您可以先创建一个项目,然后在项目中添加相关的数据源,系统会自动进行分析。',
time: '10:09',
isMe: false,
avatar: aiAvatar
},
{
id: 8,
sender: USER_NAME,
content: '明白了,谢谢你的帮助!',
time: '10:10',
isMe: true,
avatar: meAvatar
},
{
id: 9,
sender: BOT_NAME,
content: '不客气,有任何问题随时联系我。',
time: '10:11',
isMe: false,
avatar: aiAvatar
}
]
const messages = ref<ChatMessage[]>(initializeMessages())
// 工具函数
const formatCurrentTime = (): string => {
return new Date().toLocaleTimeString([], {
hour: '2-digit',
minute: '2-digit'
})
}
const scrollToBottom = (): void => {
nextTick(() => {
setTimeout(() => {
if (messageContainer.value) {
messageContainer.value.scrollTop = messageContainer.value.scrollHeight
}
}, SCROLL_DELAY)
})
}
// 消息处理方法
const sendMessage = (): void => {
const text = messageText.value.trim()
if (!text) return
const newMessage: ChatMessage = {
id: messageId.value++,
sender: USER_NAME,
content: text,
time: formatCurrentTime(),
isMe: true,
avatar: meAvatar
}
messages.value.push(newMessage)
messageText.value = ''
scrollToBottom()
}
// 聊天窗口控制方法
const openChat = (): void => {
isDrawerVisible.value = true
scrollToBottom()
}
const closeChat = (): void => {
isDrawerVisible.value = false
}
// 生命周期
onMounted(() => {
scrollToBottom()
mittBus.on('openChat', openChat)
})
onUnmounted(() => {
mittBus.off('openChat', openChat)
})
</script>
@@ -114,19 +114,9 @@
v-if="shouldShowNotification"
icon="ri:notification-2-line"
class="notice-button relative"
@click="visibleNotice"
@click.stop="visibleNotice"
>
<div class="absolute top-2 right-2 size-1.5 !bg-danger rounded-full"></div>
</ArtIconButton>
<!-- 聊天按钮 -->
<ArtIconButton
v-if="shouldShowChat"
icon="ri:message-3-line"
class="chat-button relative"
@click="openChat"
>
<div class="breathing-dot absolute top-2 right-2 size-1.5 !bg-success rounded-full"></div>
<div v-if="unreadCount > 0" class="absolute top-2 right-2 size-1.5 !bg-danger rounded-full"></div>
</ArtIconButton>
<!-- 设置按钮 -->
@@ -182,6 +172,7 @@
import { themeAnimation } from '@/utils/ui/animation'
import { useCommon } from '@/hooks/core/useCommon'
import { useHeaderBar } from '@/hooks/core/useHeaderBar'
import { useNotifyCenter } from '@/hooks/core/useNotifyCenter'
import ArtUserMenu from './widget/ArtUserMenu.vue'
defineOptions({ name: 'ArtHeaderBar' })
@@ -222,6 +213,9 @@
const showNotice = ref(false)
const notice = ref(null)
// 通知中心未读数(真实 notifications 数据,60s 轮询)
const { unreadCount } = useNotifyCenter()
// 菜单类型判断
const isLeftMenu = computed(() => menuType.value === MenuTypeEnum.LEFT)
const isDualMenu = computed(() => menuType.value === MenuTypeEnum.DUAL_MENU)
@@ -334,13 +328,6 @@
const visibleNotice = (): void => {
showNotice.value = !showNotice.value
}
/**
* 打开聊天窗口
*/
const openChat = (): void => {
mittBus.emit('openChat')
}
</script>
<style lang="scss" scoped>
@@ -461,15 +448,6 @@
animation: shake 0.5s ease-in-out;
}
.chat-button:hover :deep(.art-svg-icon) {
animation: shake 0.5s ease-in-out;
}
/* Breathing animation for chat dot */
.breathing-dot {
animation: breathing 1.5s ease-in-out infinite;
}
/* iPad breakpoint adjustments */
@media screen and (width <= 768px) {
.logo2 {
@@ -37,14 +37,6 @@
<ArtSvgIcon icon="ri:user-3-line" />
<span>{{ $t('topBar.user.userCenter') }}</span>
</li>
<li class="btn-item" @click="toDocs()">
<ArtSvgIcon icon="ri:book-2-line" />
<span>{{ $t('topBar.user.docs') }}</span>
</li>
<li class="btn-item" @click="toGithub()">
<ArtSvgIcon icon="ri:github-line" />
<span>{{ $t('topBar.user.github') }}</span>
</li>
<li class="btn-item" @click="lockScreen()">
<ArtSvgIcon icon="ri:lock-line" />
<span>{{ $t('topBar.user.lockScreen') }}</span>
@@ -64,7 +56,6 @@
import { useRouter } from 'vue-router'
import { ElMessageBox } from 'element-plus'
import { useUserStore } from '@/store/modules/user'
import { WEB_LINKS } from '@/utils/constants'
import { mittBus } from '@/utils/sys'
defineOptions({ name: 'ArtUserMenu' })
@@ -84,20 +75,6 @@
router.push(path)
}
/**
* 打开文档页面
*/
const toDocs = (): void => {
window.open(WEB_LINKS.DOCS)
}
/**
* 打开 GitHub 页面
*/
const toGithub = (): void => {
window.open(WEB_LINKS.GITHUB)
}
/**
* 打开锁屏功能
*/
@@ -1,456 +1,181 @@
<!-- 通知组件 -->
<template>
<div
class="art-notification-panel art-card-sm !shadow-xl"
:style="{
transform: show ? 'scaleY(1)' : 'scaleY(0.9)',
opacity: show ? 1 : 0
}"
v-show="visible"
@click.stop
>
<div class="flex-cb px-3.5 mt-3.5">
<span class="text-base font-medium text-g-800">{{ $t('notice.title') }}</span>
<span class="text-xs text-g-800 px-1.5 py-1 c-p select-none rounded hover:bg-g-200">
{{ $t('notice.btnRead') }}
</span>
</div>
<ul class="box-border flex items-end w-full h-12.5 px-3.5 border-b-d">
<li
v-for="(item, index) in barList"
:key="index"
class="h-12 leading-12 mr-5 overflow-hidden text-[13px] text-g-700 c-p select-none"
:class="{ 'bar-active': barActiveIndex === index }"
@click="changeBar(index)"
>
{{ item.name }} ({{ item.num }})
</li>
</ul>
<div class="w-full h-[calc(100%-95px)]">
<div class="h-[calc(100%-60px)] overflow-y-scroll scrollbar-thin">
<!-- 通知 -->
<ul v-show="barActiveIndex === 0">
<li
v-for="(item, index) in noticeList"
:key="index"
class="box-border flex-c px-3.5 py-3.5 c-p last:border-b-0 hover:bg-g-200/60"
>
<div
class="size-9 leading-9 text-center rounded-lg flex-cc"
:class="[getNoticeStyle(item.type).iconClass]"
>
<ArtSvgIcon class="text-lg !bg-transparent" :icon="getNoticeStyle(item.type).icon" />
</div>
<div class="w-[calc(100%-45px)] ml-3.5">
<h4 class="text-sm font-normal leading-5.5 text-g-900">{{ item.title }}</h4>
<p class="mt-1.5 text-xs text-g-500">{{ item.time }}</p>
</div>
</li>
</ul>
<!-- 消息 -->
<ul v-show="barActiveIndex === 1">
<li
v-for="(item, index) in msgList"
:key="index"
class="box-border flex-c px-3.5 py-3.5 c-p last:border-b-0 hover:bg-g-200/60"
>
<div class="w-9 h-9">
<img :src="item.avatar" class="w-full h-full rounded-lg" />
</div>
<div class="w-[calc(100%-45px)] ml-3.5">
<h4 class="text-xs font-normal leading-5.5">{{ item.title }}</h4>
<p class="mt-1.5 text-xs text-g-500">{{ item.time }}</p>
</div>
</li>
</ul>
<!-- 待办 -->
<ul v-show="barActiveIndex === 2">
<li
v-for="(item, index) in pendingList"
:key="index"
class="box-border px-5 py-3.5 last:border-b-0"
>
<h4>{{ item.title }}</h4>
<p class="text-xs text-g-500">{{ item.time }}</p>
</li>
</ul>
<!-- 空状态 -->
<div
v-show="currentTabIsEmpty"
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"
>{{ $t('notice.text[0]') }}{{ barList[barActiveIndex].name }}</p
>
</div>
</div>
<div class="relative box-border w-full px-3.5">
<ElButton class="w-full mt-3" @click="handleViewAll" v-ripple>
{{ $t('notice.viewAll') }}
</ElButton>
</div>
</div>
<div class="h-25"></div>
</div>
</template>
<script setup lang="ts">
import { computed, ref, watch, type Ref, type ComputedRef } from 'vue'
import { useI18n } from 'vue-i18n'
// 导入头像图片
import avatar1 from '@/assets/images/avatar/avatar1.webp'
import avatar2 from '@/assets/images/avatar/avatar2.webp'
import avatar3 from '@/assets/images/avatar/avatar3.webp'
import avatar4 from '@/assets/images/avatar/avatar4.webp'
import avatar5 from '@/assets/images/avatar/avatar5.webp'
import avatar6 from '@/assets/images/avatar/avatar6.webp'
defineOptions({ name: 'ArtNotification' })
interface NoticeItem {
/** 标题 */
title: string
/** 时间 */
time: string
/** 类型 */
type: NoticeType
}
interface MessageItem {
/** 标题 */
title: string
/** 时间 */
time: string
/** 头像 */
avatar: string
}
interface PendingItem {
/** 标题 */
title: string
/** 时间 */
time: string
}
interface BarItem {
/** 名称 */
name: ComputedRef<string>
/** 数量 */
num: number
}
interface NoticeStyle {
/** 图标 */
icon: string
/** icon 样式 */
iconClass: string
}
type NoticeType = 'email' | 'message' | 'collection' | 'user' | 'notice'
const { t } = useI18n()
const props = defineProps<{
value: boolean
}>()
const emit = defineEmits<{
'update:value': [value: boolean]
}>()
const show = ref(false)
const visible = ref(false)
const barActiveIndex = ref(0)
const useNotificationData = () => {
// 通知数据
const noticeList = ref<NoticeItem[]>([
{
title: '新增国际化',
time: '2024-6-13 0:10',
type: 'notice'
},
{
title: '冷月呆呆给你发了一条消息',
time: '2024-4-21 8:05',
type: 'message'
},
{
title: '小肥猪关注了你',
time: '2020-3-17 21:12',
type: 'collection'
},
{
title: '新增使用文档',
time: '2024-02-14 0:20',
type: 'notice'
},
{
title: '小肥猪给你发了一封邮件',
time: '2024-1-20 0:15',
type: 'email'
},
{
title: '菜单mock本地真实数据',
time: '2024-1-17 22:06',
type: 'notice'
}
])
// 消息数据
const msgList = ref<MessageItem[]>([
{
title: '池不胖 关注了你',
time: '2021-2-26 23:50',
avatar: avatar1
},
{
title: '唐不苦 关注了你',
time: '2021-2-21 8:05',
avatar: avatar2
},
{
title: '中小鱼 关注了你',
time: '2020-1-17 21:12',
avatar: avatar3
},
{
title: '何小荷 关注了你',
time: '2021-01-14 0:20',
avatar: avatar4
},
{
title: '誶誶淰 关注了你',
time: '2020-12-20 0:15',
avatar: avatar5
},
{
title: '冷月呆呆 关注了你',
time: '2020-12-17 22:06',
avatar: avatar6
}
])
// 待办数据
const pendingList = ref<PendingItem[]>([])
// 标签栏数据
const barList = computed<BarItem[]>(() => [
{
name: computed(() => t('notice.bar[0]')),
num: noticeList.value.length
},
{
name: computed(() => t('notice.bar[1]')),
num: msgList.value.length
},
{
name: computed(() => t('notice.bar[2]')),
num: pendingList.value.length
}
])
return {
noticeList,
msgList,
pendingList,
barList
}
}
// 样式管理
const useNotificationStyles = () => {
const noticeStyleMap: Record<NoticeType, NoticeStyle> = {
email: {
icon: 'ri:mail-line',
iconClass: 'bg-warning/12 text-warning'
},
message: {
icon: 'ri:volume-down-line',
iconClass: 'bg-success/12 text-success'
},
collection: {
icon: 'ri:heart-3-line',
iconClass: 'bg-danger/12 text-danger'
},
user: {
icon: 'ri:volume-down-line',
iconClass: 'bg-info/12 text-info'
},
notice: {
icon: 'ri:notification-3-line',
iconClass: 'bg-theme/12 text-theme'
}
}
const getNoticeStyle = (type: NoticeType): NoticeStyle => {
const defaultStyle: NoticeStyle = {
icon: 'ri:arrow-right-circle-line',
iconClass: 'bg-theme/12 text-theme'
}
return noticeStyleMap[type] || defaultStyle
}
return {
getNoticeStyle
}
}
// 动画管理
const useNotificationAnimation = () => {
const showNotice = (open: boolean) => {
if (open) {
visible.value = true
setTimeout(() => {
show.value = true
}, 5)
} else {
show.value = false
setTimeout(() => {
visible.value = false
}, 350)
}
}
return {
showNotice
}
}
// 标签页管理
const useTabManagement = (
noticeList: Ref<NoticeItem[]>,
msgList: Ref<MessageItem[]>,
pendingList: Ref<PendingItem[]>,
businessHandlers: {
handleNoticeAll: () => void
handleMsgAll: () => void
handlePendingAll: () => void
}
) => {
const changeBar = (index: number) => {
barActiveIndex.value = index
}
// 检查当前标签页是否为空
const currentTabIsEmpty = computed(() => {
const tabDataMap = [noticeList.value, msgList.value, pendingList.value]
const currentData = tabDataMap[barActiveIndex.value]
return currentData && currentData.length === 0
})
const handleViewAll = () => {
// 查看全部处理器映射
const viewAllHandlers: Record<number, () => void> = {
0: businessHandlers.handleNoticeAll,
1: businessHandlers.handleMsgAll,
2: businessHandlers.handlePendingAll
}
const handler = viewAllHandlers[barActiveIndex.value]
handler?.()
// 关闭通知面板
emit('update:value', false)
}
return {
changeBar,
currentTabIsEmpty,
handleViewAll
}
}
// 业务逻辑处理
const useBusinessLogic = () => {
const handleNoticeAll = () => {
// 处理查看全部通知
console.log('查看全部通知')
}
const handleMsgAll = () => {
// 处理查看全部消息
console.log('查看全部消息')
}
const handlePendingAll = () => {
// 处理查看全部待办
console.log('查看全部待办')
}
return {
handleNoticeAll,
handleMsgAll,
handlePendingAll
}
}
// 组合所有逻辑
const { noticeList, msgList, pendingList, barList } = useNotificationData()
const { getNoticeStyle } = useNotificationStyles()
const { showNotice } = useNotificationAnimation()
const { handleNoticeAll, handleMsgAll, handlePendingAll } = useBusinessLogic()
const { changeBar, currentTabIsEmpty, handleViewAll } = useTabManagement(
noticeList,
msgList,
pendingList,
{ handleNoticeAll, handleMsgAll, handlePendingAll }
)
// 监听属性变化
watch(
() => props.value,
(newValue) => {
showNotice(newValue)
}
)
</script>
<style scoped>
@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];
}
.bar-active {
color: var(--theme-color) !important;
border-bottom: 2px solid var(--theme-color);
}
.scrollbar-thin::-webkit-scrollbar {
width: 5px !important;
}
.dark .scrollbar-thin::-webkit-scrollbar-track {
background-color: var(--default-box-color);
}
.dark .scrollbar-thin::-webkit-scrollbar-thumb {
background-color: #222 !important;
}
</style>
<!-- 通知中心(37du:接真实 notifications 数据,与员工端壳子同源) -->
<template>
<div
class="art-notification-panel art-card-sm !shadow-xl"
:style="{
transform: show ? 'scaleY(1)' : 'scaleY(0.9)',
opacity: show ? 1 : 0
}"
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="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>
</div>
</div>
<div class="relative box-border w-full px-3.5">
<ElButton class="w-full mt-3" @click="goNotifyPage" v-ripple>前往通知推送管理</ElButton>
</div>
</div>
<div class="h-10"></div>
</div>
</template>
<script setup lang="ts">
import { ref, watch, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { useNotifyCenter } from '@/hooks/core/useNotifyCenter'
defineOptions({ name: 'ArtNotification' })
const props = defineProps<{
value: boolean
}>()
const emit = defineEmits<{
'update:value': [value: boolean]
}>()
const router = useRouter()
const { items, unreadCount, refresh, markAllRead, lastRead } = useNotifyCenter()
// 显隐(对齐原模板:v-show + scaleY 过渡)
const show = ref(false)
const visible = ref(false)
let hideTimer: ReturnType<typeof setTimeout> | null = null
watch(
() => props.value,
(newValue) => {
if (newValue) {
if (hideTimer) {
clearTimeout(hideTimer)
hideTimer = null
}
visible.value = true
// 打开即刷新一次,并顺带标记已读(红点熄灭)
refresh().then(() => markAllRead())
nextTick(() => {
show.value = true
})
} else {
show.value = false
hideTimer = setTimeout(() => {
visible.value = false
}, 300)
}
}
)
// 点击面板外自动关闭
function onDocClick(): void {
if (props.value) emit('update:value', false)
}
onMounted(() => document.addEventListener('click', onDocClick))
onUnmounted(() => document.removeEventListener('click', onDocClick))
// 级别样式:info=蓝 notice / warning=橙 / important=红
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' }
}
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:information-line', iconClass: 'bg-[var(--el-color-primary-light-8)] text-[var(--el-color-primary)]', tagType: 'warning' }
}
function levelName(level: string): string {
return level === 'important' ? '重要' : level === 'warning' ? '警告' : '通知'
}
function isNew(item: any): boolean {
const ts = new Date(String(item.created_at || '').replace(' ', 'T')).getTime()
return ts > (lastRead.value || 0)
}
function fmtTime(s: string): string {
return String(s || '').slice(5, 16)
}
function goNotifyPage(): void {
emit('update:value', false)
router.push('/notify')
}
</script>
<style scoped>
@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];
}
.scrollbar-thin::-webkit-scrollbar {
width: 5px !important;
}
.dark .scrollbar-thin::-webkit-scrollbar-track {
background-color: var(--default-box-color);
}
.dark .scrollbar-thin::-webkit-scrollbar-thumb {
background-color: #222 !important;
}
</style>
@@ -38,7 +38,7 @@ import { headerBarConfig } from './modules/headerBar'
const appConfig: SystemConfig = {
// 系统信息
systemInfo: {
name: 'Art Design Pro' // 系统名称
name: '37du 控制台' // 系统名称
},
// 系统主题
systemThemeStyles: {
@@ -45,14 +45,6 @@ export const globalComponentsConfig: GlobalComponentConfig[] = [
),
enabled: true
},
{
name: '聊天窗口',
key: 'chat-window',
component: defineAsyncComponent(
() => import('@/components/core/layouts/art-chat-window/index.vue')
),
enabled: true
},
{
name: '礼花效果',
key: 'fireworks-effect',
@@ -1,127 +1,95 @@
/**
* 快速入口配置
* 包含:应用列表、快速链接等配置
*/
import { WEB_LINKS } from '@/utils/constants'
import type { FastEnterConfig } from '@/types/config'
const fastEnterConfig: FastEnterConfig = {
// 显示条件(屏幕宽度)
minWidth: 1200,
// 应用列表
applications: [
{
name: '工作台',
description: '系统概览与数据统计',
icon: 'ri:pie-chart-line',
iconColor: '#377dff',
enabled: true,
order: 1,
routeName: 'Console'
},
{
name: '分析页',
description: '数据分析与可视化',
icon: 'ri:game-line',
iconColor: '#ff3b30',
enabled: true,
order: 2,
routeName: 'Analysis'
},
{
name: '礼花效果',
description: '动画特效展示',
icon: 'ri:loader-line',
iconColor: '#7A7FFF',
enabled: true,
order: 3,
routeName: 'Fireworks'
},
{
name: '聊天',
description: '即时通讯功能',
icon: 'ri:user-line',
iconColor: '#13DEB9',
enabled: true,
order: 4,
routeName: 'Chat'
},
{
name: '官方文档',
description: '使用指南与开发文档',
icon: 'ri:bill-line',
iconColor: '#ffb100',
enabled: true,
order: 5,
link: WEB_LINKS.DOCS
},
{
name: '技术支持',
description: '技术支持与问题反馈',
icon: 'ri:user-location-line',
iconColor: '#ff6b6b',
enabled: true,
order: 6,
link: WEB_LINKS.COMMUNITY
},
{
name: '更新日志',
description: '版本更新与变更记录',
icon: 'ri:gamepad-line',
iconColor: '#38C0FC',
enabled: true,
order: 7,
routeName: 'ChangeLog'
},
{
name: '哔哩哔哩',
description: '技术分享与交流',
icon: 'ri:bilibili-line',
iconColor: '#FB7299',
enabled: true,
order: 8,
link: WEB_LINKS.BILIBILI
}
],
// 快速链接
quickLinks: [
{
name: '登录',
enabled: true,
order: 1,
routeName: 'Login'
},
{
name: '注册',
enabled: true,
order: 2,
routeName: 'Register'
},
{
name: '忘记密码',
enabled: true,
order: 3,
routeName: 'ForgetPassword'
},
{
name: '定价',
enabled: true,
order: 4,
routeName: 'Pricing'
},
{
name: '个人中心',
enabled: true,
order: 5,
routeName: 'UserCenter'
},
{
name: '留言管理',
enabled: true,
order: 6,
routeName: 'ArticleComment'
}
]
}
export default Object.freeze(fastEnterConfig)
/**
* 快速入口配置(37du:仅指向控制台真实页面)
*/
import type { FastEnterConfig } from '@/types/config'
const fastEnterConfig: FastEnterConfig = {
// 显示条件(屏幕宽度)
minWidth: 1200,
// 应用列表
applications: [
{
name: '概览',
description: '插件与账号全景',
icon: 'ri:pie-chart-line',
iconColor: '#377dff',
enabled: true,
order: 1,
routeName: 'Overview'
},
{
name: '插件管理',
description: '上传发布与版本管理',
icon: 'ri:box-3-line',
iconColor: '#13DEB9',
enabled: true,
order: 2,
routeName: 'Plugins'
},
{
name: '账号管理',
description: '统一账号维护',
icon: 'ri:user-3-line',
iconColor: '#7A7FFF',
enabled: true,
order: 3,
routeName: 'Accounts'
},
{
name: '权限授权',
description: '插件/平台授权工作台',
icon: 'ri:key-2-line',
iconColor: '#ffb100',
enabled: true,
order: 4,
routeName: 'Grants'
},
{
name: '通知推送',
description: '执行机用户消息触达',
icon: 'ri:notification-3-line',
iconColor: '#ff6b6b',
enabled: true,
order: 5,
routeName: 'Notify'
},
{
name: '数据看板',
description: '运行统计与趋势',
icon: 'ri:bar-chart-2-line',
iconColor: '#38C0FC',
enabled: true,
order: 6,
routeName: 'Stats'
}
],
// 快速链接
quickLinks: [
{
name: '审计报表',
enabled: true,
order: 1,
routeName: 'Audit'
},
{
name: '运行记录',
enabled: true,
order: 2,
routeName: 'Reports'
},
{
name: '执行机设备',
enabled: true,
order: 3,
routeName: 'Devices'
},
{
name: '敏感凭证',
enabled: true,
order: 4,
routeName: 'Creds'
}
]
}
export default Object.freeze(fastEnterConfig)
@@ -43,8 +43,8 @@ export const headerBarConfig: HeaderBarFeatureConfig = {
description: '通知中心,显示系统通知和消息'
},
chat: {
enabled: true,
description: '聊天功能,提供实时沟通'
enabled: false,
description: '聊天功能(37du 未使用,已停用)'
},
language: {
enabled: true,
@@ -0,0 +1,74 @@
import { computed, ref } from 'vue'
import { fetchLatestNotifications } from '@/api/business'
/**
* 通知中心共享状态(页眉铃铛 + 通知面板共用)
*
* - 数据源:GET /api/admin/notifications/latest(active 且未过期,管理员全量可见,
* 与员工端壳子 notifier.js 消费的 /api/notifications 同源同语义)
* - 已读跟踪:localStorage 存最近已读时间戳(服务端无逐用户已读模型,控制台本地判定足够;
* 时间戳之前的视为已读,铃铛红点 = 存在更新的通知)
* - 轮询:模块级单例 60s 轻量刷新,页眉与面板不重复请求
*/
const LAST_READ_KEY = '37du-notify-last-read'
function readLastRead(): number {
try {
return Number(localStorage.getItem(LAST_READ_KEY) || 0)
} catch (e) {
return 0
}
}
const items = ref<any[]>([])
const lastRead = ref<number>(readLastRead())
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
}
/** 存在比"最近已读"更新的通知 */
const unreadCount = computed(() => {
return items.value.filter((i) => toTs(i.created_at) > lastRead.value).length
})
async function refresh(): Promise<void> {
if (loading.value) return
loading.value = true
try {
const r = await fetchLatestNotifications(30)
items.value = r.items || []
} catch (e) {
/* 未登录/网络异常静默,下轮重试 */
} finally {
loading.value = false
}
}
/** 全部标记已读:以当前时间作为已读水位 */
function markAllRead(): void {
lastRead.value = Date.now()
try {
localStorage.setItem(LAST_READ_KEY, String(lastRead.value))
} catch (e) {
/* ignore */
}
}
/** 模块级单例启动轮询(首个调用方触发) */
function ensureStarted(): void {
if (started) return
started = true
refresh()
setInterval(refresh, 60_000)
}
export function useNotifyCenter() {
ensureStarted()
return { items, unreadCount, loading, lastRead, refresh, markAllRead }
}
@@ -150,8 +150,8 @@
},
"login": {
"leftView": {
"title": "A backend system of beauty and efficiency",
"subTitle": "A sleek and practical interface for a great user experience"
"title": "37du Automation Platform - Unified Console",
"subTitle": "Plugin distribution, account authorization and runtime monitoring in one place"
},
"title": "Welcome back",
"subTitle": "Please enter your account and password to login",
@@ -150,8 +150,8 @@
},
"login": {
"leftView": {
"title": "一款兼具设计美学与高效开发的后台系统",
"subTitle": "美观实用的界面,经过视觉优化,确保卓越的用户体验"
"title": "37du 自动化平台 · 统一控制台",
"subTitle": "插件分发 · 账号授权 · 运行监控,一站式管理执行机与插件"
},
"title": "欢迎回来",
"subTitle": "输入您的账号和密码登录",
@@ -35,7 +35,6 @@
* - triggerFireworks: 触发烟花效果(可选图片URL)
* - openSetting: 打开设置面板
* - openSearchDialog: 打开搜索对话框
* - openChat: 打开聊天窗口
* - openLockScreen: 打开锁屏
*
* @module utils/sys/mittBus
@@ -51,8 +50,6 @@ type Events = {
openSetting: void
// 打开搜索对话框事件 - 无参数
openSearchDialog: void
// 打开聊天窗口事件 - 无参数
openChat: void
// 打开锁屏事件 - 无参数
openLockScreen: void
}
@@ -1,203 +1,204 @@
<script setup lang="ts">
/**
* 账号管理(37du 控制台)
* 列表/搜索/新建/编辑/重置密码/删除,对接 /api/admin/accounts*
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
fetchAccounts, createAccount, updateAccount, resetAccountPwd, deleteAccount
} from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 10, q: '' })
async function load() {
loading.value = true
try {
const r = await fetchAccounts(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 新建/编辑 ----
const dialogOpen = ref(false)
const isEdit = ref(false)
const saving = ref(false)
const form = reactive({ account: '', password: '', dept: '', nickname: '', is_admin: false, status: 1 })
function openCreate() {
isEdit.value = false
Object.assign(form, { account: '', password: '', dept: '', nickname: '', is_admin: false, status: 1 })
dialogOpen.value = true
}
function openEdit(row: any) {
isEdit.value = true
Object.assign(form, {
account: row.account, password: '', dept: row.dept || '', nickname: row.nickname || '',
is_admin: !!row.is_admin, status: row.status
})
dialogOpen.value = true
}
async function submit() {
if (!form.account) return ElMessage.warning('account 必填')
if (!isEdit.value && (!form.password || form.password.length < 8)) {
return ElMessage.warning('密码至少 8 位')
}
saving.value = true
try {
if (isEdit.value) {
await updateAccount({ account: form.account, dept: form.dept, nickname: form.nickname, is_admin: form.is_admin, status: form.status })
} else {
await createAccount(form)
}
ElMessage.success('保存成功')
dialogOpen.value = false
load()
} finally {
saving.value = false
}
}
// ---- 重置密码 ----
const pwdOpen = ref(false)
const pwdForm = reactive({ account: '', new_password: '' })
function openReset(row: any) {
Object.assign(pwdForm, { account: row.account, new_password: '' })
pwdOpen.value = true
}
async function submitReset() {
if (!pwdForm.new_password || pwdForm.new_password.length < 8) {
return ElMessage.warning('新密码至少 8 位')
}
await resetAccountPwd({ account: pwdForm.account, new_password: pwdForm.new_password })
ElMessage.success('密码已重置')
pwdOpen.value = false
}
// ---- 删除 ----
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除账号「${row.account}」?`, '删除确认', { type: 'warning' })
await deleteAccount(row.account)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">账号管理</h2>
<el-button type="primary" @click="openCreate">新建账号</el-button>
</div>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="账号 / 昵称 / 部门" clearable style="width: 240px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="account" label="账号" min-width="120" />
<el-table-column prop="nickname" label="昵称" min-width="120" />
<el-table-column prop="dept" label="部门" width="120" />
<el-table-column label="管理员" width="90">
<template #default="{ row }">
<el-tag v-if="row.is_admin" size="small" type="primary">管理员</el-tag>
<span v-else class="text-gray-400">-</span>
</template>
</el-table-column>
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'danger'" size="small">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="插件授权" width="110">
<template #default="{ row }">
<el-tag v-if="row.plugins?.length" size="small" type="info">{{ row.plugins.length }} 个</el-tag>
<span v-else class="text-gray-400">-</span>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="170" />
<el-table-column label="操作" width="220" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
<el-button link type="warning" @click="openReset(row)">重置密码</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
<!-- 新建/编辑弹窗 -->
<el-dialog v-model="dialogOpen" :title="isEdit ? '编辑账号' : '新建账号'" width="480px">
<el-form label-width="90px">
<el-form-item label="账号" required>
<el-input v-model="form.account" :disabled="isEdit" placeholder="工号" />
</el-form-item>
<el-form-item v-if="!isEdit" label="初始密码" required>
<el-input v-model="form.password" type="password" show-password placeholder="至少 8 位" />
</el-form-item>
<el-form-item label="昵称">
<el-input v-model="form.nickname" />
</el-form-item>
<el-form-item label="部门">
<el-input v-model="form.dept" />
</el-form-item>
<el-form-item label="管理员">
<el-switch v-model="form.is_admin" />
</el-form-item>
<el-form-item v-if="isEdit" label="状态">
<el-switch v-model="form.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
<!-- 重置密码弹窗 -->
<el-dialog v-model="pwdOpen" title="重置密码" width="420px">
<el-form label-width="90px">
<el-form-item label="账号">{{ pwdForm.account }}</el-form-item>
<el-form-item label="新密码" required>
<el-input v-model="pwdForm.new_password" type="password" show-password placeholder="至少 8 位" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="pwdOpen = false">取消</el-button>
<el-button type="primary" @click="submitReset">重置</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
/**
* 账号管理(37du 控制台)
* 列表/搜索/新建/编辑/重置密码/删除,对接 /api/admin/accounts*
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
fetchAccounts, createAccount, updateAccount, resetAccountPwd, deleteAccount
} from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 10, q: '' })
async function load() {
loading.value = true
try {
const r = await fetchAccounts(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 新建/编辑 ----
const dialogOpen = ref(false)
const isEdit = ref(false)
const saving = ref(false)
const form = reactive({ account: '', password: '', dept: '', nickname: '', is_admin: false, status: 1 })
function openCreate() {
isEdit.value = false
Object.assign(form, { account: '', password: '', dept: '', nickname: '', is_admin: false, status: 1 })
dialogOpen.value = true
}
function openEdit(row: any) {
isEdit.value = true
Object.assign(form, {
account: row.account, password: '', dept: row.dept || '', nickname: row.nickname || '',
is_admin: !!row.is_admin, status: row.status
})
dialogOpen.value = true
}
async function submit() {
if (!form.account) return ElMessage.warning('account 必填')
if (!isEdit.value && (!form.password || form.password.length < 8)) {
return ElMessage.warning('密码至少 8 位')
}
saving.value = true
try {
if (isEdit.value) {
await updateAccount({ account: form.account, dept: form.dept, nickname: form.nickname, is_admin: form.is_admin, status: form.status })
} else {
await createAccount(form)
}
ElMessage.success('保存成功')
dialogOpen.value = false
load()
} finally {
saving.value = false
}
}
// ---- 重置密码 ----
const pwdOpen = ref(false)
const pwdForm = reactive({ account: '', new_password: '' })
function openReset(row: any) {
Object.assign(pwdForm, { account: row.account, new_password: '' })
pwdOpen.value = true
}
async function submitReset() {
if (!pwdForm.new_password || pwdForm.new_password.length < 8) {
return ElMessage.warning('新密码至少 8 位')
}
await resetAccountPwd({ account: pwdForm.account, new_password: pwdForm.new_password })
ElMessage.success('密码已重置')
pwdOpen.value = false
}
// ---- 删除 ----
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除账号「${row.account}」?`, '删除确认', { type: 'warning' })
await deleteAccount(row.account)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="账号管理" description="统一账号维护、管理员标识与授权概览">
<template #actions>
<el-button type="primary" @click="openCreate"><ArtSvgIcon icon="ri:add-line" class="mr-1" />新建账号</el-button>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="账号 / 昵称 / 部门" clearable style="width: 240px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="account" label="账号" min-width="120" />
<el-table-column prop="nickname" label="昵称" min-width="120" />
<el-table-column prop="dept" label="部门" width="120" />
<el-table-column label="管理员" width="90">
<template #default="{ row }">
<el-tag v-if="row.is_admin" size="small" type="primary">管理员</el-tag>
<span v-else class="text-gray-400">-</span>
</template>
</el-table-column>
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'danger'" size="small">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="插件授权" width="110">
<template #default="{ row }">
<el-tag v-if="row.plugins?.length" size="small" type="info">{{ row.plugins.length }} 个</el-tag>
<span v-else class="text-gray-400">-</span>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="170" />
<el-table-column label="操作" width="220" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
<el-button link type="warning" @click="openReset(row)">重置密码</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
<!-- 新建/编辑弹窗 -->
<el-dialog v-model="dialogOpen" :title="isEdit ? '编辑账号' : '新建账号'" width="480px">
<el-form label-width="90px">
<el-form-item label="账号" required>
<el-input v-model="form.account" :disabled="isEdit" placeholder="工号" />
</el-form-item>
<el-form-item v-if="!isEdit" label="初始密码" required>
<el-input v-model="form.password" type="password" show-password placeholder="至少 8 位" />
</el-form-item>
<el-form-item label="昵称">
<el-input v-model="form.nickname" />
</el-form-item>
<el-form-item label="部门">
<el-input v-model="form.dept" />
</el-form-item>
<el-form-item label="管理员">
<el-switch v-model="form.is_admin" />
</el-form-item>
<el-form-item v-if="isEdit" label="状态">
<el-switch v-model="form.status" :active-value="1" :inactive-value="0" active-text="启用" inactive-text="停用" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
<!-- 重置密码弹窗 -->
<el-dialog v-model="pwdOpen" title="重置密码" width="420px">
<el-form label-width="90px">
<el-form-item label="账号">{{ pwdForm.account }}</el-form-item>
<el-form-item label="新密码" required>
<el-input v-model="pwdForm.new_password" type="password" show-password placeholder="至少 8 位" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="pwdOpen = false">取消</el-button>
<el-button type="primary" @click="submitReset">重置</el-button>
</template>
</el-dialog>
</div>
</template>
@@ -1,85 +1,86 @@
<script setup lang="ts">
/**
* 审计报表(37du 控制台)
* 分页 + 动作筛选 + 关键字(对接 /api/admin/audit)
*/
import { onMounted, reactive, ref } from 'vue'
import { fetchAudit } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const today = ref(0)
const query = reactive({ page: 1, page_size: 20, action: '', q: '' })
const actionOptions = ['account-create', 'account-update', 'account-reset-pwd', 'account-delete',
'grant', 'revoke-grant', 'grant-platform', 'revoke-platform', 'plugin-publish', 'plugin-delete',
'plugin-patch', 'shell-release', 'file-source-upsert', 'file-source-patch', 'file-source-delete',
'creds-seed', 'notify-create', 'notify-toggle', 'notify-delete', 'download-ticket']
async function load() {
loading.value = true
try {
const r = await fetchAudit(query)
list.value = r.items || []
total.value = r.total || 0
today.value = r.today || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">审计报表</h2>
<el-tag type="info">今日 {{ today }} 条</el-tag>
</div>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="动作">
<el-select v-model="query.action" clearable placeholder="全部" style="width: 200px" @change="search">
<el-option v-for="a in actionOptions" :key="a" :label="a" :value="a" />
</el-select>
</el-form-item>
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="账号 / 对象 / 详情" clearable style="width: 220px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '', action: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="操作者" width="120">
<template #default="{ row }">{{ row.nickname || row.account || '系统' }}</template>
</el-table-column>
<el-table-column prop="action" label="动作" min-width="150" />
<el-table-column prop="target" label="对象" min-width="150" />
<el-table-column prop="detail" label="详情" min-width="200" show-overflow-tooltip />
<el-table-column prop="at" label="时间" width="170" />
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
</div>
</template>
<script setup lang="ts">
/**
* 审计报表(37du 控制台)
* 分页 + 动作筛选 + 关键字(对接 /api/admin/audit)
*/
import { onMounted, reactive, ref } from 'vue'
import { fetchAudit } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const today = ref(0)
const query = reactive({ page: 1, page_size: 20, action: '', q: '' })
const actionOptions = ['account-create', 'account-update', 'account-reset-pwd', 'account-delete',
'grant', 'revoke-grant', 'grant-platform', 'revoke-platform', 'plugin-publish', 'plugin-delete',
'plugin-patch', 'shell-release', 'file-source-upsert', 'file-source-patch', 'file-source-delete',
'creds-seed', 'notify-create', 'notify-toggle', 'notify-delete', 'download-ticket']
async function load() {
loading.value = true
try {
const r = await fetchAudit(query)
list.value = r.items || []
total.value = r.total || 0
today.value = r.today || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="审计报表" description="管理操作全量审计日志,支持按动作与关键字检索">
<template #actions>
<el-tag type="info" effect="plain">今日 {{ today }} 条</el-tag>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="动作">
<el-select v-model="query.action" clearable placeholder="全部" style="width: 200px" @change="search">
<el-option v-for="a in actionOptions" :key="a" :label="a" :value="a" />
</el-select>
</el-form-item>
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="账号 / 对象 / 详情" clearable style="width: 220px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '', action: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="操作者" width="120">
<template #default="{ row }">{{ row.nickname || row.account || '系统' }}</template>
</el-table-column>
<el-table-column prop="action" label="动作" min-width="150" />
<el-table-column prop="target" label="对象" min-width="150" />
<el-table-column prop="detail" label="详情" min-width="200" show-overflow-tooltip />
<el-table-column prop="at" label="时间" width="170" />
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
</div>
</template>
@@ -1,104 +1,117 @@
<script setup lang="ts">
/**
* 敏感凭证(37du 控制台)
* 已登记账号列表 + 明文源录入(对接 /api/admin/creds/manage、creds/seed)
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { fetchCredsManage, seedCreds } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 20 })
async function load() {
loading.value = true
try {
const r = await fetchCredsManage(query)
list.value = r.items || []
total.value = r.total || 0
allowedKeys.value = r.allowed_keys || []
} finally {
loading.value = false
}
}
const allowedKeys = ref<string[]>([])
// ---- 录入明文源 ----
const seedOpen = ref(false)
const saving = ref(false)
const seedForm = reactive<{ account: string; values: Record<string, string> }>({ account: '', values: {} })
function openSeed(row: any) {
seedForm.account = row.account
seedForm.values = {}
for (const k of allowedKeys.value) seedForm.values[k] = row.creds?.[k] || ''
seedOpen.value = true
}
async function submitSeed() {
if (!seedForm.account) return ElMessage.warning('account 不能为空')
saving.value = true
try {
await seedCreds({ account: seedForm.account, values: seedForm.values })
ElMessage.success('明文源已保存')
seedOpen.value = false
load()
} finally {
saving.value = false
}
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">敏感凭证</h2>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="account" label="账号" min-width="140" />
<el-table-column prop="nickname" label="昵称" min-width="120" />
<el-table-column label="已上报公钥" width="110">
<template #default="{ row }">
<el-tag :type="row.has_pubkey ? 'success' : 'info'" size="small">{{ row.has_pubkey ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="已配置键" width="140">
<template #default="{ row }">
<el-tag v-for="k in Object.keys(row.creds || {})" :key="k" size="small" class="mr-1">{{ k }}</el-tag>
<span v-if="!Object.keys(row.creds || {}).length" class="text-gray-400">-</span>
</template>
</el-table-column>
<el-table-column prop="updated_at" label="更新时间" width="170" />
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openSeed(row)">录入明文</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
layout="total, prev, pager, next" @current-change="load" />
</div>
</el-card>
<el-dialog v-model="seedOpen" title="录入敏感凭证明文源" width="520px">
<el-form label-width="120px">
<el-form-item label="账号">{{ seedForm.account }}</el-form-item>
<el-form-item v-for="k in allowedKeys" :key="k" :label="k">
<el-input v-model="seedForm.values[k]" type="password" show-password placeholder="留空则清除" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="seedOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submitSeed">保存</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
/**
* 敏感凭证(37du 控制台)
* 已登记账号列表 + 明文源录入(对接 /api/admin/creds/manage、creds/seed)
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { fetchCredsManage, seedCreds } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 20 })
async function load() {
loading.value = true
try {
const r = await fetchCredsManage(query)
list.value = r.items || []
total.value = r.total || 0
allowedKeys.value = r.allowed_keys || []
} finally {
loading.value = false
}
}
const allowedKeys = ref<string[]>([])
// ---- 录入明文源 ----
const seedOpen = ref(false)
const saving = ref(false)
const seedForm = reactive<{ account: string; values: Record<string, string> }>({ account: '', values: {} })
function openSeed(row: any) {
seedForm.account = row.account
seedForm.values = {}
for (const k of allowedKeys.value) seedForm.values[k] = row.creds?.[k] || ''
seedOpen.value = true
}
async function submitSeed() {
if (!seedForm.account) return ElMessage.warning('account 不能为空')
saving.value = true
try {
await seedCreds({ account: seedForm.account, values: seedForm.values })
ElMessage.success('明文源已保存')
seedOpen.value = false
load()
} finally {
saving.value = false
}
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="敏感凭证" description="执行机敏感凭证明文源录入与 RSA 加密下发">
<template #actions>
<el-button :loading="loading" @click="load"><ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新</el-button>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="account" label="账号" min-width="140" />
<el-table-column prop="nickname" label="昵称" min-width="120" />
<el-table-column label="已上报公钥" width="110">
<template #default="{ row }">
<el-tag :type="row.has_pubkey ? 'success' : 'info'" size="small">{{ row.has_pubkey ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="已配置键" min-width="300">
<template #default="{ row }">
<div class="flex flex-wrap items-center gap-1">
<template v-if="Object.keys(row.creds || {}).length">
<el-tag
v-for="k in Object.keys(row.creds || {})"
:key="k"
size="small"
effect="plain"
class="!max-w-44 truncate"
>{{ k }}</el-tag>
</template>
<span v-else class="text-gray-400 text-xs">未配置</span>
</div>
</template>
</el-table-column>
<el-table-column prop="updated_at" label="更新时间" width="170" />
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openSeed(row)">录入明文</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
layout="total, prev, pager, next" @current-change="load" />
</div>
</el-card>
<el-dialog v-model="seedOpen" title="录入敏感凭证明文源" width="560px">
<el-form label-width="auto" label-position="left">
<el-form-item label="账号">
<span class="text-sm font-medium">{{ seedForm.account }}</span>
</el-form-item>
<el-form-item v-for="k in allowedKeys" :key="k" :label="k">
<el-input v-model="seedForm.values[k]" type="password" show-password placeholder="留空则清除" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="seedOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submitSeed">保存</el-button>
</template>
</el-dialog>
</div>
</template>
@@ -1,61 +1,190 @@
<script setup lang="ts">
/**
* 执行机设备(37du 控制台)
* 分页列表:环境信息 + Chrome 检测(对接 /api/admin/devices)
* 在线状态/Chrome 环境/客户端版本一览,支持状态与关键字筛选
* 数据:/api/admin/devices + /api/admin/devices/summary(最新壳子版本用于升级标记)
*/
import { onMounted, reactive, ref } from 'vue'
import { fetchDevices } from '@/api/business'
import { computed, onMounted, reactive, ref } from 'vue'
import { fetchDevices, fetchDevicesSummary } from '@/api/business'
import ArtPageHeader from '@/components/core/base/art-page-header/index.vue'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 20 })
const summary = ref<any>({})
const query = reactive({ page: 1, page_size: 20, status: null as number | null, q: '' })
const latest = computed(() => String(summary.value.latest_shell_version || ''))
const statCards = computed(() => [
{ title: '设备总数', count: summary.value.total || 0, icon: 'ri:computer-line', iconStyle: 'bg-[#377dff]', desc: '已上报执行机' },
{ title: '在线', count: summary.value.online || 0, icon: 'ri:wifi-line', iconStyle: 'bg-[#00b42a]', desc: '心跳正常' },
{ title: '离线', count: summary.value.offline || 0, icon: 'ri:wifi-off-line', iconStyle: 'bg-[#c0c4cc]', desc: '超时未心跳' },
{ title: 'Chrome 就绪', count: summary.value.chrome_ok || 0, icon: 'ri:chrome-line', iconStyle: 'bg-[#ff7d00]', desc: `共 ${summary.value.chrome_total || 0} 台` }
])
/** 相对时间:X 分钟前 / 小时前 / 天前 */
function relativeTime(s: string): string {
if (!s) return '—'
const ts = new Date(String(s).replace(' ', 'T')).getTime()
if (!ts) return String(s)
const diff = Date.now() - ts
const min = Math.floor(diff / 60000)
if (min < 1) return '刚刚'
if (min < 60) return `${min} 分钟前`
const h = Math.floor(min / 60)
if (h < 24) return `${h} 小时前`
const d = Math.floor(h / 24)
return `${d} 天前`
}
/** 版本升级状态:最新 / 待升级 / 未知 */
function versionState(v: string): 'latest' | 'pending' | 'unknown' {
const ver = String(v || '')
if (!ver) return 'unknown'
if (!latest.value) return 'latest'
const pa = ver.split('.').map((s) => parseInt(s, 10) || 0)
const pb = latest.value.split('.').map((s) => parseInt(s, 10) || 0)
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
const d = (pa[i] || 0) - (pb[i] || 0)
if (d !== 0) return d >= 0 ? 'latest' : 'pending'
}
return 'latest'
}
const filteredList = computed(() => {
const kw = query.q.trim().toLowerCase()
return list.value.filter((d) => {
const stOk = query.status === null || query.status === undefined || Number(d.status) === query.status
const kwOk =
!kw ||
[d.device_id, d.hostname, d.account, d.ip, d.client_version].some((v) =>
String(v || '').toLowerCase().includes(kw)
)
return stOk && kwOk
})
})
async function load() {
loading.value = true
try {
const r = await fetchDevices(query)
const [r, s] = await Promise.all([
fetchDevices({ page: query.page, page_size: query.page_size }),
fetchDevicesSummary()
])
list.value = r.items || []
total.value = r.total || 0
summary.value = s
} finally {
loading.value = false
}
}
function search() {
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">执行机设备</h2>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
<div class="p-5">
<ArtPageHeader title="执行机设备" description="执行机在线状态、Chrome 环境与壳子客户端版本">
<template #actions>
<el-tag v-if="latest" type="success" effect="light" size="large">最新壳子版本 v{{ latest }}</el-tag>
<el-button :loading="loading" @click="load"><ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新</el-button>
</template>
</ArtPageHeader>
<!-- 汇总卡 -->
<el-row :gutter="14" class="mb-3.5">
<el-col :xs="12" :md="6" 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">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="device_id" label="设备ID" min-width="150" />
<el-table-column label="账号" width="110">
<template #default="{ row }">{{ row.account || '-' }}</template>
</el-table-column>
<el-table-column prop="hostname" label="主机名" min-width="120" />
<el-table-column prop="os" label="系统" min-width="140" show-overflow-tooltip />
<el-table-column prop="ip" label="IP" width="130" />
<el-table-column label="Chrome" width="90">
<!-- 筛选工具条 -->
<div class="flex items-center gap-3 mb-3 flex-wrap">
<el-select v-model="query.status" placeholder="全部状态" clearable size="small" style="width: 120px" @change="load">
<el-option label="在线" :value="1" />
<el-option label="离线" :value="0" />
</el-select>
<el-input
v-model="query.q"
placeholder="设备ID / 主机名 / 账号 / IP"
clearable
size="small"
style="width: 240px"
@keyup.enter="search"
@clear="search"
/>
<span class="ml-auto text-xs text-gray-400">本页 {{ filteredList.length }} 台(服务端分页)</span>
</div>
<el-table v-loading="loading" :data="filteredList" border stripe>
<el-table-column label="设备" min-width="180">
<template #default="{ row }">
<el-tag :type="row.chrome_ok ? 'success' : 'danger'" size="small">
{{ row.chrome_ok ? '就绪' : '异常' }}
</el-tag>
<div>
<div class="text-sm font-medium leading-tight">{{ row.hostname || '—' }}</div>
<div class="text-xs text-gray-400">{{ row.device_id }}</div>
</div>
</template>
</el-table-column>
<el-table-column label="在线" width="80">
<el-table-column label="登录账号" width="130">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'" size="small">
{{ row.status === 1 ? '在线' : '离线' }}
</el-tag>
<span v-if="row.account">{{ row.account }}</span>
<span v-else class="text-gray-300">未登录</span>
</template>
</el-table-column>
<el-table-column prop="os" label="系统" min-width="130" show-overflow-tooltip />
<el-table-column prop="ip" label="IP" width="125" />
<el-table-column label="Chrome 环境" width="160">
<template #default="{ row }">
<div class="flex items-center gap-1.5">
<el-tag :type="row.chrome_ok ? 'success' : 'danger'" size="small" effect="light">
{{ row.chrome_ok ? '就绪' : row.chrome_installed ? '异常' : '未安装' }}
</el-tag>
<span v-if="row.chrome_version" class="text-xs text-gray-400">{{ row.chrome_version }}</span>
</div>
</template>
</el-table-column>
<el-table-column label="客户端版本" width="150" align="center">
<template #default="{ row }">
<div class="flex items-center justify-center gap-1.5">
<el-tag
size="small"
:type="versionState(row.client_version) === 'latest' ? 'success' : versionState(row.client_version) === 'pending' ? 'warning' : 'info'"
effect="light"
>
{{ row.client_version ? `v${row.client_version}` : '未上报' }}
</el-tag>
<el-tooltip v-if="versionState(row.client_version) === 'pending'" content="低于最新壳子版本,等待自动升级" placement="top">
<ArtSvgIcon icon="ri:arrow-up-circle-line" class="text-[var(--el-color-warning)] c-p" />
</el-tooltip>
</div>
</template>
</el-table-column>
<el-table-column label="在线状态" width="130">
<template #default="{ row }">
<div class="flex items-center gap-1.5">
<span
class="size-2 rounded-full inline-block"
:class="row.status === 1 ? 'bg-[#00b42a]' : 'bg-gray-300'"
></span>
<span class="text-xs" :class="row.status === 1 ? 'text-[#00b42a]' : 'text-gray-400'">
{{ row.status === 1 ? '在线' : '离线' }} · {{ relativeTime(row.last_seen) }}
</span>
</div>
</template>
</el-table-column>
<el-table-column prop="last_seen" label="最后在线" width="170" />
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
@@ -1,128 +1,129 @@
<script setup lang="ts">
/**
* 大文件源(37du 控制台)
* 列表 + 登记/启停/删除(对接 /api/admin/file-sources*)
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { fetchFileSources, upsertFileSource, patchFileSource, deleteFileSource } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 20, category: '' })
async function load() {
loading.value = true
try {
const r = await fetchFileSources(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 登记/覆盖 ----
const dialogOpen = ref(false)
const saving = ref(false)
const form = reactive({ category: '', version: '', filename: '', url: '', sha256: '', notes: '', enabled: true })
function openCreate() {
Object.assign(form, { category: '', version: '', filename: '', url: '', sha256: '', notes: '', enabled: true })
dialogOpen.value = true
}
async function submit() {
if (!form.category || !form.url) return ElMessage.warning('category 与 url 必填')
saving.value = true
try {
await upsertFileSource(form)
ElMessage.success('登记成功')
dialogOpen.value = false
load()
} finally {
saving.value = false
}
}
async function toggle(row: any) {
await patchFileSource(row.id, { enabled: row.enabled !== 1 })
load()
}
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除文件源 #${row.id}?`, '删除确认', { type: 'warning' })
await deleteFileSource(row.id)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">大文件源</h2>
<el-button type="primary" @click="openCreate">登记文件源</el-button>
</div>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="分类">
<el-select v-model="query.category" clearable placeholder="全部" style="width: 160px" @change="search">
<el-option label="shell" value="shell" /><el-option label="chrome" value="chrome" /><el-option label="python-env" value="python-env" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="id" label="ID" width="70" />
<el-table-column prop="category" label="分类" width="110" />
<el-table-column prop="version" label="版本" width="100" />
<el-table-column prop="filename" label="文件名" min-width="180" show-overflow-tooltip />
<el-table-column prop="url" label="URL" min-width="220" show-overflow-tooltip />
<el-table-column label="启用" width="80">
<template #default="{ row }">
<el-tag :type="row.enabled ? 'success' : 'info'" size="small">{{ row.enabled ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="updated_at" label="更新时间" width="170" />
<el-table-column label="操作" width="150" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="toggle(row)">{{ row.enabled ? '停用' : '启用' }}</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
layout="total, prev, pager, next" @current-change="load" />
</div>
</el-card>
<el-dialog v-model="dialogOpen" title="登记文件源" width="520px">
<el-form label-width="90px">
<el-form-item label="分类" required><el-input v-model="form.category" placeholder="shell / chrome / python-env" /></el-form-item>
<el-form-item label="版本"><el-input v-model="form.version" /></el-form-item>
<el-form-item label="文件名"><el-input v-model="form.filename" /></el-form-item>
<el-form-item label="URL" required><el-input v-model="form.url" placeholder="内网文件服务器直链" /></el-form-item>
<el-form-item label="SHA256"><el-input v-model="form.sha256" /></el-form-item>
<el-form-item label="说明"><el-input v-model="form.notes" /></el-form-item>
<el-form-item label="启用"><el-switch v-model="form.enabled" /></el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
/**
* 大文件源(37du 控制台)
* 列表 + 登记/启停/删除(对接 /api/admin/file-sources*)
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { fetchFileSources, upsertFileSource, patchFileSource, deleteFileSource } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 20, category: '' })
async function load() {
loading.value = true
try {
const r = await fetchFileSources(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 登记/覆盖 ----
const dialogOpen = ref(false)
const saving = ref(false)
const form = reactive({ category: '', version: '', filename: '', url: '', sha256: '', notes: '', enabled: true })
function openCreate() {
Object.assign(form, { category: '', version: '', filename: '', url: '', sha256: '', notes: '', enabled: true })
dialogOpen.value = true
}
async function submit() {
if (!form.category || !form.url) return ElMessage.warning('category 与 url 必填')
saving.value = true
try {
await upsertFileSource(form)
ElMessage.success('登记成功')
dialogOpen.value = false
load()
} finally {
saving.value = false
}
}
async function toggle(row: any) {
await patchFileSource(row.id, { enabled: row.enabled !== 1 })
load()
}
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除文件源 #${row.id}?`, '删除确认', { type: 'warning' })
await deleteFileSource(row.id)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="大文件源" description="壳子 / Chrome 等大文件的下载源登记与启停">
<template #actions>
<el-button type="primary" @click="openCreate"><ArtSvgIcon icon="ri:add-line" class="mr-1" />登记文件源</el-button>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="分类">
<el-select v-model="query.category" clearable placeholder="全部" style="width: 160px" @change="search">
<el-option label="shell" value="shell" /><el-option label="chrome" value="chrome" /><el-option label="python-env" value="python-env" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="id" label="ID" width="70" />
<el-table-column prop="category" label="分类" width="110" />
<el-table-column prop="version" label="版本" width="100" />
<el-table-column prop="filename" label="文件名" min-width="180" show-overflow-tooltip />
<el-table-column prop="url" label="URL" min-width="220" show-overflow-tooltip />
<el-table-column label="启用" width="80">
<template #default="{ row }">
<el-tag :type="row.enabled ? 'success' : 'info'" size="small">{{ row.enabled ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="updated_at" label="更新时间" width="170" />
<el-table-column label="操作" width="150" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="toggle(row)">{{ row.enabled ? '停用' : '启用' }}</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
layout="total, prev, pager, next" @current-change="load" />
</div>
</el-card>
<el-dialog v-model="dialogOpen" title="登记文件源" width="520px">
<el-form label-width="90px">
<el-form-item label="分类" required><el-input v-model="form.category" placeholder="shell / chrome / python-env" /></el-form-item>
<el-form-item label="版本"><el-input v-model="form.version" /></el-form-item>
<el-form-item label="文件名"><el-input v-model="form.filename" /></el-form-item>
<el-form-item label="URL" required><el-input v-model="form.url" placeholder="内网文件服务器直链" /></el-form-item>
<el-form-item label="SHA256"><el-input v-model="form.sha256" /></el-form-item>
<el-form-item label="说明"><el-input v-model="form.notes" /></el-form-item>
<el-form-item label="启用"><el-switch v-model="form.enabled" /></el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">保存</el-button>
</template>
</el-dialog>
</div>
</template>
@@ -1,107 +1,94 @@
<script setup lang="ts">
/**
* 权限授权(37du 控制台)
* 账号 × 插件授权(can_download / can_run)+ 平台白名单(对接 /api/admin/grant_data、account_grants、account_plugins、account_platforms)
* 权限授权工作台(37du 控制台,参照成熟系统重设计)
*
* - 「按用户」:主从布局(左账号列表 / 右全部插件行内开关 + 平台白名单),即时保存,
* 支持批量授予/撤销 —— 参照 GitLab 成员管理、阿里云 RAM 用户维度授权
* - 「按插件」:插件维度已授权账号表 + 搜索添加授权 + 批量撤销 —— 参照 RuoYi 角色↔用户分配、
* GitLab project members
* - 「矩阵总览」:账号 × 插件一屏网格,单元格快捷切换 —— 参照 GitHub/阿里云 RAM 授权总览
*
* 读:GET /api/admin/grants/matrix(一次拉全量,前端过滤)
* 写:行内单条 POST /api/admin/account_plugins|account_platforms;
* 批量 POST /api/admin/plugin_grants/batch|revoke(agent_cli 旧契约不受影响)
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { fetchGrantData, fetchAccountGrants, grantPlugin, grantPlatform } from '@/api/business'
import { computed, onMounted, ref } from 'vue'
import { fetchGrantsMatrix } from '@/api/business'
import UserGrantPanel from './modules/user-grant-panel.vue'
import PluginGrantPanel from './modules/plugin-grant-panel.vue'
import MatrixPanel from './modules/matrix-panel.vue'
const loading = ref(false)
const plugins = ref<any[]>([])
const accounts = ref<any[]>([])
const account = ref('')
const grants = reactive<Record<string, { canRun: boolean; canDownload: boolean }>>({})
const platforms = ref<string[]>([])
const platformOptions = ['hr', 'oa']
const activeTab = ref<'user' | 'plugin' | 'matrix'>('user')
async function loadData() {
const viewOptions = [
{ label: '按用户授权', value: 'user' },
{ label: '按插件授权', value: 'plugin' },
{ label: '矩阵总览', value: 'matrix' }
]
// 矩阵全量数据(单一数据源,变更后整体刷新)
const matrix = ref<any>({ plugins: [], accounts: [], grants: [], platforms: {} })
// 汇总指标
const summary = computed(() => {
const accounts = matrix.value.accounts?.length || 0
const plugins = matrix.value.plugins?.length || 0
const grants = matrix.value.grants?.length || 0
const covered = new Set((matrix.value.grants || []).map((g: any) => g.account)).size
const coverage = accounts ? Math.round((covered / accounts) * 100) : 0
return { accounts, plugins, grants, covered, coverage }
})
const summaryItems = computed(() => [
{ icon: 'ri:user-3-line', color: '#377dff', value: summary.value.accounts, label: '账号' },
{ icon: 'ri:box-3-line', color: '#13deb9', value: summary.value.plugins, label: '插件' },
{ icon: 'ri:key-2-line', color: '#ff7d00', value: summary.value.grants, label: '授权关系' },
{ icon: 'ri:pie-chart-2-line', color: '#f5319d', value: `${summary.value.coverage}%`, label: `覆盖 ${summary.value.covered}/${summary.value.accounts} 账号` }
])
async function loadMatrix() {
loading.value = true
try {
const d = await fetchGrantData()
plugins.value = d.plugins || []
accounts.value = d.accounts || []
matrix.value = await fetchGrantsMatrix()
} finally {
loading.value = false
}
}
async function selectAccount(acc: string) {
account.value = acc
if (!acc) return
const g = await fetchAccountGrants(acc)
const map: Record<string, { canRun: boolean; canDownload: boolean }> = {}
for (const p of g.plugins || []) {
map[p.plugin_id] = { canRun: !!p.canRun, canDownload: !!p.canDownload }
}
for (const p of plugins.value) {
if (!map[p.id]) map[p.id] = { canRun: false, canDownload: false }
}
Object.assign(grants, map)
platforms.value = g.platforms || []
}
async function toggleGrant(pid: string, field: 'canRun' | 'canDownload', val: boolean) {
if (!account.value) return
await grantPlugin({
account: account.value, plugin_id: pid, granted: true,
can_download: field === 'canDownload' ? val : grants[pid]?.canDownload,
can_run: field === 'canRun' ? val : grants[pid]?.canRun
})
ElMessage.success('已保存')
}
async function togglePlatform(pid: string, val: boolean) {
if (!account.value) return
await grantPlatform({ account: account.value, platform_id: pid, granted: val })
ElMessage.success(val ? '已授权平台' : '已撤销平台')
}
onMounted(loadData)
onMounted(loadMatrix)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">权限授权</h2>
</div>
<el-card shadow="never" class="rounded-xl">
<el-form inline>
<el-form-item label="选择账号">
<el-select v-model="account" filterable placeholder="选择账号" style="width: 240px" @change="selectAccount">
<el-option v-for="a in accounts" :key="a.account" :label="`${a.nickname || a.account} (${a.account})`" :value="a.account" />
</el-select>
</el-form-item>
</el-form>
<el-table v-if="account" :data="plugins" border stripe>
<el-table-column prop="id" label="插件ID" min-width="140" />
<el-table-column prop="name" label="名称" min-width="150" />
<el-table-column label="允许运行" width="120">
<template #default="{ row }">
<el-switch :model-value="grants[row.id]?.canRun" @change="(v: any) => toggleGrant(row.id, 'canRun', !!v)" />
</template>
</el-table-column>
<el-table-column label="允许下载" width="120">
<template #default="{ row }">
<el-switch :model-value="grants[row.id]?.canDownload" @change="(v: any) => toggleGrant(row.id, 'canDownload', !!v)" />
</template>
</el-table-column>
</el-table>
<el-empty v-else description="请先选择账号" :image-size="80" />
<template v-if="account">
<div class="mt-4 font-semibold text-sm mb-2">平台白名单</div>
<div class="flex gap-4">
<el-checkbox
v-for="p in platformOptions"
:key="p"
:model-value="platforms.includes(p)"
@change="(v: any) => togglePlatform(p, !!v)"
>{{ p.toUpperCase() }}</el-checkbox>
</div>
<div class="p-5">
<ArtPageHeader title="权限授权工作台" description="按用户、按插件或矩阵视图管理插件与平台授权">
<template #actions>
<el-button :loading="loading" @click="loadMatrix">
<ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新数据
</el-button>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl" v-loading="loading">
<!-- 工具条:视图切换 + 汇总 -->
<div class="flex items-center justify-between flex-wrap gap-3 mb-4">
<el-segmented v-model="activeTab" :options="viewOptions" size="large" />
<div class="flex items-center gap-5">
<div v-for="(s, i) in summaryItems" :key="i" class="flex items-center gap-2">
<div class="size-8 rounded-lg grid place-items-center text-base" :style="{ background: `${s.color}1a`, color: s.color }">
<ArtSvgIcon :icon="s.icon" />
</div>
<div class="leading-tight">
<div class="text-base font-semibold">{{ s.value }}</div>
<div class="text-[11px] text-gray-400">{{ s.label }}</div>
</div>
</div>
</div>
</div>
<UserGrantPanel v-show="activeTab === 'user'" :matrix="matrix" @changed="loadMatrix" />
<PluginGrantPanel v-show="activeTab === 'plugin'" :matrix="matrix" @changed="loadMatrix" />
<MatrixPanel v-show="activeTab === 'matrix'" :matrix="matrix" @changed="loadMatrix" />
</el-card>
</div>
</template>
@@ -0,0 +1,130 @@
<script setup lang="ts">
/**
* 添加授权对话框(按插件维度批量授权账号)
* 账号搜索多选(默认过滤已授权)+ 默认权限(下载/运行)→ POST /api/admin/plugin_grants/batch
*/
import { computed, nextTick, reactive, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { batchPluginGrants } from '@/api/business'
interface Props {
visible: boolean
pluginId: string
accounts: any[]
grantedAccounts: string[]
}
interface Emits {
(e: 'update:visible', value: boolean): void
(e: 'success'): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const dialogVisible = computed({
get: () => props.visible,
set: (value) => emit('update:visible', value)
})
const kw = ref('')
const tableRef = ref()
const submitting = ref(false)
const defaults = reactive({ can_download: true, can_run: true })
/** 未授权的账号(默认列表) */
const candidates = computed(() => {
const grantedSet = new Set(props.grantedAccounts || [])
const kwv = kw.value.trim().toLowerCase()
return (props.accounts || []).filter((a: any) => {
const notGranted = !grantedSet.has(a.account)
const kwOk =
!kwv ||
String(a.account).toLowerCase().includes(kwv) ||
String(a.nickname || '').toLowerCase().includes(kwv)
return notGranted && kwOk
})
})
watch(
() => props.visible,
async (visible) => {
if (!visible) return
kw.value = ''
defaults.can_download = true
defaults.can_run = true
await nextTick()
tableRef.value?.clearSelection()
}
)
async function handleSubmit() {
const rows = tableRef.value?.getSelectionRows() || []
if (!rows.length) {
ElMessage.info('请先勾选要授权的账号')
return
}
submitting.value = true
try {
await batchPluginGrants({
plugin_id: props.pluginId,
items: rows.map((r: any) => ({
account: r.account,
can_download: defaults.can_download,
can_run: defaults.can_run
}))
})
ElMessage.success(`已为 ${rows.length} 个账号授权插件「${props.pluginId}」`)
emit('success')
} finally {
submitting.value = false
}
}
</script>
<template>
<el-dialog
v-model="dialogVisible"
:title="`添加授权 — ${pluginId}`"
width="620px"
align-center
:close-on-click-modal="false"
>
<div class="flex items-center gap-3 mb-3 flex-wrap">
<el-input v-model="kw" placeholder="搜索账号 / 昵称" clearable style="width: 220px" />
<el-divider direction="vertical" />
<span class="text-sm">默认权限:</span>
<el-checkbox v-model="defaults.can_download">允许下载</el-checkbox>
<el-checkbox v-model="defaults.can_run">允许运行</el-checkbox>
</div>
<el-table
ref="tableRef"
:data="candidates"
border
stripe
size="small"
max-height="360"
@selection-change="() => {}"
>
<el-table-column type="selection" width="42" />
<el-table-column prop="account" label="账号" min-width="110" />
<el-table-column prop="nickname" label="昵称" min-width="110" />
<el-table-column prop="dept" label="部门" width="90" />
<el-table-column label="状态" width="80" align="center">
<template #default="{ row }">
<el-tag size="small" :type="row.status === 1 ? 'success' : 'danger'">
{{ row.status === 1 ? '启用' : '停用' }}
</el-tag>
</template>
</el-table-column>
</el-table>
<div class="text-xs text-gray-400 mt-2">已授权账号不在列表中;如需调整其权限,请在主表格行内开关修改</div>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" :loading="submitting" @click="handleSubmit">批量授权</el-button>
</template>
</el-dialog>
</template>
@@ -0,0 +1,211 @@
<script setup lang="ts">
/**
* 授权矩阵总览(GitHub / 阿里云 RAM 授权总览式)
* 行=账号(搜索/部门/仅看已授权),列=插件;单元格 [⬇下载][▶运行] 可点击徽标,
* 点击即切换该权限;下载+运行都关掉时自动整行撤销。首列与列头冻结,状态底色三档。
*/
import { computed, ref } from 'vue'
import { ElMessage } from 'element-plus'
import { grantPlugin } from '@/api/business'
interface Props {
matrix: any
}
const props = defineProps<Props>()
const emit = defineEmits<{ (e: 'changed'): void }>()
const kw = ref('')
const deptFilter = ref<string | null>(null)
const onlyGranted = ref(false)
const deptOptions = computed(() => {
const set = new Set<string>()
for (const a of props.matrix.accounts || []) if (a.dept) set.add(a.dept)
return [...set]
})
/** grants 快速索引:(account, pluginId) -> {can_download, can_run} */
const grantIndex = computed(() => {
const idx = new Map<string, any>()
for (const g of props.matrix.grants || []) idx.set(`${g.account}|${g.plugin_id}`, g)
return idx
})
function cellOf(account: string, pluginId: string) {
return grantIndex.value.get(`${account}|${pluginId}`)
}
function cellState(account: string, pluginId: string): 'full' | 'partial' | 'none' {
const c = cellOf(account, pluginId)
if (!c) return 'none'
return c.can_download && c.can_run ? 'full' : 'partial'
}
const rows = computed(() => {
const kwv = kw.value.trim().toLowerCase()
return (props.matrix.accounts || []).filter((a: any) => {
const kwOk =
!kwv ||
String(a.account).toLowerCase().includes(kwv) ||
String(a.nickname || '').toLowerCase().includes(kwv)
const deptOk = !deptFilter.value || a.dept === deptFilter.value
const grantedOk =
!onlyGranted.value || (props.matrix.grants || []).some((g: any) => g.account === a.account)
return kwOk && deptOk && grantedOk
})
})
const toggling = ref(false)
async function toggle(account: string, pluginId: string, field: 'can_download' | 'can_run') {
if (toggling.value) return
const cur = cellOf(account, pluginId)
const next = { can_download: !!cur?.can_download, can_run: !!cur?.can_run, [field]: !cur?.[field] }
toggling.value = true
try {
const granted = next.can_download || next.can_run
await grantPlugin({ account, plugin_id: pluginId, granted, ...next })
emit('changed')
} catch (e) {
ElMessage.error('切换失败')
} finally {
toggling.value = false
}
}
</script>
<template>
<div>
<!-- 工具条 -->
<div class="flex items-center gap-3 mb-3 flex-wrap">
<el-input v-model="kw" placeholder="搜索账号 / 昵称" clearable style="width: 200px" />
<el-select v-model="deptFilter" placeholder="全部部门" clearable style="width: 130px">
<el-option v-for="d in deptOptions" :key="d" :label="d" :value="d" />
</el-select>
<el-switch v-model="onlyGranted" size="small" active-text="仅看已授权账号" />
<div class="ml-auto flex items-center gap-2 text-xs text-gray-400">
<span>图例:</span>
<el-tag size="small" type="success" effect="light">下载+运行</el-tag>
<el-tag size="small" type="warning" effect="light">部分授权</el-tag>
<el-tag size="small" type="info" effect="plain">未授权</el-tag>
</div>
</div>
<!-- 矩阵 -->
<el-scrollbar max-height="520" class="border border-g-300/50 rounded-lg">
<table class="matrix-table">
<thead>
<tr>
<th class="sticky-col">
<div class="text-xs text-gray-400 font-normal">账号 / 插件</div>
</th>
<th v-for="p in matrix.plugins" :key="p.id" class="plugin-col">
<div class="font-medium text-[13px]">{{ p.name }}</div>
<div class="text-[11px] text-gray-400 font-normal">v{{ p.latest_version }}</div>
</th>
<th v-if="!matrix.plugins?.length">暂无插件</th>
</tr>
</thead>
<tbody>
<tr v-for="a in rows" :key="a.account">
<td class="sticky-col">
<div class="flex items-center gap-2">
<div class="size-7 rounded-lg grid place-items-center bg-[var(--el-color-primary-light-9)] text-[var(--el-color-primary)] text-xs font-bold shrink-0">
{{ (a.nickname || a.account || '?').slice(0, 1).toUpperCase() }}
</div>
<div class="min-w-0">
<div class="text-sm leading-tight truncate">{{ a.nickname || a.account }}</div>
<div class="text-[11px] text-gray-400 truncate">{{ a.account }} · {{ a.dept || '—' }}</div>
</div>
</div>
</td>
<td v-for="p in matrix.plugins" :key="p.id" align="center" :class="`state-${cellState(a.account, p.id)}`">
<div class="flex items-center justify-center gap-1.5">
<el-tooltip :content="cellOf(a.account, p.id)?.can_download ? '允许下载(点击撤销)' : '禁止下载(点击放行)'" placement="top" :show-after="300">
<el-tag
size="small"
:type="cellOf(a.account, p.id)?.can_download ? 'success' : 'info'"
:effect="cellOf(a.account, p.id)?.can_download ? 'light' : 'plain'"
class="cursor-pointer select-none cell-tag"
@click="toggle(a.account, p.id, 'can_download')"
>⬇</el-tag>
</el-tooltip>
<el-tooltip :content="cellOf(a.account, p.id)?.can_run ? '允许运行(点击撤销)' : '禁止运行(点击放行)'" placement="top" :show-after="300">
<el-tag
size="small"
:type="cellOf(a.account, p.id)?.can_run ? 'success' : 'info'"
:effect="cellOf(a.account, p.id)?.can_run ? 'light' : 'plain'"
class="cursor-pointer select-none cell-tag"
@click="toggle(a.account, p.id, 'can_run')"
>▶</el-tag>
</el-tooltip>
</div>
</td>
<td v-if="!matrix.plugins?.length" align="center">—</td>
</tr>
<tr v-if="!rows.length">
<td :colspan="(matrix.plugins?.length || 0) + 1" align="center" class="py-8 text-gray-400 text-sm">无匹配账号</td>
</tr>
</tbody>
</table>
</el-scrollbar>
<div class="mt-2 text-xs text-gray-400">
点击单元格内的 ⬇ / ▶ 徽标切换对应权限;下载与运行都关闭时自动撤销整条授权。
</div>
</div>
</template>
<style scoped>
@reference '@styles/core/tailwind.css';
.matrix-table {
border-collapse: separate;
border-spacing: 0;
width: max-content;
min-width: 100%;
}
.matrix-table th,
.matrix-table td {
border-bottom: 1px solid var(--el-border-color-lighter);
border-right: 1px solid var(--el-border-color-lighter);
padding: 8px 12px;
white-space: nowrap;
}
.matrix-table thead th {
background: var(--el-fill-color-light);
position: sticky;
top: 0;
z-index: 2;
text-align: center;
}
.matrix-table .sticky-col {
position: sticky;
left: 0;
background: var(--el-bg-color);
z-index: 1;
min-width: 180px;
text-align: left;
}
.matrix-table thead .sticky-col {
z-index: 3;
}
.matrix-table td.state-full {
background: var(--el-color-success-light-9);
}
.matrix-table td.state-partial {
background: var(--el-color-warning-light-9);
}
.matrix-table tbody tr:hover td {
background-color: var(--el-fill-color-light);
}
.matrix-table tbody tr:hover td.state-full {
background: var(--el-color-success-light-8);
}
.matrix-table tbody tr:hover td.state-partial {
background: var(--el-color-warning-light-8);
}
.cell-tag {
font-size: 12px;
padding: 0 7px;
}
</style>
@@ -0,0 +1,228 @@
<script setup lang="ts">
/**
* 按插件授权面板(GitLab project members / RuoYi 分配用户式)
* - 左:插件列表(搜索、已授权人数角标、选中高亮)
* - 右:该插件已授权账号表(行内开关、多选批量撤销)+「添加授权」对话框(账号多选 + 默认权限)
*/
import { computed, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { grantPlugin, revokePluginGrants } from '@/api/business'
import GrantAccountsDialog from './grant-accounts-dialog.vue'
interface Props {
matrix: any
}
const props = defineProps<Props>()
const emit = defineEmits<{ (e: 'changed'): void }>()
// ---------- 左侧插件列表 ----------
const pluginKw = ref('')
const selectedPlugin = ref('')
const pluginList = computed(() => {
const kw = pluginKw.value.trim().toLowerCase()
return (props.matrix.plugins || []).filter((p: any) => {
return !kw || String(p.id).toLowerCase().includes(kw) || String(p.name || '').toLowerCase().includes(kw)
})
})
function grantsOf(pluginId: string): any[] {
return (props.matrix.grants || []).filter((g: any) => g.plugin_id === pluginId)
}
const selectedPluginInfo = computed(() =>
(props.matrix.plugins || []).find((p: any) => p.id === selectedPlugin.value)
)
const grantedRows = computed(() => {
const accMap = new Map<string, any>()
for (const a of props.matrix.accounts || []) accMap.set(a.account, a)
return grantsOf(selectedPlugin.value).map((g: any) => ({
...g,
nickname: accMap.get(g.account)?.nickname || '',
dept: accMap.get(g.account)?.dept || '',
status: accMap.get(g.account)?.status
}))
})
const statusTag = (s: string) => (s === 'published' ? 'success' : s === 'disabled' ? 'warning' : 'danger')
const statusLabel = (s: string) => (s === 'published' ? '已发布' : s === 'disabled' ? '已停用' : '已吊销')
// ---------- 表格多选批量撤销 ----------
const tableRef = ref()
const selectedAccounts = computed(() => (tableRef.value?.getSelectionRows() || []).map((r: any) => r.account))
async function togglePerm(row: any, field: 'can_download' | 'can_run', val: boolean) {
const next = { can_download: row.can_download, can_run: row.can_run, [field]: val }
const granted = next.can_download || next.can_run
try {
await grantPlugin({ account: row.account, plugin_id: selectedPlugin.value, granted, ...next })
row.can_download = next.can_download
row.can_run = next.can_run
emit('changed')
} catch (e) {
ElMessage.error('保存失败,已还原')
emit('changed')
}
}
async function revokeOne(row: any) {
await ElMessageBox.confirm(`撤销账号「${row.account}」对插件「${selectedPlugin.value}」的授权?`, '撤销确认', {
type: 'warning', confirmButtonText: '撤销', cancelButtonText: '取消'
})
await grantPlugin({ account: row.account, plugin_id: selectedPlugin.value, granted: false })
ElMessage.success('已撤销')
emit('changed')
}
async function batchRevoke() {
if (!selectedAccounts.value.length) {
ElMessage.info('请先勾选要撤销的账号')
return
}
await ElMessageBox.confirm(
`将撤销 ${selectedAccounts.value.length} 个账号对插件「${selectedPlugin.value}」的授权,确认?`,
'批量撤销',
{ type: 'warning', confirmButtonText: '撤销', cancelButtonText: '取消' }
)
await revokePluginGrants({ plugin_id: selectedPlugin.value, accounts: selectedAccounts.value })
ElMessage.success('批量撤销完成')
emit('changed')
}
// ---------- 添加授权对话框 ----------
const addVisible = ref(false)
function openAdd() {
if (!selectedPlugin.value) return
addVisible.value = true
}
function handleGranted() {
addVisible.value = false
emit('changed')
}
</script>
<template>
<div class="grid grid-cols-[300px_1fr] gap-4 min-h-[560px] max-md:grid-cols-1">
<!-- 左:插件列表 -->
<el-card shadow="never" class="rounded-xl !p-0 overflow-hidden">
<div class="flex items-center justify-between px-3.5 py-3 border-b border-g-300/50">
<div class="flex items-center gap-2">
<div class="size-7 rounded-lg grid place-items-center bg-[#13deb91a] text-[#13deb9]">
<ArtSvgIcon icon="ri:box-3-line" class="text-sm" />
</div>
<span class="text-sm font-semibold">插件</span>
<el-tag size="small" round effect="plain">{{ pluginList.length }}</el-tag>
</div>
</div>
<div class="px-3 py-2.5 border-b border-g-300/50">
<el-input v-model="pluginKw" placeholder="搜索插件" clearable size="small" />
</div>
<el-scrollbar height="460px">
<div class="p-2">
<div
v-for="p in pluginList"
:key="p.id"
class="flex items-center gap-2.5 px-2.5 py-2 mb-1 rounded-lg cursor-pointer transition-colors border-l-2"
:class="p.id === selectedPlugin
? 'bg-[var(--el-color-primary-light-9)] border-[var(--el-color-primary)]'
: 'border-transparent hover:bg-[var(--el-fill-color-light)]'"
@click="selectedPlugin = p.id"
>
<div
class="size-8 rounded-lg grid place-items-center shrink-0"
:class="p.id === selectedPlugin ? 'bg-[var(--el-color-primary)] text-white' : 'bg-[var(--el-color-primary-light-9)] text-[var(--el-color-primary)]'"
>
<ArtSvgIcon icon="ri:box-3-line" class="text-sm" />
</div>
<div class="flex-1 min-w-0">
<div class="text-sm font-medium leading-tight truncate">{{ p.name }}</div>
<div class="text-[11px] text-gray-400 truncate">v{{ p.latest_version }} · {{ p.id }}</div>
</div>
<el-tag v-if="grantsOf(p.id).length" size="small" type="primary" effect="light" round>
{{ grantsOf(p.id).length }}
</el-tag>
</div>
<el-empty v-if="!pluginList.length" description="无插件" :image-size="60" />
</div>
</el-scrollbar>
</el-card>
<!-- 右:插件授权账号表 -->
<el-card shadow="never" class="rounded-xl">
<template #header>
<div class="flex items-center justify-between flex-wrap gap-2">
<div class="flex items-center gap-2.5">
<div class="size-9 rounded-lg grid place-items-center bg-[#13deb91a] text-[#13deb9]">
<ArtSvgIcon icon="ri:box-3-line" class="text-base" />
</div>
<div>
<div class="text-sm font-semibold leading-tight flex items-center gap-2">
{{ selectedPluginInfo?.name || selectedPlugin }}
<el-tag v-if="selectedPluginInfo" size="small" :type="statusTag(selectedPluginInfo.status)">
{{ statusLabel(selectedPluginInfo.status) }}
</el-tag>
</div>
<div class="text-xs text-gray-400">
{{ selectedPlugin }} · v{{ selectedPluginInfo?.latest_version || '-' }} · 已授权 {{ grantedRows.length }} 个账号
</div>
</div>
</div>
<div class="flex gap-2">
<el-button size="small" type="primary" @click="openAdd">
<ArtSvgIcon icon="ri:user-add-line" class="mr-1" />添加授权
</el-button>
<el-button size="small" type="danger" plain :disabled="!selectedAccounts.length" @click="batchRevoke">
<ArtSvgIcon icon="ri:delete-bin-line" class="mr-1" />批量撤销{{ selectedAccounts.length ? `(${selectedAccounts.length})` : '' }}
</el-button>
</div>
</div>
</template>
<el-table ref="tableRef" :data="grantedRows" border stripe size="small" max-height="480">
<el-table-column type="selection" width="42" />
<el-table-column label="账号" min-width="150">
<template #default="{ row }">
<div class="flex items-center gap-2.5">
<div class="size-7 rounded-lg grid place-items-center bg-[var(--el-color-primary-light-9)] text-[var(--el-color-primary)] text-xs font-bold shrink-0">
{{ (row.nickname || row.account || '?').slice(0, 1).toUpperCase() }}
</div>
<div>
<div class="text-sm leading-tight">{{ row.nickname || row.account }}</div>
<div class="text-xs text-gray-400">{{ row.account }}</div>
</div>
</div>
</template>
</el-table-column>
<el-table-column prop="dept" label="部门" width="90" />
<el-table-column label="允许下载" width="95" align="center">
<template #default="{ row }">
<el-switch :model-value="row.can_download" @change="(v: any) => togglePerm(row, 'can_download', !!v)" />
</template>
</el-table-column>
<el-table-column label="允许运行" width="95" align="center">
<template #default="{ row }">
<el-switch :model-value="row.can_run" @change="(v: any) => togglePerm(row, 'can_run', !!v)" />
</template>
</el-table-column>
<el-table-column prop="updated_at" label="更新时间" width="160" />
<el-table-column label="操作" width="80" fixed="right">
<template #default="{ row }">
<el-button link type="danger" size="small" @click="revokeOne(row)">撤销</el-button>
</template>
</el-table-column>
</el-table>
<el-empty v-if="!grantedRows.length" description="该插件还没有授权账号,点击右上角「添加授权」" :image-size="80" />
</el-card>
<GrantAccountsDialog
v-model:visible="addVisible"
:plugin-id="selectedPlugin"
:accounts="matrix.accounts || []"
:granted-accounts="grantedRows.map((r: any) => r.account)"
@success="handleGranted"
/>
</div>
</template>
@@ -0,0 +1,294 @@
<script setup lang="ts">
/**
* 按用户授权面板(GitLab 成员管理 / RuoYi 用户维度授权式)
* - 左:账号列表(搜索、部门过滤、授权数角标、选中高亮)
* - 右:该账号全部插件行内开关(即时保存)+ 平台按钮组 + 批量授予/撤销
*/
import { computed, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { grantPlatform, grantPlugin } from '@/api/business'
interface Props {
matrix: any
}
const props = defineProps<Props>()
const emit = defineEmits<{ (e: 'changed'): void }>()
const platformOptions = ['hr', 'oa']
// ---------- 左侧账号列表 ----------
const accountKw = ref('')
const deptFilter = ref<string | null>(null)
const selectedAccount = ref('')
const deptOptions = computed(() => {
const set = new Set<string>()
for (const a of props.matrix.accounts || []) if (a.dept) set.add(a.dept)
return [...set]
})
const accountList = computed(() => {
const kw = accountKw.value.trim().toLowerCase()
return (props.matrix.accounts || []).filter((a: any) => {
const kwOk =
!kw ||
String(a.account).toLowerCase().includes(kw) ||
String(a.nickname || '').toLowerCase().includes(kw)
const deptOk = !deptFilter.value || a.dept === deptFilter.value
return kwOk && deptOk
})
})
/** 某账号已授权插件数 */
function grantCount(account: string): number {
return (props.matrix.grants || []).filter((g: any) => g.account === account).length
}
function platformOf(account: string): string[] {
return props.matrix.platforms?.[account] || []
}
function initial(name: string): string {
return (name || '?').slice(0, 1).toUpperCase()
}
// ---------- 右侧:选中账号的授权编辑 ----------
const selectedInfo = computed(() =>
(props.matrix.accounts || []).find((a: any) => a.account === selectedAccount.value)
)
const pluginKw = ref('')
const onlyGranted = ref(false)
const pluginRows = computed(() => {
const kw = pluginKw.value.trim().toLowerCase()
const grantsByPlugin = new Map<string, any>()
for (const g of props.matrix.grants || []) {
if (g.account === selectedAccount.value) grantsByPlugin.set(g.plugin_id, g)
}
return (props.matrix.plugins || []).filter((p: any) => {
const kwOk = !kw || String(p.id).toLowerCase().includes(kw) || String(p.name || '').toLowerCase().includes(kw)
return kwOk && (!onlyGranted.value || grantsByPlugin.has(p.id))
}).map((p: any) => {
const g = grantsByPlugin.get(p.id)
return { ...p, can_download: !!g?.can_download, can_run: !!g?.can_run, granted: !!g }
})
})
const grantedTotal = computed(() => grantCount(selectedAccount.value))
/** 行内切换单条权限(granted=false 表示整行撤销) */
async function togglePerm(row: any, field: 'can_download' | 'can_run', val: boolean) {
const next = { can_download: row.can_download, can_run: row.can_run, [field]: val }
const granted = next.can_download || next.can_run
try {
await grantPlugin({
account: selectedAccount.value,
plugin_id: row.id,
granted,
can_download: next.can_download,
can_run: next.can_run
})
row.can_download = next.can_download
row.can_run = next.can_run
row.granted = granted
emit('changed')
} catch (e) {
ElMessage.error('保存失败,已还原')
emit('changed') // 还原为服务端状态
}
}
/** 平台按钮组:diff 变更项逐个授权/撤销 */
async function onPlatformChange(vals: any[]) {
const now = (vals || []).map(String)
const cur = platformOf(selectedAccount.value)
try {
for (const p of platformOptions) {
const after = now.includes(p)
const before = cur.includes(p)
if (after !== before) {
await grantPlatform({ account: selectedAccount.value, platform_id: p, granted: after })
}
}
ElMessage.success('平台白名单已更新')
} catch (e) {
ElMessage.error('平台授权保存失败')
} finally {
emit('changed')
}
}
// ---------- 批量操作 ----------
const batching = ref(false)
async function batchGrantAll(field: 'can_download' | 'can_run') {
const target = (props.matrix.plugins || []).map((p: any) => p.id)
await ElMessageBox.confirm(
`将把账号「${selectedAccount.value}」的全部 ${target.length} 个插件设为「${field === 'can_download' ? '允许下载' : '允许运行'}」,确认?`,
'批量授权',
{ type: 'warning', confirmButtonText: '执行', cancelButtonText: '取消' }
)
batching.value = true
try {
for (const pid of target) {
const cur = (props.matrix.grants || []).find((g: any) => g.account === selectedAccount.value && g.plugin_id === pid)
const next = { can_download: field === 'can_download' ? true : !!cur?.can_download, can_run: field === 'can_run' ? true : !!cur?.can_run }
await grantPlugin({ account: selectedAccount.value, plugin_id: pid, granted: true, ...next })
}
ElMessage.success('批量授权完成')
emit('changed')
} finally {
batching.value = false
}
}
async function batchRevokeAll() {
const granted = (props.matrix.grants || []).filter((g: any) => g.account === selectedAccount.value)
if (!granted.length) {
ElMessage.info('该账号暂无插件授权')
return
}
await ElMessageBox.confirm(
`将撤销账号「${selectedAccount.value}」的全部 ${granted.length} 个插件授权,确认?`,
'批量撤销',
{ type: 'warning', confirmButtonText: '撤销', cancelButtonText: '取消' }
)
batching.value = true
try {
for (const g of granted) {
await grantPlugin({ account: selectedAccount.value, plugin_id: g.plugin_id, granted: false })
}
ElMessage.success('批量撤销完成')
emit('changed')
} finally {
batching.value = false
}
}
</script>
<template>
<div class="grid grid-cols-[300px_1fr] gap-4 min-h-[560px] max-md:grid-cols-1">
<!-- 左:账号列表 -->
<el-card shadow="never" class="rounded-xl !p-0 overflow-hidden">
<div class="flex items-center justify-between px-3.5 py-3 border-b border-g-300/50">
<div class="flex items-center gap-2">
<div class="size-7 rounded-lg grid place-items-center bg-[#377dff1a] text-[#377dff]">
<ArtSvgIcon icon="ri:user-3-line" class="text-sm" />
</div>
<span class="text-sm font-semibold">账号</span>
<el-tag size="small" round effect="plain">{{ accountList.length }}</el-tag>
</div>
</div>
<div class="px-3 py-2.5 space-y-2 border-b border-g-300/50">
<el-input v-model="accountKw" placeholder="搜索账号 / 昵称" clearable size="small" />
<el-select v-model="deptFilter" placeholder="全部部门" clearable size="small" style="width: 100%">
<el-option v-for="d in deptOptions" :key="d" :label="d" :value="d" />
</el-select>
</div>
<el-scrollbar height="420px">
<div class="p-2">
<div
v-for="a in accountList"
:key="a.account"
class="flex items-center gap-2.5 px-2.5 py-2 mb-1 rounded-lg cursor-pointer transition-colors border-l-2"
:class="a.account === selectedAccount
? 'bg-[var(--el-color-primary-light-9)] border-[var(--el-color-primary)]'
: 'border-transparent hover:bg-[var(--el-fill-color-light)]'"
@click="selectedAccount = a.account"
>
<div
class="size-8 rounded-lg grid place-items-center text-xs font-bold shrink-0"
:class="a.account === selectedAccount ? 'bg-[var(--el-color-primary)] text-white' : 'bg-[var(--el-fill-color)] text-g-600'"
>
{{ initial(a.nickname || a.account) }}
</div>
<div class="flex-1 min-w-0">
<div class="text-sm font-medium leading-tight truncate">{{ a.nickname || a.account }}</div>
<div class="text-[11px] text-gray-400 truncate">{{ a.account }} · {{ a.dept || '—' }}</div>
</div>
<el-tag v-if="grantCount(a.account)" size="small" type="primary" effect="light" round>
{{ grantCount(a.account) }}
</el-tag>
</div>
<el-empty v-if="!accountList.length" description="无匹配账号" :image-size="60" />
</div>
</el-scrollbar>
</el-card>
<!-- 右:选中账号的授权编辑 -->
<el-card shadow="never" class="rounded-xl">
<template #header>
<div class="flex items-center justify-between flex-wrap gap-2">
<div class="flex items-center gap-2.5">
<div class="size-9 rounded-lg grid place-items-center bg-[var(--el-color-primary)] text-white text-sm font-bold">
{{ initial(selectedInfo?.nickname || selectedAccount) }}
</div>
<div>
<div class="text-sm font-semibold leading-tight">{{ selectedInfo?.nickname || selectedAccount }}</div>
<div class="text-xs text-gray-400">{{ selectedAccount }} · {{ selectedInfo?.dept || '—' }} · 已授权 {{ grantedTotal }} 个插件</div>
</div>
</div>
<div class="flex gap-2">
<el-button size="small" type="primary" plain :loading="batching" @click="batchGrantAll('can_download')">全部可下载</el-button>
<el-button size="small" type="primary" plain :loading="batching" @click="batchGrantAll('can_run')">全部可运行</el-button>
<el-button size="small" type="danger" plain :loading="batching" @click="batchRevokeAll">全部撤销</el-button>
</div>
</div>
</template>
<div class="flex items-center gap-3 mb-3 flex-wrap">
<span class="text-xs text-gray-500 flex items-center gap-1.5">
<ArtSvgIcon icon="ri:global-line" />平台白名单
</span>
<el-checkbox-group :model-value="platformOf(selectedAccount)" size="small" @change="onPlatformChange">
<el-checkbox-button value="hr">HR 系统</el-checkbox-button>
<el-checkbox-button value="oa">OA 系统</el-checkbox-button>
</el-checkbox-group>
<el-divider direction="vertical" />
<el-input v-model="pluginKw" placeholder="搜索插件" clearable size="small" style="width: 180px" />
<el-switch v-model="onlyGranted" size="small" active-text="仅看已授权" />
</div>
<el-table :data="pluginRows" border stripe size="small" max-height="430">
<el-table-column label="插件" min-width="220">
<template #default="{ row }">
<div class="flex items-center gap-2.5">
<div class="size-8 rounded-lg grid place-items-center bg-[var(--el-color-primary-light-9)] text-[var(--el-color-primary)] shrink-0">
<ArtSvgIcon icon="ri:box-3-line" class="text-sm" />
</div>
<div class="min-w-0">
<div class="text-sm font-medium leading-tight flex items-center gap-1.5">
{{ row.name }}
<el-tag v-if="row.status !== 'published'" size="small" type="danger">{{ row.status }}</el-tag>
</div>
<div class="text-xs text-gray-400 truncate">{{ row.id }}</div>
</div>
</div>
</template>
</el-table-column>
<el-table-column label="最新版本" width="100" align="center">
<template #default="{ row }">
<el-tag size="small" effect="plain">v{{ row.latest_version }}</el-tag>
</template>
</el-table-column>
<el-table-column label="允许下载" width="100" align="center">
<template #default="{ row }">
<el-switch :model-value="row.can_download" @change="(v: any) => togglePerm(row, 'can_download', !!v)" />
</template>
</el-table-column>
<el-table-column label="允许运行" width="100" align="center">
<template #default="{ row }">
<el-switch :model-value="row.can_run" @change="(v: any) => togglePerm(row, 'can_run', !!v)" />
</template>
</el-table-column>
<el-table-column label="授权状态" width="100" align="center">
<template #default="{ row }">
<el-tag v-if="row.granted" size="small" type="success" effect="light">已授权</el-tag>
<span v-else class="text-xs text-gray-300">未授权</span>
</template>
</el-table-column>
</el-table>
</el-card>
</div>
</template>
@@ -1,147 +1,179 @@
<script setup lang="ts">
/**
* 通知推送(37du 控制台)
* 列表 + 新建/启停/删除(对接 /api/admin/notifications*)
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { fetchNotifications, createNotification, toggleNotification, deleteNotification } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 20, q: '' })
const levelMap: Record<string, { label: string; type: any }> = {
info: { label: '普通', type: 'info' },
warning: { label: '警告', type: 'warning' },
important: { label: '重要', type: 'danger' }
}
async function load() {
loading.value = true
try {
const r = await fetchNotifications(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 新建 ----
const dialogOpen = ref(false)
const saving = ref(false)
const form = reactive({ title: '', content: '', level: 'info', target: 'all', account: '', expires_at: '' })
function openCreate() {
Object.assign(form, { title: '', content: '', level: 'info', target: 'all', account: '', expires_at: '' })
dialogOpen.value = true
}
async function submit() {
if (!form.title) return ElMessage.warning('标题不能为空')
saving.value = true
try {
await createNotification(form)
ElMessage.success('通知已下发')
dialogOpen.value = false
load()
} finally {
saving.value = false
}
}
async function toggle(row: any) {
await toggleNotification(row.id, row.active !== 1)
load()
}
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除通知「${row.title}」?`, '删除确认', { type: 'warning' })
await deleteNotification(row.id)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">通知推送</h2>
<el-button type="primary" @click="openCreate">新建通知</el-button>
</div>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="标题 / 内容 / 账号" clearable style="width: 240px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="title" label="标题" min-width="160" />
<el-table-column prop="content" label="内容" min-width="220" show-overflow-tooltip />
<el-table-column label="级别" width="90">
<template #default="{ row }">
<el-tag :type="levelMap[row.level]?.type || 'info'" size="small">{{ levelMap[row.level]?.label || row.level }}</el-tag>
</template>
</el-table-column>
<el-table-column label="范围" width="100">
<template #default="{ row }">{{ row.target === 'all' ? '全部' : row.account }}</template>
</el-table-column>
<el-table-column label="状态" width="80">
<template #default="{ row }">
<el-tag :type="row.active === 1 ? 'success' : 'info'" size="small">{{ row.active === 1 ? '启用' : '停用' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="170" />
<el-table-column label="操作" width="150" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="toggle(row)">{{ row.active === 1 ? '停用' : '启用' }}</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
layout="total, prev, pager, next" @current-change="load" />
</div>
</el-card>
<el-dialog v-model="dialogOpen" title="新建通知" width="520px">
<el-form label-width="90px">
<el-form-item label="标题" required><el-input v-model="form.title" /></el-form-item>
<el-form-item label="内容"><el-input v-model="form.content" type="textarea" :rows="3" /></el-form-item>
<el-form-item label="级别">
<el-select v-model="form.level">
<el-option label="普通" value="info" /><el-option label="警告" value="warning" /><el-option label="重要" value="important" />
</el-select>
</el-form-item>
<el-form-item label="范围">
<el-radio-group v-model="form.target">
<el-radio value="all">全部账号</el-radio>
<el-radio value="account">指定账号</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="form.target === 'account'" label="账号" required>
<el-input v-model="form.account" placeholder="工号" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">下发</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
/**
* 通知推送(37du 控制台)
* 列表 + 新建/启停/删除(对接 /api/admin/notifications*)
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
fetchNotifications, createNotification, toggleNotification, deleteNotification, fetchGrantData
} from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 20, q: '' })
// 账号选择数据源(启用中的账号)
const accounts = ref<any[]>([])
const accountsLoaded = ref(false)
async function loadAccounts() {
if (accountsLoaded.value) return
try {
const d = await fetchGrantData()
accounts.value = d.accounts || []
accountsLoaded.value = true
} catch (e) {
/* 拉取失败不阻断,仍可手输工号 */
}
}
const levelMap: Record<string, { label: string; type: any }> = {
info: { label: '普通', type: 'info' },
warning: { label: '警告', type: 'warning' },
important: { label: '重要', type: 'danger' }
}
async function load() {
loading.value = true
try {
const r = await fetchNotifications(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 新建 ----
const dialogOpen = ref(false)
const saving = ref(false)
const form = reactive({ title: '', content: '', level: 'info', target: 'all', account: '', expires_at: '' })
function openCreate() {
Object.assign(form, { title: '', content: '', level: 'info', target: 'all', account: '', expires_at: '' })
loadAccounts()
dialogOpen.value = true
}
async function submit() {
if (!form.title) return ElMessage.warning('标题不能为空')
if (form.target === 'account' && !form.account) return ElMessage.warning('请选择目标账号')
saving.value = true
try {
await createNotification(form)
ElMessage.success('通知已下发')
dialogOpen.value = false
load()
} finally {
saving.value = false
}
}
async function toggle(row: any) {
await toggleNotification(row.id, row.active !== 1)
load()
}
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除通知「${row.title}」?`, '删除确认', { type: 'warning' })
await deleteNotification(row.id)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="通知推送" description="面向执行机用户的消息触达,员工端壳子实时拉取">
<template #actions>
<el-button type="primary" @click="openCreate"><ArtSvgIcon icon="ri:add-line" class="mr-1" />新建通知</el-button>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="标题 / 内容 / 账号" clearable style="width: 240px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="title" label="标题" min-width="160" />
<el-table-column prop="content" label="内容" min-width="220" show-overflow-tooltip />
<el-table-column label="级别" width="90">
<template #default="{ row }">
<el-tag :type="levelMap[row.level]?.type || 'info'" size="small">{{ levelMap[row.level]?.label || row.level }}</el-tag>
</template>
</el-table-column>
<el-table-column label="范围" width="100">
<template #default="{ row }">{{ row.target === 'all' ? '全部' : row.account }}</template>
</el-table-column>
<el-table-column label="状态" width="80">
<template #default="{ row }">
<el-tag :type="row.active === 1 ? 'success' : 'info'" size="small">{{ row.active === 1 ? '启用' : '停用' }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="170" />
<el-table-column label="操作" width="150" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="toggle(row)">{{ row.active === 1 ? '停用' : '启用' }}</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination v-model:current-page="query.page" v-model:page-size="query.page_size" :total="total"
layout="total, prev, pager, next" @current-change="load" />
</div>
</el-card>
<el-dialog v-model="dialogOpen" title="新建通知" width="520px">
<el-form label-width="90px">
<el-form-item label="标题" required><el-input v-model="form.title" /></el-form-item>
<el-form-item label="内容"><el-input v-model="form.content" type="textarea" :rows="3" /></el-form-item>
<el-form-item label="级别">
<el-select v-model="form.level">
<el-option label="普通" value="info" /><el-option label="警告" value="warning" /><el-option label="重要" value="important" />
</el-select>
</el-form-item>
<el-form-item label="范围">
<el-radio-group v-model="form.target">
<el-radio value="all">全部账号</el-radio>
<el-radio value="account">指定账号</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item v-if="form.target === 'account'" label="目标账号" required>
<el-select
v-model="form.account"
filterable
placeholder="搜索昵称 / 工号选择账号"
style="width: 100%"
>
<el-option
v-for="a in accounts"
:key="a.account"
:label="`${a.nickname || a.account}(${a.account}${a.dept ? ' · ' + a.dept : ''})`"
:value="a.account"
/>
</el-select>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogOpen = false">取消</el-button>
<el-button type="primary" :loading="saving" @click="submit">下发</el-button>
</template>
</el-dialog>
</div>
</template>
@@ -1,28 +1,57 @@
<script setup lang="ts">
/**
* 概览(37du 控制台)
* 统计卡片来自 /api/admin/overview + /api/admin/stats
* 统计卡片 + 运行趋势图 + 插件状态分布 + 管理员/平台速览
* 数据:/api/admin/overview + /api/admin/stats
*/
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { fetchOverview, fetchStats } from '@/api/business'
import ArtPageHeader from '@/components/core/base/art-page-header/index.vue'
const router = useRouter()
const loading = ref(false)
const overview = ref<any>({})
const overview = ref<any>({ plugins: [], accounts: [], admins: [] })
const stats = ref<any>({})
const statCards = ref([
{ key: 'plugins', label: '插件总数', value: 0, icon: 'ri:box-3-line', color: '#377dff' },
{ key: 'accounts', label: '账号总数', value: 0, icon: 'ri:user-3-line', color: '#00b42a' },
{ key: 'admins', label: '管理员', value: 0, icon: 'ri:shield-user-line', color: '#ff7d00' },
{ key: 'authorized', label: '已授权账号', value: 0, icon: 'ri:key-2-line', color: '#f5319d' }
])
const pluginCount = computed(() => overview.value.plugins?.length || 0)
const accountCount = computed(() => overview.value.accounts?.length || 0)
const adminCount = computed(() => overview.value.admins?.length || 0)
const authorizedCount = computed(() => stats.value.users?.authorized || 0)
const runCards = ref([
{ key: 'total', label: '运行总次数', value: 0, icon: 'ri:play-circle-line', color: '#377dff' },
{ key: 'success', label: '成功', value: 0, icon: 'ri:checkbox-circle-line', color: '#00b42a' },
{ key: 'failed', label: '失败', value: 0, icon: 'ri:close-circle-line', color: '#f53f3f' },
{ key: 'activeUsers', label: '活跃用户', value: 0, icon: 'ri:user-heart-line', color: '#ff7d00' }
])
const pluginStatus = computed(() => {
const plugins = overview.value.plugins || []
const published = plugins.filter((p: any) => p.status === 'published').length
const disabled = plugins.filter((p: any) => p.status === 'disabled').length
const revoked = plugins.filter((p: any) => p.status === 'revoked').length
return [
{ name: '已发布', value: published },
{ name: '已停用', value: disabled },
{ name: '已吊销', value: revoked }
]
})
const trendData = computed(() => {
const trend = stats.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(() => (stats.value.trend || []).map((t: any) => t.day))
/** 最近发布的插件(前 6 个) */
const recentPlugins = computed(() =>
(overview.value.plugins || [])
.slice()
.sort((a: any, b: any) => (b.versions?.[0]?.uploaded_at || '').localeCompare(a.versions?.[0]?.uploaded_at || ''))
.slice(0, 6)
)
const statusTag = (s: string) => (s === 'published' ? 'success' : s === 'disabled' ? 'warning' : 'danger')
const statusLabel = (s: string) => (s === 'published' ? '已发布' : s === 'disabled' ? '已停用' : '已吊销')
async function load() {
loading.value = true
@@ -30,17 +59,6 @@ async function load() {
const [ov, st] = await Promise.all([fetchOverview(), fetchStats()])
overview.value = ov
stats.value = st
statCards.value = statCards.value.map((c) => {
if (c.key === 'plugins') return { ...c, value: ov.plugins?.length || 0 }
if (c.key === 'accounts') return { ...c, value: ov.accounts?.length || 0 }
if (c.key === 'admins') return { ...c, value: ov.admins?.length || 0 }
if (c.key === 'authorized') return { ...c, value: st.users?.authorized || 0 }
return c
})
runCards.value = runCards.value.map((c) => ({
...c,
value: st.runs?.[c.key] ?? 0
}))
} finally {
loading.value = false
}
@@ -50,71 +68,148 @@ onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">概览</h2>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
<div class="p-5">
<ArtPageHeader title="概览" description="平台全景:插件、账号、授权与运行态势">
<template #actions>
<el-button :loading="loading" @click="load">
<ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新
</el-button>
<el-button type="primary" @click="router.push('/plugins')">
<ArtSvgIcon icon="ri:upload-2-line" class="mr-1" />发布插件
</el-button>
</template>
</ArtPageHeader>
<el-row :gutter="16">
<el-col v-for="c in statCards" :key="c.key" :span="6">
<!-- 资源统计 -->
<el-row :gutter="14" class="mb-3.5">
<el-col :xs="12" :sm="12" :md="6" v-for="(c, i) in [
{ title: '插件总数', count: pluginCount, icon: 'ri:box-3-line', iconStyle: 'bg-[#377dff]', desc: '已注册插件' },
{ title: '账号总数', count: accountCount, icon: 'ri:user-3-line', iconStyle: 'bg-[#00b42a]', desc: '统一账号' },
{ title: '管理员', count: adminCount, icon: 'ri:shield-user-line', iconStyle: 'bg-[#ff7d00]', desc: '拥有管理权限' },
{ title: '已授权账号', count: authorizedCount, icon: 'ri:key-2-line', iconStyle: 'bg-[#f5319d]', desc: '至少授权 1 个插件' }
]" :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-row :gutter="14" class="mb-3.5">
<el-col :xs="12" :sm="12" :md="6" v-for="(c, i) in [
{ title: '运行总次数', count: stats.runs?.total || 0, icon: 'ri:play-circle-line', iconStyle: 'bg-[#377dff]', desc: '全部触发' },
{ title: '成功', count: stats.runs?.success || 0, icon: 'ri:checkbox-circle-line', iconStyle: 'bg-[#00b42a]', desc: 'done / success' },
{ title: '失败', count: stats.runs?.failed || 0, icon: 'ri:close-circle-line', iconStyle: 'bg-[#f53f3f]', desc: 'error / failed' },
{ title: '活跃用户', count: stats.runs?.activeUsers || 0, icon: 'ri:user-heart-line', iconStyle: 'bg-[#ff7d00]', desc: '有触发记录' }
]" :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-row :gutter="14" class="mb-3.5">
<el-col :md="16" :xs="24">
<el-card shadow="never" class="rounded-xl">
<div class="flex items-center gap-3">
<div class="w-11 h-11 rounded-lg grid place-items-center text-white text-xl" :style="{ background: c.color }">
<i :class="c.icon" />
<template #header>
<div class="flex items-center justify-between">
<span class="font-semibold">14 天运行趋势</span>
<span class="text-xs text-gray-400">总时长 {{ stats.runs?.durationSec || 0 }} 秒 · 活跃插件 {{ stats.runs?.activePlugins || 0 }}</span>
</div>
<div>
<div class="text-2xl font-bold leading-none">{{ c.value }}</div>
<div class="text-xs text-gray-500 mt-1">{{ c.label }}</div>
</div>
</div>
</template>
<ArtLineChart
:data="trendData"
:x-axis-data="trendX"
:show-legend="true"
:show-area-color="true"
height="300px"
:loading="loading"
/>
</el-card>
</el-col>
<el-col :md="8" :xs="24">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">插件状态分布</span></template>
<ArtRingChart :data="pluginStatus" :center-text="`${pluginCount}`" height="300px" :loading="loading" />
</el-card>
</el-col>
</el-row>
<el-row :gutter="16">
<el-col v-for="c in runCards" :key="c.key" :span="6">
<!-- 最近插件 + 管理员 -->
<el-row :gutter="14">
<el-col :md="16" :xs="24">
<el-card shadow="never" class="rounded-xl">
<div class="flex items-center gap-3">
<div class="w-11 h-11 rounded-lg grid place-items-center text-white text-xl" :style="{ background: c.color }">
<i :class="c.icon" />
<template #header>
<div class="flex items-center justify-between">
<span class="font-semibold">最近更新的插件</span>
<el-button link type="primary" @click="router.push('/plugins')">管理插件 →</el-button>
</div>
<div>
<div class="text-2xl font-bold leading-none">{{ c.value }}</div>
<div class="text-xs text-gray-500 mt-1">{{ c.label }}</div>
</template>
<el-table :data="recentPlugins" size="small" :show-header="false" v-loading="loading">
<el-table-column label="插件" min-width="220">
<template #default="{ row }">
<div class="flex items-center gap-2.5">
<div class="size-8 rounded-lg grid place-items-center bg-[var(--el-color-primary-light-9)] text-[var(--el-color-primary)]">
<ArtSvgIcon :icon="row.icon && row.icon.startsWith('ri:') ? row.icon : 'ri:box-3-line'" class="text-base" />
</div>
<div>
<div class="text-sm font-medium leading-tight">{{ row.name }}</div>
<div class="text-xs text-gray-400">{{ row.id }}</div>
</div>
</div>
</template>
</el-table-column>
<el-table-column label="最新版本" width="100">
<template #default="{ row }">
<el-tag size="small" effect="plain">v{{ row.latest_version }}</el-tag>
</template>
</el-table-column>
<el-table-column label="版本数" width="80" align="center">
<template #default="{ row }">{{ row.versions?.length || 0 }}</template>
</el-table-column>
<el-table-column label="状态" width="90" align="center">
<template #default="{ row }">
<el-tag size="small" :type="statusTag(row.status)">{{ statusLabel(row.status) }}</el-tag>
</template>
</el-table-column>
</el-table>
<el-empty v-if="!recentPlugins.length && !loading" description="还没有插件,去发布第一个吧" :image-size="70" />
</el-card>
</el-col>
<el-col :md="8" :xs="24">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">管理员与账号</span></template>
<div class="space-y-2">
<div class="flex items-center justify-between px-3 py-2 rounded-lg bg-[var(--el-fill-color-light)]">
<span class="text-sm text-g-600">普通账号</span>
<span class="text-lg font-semibold">{{ Math.max(0, accountCount - adminCount) }}</span>
</div>
<div
v-for="a in overview.admins"
:key="a"
class="flex items-center gap-2.5 px-3 py-2 rounded-lg bg-[var(--el-fill-color-light)]"
>
<div class="size-7 rounded-full grid place-items-center bg-[#ff7d00] text-white text-xs">
<ArtSvgIcon icon="ri:shield-star-line" />
</div>
<span class="text-sm">{{ a }}</span>
<el-tag size="small" type="warning" class="ml-auto">管理员</el-tag>
</div>
<el-button class="w-full mt-1" plain @click="router.push('/accounts')">前往账号管理 →</el-button>
</div>
</el-card>
</el-col>
</el-row>
<el-row :gutter="16">
<el-col :span="12">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">运行统计</span></template>
<el-descriptions :column="2" border>
<el-descriptions-item label="运行总时长">{{ stats.runs?.durationSec || 0 }} 秒</el-descriptions-item>
<el-descriptions-item label="活跃插件">{{ stats.runs?.activePlugins || 0 }}</el-descriptions-item>
<el-descriptions-item label="今日">{{ stats.today || '-' }}</el-descriptions-item>
<el-descriptions-item label="插件发布状态">
{{ stats.plugins?.published || 0 }} 发布 / {{ stats.plugins?.disabled || 0 }} 禁用
</el-descriptions-item>
</el-descriptions>
</el-card>
</el-col>
<el-col :span="12">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">账号概览</span></template>
<el-descriptions :column="2" border>
<el-descriptions-item label="管理员">
<el-tag size="small" type="primary">{{ overview.admins?.length || 0 }}</el-tag>
</el-descriptions-item>
<el-descriptions-item label="普通账号">
{{ (overview.accounts?.length || 0) - (overview.admins?.length || 0) }}
</el-descriptions-item>
</el-descriptions>
</el-card>
</el-col>
</el-row>
</div>
</template>
@@ -1,183 +1,184 @@
<script setup lang="ts">
/**
* 插件管理(37du 控制台)
* 列表/搜索/上传发布/状态切换/删除,对接 /api/admin/plugins、/pkg、/plugin/patch、/plugin/delete
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { fetchPlugins, uploadPlugin, patchPlugin, deletePlugin } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 10, q: '' })
const statusMap: Record<string, { label: string; type: any }> = {
published: { label: '已发布', type: 'success' },
disabled: { label: '已禁用', type: 'warning' },
revoked: { label: '已下架', type: 'danger' }
}
async function load() {
loading.value = true
try {
const r = await fetchPlugins(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 上传发布 ----
const uploadOpen = ref(false)
const uploading = ref(false)
const uploadForm = reactive({ plugin_id: '', name: '', version: '', file: null as File | null })
function openUpload() {
Object.assign(uploadForm, { plugin_id: '', name: '', version: '', file: null })
uploadOpen.value = true
}
async function submitUpload() {
if (!uploadForm.file || !uploadForm.plugin_id || !uploadForm.version) {
ElMessage.warning('请填写 plugin_id / version 并选择安装包')
return
}
uploading.value = true
try {
await uploadPlugin(uploadForm.file, {
plugin_id: uploadForm.plugin_id,
name: uploadForm.name,
version: uploadForm.version
})
ElMessage.success('上传发布成功')
uploadOpen.value = false
load()
} finally {
uploading.value = false
}
}
// ---- 状态切换 ----
async function setStatus(row: any, status: string) {
await patchPlugin(row.id, { status })
ElMessage.success(`已${statusMap[status]?.label || status}`)
load()
}
// ---- 删除 ----
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除插件「${row.id}」?将连带删除版本与授权。`, '删除确认', {
type: 'warning'
})
await deletePlugin(row.id)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">插件管理</h2>
<el-button type="primary" @click="openUpload">上传发布</el-button>
</div>
<!-- 搜索 -->
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="ID / 名称" clearable style="width: 240px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<!-- 表格 -->
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<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 label="状态" width="100">
<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="220">
<template #default="{ row }">
<el-tooltip v-if="row.versions?.length" :content="row.versions.map((v: any) => v.version).join(', ')">
<el-tag size="small" type="info">{{ row.versions.length }} 个版本</el-tag>
</el-tooltip>
<span v-else class="text-gray-400">-</span>
</template>
</el-table-column>
<el-table-column label="操作" width="220" fixed="right">
<template #default="{ row }">
<el-button
v-if="row.status === 'disabled'"
link type="success"
@click="setStatus(row, 'published')"
>启用</el-button>
<el-button
v-if="row.status === 'published'"
link type="warning"
@click="setStatus(row, 'disabled')"
>禁用</el-button>
<el-button
v-if="row.status !== 'revoked'"
link type="danger"
@click="setStatus(row, 'revoked')"
>下架</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
<!-- 上传发布弹窗 -->
<el-dialog v-model="uploadOpen" title="上传发布插件" width="480px">
<el-form label-width="90px">
<el-form-item label="插件ID" required>
<el-input v-model="uploadForm.plugin_id" placeholder="如 seal_check(与 plugin.json 内 id 一致)" />
</el-form-item>
<el-form-item label="版本号" required>
<el-input v-model="uploadForm.version" placeholder="如 1.2.0" />
</el-form-item>
<el-form-item label="名称">
<el-input v-model="uploadForm.name" placeholder="留空则取 plugin.json name" />
</el-form-item>
<el-form-item label="安装包" required>
<input type="file" accept=".zip" @change="(e: any) => (uploadForm.file = e.target.files[0] || null)" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="uploadOpen = false">取消</el-button>
<el-button type="primary" :loading="uploading" @click="submitUpload">发布</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
/**
* 插件管理(37du 控制台)
* 列表/搜索/上传发布/状态切换/删除,对接 /api/admin/plugins、/pkg、/plugin/patch、/plugin/delete
*/
import { onMounted, reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { fetchPlugins, uploadPlugin, patchPlugin, deletePlugin } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const query = reactive({ page: 1, page_size: 10, q: '' })
const statusMap: Record<string, { label: string; type: any }> = {
published: { label: '已发布', type: 'success' },
disabled: { label: '已禁用', type: 'warning' },
revoked: { label: '已下架', type: 'danger' }
}
async function load() {
loading.value = true
try {
const r = await fetchPlugins(query)
list.value = r.items || []
total.value = r.total || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
// ---- 上传发布 ----
const uploadOpen = ref(false)
const uploading = ref(false)
const uploadForm = reactive({ plugin_id: '', name: '', version: '', file: null as File | null })
function openUpload() {
Object.assign(uploadForm, { plugin_id: '', name: '', version: '', file: null })
uploadOpen.value = true
}
async function submitUpload() {
if (!uploadForm.file || !uploadForm.plugin_id || !uploadForm.version) {
ElMessage.warning('请填写 plugin_id / version 并选择安装包')
return
}
uploading.value = true
try {
await uploadPlugin(uploadForm.file, {
plugin_id: uploadForm.plugin_id,
name: uploadForm.name,
version: uploadForm.version
})
ElMessage.success('上传发布成功')
uploadOpen.value = false
load()
} finally {
uploading.value = false
}
}
// ---- 状态切换 ----
async function setStatus(row: any, status: string) {
await patchPlugin(row.id, { status })
ElMessage.success(statusMap[status]?.label || `状态已更新为 ${status}`)
load()
}
// ---- 删除 ----
async function remove(row: any) {
await ElMessageBox.confirm(`确认删除插件「${row.id}」?将连带删除版本与授权。`, '删除确认', {
type: 'warning'
})
await deletePlugin(row.id)
ElMessage.success('已删除')
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="插件管理" description="插件上传发布、版本管理与强制更新">
<template #actions>
<el-button type="primary" @click="openUpload"><ArtSvgIcon icon="ri:upload-2-line" class="mr-1" />上传发布</el-button>
</template>
</ArtPageHeader>
<!-- 搜索 -->
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="ID / 名称" clearable style="width: 240px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<!-- 表格 -->
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<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 label="状态" width="100">
<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="220">
<template #default="{ row }">
<el-tooltip v-if="row.versions?.length" :content="row.versions.map((v: any) => v.version).join(', ')">
<el-tag size="small" type="info">{{ row.versions.length }} 个版本</el-tag>
</el-tooltip>
<span v-else class="text-gray-400">-</span>
</template>
</el-table-column>
<el-table-column label="操作" width="220" fixed="right">
<template #default="{ row }">
<el-button
v-if="row.status === 'disabled'"
link type="success"
@click="setStatus(row, 'published')"
>启用</el-button>
<el-button
v-if="row.status === 'published'"
link type="warning"
@click="setStatus(row, 'disabled')"
>禁用</el-button>
<el-button
v-if="row.status !== 'revoked'"
link type="danger"
@click="setStatus(row, 'revoked')"
>下架</el-button>
<el-button link type="danger" @click="remove(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
<!-- 上传发布弹窗 -->
<el-dialog v-model="uploadOpen" title="上传发布插件" width="480px">
<el-form label-width="90px">
<el-form-item label="插件ID" required>
<el-input v-model="uploadForm.plugin_id" placeholder="如 seal_check(与 plugin.json 内 id 一致)" />
</el-form-item>
<el-form-item label="版本号" required>
<el-input v-model="uploadForm.version" placeholder="如 1.2.0" />
</el-form-item>
<el-form-item label="名称">
<el-input v-model="uploadForm.name" placeholder="留空则取 plugin.json name" />
</el-form-item>
<el-form-item label="安装包" required>
<input type="file" accept=".zip" @change="(e: any) => (uploadForm.file = e.target.files[0] || null)" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="uploadOpen = false">取消</el-button>
<el-button type="primary" :loading="uploading" @click="submitUpload">发布</el-button>
</template>
</el-dialog>
</div>
</template>
@@ -1,101 +1,100 @@
<script setup lang="ts">
/**
* 运行记录(37du 控制台)
* 分页 + 状态筛选 + 关键字(对接 /api/admin/reports)
*/
import { onMounted, reactive, ref } from 'vue'
import { fetchReports } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const today = ref(0)
const failed = ref(0)
const query = reactive({ page: 1, page_size: 20, status: '', q: '' })
const statusMap: Record<string, { label: string; type: any }> = {
start: { label: '启动', type: 'info' },
done: { label: '完成', type: 'success' },
success: { label: '成功', type: 'success' },
error: { label: '错误', type: 'danger' },
failed: { label: '失败', type: 'danger' }
}
async function load() {
loading.value = true
try {
const r = await fetchReports(query)
list.value = r.items || []
total.value = r.total || 0
today.value = r.today || 0
failed.value = r.failed || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">运行记录</h2>
<div>
<el-tag type="info" class="mr-2">今日 {{ today }} 条</el-tag>
<el-tag type="danger">失败 {{ failed }} 条</el-tag>
</div>
</div>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="状态">
<el-select v-model="query.status" clearable placeholder="全部" style="width: 160px" @change="search">
<el-option v-for="(v, k) in statusMap" :key="k" :label="v.label" :value="k" />
</el-select>
</el-form-item>
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="账号 / 设备 / 插件 / 消息" clearable style="width: 220px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '', status: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="账号" width="110">
<template #default="{ row }">{{ row.nickname || row.account || '-' }}</template>
</el-table-column>
<el-table-column prop="pluginId" label="插件" min-width="120" />
<el-table-column prop="version" label="版本" width="90" />
<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 prop="durationSec" label="时长(秒)" width="90" />
<el-table-column prop="msg" label="消息" min-width="200" show-overflow-tooltip />
<el-table-column prop="at" label="时间" width="170" />
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
</div>
</template>
<script setup lang="ts">
/**
* 运行记录(37du 控制台)
* 分页 + 状态筛选 + 关键字(对接 /api/admin/reports)
*/
import { onMounted, reactive, ref } from 'vue'
import { fetchReports } from '@/api/business'
const loading = ref(false)
const list = ref<any[]>([])
const total = ref(0)
const today = ref(0)
const failed = ref(0)
const query = reactive({ page: 1, page_size: 20, status: '', q: '' })
const statusMap: Record<string, { label: string; type: any }> = {
start: { label: '启动', type: 'info' },
done: { label: '完成', type: 'success' },
success: { label: '成功', type: 'success' },
error: { label: '错误', type: 'danger' },
failed: { label: '失败', type: 'danger' }
}
async function load() {
loading.value = true
try {
const r = await fetchReports(query)
list.value = r.items || []
total.value = r.total || 0
today.value = r.today || 0
failed.value = r.failed || 0
} finally {
loading.value = false
}
}
function search() {
query.page = 1
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="运行记录" description="插件运行上报明细与失败追踪">
<template #actions>
<el-tag type="info" effect="plain" class="mr-2">今日 {{ today }} 条</el-tag>
<el-tag type="danger" effect="plain">失败 {{ failed }} 条</el-tag>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-form inline @submit.prevent="search">
<el-form-item label="状态">
<el-select v-model="query.status" clearable placeholder="全部" style="width: 160px" @change="search">
<el-option v-for="(v, k) in statusMap" :key="k" :label="v.label" :value="k" />
</el-select>
</el-form-item>
<el-form-item label="关键字">
<el-input v-model="query.q" placeholder="账号 / 设备 / 插件 / 消息" clearable style="width: 220px" @keyup.enter="search" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="search">查询</el-button>
<el-button @click="Object.assign(query, { q: '', status: '' }); search()">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe>
<el-table-column prop="id" label="ID" width="80" />
<el-table-column label="账号" width="110">
<template #default="{ row }">{{ row.nickname || row.account || '-' }}</template>
</el-table-column>
<el-table-column prop="pluginId" label="插件" min-width="120" />
<el-table-column prop="version" label="版本" width="90" />
<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 prop="durationSec" label="时长(秒)" width="90" />
<el-table-column prop="msg" label="消息" min-width="200" show-overflow-tooltip />
<el-table-column prop="at" label="时间" width="170" />
</el-table>
<div class="flex justify-end mt-4">
<el-pagination
v-model:current-page="query.page"
v-model:page-size="query.page_size"
:total="total"
layout="total, prev, pager, next"
@current-change="load"
/>
</div>
</el-card>
</div>
</template>
@@ -1,21 +1,46 @@
<script setup lang="ts">
/**
* 数据看板(37du 控制台)
* 运行统计 + 插件排行 + 活跃用户 + 近14天趋势(对接 /api/admin/stats)
* 运行统计卡 + 近14天趋势折线 + 插件排行/活跃用户横向柱图 + 明细表
* 数据:/api/admin/stats
*/
import { onMounted, ref } from 'vue'
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 runCards = [
{ key: 'total', label: '运行总次数', color: '#377dff' },
{ key: 'success', label: '成功', color: '#00b42a' },
{ key: 'failed', label: '失败', color: '#f53f3f' },
{ key: 'activeUsers', label: '活跃用户', color: '#ff7d00' },
{ key: 'activePlugins', label: '活跃插件', color: '#f5319d' }
]
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 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 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 statusTag = (s: string) => (s === 'published' ? 'success' : s === 'disabled' ? 'warning' : 'danger')
async function load() {
loading.value = true
@@ -30,63 +55,132 @@ onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">数据看板</h2>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
<div class="p-5">
<ArtPageHeader title="数据看板" description="运行统计、插件排行与活跃用户(近 14 天)">
<template #actions>
<el-button :loading="loading" @click="load">
<ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新
</el-button>
</template>
</ArtPageHeader>
<el-row :gutter="16">
<el-col v-for="c in runCards" :key="c.key" :span="4">
<el-card shadow="never" class="rounded-xl">
<div class="text-2xl font-bold" :style="{ color: c.color }">{{ data.runs?.[c.key] || 0 }}</div>
<div class="text-xs text-gray-500 mt-1">{{ c.label }}</div>
</el-card>
</el-col>
<el-col :span="4">
<el-card shadow="never" class="rounded-xl">
<div class="text-2xl font-bold">{{ data.runs?.durationSec || 0 }}s</div>
<div class="text-xs text-gray-500 mt-1">总时长</div>
</el-card>
<!-- 统计卡 -->
<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-row :gutter="16">
<el-col :span="12">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">插件排行(Top 8)</span></template>
<el-table :data="data.topPlugins || []" size="small" border>
<el-table-column prop="pluginId" label="插件" min-width="120" />
<el-table-column prop="name" label="名称" min-width="140" />
<el-table-column prop="runs" label="触发次数" width="90" />
<el-table-column prop="success" label="成功" width="70" />
<el-table-column prop="failed" label="失败" width="70" />
</el-table>
</el-card>
</el-col>
<el-col :span="12">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">活跃用户(Top 8)</span></template>
<el-table :data="data.topUsers || []" size="small" border>
<el-table-column prop="account" label="账号" min-width="120" />
<el-table-column prop="nickname" label="昵称" min-width="120" />
<el-table-column prop="runs" label="运行次数" width="100" />
</el-table>
</el-card>
</el-col>
</el-row>
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">近 14 天运行趋势</span></template>
<div v-if="data.trend?.length" class="flex items-end gap-1" style="height: 120px">
<div v-for="t in data.trend" :key="t.day" class="flex-1 flex flex-col items-center gap-1">
<div class="text-[10px] text-gray-500">{{ t.runs }}</div>
<div class="w-full rounded-sm" :title="`${t.day} 运行 ${t.runs} 次`"
:style="{ height: `${Math.max(2, Math.round((t.runs / Math.max(1, ...data.trend.map((x: any) => x.runs))) * 100))}px`, background: '#377dff' }" />
<div class="text-[10px] text-gray-400">{{ t.day }}</div>
<!-- 趋势 -->
<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>
</div>
</div>
<el-empty v-else description="暂无趋势数据" :image-size="60" />
</template>
<ArtLineChart
:data="trendData"
:x-axis-data="trendX"
:show-legend="true"
:show-area-color="true"
height="300px"
:loading="loading"
/>
</el-card>
<!-- 排行图 -->
<el-row :gutter="14" class="mb-3.5">
<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="pluginBarData"
:x-axis-data="pluginBarX"
height="260px"
: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-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) }}
</div>
<div>
<div class="text-sm leading-tight">{{ row.nickname || row.account }}</div>
<div class="text-xs text-gray-400">{{ row.account }}</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>
</el-card>
</el-col>
</el-row>
</div>
</template>
@@ -1,96 +1,95 @@
<script setup lang="ts">
/**
* 系统管理-部门(37du 重构版,走 /api/admin/sys/departments,后端构建树)
* 数据范围"本部门及以下"的载体;支持新增 / 编辑 / 删除(有子级或在用用户拒绝)
*/
import { onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysDeptDel, sysDepartments } from '@/api/sys'
import DepartmentDialog from './modules/department-dialog.vue'
const loading = ref(false)
const list = ref<any[]>([])
async function load() {
loading.value = true
try {
const r = await sysDepartments()
list.value = r.items || []
} finally {
loading.value = false
}
}
const dialogVisible = ref(false)
const dialogType = ref<'add' | 'edit'>('add')
const currentDept = ref<any>(null)
const presetParentId = ref<number | null>(null)
function openAdd(parent?: any) {
dialogType.value = 'add'
currentDept.value = null
presetParentId.value = parent ? Number(parent.id) : null
dialogVisible.value = true
}
function openEdit(row: any) {
dialogType.value = 'edit'
currentDept.value = row
presetParentId.value = null
dialogVisible.value = true
}
async function handleDel(row: any) {
await ElMessageBox.confirm(`确认删除部门「${row.name}」?`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysDeptDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
dialogVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">部门管理</h2>
<div class="flex gap-2">
<el-button type="primary" @click="openAdd()">新增部门</el-button>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
</div>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe row-key="id" default-expand-all>
<el-table-column prop="name" label="部门名称" min-width="220" />
<el-table-column prop="orderNum" label="排序" width="80" />
<el-table-column prop="createTime" label="创建时间" min-width="170" />
<el-table-column label="操作" width="170" fixed="right">
<template #default="{ row }">
<el-button link type="primary" size="small" @click="openAdd(row)">添加子级</el-button>
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<DepartmentDialog
v-model:visible="dialogVisible"
:type="dialogType"
:dept-data="currentDept"
:preset-parent-id="presetParentId"
:tree="list"
@submit="handleSubmit"
/>
</div>
</template>
<script setup lang="ts">
/**
* 系统管理-部门(37du 重构版,走 /api/admin/sys/departments,后端构建树)
* 数据范围"本部门及以下"的载体;支持新增 / 编辑 / 删除(有子级或在用用户拒绝)
*/
import { onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysDeptDel, sysDepartments } from '@/api/sys'
import DepartmentDialog from './modules/department-dialog.vue'
const loading = ref(false)
const list = ref<any[]>([])
async function load() {
loading.value = true
try {
const r = await sysDepartments()
list.value = r.items || []
} finally {
loading.value = false
}
}
const dialogVisible = ref(false)
const dialogType = ref<'add' | 'edit'>('add')
const currentDept = ref<any>(null)
const presetParentId = ref<number | null>(null)
function openAdd(parent?: any) {
dialogType.value = 'add'
currentDept.value = null
presetParentId.value = parent ? Number(parent.id) : null
dialogVisible.value = true
}
function openEdit(row: any) {
dialogType.value = 'edit'
currentDept.value = row
presetParentId.value = null
dialogVisible.value = true
}
async function handleDel(row: any) {
await ElMessageBox.confirm(`确认删除部门「${row.name}」?`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysDeptDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
dialogVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="部门管理" description="部门树(数据范围“本部门及以下”的载体)">
<template #actions>
<el-button :loading="loading" @click="load"><ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新</el-button>
<el-button type="primary" @click="openAdd()"><ArtSvgIcon icon="ri:add-line" class="mr-1" />新增部门</el-button>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe row-key="id" default-expand-all>
<el-table-column prop="name" label="部门名称" min-width="220" />
<el-table-column prop="orderNum" label="排序" width="80" />
<el-table-column prop="createTime" label="创建时间" min-width="170" />
<el-table-column label="操作" width="170" fixed="right">
<template #default="{ row }">
<el-button link type="primary" size="small" @click="openAdd(row)">添加子级</el-button>
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<DepartmentDialog
v-model:visible="dialogVisible"
:type="dialogType"
:dept-data="currentDept"
:preset-parent-id="presetParentId"
:tree="list"
@submit="handleSubmit"
/>
</div>
</template>
@@ -1,107 +1,106 @@
<script setup lang="ts">
/**
* 系统管理-菜单(37du 重构版,走 /api/admin/sys/menus,后端构建树)
* 支持:新增 / 编辑 / 删除(有子级拒绝);type: 0目录 1菜单 2按钮
*/
import { onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysMenuDel, sysMenus } from '@/api/sys'
import MenuDialog from './modules/menu-dialog.vue'
const loading = ref(false)
const list = ref<any[]>([])
const typeName = (t: number) => (Number(t) === 0 ? '目录' : Number(t) === 1 ? '菜单' : '按钮')
const typeTag = (t: number) => (Number(t) === 0 ? 'info' : Number(t) === 1 ? 'success' : 'warning')
async function load() {
loading.value = true
try {
const r = await sysMenus()
list.value = r.items || []
} finally {
loading.value = false
}
}
// ---- 新增/编辑对话框 ----
const dialogVisible = ref(false)
const dialogType = ref<'add' | 'edit'>('add')
const currentMenu = ref<any>(null)
const presetParentId = ref<number | null>(null)
function openAdd(parent?: any) {
dialogType.value = 'add'
currentMenu.value = null
presetParentId.value = parent ? Number(parent.id) : null
dialogVisible.value = true
}
function openEdit(row: any) {
dialogType.value = 'edit'
currentMenu.value = row
presetParentId.value = null
dialogVisible.value = true
}
async function handleDel(row: any) {
await ElMessageBox.confirm(`确认删除菜单「${row.name}」?`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysMenuDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
dialogVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">菜单管理</h2>
<div class="flex gap-2">
<el-button type="primary" @click="openAdd()">新增菜单</el-button>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
</div>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe row-key="id" default-expand-all>
<el-table-column prop="name" label="名称" min-width="180" />
<el-table-column label="类型" width="80">
<template #default="{ row }">
<el-tag size="small" :type="typeTag(row.type)">{{ typeName(row.type) }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="router" label="路由" min-width="150" show-overflow-tooltip />
<el-table-column prop="perms" label="权限标识" min-width="210" show-overflow-tooltip />
<el-table-column prop="icon" label="图标" width="130" show-overflow-tooltip />
<el-table-column prop="orderNum" label="排序" width="70" />
<el-table-column label="操作" width="170" fixed="right">
<template #default="{ row }">
<el-button v-if="Number(row.type) !== 2" link type="primary" size="small" @click="openAdd(row)">添加子级</el-button>
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<MenuDialog
v-model:visible="dialogVisible"
:type="dialogType"
:menu-data="currentMenu"
:preset-parent-id="presetParentId"
:tree="list"
@submit="handleSubmit"
/>
</div>
</template>
<script setup lang="ts">
/**
* 系统管理-菜单(37du 重构版,走 /api/admin/sys/menus,后端构建树)
* 支持:新增 / 编辑 / 删除(有子级拒绝);type: 0目录 1菜单 2按钮
*/
import { onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysMenuDel, sysMenus } from '@/api/sys'
import MenuDialog from './modules/menu-dialog.vue'
const loading = ref(false)
const list = ref<any[]>([])
const typeName = (t: number) => (Number(t) === 0 ? '目录' : Number(t) === 1 ? '菜单' : '按钮')
const typeTag = (t: number) => (Number(t) === 0 ? 'info' : Number(t) === 1 ? 'success' : 'warning')
async function load() {
loading.value = true
try {
const r = await sysMenus()
list.value = r.items || []
} finally {
loading.value = false
}
}
// ---- 新增/编辑对话框 ----
const dialogVisible = ref(false)
const dialogType = ref<'add' | 'edit'>('add')
const currentMenu = ref<any>(null)
const presetParentId = ref<number | null>(null)
function openAdd(parent?: any) {
dialogType.value = 'add'
currentMenu.value = null
presetParentId.value = parent ? Number(parent.id) : null
dialogVisible.value = true
}
function openEdit(row: any) {
dialogType.value = 'edit'
currentMenu.value = row
presetParentId.value = null
dialogVisible.value = true
}
async function handleDel(row: any) {
await ElMessageBox.confirm(`确认删除菜单「${row.name}」?`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysMenuDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
dialogVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="菜单管理" description="控制台菜单树与按钮权限标识维护">
<template #actions>
<el-button :loading="loading" @click="load"><ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新</el-button>
<el-button type="primary" @click="openAdd()"><ArtSvgIcon icon="ri:add-line" class="mr-1" />新增菜单</el-button>
</template>
</ArtPageHeader>
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="list" border stripe row-key="id" default-expand-all>
<el-table-column prop="name" label="名称" min-width="180" />
<el-table-column label="类型" width="80">
<template #default="{ row }">
<el-tag size="small" :type="typeTag(row.type)">{{ typeName(row.type) }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="router" label="路由" min-width="150" show-overflow-tooltip />
<el-table-column prop="perms" label="权限标识" min-width="210" show-overflow-tooltip />
<el-table-column prop="icon" label="图标" width="130" show-overflow-tooltip />
<el-table-column prop="orderNum" label="排序" width="70" />
<el-table-column label="操作" width="170" fixed="right">
<template #default="{ row }">
<el-button v-if="Number(row.type) !== 2" link type="primary" size="small" @click="openAdd(row)">添加子级</el-button>
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</el-card>
<MenuDialog
v-model:visible="dialogVisible"
:type="dialogType"
:menu-data="currentMenu"
:preset-parent-id="presetParentId"
:tree="list"
@submit="handleSubmit"
/>
</div>
</template>
@@ -1,141 +1,140 @@
<script setup lang="ts">
/**
* 系统管理-角色(37du 重构版,走 /api/admin/sys/roles)
* 支持:搜索 / 新增 / 编辑 / 授权(菜单+部门树)/ 删除;内置超管角色(id=1 或 label=admin)受保护
*/
import { computed, onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysRoleDel, sysRoles } from '@/api/sys'
import RoleSearch from './modules/role-search.vue'
import RoleEditDialog from './modules/role-edit-dialog.vue'
import RolePermissionDialog from './modules/role-permission-dialog.vue'
const loading = ref(false)
const all = ref<any[]>([])
const keyword = ref('')
const filteredList = computed(() => {
const kw = keyword.value.trim().toLowerCase()
if (!kw) return all.value
return all.value.filter(
(r) =>
String(r.name || '').toLowerCase().includes(kw) ||
String(r.label || '').toLowerCase().includes(kw) ||
String(r.remark || '').toLowerCase().includes(kw)
)
})
async function load() {
loading.value = true
try {
const r = await sysRoles()
all.value = r.items || []
} finally {
loading.value = false
}
}
function handleSearch(params: { keyword: string }) {
keyword.value = params.keyword
}
// ---- 编辑对话框 ----
const editVisible = ref(false)
const editType = ref<'add' | 'edit'>('add')
const currentRole = ref<any>(null)
function openAdd() {
editType.value = 'add'
currentRole.value = null
editVisible.value = true
}
function openEdit(row: any) {
editType.value = 'edit'
currentRole.value = row
editVisible.value = true
}
// ---- 权限对话框 ----
const permVisible = ref(false)
const permRole = ref<any>(null)
function openPerm(row: any) {
permRole.value = row
permVisible.value = true
}
async function handleDel(row: any) {
if (row.protected) {
ElMessage.warning('内置超管角色不允许删除')
return
}
await ElMessageBox.confirm(`确认删除角色「${row.name}」?将一并解除该角色的用户绑定与授权关系`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysRoleDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
editVisible.value = false
load()
}
function handlePermSaved() {
permVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">角色管理</h2>
<div class="flex gap-2">
<el-button type="primary" @click="openAdd">新增角色</el-button>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
</div>
<RoleSearch @search="handleSearch" />
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="filteredList" border stripe>
<el-table-column prop="id" label="ID" width="70" />
<el-table-column prop="name" label="角色名" min-width="140">
<template #default="{ row }">
<span>{{ row.name }}</span>
<el-tag v-if="row.protected" size="small" type="warning" class="ml-1">内置</el-tag>
</template>
</el-table-column>
<el-table-column prop="label" label="标识" min-width="110" />
<el-table-column prop="remark" label="备注" min-width="170" show-overflow-tooltip />
<el-table-column label="数据权限关联上下级" width="150">
<template #default="{ row }">
<el-tag :type="row.relevance ? 'primary' : 'info'" size="small">{{ row.relevance ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="180" fixed="right">
<template #default="{ row }">
<template v-if="!row.protected">
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="primary" size="small" @click="openPerm(row)">授权</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
<span v-else class="text-xs text-gray-400">全部权限</span>
</template>
</el-table-column>
</el-table>
</el-card>
<RoleEditDialog v-model:visible="editVisible" :type="editType" :role-data="currentRole" @submit="handleSubmit" />
<RolePermissionDialog v-model:visible="permVisible" :role-data="permRole" @success="handlePermSaved" />
</div>
</template>
<script setup lang="ts">
/**
* 系统管理-角色(37du 重构版,走 /api/admin/sys/roles)
* 支持:搜索 / 新增 / 编辑 / 授权(菜单+部门树)/ 删除;内置超管角色(id=1 或 label=admin)受保护
*/
import { computed, onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysRoleDel, sysRoles } from '@/api/sys'
import RoleSearch from './modules/role-search.vue'
import RoleEditDialog from './modules/role-edit-dialog.vue'
import RolePermissionDialog from './modules/role-permission-dialog.vue'
const loading = ref(false)
const all = ref<any[]>([])
const keyword = ref('')
const filteredList = computed(() => {
const kw = keyword.value.trim().toLowerCase()
if (!kw) return all.value
return all.value.filter(
(r) =>
String(r.name || '').toLowerCase().includes(kw) ||
String(r.label || '').toLowerCase().includes(kw) ||
String(r.remark || '').toLowerCase().includes(kw)
)
})
async function load() {
loading.value = true
try {
const r = await sysRoles()
all.value = r.items || []
} finally {
loading.value = false
}
}
function handleSearch(params: { keyword: string }) {
keyword.value = params.keyword
}
// ---- 编辑对话框 ----
const editVisible = ref(false)
const editType = ref<'add' | 'edit'>('add')
const currentRole = ref<any>(null)
function openAdd() {
editType.value = 'add'
currentRole.value = null
editVisible.value = true
}
function openEdit(row: any) {
editType.value = 'edit'
currentRole.value = row
editVisible.value = true
}
// ---- 权限对话框 ----
const permVisible = ref(false)
const permRole = ref<any>(null)
function openPerm(row: any) {
permRole.value = row
permVisible.value = true
}
async function handleDel(row: any) {
if (row.protected) {
ElMessage.warning('内置超管角色不允许删除')
return
}
await ElMessageBox.confirm(`确认删除角色「${row.name}」?将一并解除该角色的用户绑定与授权关系`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysRoleDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
editVisible.value = false
load()
}
function handlePermSaved() {
permVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="角色管理" description="RBAC 角色维护与菜单/部门授权">
<template #actions>
<el-button :loading="loading" @click="load"><ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新</el-button>
<el-button type="primary" @click="openAdd"><ArtSvgIcon icon="ri:add-line" class="mr-1" />新增角色</el-button>
</template>
</ArtPageHeader>
<RoleSearch @search="handleSearch" />
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="filteredList" border stripe>
<el-table-column prop="id" label="ID" width="70" />
<el-table-column prop="name" label="角色名" min-width="140">
<template #default="{ row }">
<span>{{ row.name }}</span>
<el-tag v-if="row.protected" size="small" type="warning" class="ml-1">内置</el-tag>
</template>
</el-table-column>
<el-table-column prop="label" label="标识" min-width="110" />
<el-table-column prop="remark" label="备注" min-width="170" show-overflow-tooltip />
<el-table-column label="数据权限关联上下级" width="150">
<template #default="{ row }">
<el-tag :type="row.relevance ? 'primary' : 'info'" size="small">{{ row.relevance ? '是' : '否' }}</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="180" fixed="right">
<template #default="{ row }">
<template v-if="!row.protected">
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="primary" size="small" @click="openPerm(row)">授权</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
<span v-else class="text-xs text-gray-400">全部权限</span>
</template>
</el-table-column>
</el-table>
</el-card>
<RoleEditDialog v-model:visible="editVisible" :type="editType" :role-data="currentRole" @submit="handleSubmit" />
<RolePermissionDialog v-model:visible="permVisible" :role-data="permRole" @success="handlePermSaved" />
</div>
</template>
@@ -1,247 +1,201 @@
<!-- 个人中心页面 -->
<template>
<div class="w-full h-full p-0 bg-transparent border-none shadow-none">
<div class="relative flex-b mt-2.5 max-md:block max-md:mt-1">
<div class="w-112 mr-5 max-md:w-full max-md:mr-0">
<div class="art-card-sm relative p-9 pb-6 overflow-hidden text-center">
<img class="absolute top-0 left-0 w-full h-50 object-cover" src="@imgs/user/bg.webp" />
<img
class="relative z-10 w-20 h-20 mt-30 mx-auto object-cover border-2 border-white rounded-full"
src="@imgs/user/avatar.webp"
/>
<h2 class="mt-5 text-xl font-normal">{{ userInfo.userName }}</h2>
<p class="mt-5 text-sm">专注于用户体验跟视觉设计</p>
<div class="w-75 mx-auto mt-7.5 text-left">
<div class="mt-2.5">
<ArtSvgIcon icon="ri:mail-line" class="text-g-700" />
<span class="ml-2 text-sm">jdkjjfnndf@mall.com</span>
</div>
<div class="mt-2.5">
<ArtSvgIcon icon="ri:user-3-line" class="text-g-700" />
<span class="ml-2 text-sm">交互专家</span>
</div>
<div class="mt-2.5">
<ArtSvgIcon icon="ri:map-pin-line" class="text-g-700" />
<span class="ml-2 text-sm">广东省深圳市</span>
</div>
<div class="mt-2.5">
<ArtSvgIcon icon="ri:dribbble-fill" class="text-g-700" />
<span class="ml-2 text-sm">字节跳动-某某平台部-UED</span>
</div>
</div>
<div class="mt-10">
<h3 class="text-sm font-medium">标签</h3>
<div class="flex flex-wrap justify-center mt-3.5">
<div
v-for="item in lableList"
:key="item"
class="py-1 px-1.5 mr-2.5 mb-2.5 text-xs border border-g-300 rounded"
>
{{ item }}
</div>
</div>
</div>
</div>
</div>
<div class="flex-1 overflow-hidden max-md:w-full max-md:mt-3.5">
<div class="art-card-sm">
<h1 class="p-4 text-xl font-normal border-b border-g-300">基本设置</h1>
<ElForm
:model="form"
class="box-border p-5 [&>.el-row_.el-form-item]:w-[calc(50%-10px)] [&>.el-row_.el-input]:w-full [&>.el-row_.el-select]:w-full"
ref="ruleFormRef"
:rules="rules"
label-width="86px"
label-position="top"
>
<ElRow>
<ElFormItem label="姓名" prop="realName">
<ElInput v-model="form.realName" :disabled="!isEdit" />
</ElFormItem>
<ElFormItem label="性别" prop="sex" class="ml-5">
<ElSelect v-model="form.sex" placeholder="Select" :disabled="!isEdit">
<ElOption
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</ElSelect>
</ElFormItem>
</ElRow>
<ElRow>
<ElFormItem label="昵称" prop="nikeName">
<ElInput v-model="form.nikeName" :disabled="!isEdit" />
</ElFormItem>
<ElFormItem label="邮箱" prop="email" class="ml-5">
<ElInput v-model="form.email" :disabled="!isEdit" />
</ElFormItem>
</ElRow>
<ElRow>
<ElFormItem label="手机" prop="mobile">
<ElInput v-model="form.mobile" :disabled="!isEdit" />
</ElFormItem>
<ElFormItem label="地址" prop="address" class="ml-5">
<ElInput v-model="form.address" :disabled="!isEdit" />
</ElFormItem>
</ElRow>
<ElFormItem label="个人介绍" prop="des" class="h-32">
<ElInput type="textarea" :rows="4" v-model="form.des" :disabled="!isEdit" />
</ElFormItem>
<div class="flex-c justify-end [&_.el-button]:!w-27.5">
<ElButton type="primary" class="w-22.5" v-ripple @click="edit">
{{ isEdit ? '保存' : '编辑' }}
</ElButton>
</div>
</ElForm>
</div>
<div class="art-card-sm my-5">
<h1 class="p-4 text-xl font-normal border-b border-g-300">更改密码</h1>
<ElForm :model="pwdForm" class="box-border p-5" label-width="86px" label-position="top">
<ElFormItem label="当前密码" prop="password">
<ElInput
v-model="pwdForm.password"
type="password"
:disabled="!isEditPwd"
show-password
/>
</ElFormItem>
<ElFormItem label="新密码" prop="newPassword">
<ElInput
v-model="pwdForm.newPassword"
type="password"
:disabled="!isEditPwd"
show-password
/>
</ElFormItem>
<ElFormItem label="确认新密码" prop="confirmPassword">
<ElInput
v-model="pwdForm.confirmPassword"
type="password"
:disabled="!isEditPwd"
show-password
/>
</ElFormItem>
<div class="flex-c justify-end [&_.el-button]:!w-27.5">
<ElButton type="primary" class="w-22.5" v-ripple @click="editPwd">
{{ isEditPwd ? '保存' : '编辑' }}
</ElButton>
</div>
</ElForm>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { useUserStore } from '@/store/modules/user'
import type { FormInstance, FormRules } from 'element-plus'
defineOptions({ name: 'UserCenter' })
const userStore = useUserStore()
const userInfo = computed(() => userStore.getUserInfo)
const isEdit = ref(false)
const isEditPwd = ref(false)
const date = ref('')
const ruleFormRef = ref<FormInstance>()
/**
* 用户信息表单
*/
const form = reactive({
realName: 'John Snow',
nikeName: '皮卡丘',
email: '59301283@mall.com',
mobile: '18888888888',
address: '广东省深圳市宝安区西乡街道101栋201',
sex: '2',
des: 'Art Design Pro 是一款兼具设计美学与高效开发的后台系统.'
})
/**
* 密码修改表单
*/
const pwdForm = reactive({
password: '123456',
newPassword: '123456',
confirmPassword: '123456'
})
/**
* 表单验证规则
*/
const rules = reactive<FormRules>({
realName: [
{ required: true, message: '请输入姓名', trigger: 'blur' },
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
],
nikeName: [
{ required: true, message: '请输入昵称', trigger: 'blur' },
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
],
email: [{ required: true, message: '请输入邮箱', trigger: 'blur' }],
mobile: [{ required: true, message: '请输入手机号码', trigger: 'blur' }],
address: [{ required: true, message: '请输入地址', trigger: 'blur' }],
sex: [{ required: true, message: '请选择性别', trigger: 'blur' }]
})
/**
* 性别选项
*/
const options = [
{ value: '1', label: '男' },
{ value: '2', label: '女' }
]
/**
* 用户标签列表
*/
const lableList: Array<string> = ['专注设计', '很有想法', '辣~', '大长腿', '川妹子', '海纳百川']
onMounted(() => {
getDate()
})
/**
* 根据当前时间获取问候语
*/
const getDate = () => {
const h = new Date().getHours()
if (h >= 6 && h < 9) date.value = '早上好'
else if (h >= 9 && h < 11) date.value = '上午好'
else if (h >= 11 && h < 13) date.value = '中午好'
else if (h >= 13 && h < 18) date.value = '下午好'
else if (h >= 18 && h < 24) date.value = '晚上好'
else date.value = '很晚了,早点睡'
}
/**
* 切换用户信息编辑状态
*/
const edit = () => {
isEdit.value = !isEdit.value
}
/**
* 切换密码编辑状态
*/
const editPwd = () => {
isEditPwd.value = !isEditPwd.value
}
</script>
<!-- 个人中心(37du:accounts 身份体系,自助改密 + 头像上传) -->
<template>
<div class="w-full h-full p-0 bg-transparent border-none shadow-none">
<div class="relative flex-b mt-2.5 max-md:block max-md:mt-1">
<!-- 左:身份卡 -->
<div class="w-112 mr-5 max-md:w-full max-md:mr-0">
<div class="art-card-sm relative p-9 pb-6 overflow-hidden text-center">
<img class="absolute top-0 left-0 w-full h-50 object-cover" src="@imgs/user/bg.webp" />
<img
class="relative z-10 w-20 h-20 mt-30 mx-auto object-cover border-2 border-white rounded-full"
:src="avatarUrl"
@error="avatarError = true"
/>
<h2 class="mt-5 text-xl font-normal">{{ me.nickname || me.account }}</h2>
<p v-if="mustChangePwd" class="mt-2 text-xs text-[var(--el-color-danger)]">
当前为初始密码,请尽快修改
</p>
<div class="w-75 mx-auto mt-6 text-left">
<div class="mt-2.5">
<ArtSvgIcon icon="ri:user-3-line" class="text-g-700" />
<span class="ml-2 text-sm">账号:{{ me.account }}</span>
</div>
<div class="mt-2.5">
<ArtSvgIcon icon="ri:building-line" class="text-g-700" />
<span class="ml-2 text-sm">部门:{{ me.dept || '—' }}</span>
</div>
<div class="mt-2.5">
<ArtSvgIcon icon="ri:shield-check-line" class="text-g-700" />
<span class="ml-2 text-sm">身份:{{ me.is_admin ? '管理员' : '普通用户' }}</span>
</div>
</div>
<div class="mt-8">
<el-upload
:show-file-list="false"
accept=".jpg,.jpeg,.png,.gif,.webp"
:before-upload="beforeAvatarUpload"
:http-request="handleAvatarUpload"
>
<el-button size="small" plain>更换头像</el-button>
</el-upload>
<div class="mt-2 text-[11px] text-gray-400">支持 jpg/png/gif/webp,≤2MB</div>
</div>
</div>
</div>
<!-- 右:修改密码 -->
<div class="flex-1 overflow-hidden max-md:w-full max-md:mt-3.5">
<div class="art-card-sm">
<h1 class="p-4 text-xl font-normal border-b border-g-300">修改密码</h1>
<el-form
ref="pwdFormRef"
:model="pwdForm"
:rules="pwdRules"
class="box-border p-5 max-w-140"
label-width="96px"
label-position="top"
>
<el-form-item label="当前密码" prop="old_password">
<el-input v-model="pwdForm.old_password" type="password" show-password placeholder="输入当前密码" />
</el-form-item>
<el-form-item label="新密码" prop="new_password">
<el-input
v-model="pwdForm.new_password"
type="password"
show-password
placeholder="至少 8 位"
/>
</el-form-item>
<el-form-item label="确认新密码" prop="confirm_password">
<el-input v-model="pwdForm.confirm_password" type="password" show-password placeholder="再次输入新密码" />
</el-form-item>
<div class="flex-c justify-end [&_.el-button]:!w-27.5">
<el-button type="primary" :loading="submitting" v-ripple @click="submitPwd">保存修改</el-button>
</div>
<div class="mt-2 text-xs text-gray-400">
修改成功后当前登录仍有效;执行机侧下次登录请使用新密码。
</div>
</el-form>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { computed, reactive, ref } from 'vue'
import { ElMessage, type FormInstance, type FormRules, type UploadRequestOptions } from 'element-plus'
import { fetchGetUserInfo } from '@/api/auth'
import { changePassword, uploadAvatar } from '@/api/business'
import { useUserStore } from '@/store/modules/user'
import defaultAvatar from '@imgs/user/avatar.webp'
defineOptions({ name: 'UserCenter' })
const userStore = useUserStore()
// ---- 当前身份(/api/admin/me 实时拉取) ----
const me = ref<any>({ account: '', nickname: '', dept: '', is_admin: false, must_change_pwd: false, avatar: '' })
const avatarError = ref(false)
const avatarVersion = ref(Date.now())
const avatarUrl = computed(() => {
if (!me.value.account) return defaultAvatar
if (avatarError.value || !me.value.avatar) return defaultAvatar
return `/api/avatar/${encodeURIComponent(me.value.account)}?v=${avatarVersion.value}`
})
const mustChangePwd = computed(() => !!me.value.must_change_pwd)
async function loadMe() {
const info = await fetchGetUserInfo()
me.value = { ...info }
avatarError.value = false
avatarVersion.value = Date.now()
// 同步全局用户信息(昵称/头像展示用)
userStore.setUserInfo({
...userStore.getUserInfo,
nickname: info.nickname,
account: info.account
} as any)
}
// ---- 头像上传 ----
function beforeAvatarUpload(file: File): boolean {
const okType = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].includes(file.type)
if (!okType) {
ElMessage.error('仅支持 jpg/png/gif/webp')
return false
}
if (file.size > 2 * 1024 * 1024) {
ElMessage.error('头像不能超过 2MB')
return false
}
return true
}
async function handleAvatarUpload(options: UploadRequestOptions) {
await uploadAvatar(options.file as File, me.value.account)
ElMessage.success('头像已更新')
await loadMe()
}
// ---- 修改密码 ----
const pwdFormRef = ref<FormInstance>()
const submitting = ref(false)
const pwdForm = reactive({
old_password: '',
new_password: '',
confirm_password: ''
})
const pwdRules: FormRules = {
old_password: [{ required: true, message: '请输入当前密码', trigger: 'blur' }],
new_password: [
{ required: true, message: '请输入新密码', trigger: 'blur' },
{ min: 8, max: 64, message: '新密码至少 8 位', trigger: 'blur' }
],
confirm_password: [
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
{
validator: (_rule, value, callback) => {
if (value !== pwdForm.new_password) {
callback(new Error('两次输入的新密码不一致'))
} else {
callback()
}
},
trigger: 'blur'
}
]
}
async function submitPwd() {
if (!pwdFormRef.value) return
await pwdFormRef.value.validate()
submitting.value = true
try {
await changePassword({
account: me.value.account,
old_password: pwdForm.old_password,
new_password: pwdForm.new_password
})
ElMessage.success('密码修改成功')
pwdForm.old_password = ''
pwdForm.new_password = ''
pwdForm.confirm_password = ''
pwdFormRef.value?.clearValidate()
await loadMe()
} finally {
submitting.value = false
}
}
loadMe()
</script>
@@ -1,136 +1,135 @@
<script setup lang="ts">
/**
* 系统管理-用户(37du 重构版,走 /api/admin/sys/users)
* 说明:此为控制台登录账号(base_sys_user)管理;业务账号管理在"账号管理"页
* 支持:搜索 / 新增 / 编辑(改密/部门/角色)/ 删除;内置 admin 行受保护
*/
import { computed, onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysUserDel, sysUsers } from '@/api/sys'
import UserSearch from './modules/user-search.vue'
import UserDialog from './modules/user-dialog.vue'
const loading = ref(false)
const list = ref<any[]>([])
const all = ref<any[]>([])
// 搜索条件(客户端过滤)
const keyword = ref('')
const status = ref<number | null>(null)
const filteredList = computed(() => {
return all.value.filter((u) => {
const kw = keyword.value.trim().toLowerCase()
const kwOk =
!kw ||
String(u.username || '').toLowerCase().includes(kw) ||
String(u.nickName || '').toLowerCase().includes(kw) ||
String(u.roleName || '').toLowerCase().includes(kw)
const stOk = status.value === null || status.value === undefined || Number(u.status) === status.value
return kwOk && stOk
})
})
async function load() {
loading.value = true
try {
const r = await sysUsers()
all.value = r.items || []
list.value = all.value
} finally {
loading.value = false
}
}
function handleSearch(params: { keyword: string; status: number | null }) {
keyword.value = params.keyword
status.value = params.status
}
// ---- 新增/编辑对话框 ----
const dialogVisible = ref(false)
const dialogType = ref<'add' | 'edit'>('add')
const currentUser = ref<any>(null)
function openAdd() {
dialogType.value = 'add'
currentUser.value = null
dialogVisible.value = true
}
function openEdit(row: any) {
dialogType.value = 'edit'
currentUser.value = row
dialogVisible.value = true
}
async function handleDel(row: any) {
if (row.usernameProtected) {
ElMessage.warning('内置管理员不允许删除')
return
}
await ElMessageBox.confirm(`确认删除用户「${row.username}」?删除后该控制台账号无法登录`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysUserDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
dialogVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">用户管理(控制台)</h2>
<div class="flex gap-2">
<el-button type="primary" @click="openAdd">新增用户</el-button>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
</div>
<UserSearch @search="handleSearch" />
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="filteredList" border stripe>
<el-table-column prop="id" label="ID" width="70" />
<el-table-column prop="username" label="用户名" min-width="120">
<template #default="{ row }">
<span>{{ row.username }}</span>
<el-tag v-if="row.usernameProtected" size="small" type="warning" class="ml-1">内置</el-tag>
</template>
</el-table-column>
<el-table-column prop="nickName" label="昵称" min-width="110" />
<el-table-column prop="departmentName" label="部门" min-width="110" />
<el-table-column prop="roleName" label="角色" min-width="140" show-overflow-tooltip />
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'danger'" size="small">
{{ row.status === 1 ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" min-width="165" />
<el-table-column label="操作" width="140" fixed="right">
<template #default="{ row }">
<template v-if="!row.usernameProtected">
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
<span v-else class="text-xs text-gray-400">受保护</span>
</template>
</el-table-column>
</el-table>
</el-card>
<UserDialog v-model:visible="dialogVisible" :type="dialogType" :user-data="currentUser" @submit="handleSubmit" />
</div>
</template>
<script setup lang="ts">
/**
* 系统管理-用户(37du 重构版,走 /api/admin/sys/users)
* 说明:此为控制台登录账号(base_sys_user)管理;业务账号管理在"账号管理"页
* 支持:搜索 / 新增 / 编辑(改密/部门/角色)/ 删除;内置 admin 行受保护
*/
import { computed, onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { sysUserDel, sysUsers } from '@/api/sys'
import UserSearch from './modules/user-search.vue'
import UserDialog from './modules/user-dialog.vue'
const loading = ref(false)
const list = ref<any[]>([])
const all = ref<any[]>([])
// 搜索条件(客户端过滤)
const keyword = ref('')
const status = ref<number | null>(null)
const filteredList = computed(() => {
return all.value.filter((u) => {
const kw = keyword.value.trim().toLowerCase()
const kwOk =
!kw ||
String(u.username || '').toLowerCase().includes(kw) ||
String(u.nickName || '').toLowerCase().includes(kw) ||
String(u.roleName || '').toLowerCase().includes(kw)
const stOk = status.value === null || status.value === undefined || Number(u.status) === status.value
return kwOk && stOk
})
})
async function load() {
loading.value = true
try {
const r = await sysUsers()
all.value = r.items || []
list.value = all.value
} finally {
loading.value = false
}
}
function handleSearch(params: { keyword: string; status: number | null }) {
keyword.value = params.keyword
status.value = params.status
}
// ---- 新增/编辑对话框 ----
const dialogVisible = ref(false)
const dialogType = ref<'add' | 'edit'>('add')
const currentUser = ref<any>(null)
function openAdd() {
dialogType.value = 'add'
currentUser.value = null
dialogVisible.value = true
}
function openEdit(row: any) {
dialogType.value = 'edit'
currentUser.value = row
dialogVisible.value = true
}
async function handleDel(row: any) {
if (row.usernameProtected) {
ElMessage.warning('内置管理员不允许删除')
return
}
await ElMessageBox.confirm(`确认删除用户「${row.username}」?删除后该控制台账号无法登录`, '删除确认', {
type: 'warning',
confirmButtonText: '删除',
cancelButtonText: '取消'
})
await sysUserDel(row.id)
ElMessage.success('删除成功')
load()
}
function handleSubmit() {
dialogVisible.value = false
load()
}
onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<ArtPageHeader title="用户管理" description="控制台登录账号(RBAC 用户体系)">
<template #actions>
<el-button :loading="loading" @click="load"><ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新</el-button>
<el-button type="primary" @click="openAdd"><ArtSvgIcon icon="ri:add-line" class="mr-1" />新增用户</el-button>
</template>
</ArtPageHeader>
<UserSearch @search="handleSearch" />
<el-card shadow="never" class="rounded-xl">
<el-table v-loading="loading" :data="filteredList" border stripe>
<el-table-column prop="id" label="ID" width="70" />
<el-table-column prop="username" label="用户名" min-width="120">
<template #default="{ row }">
<span>{{ row.username }}</span>
<el-tag v-if="row.usernameProtected" size="small" type="warning" class="ml-1">内置</el-tag>
</template>
</el-table-column>
<el-table-column prop="nickName" label="昵称" min-width="110" />
<el-table-column prop="departmentName" label="部门" min-width="110" />
<el-table-column prop="roleName" label="角色" min-width="140" show-overflow-tooltip />
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'danger'" size="small">
{{ row.status === 1 ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" min-width="165" />
<el-table-column label="操作" width="140" fixed="right">
<template #default="{ row }">
<template v-if="!row.usernameProtected">
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
<el-button link type="danger" size="small" @click="handleDel(row)">删除</el-button>
</template>
<span v-else class="text-xs text-gray-400">受保护</span>
</template>
</el-table-column>
</el-table>
</el-card>
<UserDialog v-model:visible="dialogVisible" :type="dialogType" :user-data="currentUser" @submit="handleSubmit" />
</div>
</template>
@@ -1,14 +1,70 @@
<script setup lang="ts">
/**
* 升级进度(37du 控制台)
* 按账号展示执行机数量与最后在线(对接 /api/admin/devices/summary)
* 壳子客户端版本分布 + 最新版对比 + 按账号追踪
* 数据:/api/admin/devices/summary(含 client_version 分布与最新壳子版本)
*/
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { fetchDevicesSummary } from '@/api/business'
import ArtPageHeader from '@/components/core/base/art-page-header/index.vue'
const loading = ref(false)
const data = ref<any>({})
const latest = computed(() => String(data.value.latest_shell_version || ''))
/** 版本比较:'1.10' > '1.9';'未知' 单独归类 */
function cmpVersion(a: string, b: string): number {
const pa = String(a || '').split('.').map((s) => parseInt(s, 10) || 0)
const pb = String(b || '').split('.').map((s) => parseInt(s, 10) || 0)
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
const d = (pa[i] || 0) - (pb[i] || 0)
if (d !== 0) return d
}
return 0
}
const total = computed(() => data.value.total || 0)
interface VersionRow {
version: string
count: number
pct: number
state: 'latest' | 'pending' | 'unknown'
}
const versionRows = computed<VersionRow[]>(() => {
const rows = (data.value.by_version || []).map((r: any) => {
const v = String(r.client_version || '未知')
const known = v !== '未知'
let state: 'latest' | 'pending' | 'unknown' = 'unknown'
if (known && latest.value) state = cmpVersion(v, latest.value) >= 0 ? 'latest' : 'pending'
else if (known && !latest.value) state = 'latest'
return { version: v, count: Number(r.count), pct: total.value ? Math.round((Number(r.count) / total.value) * 100) : 0, state }
})
// 最新版在前,未知殿后
return rows.sort((a: VersionRow, b: VersionRow) => {
const rank = (s: VersionRow['state']) => (s === 'latest' ? 0 : s === 'pending' ? 1 : 2)
return rank(a.state) - rank(b.state) || b.count - a.count
})
})
const statCards = computed(() => {
const latestCount = versionRows.value.filter((r) => r.state === 'latest').reduce((s, r) => s + r.count, 0)
const pendingCount = versionRows.value.filter((r) => r.state === 'pending').reduce((s, r) => s + r.count, 0)
const unknownCount = versionRows.value.filter((r) => r.state === 'unknown').reduce((s, r) => s + r.count, 0)
return [
{ title: '设备总数', count: total.value, icon: 'ri:computer-line', iconStyle: 'bg-[#377dff]', desc: '已上报执行机' },
{ title: '已是最新', count: latestCount, icon: 'ri:checkbox-circle-line', iconStyle: 'bg-[#00b42a]', desc: latest.value ? `最新版本 v${latest.value}` : '未配置壳子版本源' },
{ title: '待升级', count: pendingCount, icon: 'ri:upload-cloud-2-line', iconStyle: 'bg-[#ff7d00]', desc: '低于最新版本' },
{ title: '版本未知', count: unknownCount, icon: 'ri:question-line', iconStyle: 'bg-[#f5319d]', desc: '旧壳未上报版本' }
]
})
const stateTag = (s: VersionRow['state']): { type: 'success' | 'warning' | 'info'; label: string } =>
s === 'latest' ? { type: 'success', label: '最新' } : s === 'pending' ? { type: 'warning', label: '待升级' } : { type: 'info', label: '未上报' }
const barColor = (s: string) => (s === 'latest' ? '#00b42a' : s === 'pending' ? '#ff7d00' : '#c0c4cc')
async function load() {
loading.value = true
try {
@@ -22,25 +78,92 @@ onMounted(load)
</script>
<template>
<div class="p-5 space-y-4">
<div class="flex items-center justify-between">
<h2 class="text-lg font-bold">升级进度</h2>
<el-button :loading="loading" @click="load">刷新</el-button>
</div>
<el-card shadow="never" class="rounded-xl">
<template #header>
<span class="font-semibold">执行机汇总(共 {{ data.total || 0 }} 台)</span>
<div class="p-5">
<ArtPageHeader title="升级进度" description="壳子客户端版本分布与按账号升级追踪">
<template #actions>
<el-tag v-if="latest" type="success" effect="light" size="large">
<ArtSvgIcon icon="ri:rocket-line" class="mr-1" />最新壳子版本 v{{ latest }}
</el-tag>
<el-tag v-else type="info" effect="plain" size="large">未配置壳子版本源(大文件源 shell 分类)</el-tag>
<el-button :loading="loading" @click="load">
<ArtSvgIcon icon="ri:refresh-line" class="mr-1" />刷新
</el-button>
</template>
<el-table :data="data.by_account || []" border stripe>
<el-table-column label="账号" min-width="120">
<template #default="{ row }">{{ row.nickname || row.account }}</template>
</el-table-column>
<el-table-column prop="account" label="工号" width="120" />
<el-table-column prop="dept" label="部门" width="120" />
<el-table-column prop="device_count" label="设备数" width="90" />
<el-table-column prop="last_seen" label="最后在线" min-width="170" />
</el-table>
</el-card>
</ArtPageHeader>
<!-- 汇总卡 -->
<el-row :gutter="14" class="mb-3.5">
<el-col :xs="12" :md="6" 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-row :gutter="14">
<!-- 版本分布 -->
<el-col :md="10" :xs="24">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">版本分布</span></template>
<div class="space-y-4">
<div v-for="r in versionRows" :key="r.version">
<div class="flex items-center justify-between mb-1.5">
<div class="flex items-center gap-2">
<span class="text-sm font-medium">v{{ r.version }}</span>
<el-tag size="small" :type="stateTag(r.state).type" effect="light">{{ stateTag(r.state).label }}</el-tag>
</div>
<span class="text-sm text-g-600">{{ r.count }} 台 · {{ r.pct }}%</span>
</div>
<el-progress
:percentage="r.pct"
:stroke-width="10"
:show-text="false"
:color="barColor(r.state)"
/>
</div>
<el-empty v-if="!versionRows.length" description="还没有设备上报" :image-size="70" />
</div>
</el-card>
</el-col>
<!-- 按账号追踪 -->
<el-col :md="14" :xs="24">
<el-card shadow="never" class="rounded-xl">
<template #header><span class="font-semibold">按账号追踪</span></template>
<el-table :data="data.by_account || []" size="small" v-loading="loading">
<el-table-column label="用户" min-width="170">
<template #default="{ row }">
<div class="flex items-center gap-2.5">
<div class="size-7 rounded-lg grid place-items-center bg-[var(--el-color-primary-light-9)] text-[var(--el-color-primary)] text-xs font-bold shrink-0">
{{ (row.nickname || row.account || '?').slice(0, 1).toUpperCase() }}
</div>
<div>
<div class="text-sm leading-tight">{{ row.nickname || row.account }}</div>
<div class="text-xs text-gray-400">{{ row.account }} · {{ row.dept || '—' }}</div>
</div>
</div>
</template>
</el-table-column>
<el-table-column label="客户端版本" width="150" align="center">
<template #default="{ row }">
<el-tag
size="small"
:type="row.client_version === '未知' ? 'info' : (latest && cmpVersion(row.client_version, latest) < 0 ? 'warning' : 'success')"
effect="light"
>v{{ row.client_version }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="device_count" label="设备数" width="80" align="center" />
<el-table-column prop="last_seen" label="最近在线" width="165" />
</el-table>
<el-empty v-if="!(data.by_account || []).length && !loading" description="暂无数据" :image-size="70" />
</el-card>
</el-col>
</el-row>
</div>
</template>