Files
37duAutomation/desktop/controlplane-next/frontend/src/views/grants/index.vue
T
puddy 60c28fe507 feat: 重构控制台为37du自动化平台,新增权限授权与通知中心功能
- 更新系统名称、登录页宣传文案为37du平台相关内容
- 移除聊天功能相关代码与配置
- 新增客户端版本上报字段与设备统计接口
- 新增通知中心功能(60s轮询、localStorage已读标记)
- 新增权限授权工作台相关接口与页面
- 新增统一页头组件ArtPageHeader
- 调整快速入口配置指向真实功能页面
- 修复控制面地址为内网生产库
2026-10-15 18:01:29 +08:00

95 lines
4.1 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/**
* 权限授权工作台(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 { 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 activeTab = ref<'user' | 'plugin' | 'matrix'>('user')
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 {
matrix.value = await fetchGrantsMatrix()
} finally {
loading.value = false
}
}
onMounted(loadMatrix)
</script>
<template>
<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>