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

- 更新系统名称、登录页宣传文案为37du平台相关内容
- 移除聊天功能相关代码与配置
- 新增客户端版本上报字段与设备统计接口
- 新增通知中心功能(60s轮询、localStorage已读标记)
- 新增权限授权工作台相关接口与页面
- 新增统一页头组件ArtPageHeader
- 调整快速入口配置指向真实功能页面
- 修复控制面地址为内网生产库
This commit is contained in:
2026-10-15 18:01:29 +08:00
parent f27639777f
commit 60c28fe507
49 changed files with 4925 additions and 2904 deletions
@@ -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>