feat: 重构控制台为37du自动化平台,新增权限授权与通知中心功能
- 更新系统名称、登录页宣传文案为37du平台相关内容 - 移除聊天功能相关代码与配置 - 新增客户端版本上报字段与设备统计接口 - 新增通知中心功能(60s轮询、localStorage已读标记) - 新增权限授权工作台相关接口与页面 - 新增统一页头组件ArtPageHeader - 调整快速入口配置指向真实功能页面 - 修复控制面地址为内网生产库
This commit is contained in:
+130
@@ -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>
|
||||
Reference in New Issue
Block a user