feat: 完成插件管理系统产品化P0闭环落地
此提交实现完整的插件管理产品化闭环: 1. 中心机新增Ed25519密钥、审计/运行上报表、插件扩展字段,实现票据/管控清单签发、鉴权下载能力 2. 部署端新增设备级单活调度器、用户私有插件库、离线/联网校验链、插件下载安装流程 3. 控制面与部署前端同步更新UI与接口适配,新增审计页、插件管理增强功能 4. 修复两个工作流脚本的过滤与Excel导出问题,优化打包依赖与日志面板 5. 新增完整架构设计与实施文档
This commit is contained in:
@@ -1,137 +1,227 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="page-head">
|
||||
<div class="page">
|
||||
<div class="page-head cp-rise">
|
||||
<div>
|
||||
<h3>权限授权</h3>
|
||||
<h3>权限授权 <span class="badge">Grants</span></h3>
|
||||
<p>按账号勾选可用插件与可登录平台,保存时仅提交差异项</p>
|
||||
</div>
|
||||
<el-button :icon="Refresh" :loading="overviewBusy" @click="refresh">刷新</el-button>
|
||||
<n-button :loading="overviewBusy" @click="refresh">
|
||||
<template #icon><n-icon><Refresh /></n-icon></template>刷新
|
||||
</n-button>
|
||||
</div>
|
||||
|
||||
<el-card shadow="never" class="block">
|
||||
<el-form inline>
|
||||
<el-form-item label="选择账号">
|
||||
<el-select v-model="account" placeholder="选择账号…" style="width: 240px" filterable>
|
||||
<el-option v-for="a in accounts" :key="a.account" :value="a.account"
|
||||
:label="a.dept ? `${a.account} · ${a.dept}` : a.account" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="account">
|
||||
<el-text type="info" size="small">
|
||||
{{ account }} · 已授权 {{ checked.length }} 个插件 / {{ platChecked.length }} 个平台
|
||||
</el-text>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
<n-card class="block cp-rise" :bordered="false">
|
||||
<n-form inline>
|
||||
<n-form-item label="选择账号">
|
||||
<n-select
|
||||
v-model:value="account"
|
||||
:options="accountOptions"
|
||||
placeholder="选择账号…"
|
||||
style="width: 240px"
|
||||
filterable
|
||||
clearable
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item v-if="account">
|
||||
<span class="sel-hint">{{ account }} · 已授权 {{ grantedIds.length }} 个插件 / {{ platChecked.length }} 个平台</span>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</n-card>
|
||||
|
||||
<template v-if="account">
|
||||
<el-card shadow="never" class="block">
|
||||
<n-card class="block cp-rise" :bordered="false">
|
||||
<template #header>
|
||||
<div class="card-head"><b>插件授权</b>
|
||||
<el-button type="primary" size="small" :loading="saving" @click="saveGrant">保存插件授权</el-button>
|
||||
<div class="card-head">
|
||||
<b>插件授权</b>
|
||||
<n-button type="primary" size="small" :loading="saving" @click="saveGrant">保存插件授权</n-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-checkbox-group v-model="checked" v-if="plugins.length">
|
||||
<el-checkbox v-for="p in plugins" :key="p.id" :value="p.id" class="ck">
|
||||
{{ p.id }}<span class="dim">({{ p.name }})</span>
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
<el-empty description="暂无插件,请先在「插件管理」上传" :image-size="60" v-else />
|
||||
</el-card>
|
||||
<n-checkbox-group v-model:value="grantedIds" v-if="plugins.length">
|
||||
<div class="ck-grid">
|
||||
<n-checkbox v-for="p in plugins" :key="p.id" :value="p.id" class="ck">
|
||||
<span class="ck-main">
|
||||
<span>{{ p.id }}<span class="dim">({{ p.name }})</span></span>
|
||||
<span class="ck-sub" v-if="grantState[p.id]?.granted">
|
||||
<n-switch size="small" :value="grantState[p.id].canRun"
|
||||
@update:value="v => setGrant(p.id, { canRun: v })">
|
||||
<template #checked>可运行</template>
|
||||
<template #unchecked>禁运行</template>
|
||||
</n-switch>
|
||||
<n-switch size="small" :value="grantState[p.id].canDownload"
|
||||
@update:value="v => setGrant(p.id, { canDownload: v })">
|
||||
<template #checked>可下载</template>
|
||||
<template #unchecked>禁下载</template>
|
||||
</n-switch>
|
||||
</span>
|
||||
</span>
|
||||
</n-checkbox>
|
||||
</div>
|
||||
</n-checkbox-group>
|
||||
<n-empty v-else description="暂无插件,请先在「插件管理」上传" size="small" />
|
||||
</n-card>
|
||||
|
||||
<el-card shadow="never" class="block">
|
||||
<n-card class="block cp-rise" :bordered="false">
|
||||
<template #header>
|
||||
<div class="card-head"><b>平台授权</b>
|
||||
<el-button type="primary" size="small" :loading="savingPlat" @click="savePlat">保存平台授权</el-button>
|
||||
<div class="card-head">
|
||||
<b>平台授权</b>
|
||||
<n-button type="primary" size="small" :loading="savingPlat" @click="savePlat">保存平台授权</n-button>
|
||||
</div>
|
||||
</template>
|
||||
<el-checkbox-group v-model="platChecked">
|
||||
<el-checkbox v-for="pf in PLATFORM_OPTS" :key="pf.id" :value="pf.id" class="ck">
|
||||
{{ pf.label }}<span class="dim">({{ pf.id }})</span>
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-card>
|
||||
<n-checkbox-group v-model:value="platChecked">
|
||||
<div class="ck-grid">
|
||||
<n-checkbox v-for="pf in PLATFORM_OPTS" :key="pf.id" :value="pf.id" class="ck">
|
||||
{{ pf.label }}<span class="dim">({{ pf.id }})</span>
|
||||
</n-checkbox>
|
||||
</div>
|
||||
</n-checkbox-group>
|
||||
</n-card>
|
||||
</template>
|
||||
<el-empty v-else description="先在上方选择一个账号" :image-size="90" />
|
||||
|
||||
<n-empty v-else description="先在上方选择一个账号" class="no-acc cp-rise" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { Refresh } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { overview, overviewBusy, loadOverview } from '../store'
|
||||
import { adminGrant, adminPlatformGrant } from '../api'
|
||||
import { adminGrant, adminPlatformGrant, adminPlatforms } from '../api'
|
||||
import { message } from '../naive'
|
||||
|
||||
const PLATFORM_OPTS = [
|
||||
{ id: 'hr', label: 'HR 系统' },
|
||||
{ id: 'oa', label: 'OA 系统' },
|
||||
]
|
||||
const PLATFORM_OPTS = ref([])
|
||||
|
||||
const plugins = computed(() => overview.value?.plugins || [])
|
||||
const accounts = computed(() => overview.value?.accounts || [])
|
||||
const accountOptions = computed(() => accounts.value.map(a => ({
|
||||
label: a.dept ? `${a.account} · ${a.dept}` : a.account,
|
||||
value: a.account,
|
||||
})))
|
||||
|
||||
const account = ref('')
|
||||
const checked = ref([])
|
||||
const grantedIds = ref([])
|
||||
const grantState = ref({}) // plugin_id -> { granted, canRun, canDownload }
|
||||
const platChecked = ref([])
|
||||
const saving = ref(false)
|
||||
const savingPlat = ref(false)
|
||||
let heldPlugins = new Set()
|
||||
let heldGrantState = {} // 已保存快照,用于差异比对
|
||||
let heldPlatforms = new Set()
|
||||
|
||||
function setGrant(pid, patch) {
|
||||
grantState.value[pid] = { ...grantState.value[pid], ...patch }
|
||||
grantState.value = { ...grantState.value }
|
||||
}
|
||||
|
||||
// 选中账号即自动载入其现有授权
|
||||
watch(account, (acc) => {
|
||||
const a = accounts.value.find(x => x.account === acc)
|
||||
heldPlugins = new Set(a?.plugins || [])
|
||||
const state = {}
|
||||
;(a?.plugins || []).forEach(pid => {
|
||||
const g = a?.grants?.[pid] || {}
|
||||
state[pid] = { granted: true, canRun: g.canRun !== false, canDownload: g.canDownload !== false }
|
||||
})
|
||||
heldGrantState = JSON.parse(JSON.stringify(state))
|
||||
grantState.value = JSON.parse(JSON.stringify(state))
|
||||
grantedIds.value = [...(a?.plugins || [])]
|
||||
heldPlatforms = new Set(a?.platforms || [])
|
||||
checked.value = [...heldPlugins]
|
||||
platChecked.value = [...heldPlatforms]
|
||||
})
|
||||
|
||||
// 勾选/取消勾选插件时同步 granted 状态
|
||||
watch(grantedIds, (ids) => {
|
||||
const state = { ...grantState.value }
|
||||
ids.forEach(pid => {
|
||||
if (!state[pid]) state[pid] = { granted: true, canRun: true, canDownload: true }
|
||||
else state[pid].granted = true
|
||||
})
|
||||
Object.keys(state).forEach(pid => {
|
||||
if (!ids.includes(pid)) state[pid].granted = false
|
||||
})
|
||||
grantState.value = state
|
||||
})
|
||||
|
||||
async function refresh() {
|
||||
try { await loadOverview(true) } catch (e) { ElMessage.error('读取失败:' + (e.message || e)) }
|
||||
try { await loadOverview(true) } catch (e) { message.error('读取失败:' + (e.message || e)) }
|
||||
}
|
||||
// 拉取可授权平台列表(后端只读接口,替代写死 hr/oa)
|
||||
async function loadPlatforms() {
|
||||
try {
|
||||
const r = await adminPlatforms()
|
||||
PLATFORM_OPTS.value = (r.platforms || []).map(p => ({ id: p.id, label: p.label }))
|
||||
} catch (e) { message.error('平台列表读取失败:' + (e.message || e)) }
|
||||
}
|
||||
|
||||
async function saveGrant() {
|
||||
const acc = account.value; if (!acc) return
|
||||
const want = new Set(checked.value)
|
||||
let n = 0
|
||||
saving.value = true
|
||||
for (const pid of new Set([...want, ...heldPlugins])) {
|
||||
const g = want.has(pid)
|
||||
if (g === heldPlugins.has(pid)) continue
|
||||
try { await adminGrant({ account: acc, plugin_id: pid, granted: g }); n++ }
|
||||
catch (e) { ElMessage.error(e.message || e) }
|
||||
}
|
||||
heldPlugins = want
|
||||
saving.value = false
|
||||
await refresh()
|
||||
ElMessage.success(n ? `已更新 ${n} 项插件授权` : '插件授权无需变更')
|
||||
try {
|
||||
const want = {}
|
||||
Object.entries(grantState.value).forEach(([pid, s]) => {
|
||||
if (s.granted) want[pid] = s
|
||||
})
|
||||
const allPids = [...new Set([...Object.keys(want), ...Object.keys(heldGrantState)])]
|
||||
const diff = allPids.filter(pid => {
|
||||
const w = want[pid]; const h = heldGrantState[pid]
|
||||
if (!!w !== !!h) return true
|
||||
if (w && h) return w.canRun !== h.canRun || w.canDownload !== h.canDownload
|
||||
return false
|
||||
})
|
||||
if (!diff.length) { message.info('插件授权无需变更'); return }
|
||||
const results = await Promise.allSettled(diff.map(pid => adminGrant({
|
||||
account: acc, plugin_id: pid, granted: !!want[pid],
|
||||
can_run: want[pid]?.canRun !== false, can_download: want[pid]?.canDownload !== false,
|
||||
})))
|
||||
const failed = results.filter(r => r.status === 'rejected')
|
||||
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
|
||||
if (failed.length) { message.warning(`插件授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return }
|
||||
message.success(`已更新 ${diff.length} 项插件授权`)
|
||||
heldGrantState = JSON.parse(JSON.stringify(grantState.value))
|
||||
await refresh()
|
||||
} finally { saving.value = false }
|
||||
}
|
||||
async function savePlat() {
|
||||
const acc = account.value; if (!acc) return
|
||||
const want = new Set(platChecked.value)
|
||||
let n = 0
|
||||
savingPlat.value = true
|
||||
for (const pf of new Set([...want, ...heldPlatforms])) {
|
||||
const g = want.has(pf)
|
||||
if (g === heldPlatforms.has(pf)) continue
|
||||
try { await adminPlatformGrant({ account: acc, platform_id: pf, granted: g }); n++ }
|
||||
catch (e) { ElMessage.error(e.message || e) }
|
||||
}
|
||||
heldPlatforms = want
|
||||
savingPlat.value = false
|
||||
await refresh()
|
||||
ElMessage.success(n ? `已更新 ${n} 项平台授权` : '平台授权无需变更')
|
||||
try {
|
||||
const want = new Set(platChecked.value)
|
||||
const diff = [...new Set([...want, ...heldPlatforms])].filter(pf => want.has(pf) !== heldPlatforms.has(pf))
|
||||
if (!diff.length) { message.info('平台授权无需变更'); return }
|
||||
const results = await Promise.allSettled(diff.map(pf => adminPlatformGrant({
|
||||
account: acc, platform_id: pf, granted: want.has(pf),
|
||||
})))
|
||||
const failed = results.filter(r => r.status === 'rejected')
|
||||
failed.forEach(r => message.error(r.reason?.message || String(r.reason)))
|
||||
if (failed.length) { message.warning(`平台授权:${diff.length - failed.length} 项成功,${failed.length} 项失败`); return }
|
||||
message.success(`已更新 ${diff.length} 项平台授权`)
|
||||
heldPlatforms = new Set(platChecked.value)
|
||||
await refresh()
|
||||
} finally { savingPlat.value = false }
|
||||
}
|
||||
onMounted(refresh)
|
||||
onMounted(() => { refresh(); loadPlatforms() })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
|
||||
.page-head h3 { margin: 0 0 4px; font-size: 17px; }
|
||||
.page-head p { margin: 0; font-size: 12px; color: var(--el-text-color-secondary); }
|
||||
.block { margin-bottom: 14px; }
|
||||
.card-head { display: flex; justify-content: space-between; align-items: center; }
|
||||
.ck { margin-right: 18px; }
|
||||
.dim { color: var(--el-text-color-secondary); font-size: 12px; margin-left: 2px; }
|
||||
.sel-hint { font-size: 12px; color: var(--cp-ink-2); }
|
||||
.no-acc { margin-top: 60px; }
|
||||
|
||||
/* 授权项:卡片式勾选 */
|
||||
.ck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
|
||||
.ck-main { display: flex; flex-direction: column; gap: 8px; min-width: 0; line-height: 1.2; }
|
||||
.ck-sub { display: flex; align-items: center; gap: 10px; }
|
||||
:deep(.n-checkbox) {
|
||||
display: flex; align-items: center; margin: 0;
|
||||
width: 100%;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--cp-border);
|
||||
border-radius: 12px;
|
||||
background: rgba(255, 255, 255, .65);
|
||||
transition: border-color .18s, background .18s, box-shadow .18s;
|
||||
}
|
||||
:deep(.n-checkbox:hover) { border-color: rgba(59, 108, 255, .4); }
|
||||
:deep(.n-checkbox.n-checkbox--checked) {
|
||||
border-color: rgba(59, 108, 255, .45);
|
||||
background: linear-gradient(135deg, rgba(59, 108, 255, .08), rgba(34, 199, 232, .06));
|
||||
box-shadow: 0 8px 18px -10px rgba(59, 108, 255, .35);
|
||||
}
|
||||
:deep(.n-checkbox .n-checkbox__label) { padding-left: 4px; flex: 1; min-width: 0; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user