restore: 恢复 11-06~11-09 本地未提交改动
- libs: 新增 hr_sdk / hotel_report / dingtalk,更新 desktopauto - controlplane-next: SDK 管理模块(controller/entity/migrations)与前端视图 - electron-shell: 插件同步、注册表、runner 调整 - plugins: XQ0035/XQ0041/XQ0042/XQ0045_XQ0046/XQ0048/XQ0076/XQ0078 等版本更新 - tests/tools: 新增 SDK 兼容性检查与打包工具(sdk_pack.py、sdk_compat_check.py)
This commit is contained in:
@@ -15,9 +15,21 @@ export function fetchStats() {
|
||||
return request.get<any>({ url: '/api/admin/stats' })
|
||||
}
|
||||
|
||||
/** 插件列表 */
|
||||
export function fetchPlugins(params: { page?: number; page_size?: number; q?: string }) {
|
||||
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/plugins', params })
|
||||
/** 插件列表(支持关键字/分类/状态多选/快捷标记/排序) */
|
||||
export function fetchPlugins(params: {
|
||||
page?: number
|
||||
page_size?: number
|
||||
q?: string
|
||||
status?: string
|
||||
category?: string
|
||||
flags?: string
|
||||
sort?: string
|
||||
order?: string
|
||||
}) {
|
||||
return request.get<{ items: any[]; total: number; stats?: Record<string, number> }>({
|
||||
url: '/api/admin/plugins',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
/** 上传发布插件包(multipart;channel=test 进测试通道,仅管理员可见) */
|
||||
@@ -37,6 +49,35 @@ export function patchPlugin(plugin_id: string, body: any) {
|
||||
return request.post<any>({ url: '/api/admin/plugin/patch', params: { plugin_id }, data: body })
|
||||
}
|
||||
|
||||
// ==================== SDK(挂载到执行机的纯 Python 运行库) ====================
|
||||
|
||||
/** SDK 列表(含版本历史与当前可用版本) */
|
||||
export function fetchSdks() {
|
||||
return request.get<{ items: any[]; total: number }>({ url: '/api/admin/sdks' })
|
||||
}
|
||||
|
||||
/** 上传发布 SDK 包(multipart;channel=test 进测试通道,仅管理员账号可同步) */
|
||||
export function uploadSdk(file: File, params: { sdk_id: string; name?: string; version: string; channel?: string }) {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
return request.post<any>({ url: '/api/admin/sdk-pkg', data: fd, params, timeout: 300000 })
|
||||
}
|
||||
|
||||
/** 更新 SDK 状态(published=把在测版本转正) */
|
||||
export function patchSdk(sdk_id: string, body: any) {
|
||||
return request.post<any>({ url: '/api/admin/sdk/patch', params: { sdk_id }, data: body })
|
||||
}
|
||||
|
||||
/** 撤回某个 SDK 版本(执行机下次同步回落到最高可用版本) */
|
||||
export function yankSdk(sdk_id: string, version: string) {
|
||||
return request.post<any>({ url: '/api/admin/sdk-yank', data: { sdk_id, version } })
|
||||
}
|
||||
|
||||
/** 删除 SDK(连带版本与磁盘包文件) */
|
||||
export function deleteSdk(sdk_id: string) {
|
||||
return request.post<any>({ url: '/api/admin/sdk/delete', data: { sdk_id } })
|
||||
}
|
||||
|
||||
// ==================== 字典(可维护枚举,如场景分类 plugin_category) ====================
|
||||
|
||||
/** 字典项列表(sort,id 升序) */
|
||||
|
||||
@@ -1,211 +1,300 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 授权矩阵总览(账号 × 插件)—— 面向插件持续膨胀(25 → 50 → 100+)
|
||||
*
|
||||
* 纯横向铺列在几十个插件时就没法用了,所以按「降维」思路收敛:
|
||||
* 1) 分类 Tab:一次只看一个分类(财务 / 人事 / 其他…),列数天然有界;
|
||||
* 2) 列分页:单分类也很长时按每页 N 列翻页(默认 15),账号列与行始终不变、只翻插件列;
|
||||
* 3) 列筛选:插件多选(空=全部)/ 搜索 / 仅看已授权插件,选择记 localStorage;
|
||||
* 4) 两行 sticky 表头(分类分组 + 插件)+ 悬停列高亮 + 点击列头只看该插件,长表也能横向跟踪。
|
||||
* 单元格仍是 [⬇下载][▶运行] 徽标,点一下切一位,两位都关掉自动整行撤销。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { grantPlugin } from '@/api/business'
|
||||
/**
|
||||
* 授权矩阵总览(账号 × 插件)—— 面向插件持续膨胀(25 → 50 → 100+)
|
||||
*
|
||||
* 可读性设计(每个格子 = 一个账号对一个插件的授权):
|
||||
* 1) 格子内两个中文按钮「下」(允许下载)/「运」(允许运行),亮绿=已开、灰色空=未开,
|
||||
* 不再用 ⬇ ▶ 这类需要猜的符号;两个都关 = 自动撤销整条授权;
|
||||
* 2) 格子淡色底一眼扫状态:绿=完整授权、黄=只开了一项、白=未授权,图例与格子同款样式;
|
||||
* 3) 分类 Tab + 列分页 + 列筛选,避免几十个插件时横铺到天边;
|
||||
* 4) 列头显示「已授权 N 人」,行首显示已授权插件数,避免逐个格子去数;
|
||||
* 5) 列头眼睛按钮 = 只看该插件(不用点整列头,避免误触);
|
||||
* 6) 左右双向 sticky(账号列 + 两行表头)+ 悬停列高亮,长表也不串行。
|
||||
*/
|
||||
import { computed, ref, watch } 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 LS_COLS = 'xq.grants.matrix.cols'
|
||||
const LS_COMPACT = 'xq.grants.matrix.compact'
|
||||
const LS_PAGE_SIZE = 'xq.grants.matrix.pageSize'
|
||||
const PAGE_SIZES = [10, 15, 20, 30, 50]
|
||||
|
||||
function readCols(): string[] {
|
||||
try {
|
||||
const raw = localStorage.getItem(LS_COLS)
|
||||
const arr = raw ? JSON.parse(raw) : []
|
||||
return Array.isArray(arr) ? arr.map(String) : []
|
||||
} catch {
|
||||
return []
|
||||
interface Props {
|
||||
matrix: any
|
||||
}
|
||||
}
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<{ (e: 'changed'): void }>()
|
||||
|
||||
function readPageSize(): number {
|
||||
const n = Number(localStorage.getItem(LS_PAGE_SIZE))
|
||||
return PAGE_SIZES.includes(n) ? n : 15
|
||||
}
|
||||
const LS_COLS = 'xq.grants.matrix.cols'
|
||||
const LS_COMPACT = 'xq.grants.matrix.compact'
|
||||
const LS_PAGE_SIZE = 'xq.grants.matrix.pageSize'
|
||||
const PAGE_SIZES = [10, 15, 20, 30, 50]
|
||||
|
||||
// 账号侧
|
||||
const kw = ref('')
|
||||
const deptFilter = ref<string | null>(null)
|
||||
const onlyGranted = ref(false)
|
||||
|
||||
// 插件侧
|
||||
const picked = ref<string[]>(readCols())
|
||||
const pluginKw = ref('')
|
||||
const onlyGrantedPlugins = ref(false)
|
||||
const catFilter = ref('')
|
||||
const compact = ref(localStorage.getItem(LS_COMPACT) === '1')
|
||||
const pageSize = ref(readPageSize())
|
||||
const page = ref(1)
|
||||
|
||||
const plugins = computed<any[]>(() => props.matrix.plugins || [])
|
||||
const grants = computed<any[]>(() => props.matrix.grants || [])
|
||||
|
||||
watch(picked, v => localStorage.setItem(LS_COLS, JSON.stringify(v)), { deep: true })
|
||||
watch(compact, v => localStorage.setItem(LS_COMPACT, v ? '1' : '0'))
|
||||
watch(pageSize, v => localStorage.setItem(LS_PAGE_SIZE, String(v)))
|
||||
|
||||
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 catOf = (p: any) => String(p.category || '未分类')
|
||||
|
||||
/** 分类清单(带插件数),只有一个分类时不显示 Tab */
|
||||
const categories = computed(() => {
|
||||
const map = new Map<string, number>()
|
||||
for (const p of plugins.value) map.set(catOf(p), (map.get(catOf(p)) || 0) + 1)
|
||||
return [...map.entries()].map(([label, count]) => ({ label, count }))
|
||||
})
|
||||
|
||||
/** grants 快速索引:(account, pluginId) -> {can_download, can_run} */
|
||||
const grantIndex = computed(() => {
|
||||
const idx = new Map<string, any>()
|
||||
for (const g of grants.value) 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 grantedPluginIds = computed(() => new Set(grants.value.map((g: any) => String(g.plugin_id))))
|
||||
|
||||
/** 插件列过滤(分类 Tab + 多选 + 搜索 + 仅已授权) */
|
||||
const visiblePlugins = computed<any[]>(() => {
|
||||
const kwv = pluginKw.value.trim().toLowerCase()
|
||||
return plugins.value.filter((p: any) => {
|
||||
if (catFilter.value && catOf(p) !== catFilter.value) return false
|
||||
if (picked.value.length && !picked.value.includes(p.id)) return false
|
||||
if (onlyGrantedPlugins.value && !grantedPluginIds.value.has(p.id)) return false
|
||||
if (kwv) {
|
||||
const hay = `${p.name || ''} ${p.id} ${catOf(p)}`.toLowerCase()
|
||||
if (!hay.includes(kwv)) return false
|
||||
function readCols(): string[] {
|
||||
try {
|
||||
const raw = localStorage.getItem(LS_COLS)
|
||||
const arr = raw ? JSON.parse(raw) : []
|
||||
return Array.isArray(arr) ? arr.map(String) : []
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function readPageSize(): number {
|
||||
const n = Number(localStorage.getItem(LS_PAGE_SIZE))
|
||||
return PAGE_SIZES.includes(n) ? n : 15
|
||||
}
|
||||
|
||||
// 账号侧
|
||||
const kw = ref('')
|
||||
const deptFilter = ref<string | null>(null)
|
||||
const onlyGranted = ref(false)
|
||||
|
||||
// 插件侧
|
||||
const picked = ref<string[]>(readCols())
|
||||
const pluginKw = ref('')
|
||||
const onlyGrantedPlugins = ref(false)
|
||||
const catFilter = ref('')
|
||||
const compact = ref(localStorage.getItem(LS_COMPACT) === '1')
|
||||
const pageSize = ref(readPageSize())
|
||||
const page = ref(1)
|
||||
|
||||
const plugins = computed<any[]>(() => props.matrix.plugins || [])
|
||||
|
||||
/** 只统计真正生效的授权行(两个权限都关的空行不算) */
|
||||
const activeGrants = computed<any[]>(() =>
|
||||
(props.matrix.grants || []).filter((g: any) => g.can_download || g.can_run)
|
||||
)
|
||||
|
||||
watch(picked, (v) => localStorage.setItem(LS_COLS, JSON.stringify(v)), { deep: true })
|
||||
watch(compact, (v) => localStorage.setItem(LS_COMPACT, v ? '1' : '0'))
|
||||
watch(pageSize, (v) => localStorage.setItem(LS_PAGE_SIZE, String(v)))
|
||||
|
||||
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 columns = computed<any[]>(() => {
|
||||
const list = [...visiblePlugins.value]
|
||||
const order: string[] = []
|
||||
for (const p of list) {
|
||||
const c = catOf(p)
|
||||
if (!order.includes(c)) order.push(c)
|
||||
}
|
||||
return list.sort((a, b) => order.indexOf(catOf(a)) - order.indexOf(catOf(b)))
|
||||
})
|
||||
const catOf = (p: any) => String(p.category || '未分类')
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(columns.value.length / pageSize.value)))
|
||||
|
||||
/** 当前页要渲染的插件列(账号行不参与分页) */
|
||||
const pagedColumns = computed(() =>
|
||||
columns.value.slice((page.value - 1) * pageSize.value, page.value * pageSize.value)
|
||||
)
|
||||
|
||||
const rangeText = computed(() => {
|
||||
const total = columns.value.length
|
||||
if (!total) return '0 / 0 列'
|
||||
const from = (page.value - 1) * pageSize.value + 1
|
||||
const to = Math.min(total, page.value * pageSize.value)
|
||||
return `${from}-${to} / 共 ${total} 列`
|
||||
})
|
||||
|
||||
const pluginGroups = computed(() => {
|
||||
const out: { label: string; span: number }[] = []
|
||||
for (const p of pagedColumns.value) {
|
||||
const label = catOf(p)
|
||||
const last = out[out.length - 1]
|
||||
if (last && last.label === label) last.span += 1
|
||||
else out.push({ label, span: 1 })
|
||||
}
|
||||
return out
|
||||
})
|
||||
|
||||
watch([picked, pluginKw, onlyGrantedPlugins, catFilter, pageSize], () => {
|
||||
page.value = 1
|
||||
})
|
||||
watch(totalPages, tp => {
|
||||
if (page.value > tp) page.value = tp
|
||||
})
|
||||
|
||||
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 || grants.value.some((g: any) => g.account === a.account)
|
||||
return kwOk && deptOk && grantedOk
|
||||
/** 分类清单(带插件数),只有一个分类时不显示 Tab */
|
||||
const categories = computed(() => {
|
||||
const map = new Map<string, number>()
|
||||
for (const p of plugins.value) map.set(catOf(p), (map.get(catOf(p)) || 0) + 1)
|
||||
return [...map.entries()].map(([label, count]) => ({ label, count }))
|
||||
})
|
||||
})
|
||||
|
||||
/** 悬停列高亮,缓解长表横向串行 */
|
||||
const hoverCol = ref('')
|
||||
/** grants 快速索引:(account, pluginId) -> {can_download, can_run} */
|
||||
const grantIndex = computed(() => {
|
||||
const idx = new Map<string, any>()
|
||||
for (const g of activeGrants.value) idx.set(`${g.account}|${g.plugin_id}`, g)
|
||||
return idx
|
||||
})
|
||||
|
||||
function focusPlugin(id: string) {
|
||||
picked.value = picked.value.length === 1 && picked.value[0] === id ? [] : [id]
|
||||
}
|
||||
|
||||
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
|
||||
function cellOf(account: string, pluginId: string) {
|
||||
return grantIndex.value.get(`${account}|${pluginId}`)
|
||||
}
|
||||
|
||||
function pinOf(account: string, pluginId: string, field: 'can_download' | 'can_run') {
|
||||
return !!cellOf(account, pluginId)?.[field]
|
||||
}
|
||||
|
||||
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 grantedPluginIds = computed(
|
||||
() => new Set(activeGrants.value.map((g: any) => String(g.plugin_id)))
|
||||
)
|
||||
|
||||
/** 每个插件被多少人授权 / 每个账号授权了多少插件 */
|
||||
const grantedCountByPlugin = computed(() => {
|
||||
const m = new Map<string, number>()
|
||||
for (const g of activeGrants.value)
|
||||
m.set(String(g.plugin_id), (m.get(String(g.plugin_id)) || 0) + 1)
|
||||
return m
|
||||
})
|
||||
|
||||
const grantedCountByAccount = computed(() => {
|
||||
const m = new Map<string, number>()
|
||||
for (const g of activeGrants.value)
|
||||
m.set(String(g.account), (m.get(String(g.account)) || 0) + 1)
|
||||
return m
|
||||
})
|
||||
|
||||
/** 插件列过滤(分类 Tab + 多选 + 搜索 + 仅已授权) */
|
||||
const visiblePlugins = computed<any[]>(() => {
|
||||
const kwv = pluginKw.value.trim().toLowerCase()
|
||||
return plugins.value.filter((p: any) => {
|
||||
if (catFilter.value && catOf(p) !== catFilter.value) return false
|
||||
if (picked.value.length && !picked.value.includes(p.id)) return false
|
||||
if (onlyGrantedPlugins.value && !grantedPluginIds.value.has(p.id)) return false
|
||||
if (kwv) {
|
||||
const hay = `${p.name || ''} ${p.id} ${catOf(p)}`.toLowerCase()
|
||||
if (!hay.includes(kwv)) return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
})
|
||||
|
||||
/** 同分类连续排列,两级表头才能成段 */
|
||||
const columns = computed<any[]>(() => {
|
||||
const list = [...visiblePlugins.value]
|
||||
const order: string[] = []
|
||||
for (const p of list) {
|
||||
const c = catOf(p)
|
||||
if (!order.includes(c)) order.push(c)
|
||||
}
|
||||
return list.sort((a, b) => order.indexOf(catOf(a)) - order.indexOf(catOf(b)))
|
||||
})
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(columns.value.length / pageSize.value)))
|
||||
|
||||
/** 当前页要渲染的插件列(账号行不参与分页) */
|
||||
const pagedColumns = computed(() =>
|
||||
columns.value.slice((page.value - 1) * pageSize.value, page.value * pageSize.value)
|
||||
)
|
||||
|
||||
/** 只有出现多个分类、或唯一分类有实际业务名时才需要分类分组行(全是「未分类」时不加那条灰带) */
|
||||
const hasGroups = computed(() => {
|
||||
if (catFilter.value) return false
|
||||
const set = new Set(pagedColumns.value.map(catOf))
|
||||
if (set.size > 1) return true
|
||||
return set.size === 1 && !set.has('未分类')
|
||||
})
|
||||
|
||||
const rangeText = computed(() => {
|
||||
const total = columns.value.length
|
||||
if (!total) return '0 / 0 列'
|
||||
const from = (page.value - 1) * pageSize.value + 1
|
||||
const to = Math.min(total, page.value * pageSize.value)
|
||||
return `${from}-${to} / 共 ${total} 列`
|
||||
})
|
||||
|
||||
const pluginGroups = computed(() => {
|
||||
const out: { label: string; span: number }[] = []
|
||||
for (const p of pagedColumns.value) {
|
||||
const label = catOf(p)
|
||||
const last = out[out.length - 1]
|
||||
if (last && last.label === label) last.span += 1
|
||||
else out.push({ label, span: 1 })
|
||||
}
|
||||
if (!hasGroups.value) return []
|
||||
// 单分类时合并成一个分组标签,避免被分页切断成多段
|
||||
return out.length > 1 ? out : [{ label: out[0].label, span: out[0].span }]
|
||||
})
|
||||
|
||||
watch([picked, pluginKw, onlyGrantedPlugins, catFilter, pageSize], () => {
|
||||
page.value = 1
|
||||
})
|
||||
watch(totalPages, (tp) => {
|
||||
if (page.value > tp) page.value = tp
|
||||
})
|
||||
|
||||
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 || grantedCountByAccount.value.has(String(a.account))
|
||||
return kwOk && deptOk && grantedOk
|
||||
})
|
||||
})
|
||||
|
||||
/** 悬停列高亮,缓解长表横向串行 */
|
||||
const hoverCol = ref('')
|
||||
const isPinned = (id: string) => picked.value.length === 1 && picked.value[0] === id
|
||||
|
||||
function focusPlugin(id: string) {
|
||||
picked.value = isPinned(id) ? [] : [id]
|
||||
}
|
||||
|
||||
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 {
|
||||
ElMessage.error('切换失败')
|
||||
} finally {
|
||||
toggling.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<!-- 工具条 1:账号维度 -->
|
||||
<!-- 工具条 1:账号筛选 + 状态图例 -->
|
||||
<div class="flex items-center gap-3 mb-2 flex-wrap">
|
||||
<el-input v-model="kw" placeholder="搜索账号 / 昵称" clearable style="width: 200px" />
|
||||
<el-select v-model="deptFilter" placeholder="全部部门" clearable style="width: 130px">
|
||||
<span class="text-xs text-gray-400 shrink-0">账号</span>
|
||||
<el-input
|
||||
v-model="kw"
|
||||
placeholder="搜索账号 / 昵称"
|
||||
clearable
|
||||
size="small"
|
||||
style="width: 190px"
|
||||
/>
|
||||
<el-select
|
||||
v-model="deptFilter"
|
||||
placeholder="全部部门"
|
||||
clearable
|
||||
size="small"
|
||||
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 class="ml-auto flex items-center gap-2.5 text-xs text-gray-400 flex-wrap">
|
||||
<span class="inline-flex items-center gap-1">
|
||||
格内 <i class="legend-chip is-on">下</i> = 允许下载
|
||||
<i class="legend-chip is-on">运</i> = 允许运行
|
||||
</span>
|
||||
<span class="w-px h-3.5 bg-[var(--el-border-color)]" />
|
||||
<span class="inline-flex items-center gap-1">
|
||||
<i class="legend-chip is-on">下</i>
|
||||
<i class="legend-chip is-on">运</i>
|
||||
<span class="ml-0.5">完整授权</span>
|
||||
</span>
|
||||
<span class="inline-flex items-center gap-1">
|
||||
<i class="legend-chip is-on">下</i>
|
||||
<i class="legend-chip">运</i>
|
||||
<span class="ml-0.5">部分授权</span>
|
||||
</span>
|
||||
<span class="inline-flex items-center gap-1">
|
||||
<i class="legend-chip">下</i>
|
||||
<i class="legend-chip">运</i>
|
||||
<span class="ml-0.5">未授权</span>
|
||||
</span>
|
||||
<el-popover placement="bottom-end" trigger="click" :width="300">
|
||||
<template #reference>
|
||||
<el-button size="small" text bg circle>
|
||||
<ArtSvgIcon icon="ri:question-line" />
|
||||
</el-button>
|
||||
</template>
|
||||
<div class="text-xs leading-6 text-g-600">
|
||||
<div class="font-semibold mb-1">怎么看这张表</div>
|
||||
<div>· 行 = 账号,列 = 插件,交叉格 = 这个人对这个插件有什么权限。</div>
|
||||
<div>· 格内两个按钮:<b>下</b> 允许下载安装,<b>运</b> 允许在本机运行。</div>
|
||||
<div>· 点一下即开/关并立即保存;两个都关掉,等于撤销这个插件的授权。</div>
|
||||
<div>· 绿底 = 下载+运行都有;黄底 = 只开了一项;白底 = 未授权。</div>
|
||||
<div>· 列头 <ArtSvgIcon icon="ri:eye-line" /> 按钮可只看该插件,再点一次恢复。</div>
|
||||
</div>
|
||||
</el-popover>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -222,13 +311,15 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
|
||||
<!-- 工具条 3:插件列筛选 + 分页 -->
|
||||
<div class="flex items-center gap-3 mb-3 flex-wrap">
|
||||
<span class="text-xs text-gray-400 shrink-0">插件列</span>
|
||||
<el-select
|
||||
v-model="picked"
|
||||
multiple
|
||||
filterable
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
placeholder="全部插件列"
|
||||
placeholder="全部插件"
|
||||
size="small"
|
||||
style="width: 220px"
|
||||
>
|
||||
<el-option
|
||||
@@ -238,18 +329,24 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
:value="p.id"
|
||||
/>
|
||||
</el-select>
|
||||
<el-input v-model="pluginKw" placeholder="搜索插件名 / ID / 分类" clearable style="width: 190px" />
|
||||
<el-input
|
||||
v-model="pluginKw"
|
||||
placeholder="搜索插件名 / ID"
|
||||
clearable
|
||||
size="small"
|
||||
style="width: 170px"
|
||||
/>
|
||||
<el-switch v-model="onlyGrantedPlugins" size="small" active-text="仅看已授权插件" />
|
||||
<el-switch v-model="compact" size="small" active-text="紧凑模式" />
|
||||
<el-button v-if="picked.length" size="small" text bg @click="picked = []">
|
||||
显示全部插件列
|
||||
取消只看({{ picked.length }})
|
||||
</el-button>
|
||||
|
||||
<div class="ml-auto flex items-center gap-2">
|
||||
<span class="text-xs text-gray-400">
|
||||
账号 {{ rows.length }} / {{ (matrix.accounts || []).length }}
|
||||
</span>
|
||||
<span class="text-xs text-gray-400">·</span>
|
||||
<el-divider direction="vertical" />
|
||||
<span class="text-xs text-gray-400">{{ rangeText }}</span>
|
||||
<template v-if="totalPages > 1">
|
||||
<el-button size="small" :disabled="page <= 1" @click="page--">上一页</el-button>
|
||||
@@ -264,11 +361,11 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
|
||||
<!-- 矩阵 -->
|
||||
<el-scrollbar :max-height="compact ? 560 : 520" class="border border-g-300/50 rounded-lg">
|
||||
<table class="matrix-table" :class="{ 'is-compact': compact }">
|
||||
<table class="matrix-table" :class="{ 'is-compact': compact, 'has-groups': hasGroups }">
|
||||
<thead>
|
||||
<tr class="group-row">
|
||||
<tr v-if="hasGroups" class="group-row">
|
||||
<th class="sticky-col">
|
||||
<div class="text-xs text-gray-400 font-normal">账号 / 插件</div>
|
||||
<span class="text-[11px] text-gray-400 font-normal">插件分类</span>
|
||||
</th>
|
||||
<th
|
||||
v-for="(g, gi) in pluginGroups"
|
||||
@@ -281,24 +378,40 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="sticky-col">
|
||||
<div class="text-xs text-gray-400 font-normal">账号 / 插件</div>
|
||||
<div class="flex items-center gap-1 text-[11px] text-gray-400 font-normal">
|
||||
<span>账号</span>
|
||||
<ArtSvgIcon icon="ri:arrow-down-line" class="text-[10px]" />
|
||||
<span>插件</span>
|
||||
<ArtSvgIcon icon="ri:arrow-right-line" class="text-[10px]" />
|
||||
</div>
|
||||
</th>
|
||||
<th
|
||||
v-for="p in pagedColumns"
|
||||
:key="p.id"
|
||||
class="plugin-col"
|
||||
:class="{ 'col-active': hoverCol === p.id }"
|
||||
:title="`${p.name}(${p.id})· 点击只看此插件`"
|
||||
@click="focusPlugin(p.id)"
|
||||
:class="{ 'col-active': hoverCol === p.id, 'is-pinned': isPinned(p.id) }"
|
||||
:title="`${p.name}(${p.id})· v${p.latest_version}`"
|
||||
@mouseenter="hoverCol = p.id"
|
||||
@mouseleave="hoverCol = ''"
|
||||
>
|
||||
<div class="font-medium text-[13px] name">{{ p.name }}</div>
|
||||
<div v-if="!compact" class="text-[11px] text-gray-400 font-normal">
|
||||
v{{ p.latest_version }}
|
||||
<span v-if="p.status && p.status !== 'published'" class="text-gray-400">
|
||||
· {{ p.status }}
|
||||
</span>
|
||||
<div class="flex items-center gap-1 justify-center">
|
||||
<span class="name font-medium text-[13px]">{{ p.name }}</span>
|
||||
<button
|
||||
class="pin-btn"
|
||||
:class="{ 'is-on': isPinned(p.id) }"
|
||||
:title="isPinned(p.id) ? '恢复显示全部插件列' : '只看此插件'"
|
||||
@click.stop="focusPlugin(p.id)"
|
||||
>
|
||||
<ArtSvgIcon icon="ri:eye-line" />
|
||||
</button>
|
||||
</div>
|
||||
<div v-if="!compact" class="text-[11px] text-gray-400 font-normal mt-0.5">
|
||||
{{ grantedCountByPlugin.get(p.id) || 0 }} 人已授权
|
||||
<span
|
||||
v-if="p.status && p.status !== 'published'"
|
||||
class="text-[var(--el-color-warning)]"
|
||||
>· {{ p.status }}</span
|
||||
>
|
||||
</div>
|
||||
</th>
|
||||
<th v-if="!pagedColumns.length">无匹配插件列</th>
|
||||
@@ -314,55 +427,75 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
{{ (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 class="text-sm leading-tight truncate flex items-center gap-1.5">
|
||||
<span class="truncate">{{ a.nickname || a.account }}</span>
|
||||
<span v-if="a.status === 0" class="badge-off">停用</span>
|
||||
</div>
|
||||
<div class="text-[11px] text-gray-400 truncate"
|
||||
>{{ a.account }} · {{ a.dept || '—' }}</div
|
||||
>
|
||||
</div>
|
||||
<el-tag
|
||||
v-if="grantedCountByAccount.get(a.account)"
|
||||
size="small"
|
||||
type="primary"
|
||||
effect="light"
|
||||
round
|
||||
class="shrink-0 ml-auto"
|
||||
:title="`已授权 ${grantedCountByAccount.get(a.account)} 个插件`"
|
||||
>
|
||||
{{ grantedCountByAccount.get(a.account) }}
|
||||
</el-tag>
|
||||
</div>
|
||||
</td>
|
||||
<td
|
||||
v-for="p in pagedColumns"
|
||||
:key="p.id"
|
||||
align="center"
|
||||
class="perm-cell"
|
||||
:class="[`state-${cellState(a.account, p.id)}`, { 'col-active': hoverCol === p.id }]"
|
||||
@mouseenter="hoverCol = p.id"
|
||||
@mouseleave="hoverCol = ''"
|
||||
>
|
||||
<div class="flex items-center justify-center gap-1.5">
|
||||
<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"
|
||||
:title="cellOf(a.account, p.id)?.can_download ? '允许下载(点击撤销)' : '禁止下载(点击放行)'"
|
||||
<div class="flex items-center justify-center gap-1">
|
||||
<button
|
||||
class="perm-chip"
|
||||
:class="{ 'is-on': pinOf(a.account, p.id, 'can_download') }"
|
||||
:title="
|
||||
pinOf(a.account, p.id, 'can_download') ? '已允许下载,点击关闭' : '点击允许下载'
|
||||
"
|
||||
:disabled="toggling"
|
||||
@click="toggle(a.account, p.id, 'can_download')"
|
||||
>
|
||||
⬇
|
||||
</el-tag>
|
||||
<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"
|
||||
:title="cellOf(a.account, p.id)?.can_run ? '允许运行(点击撤销)' : '禁止运行(点击放行)'"
|
||||
下
|
||||
</button>
|
||||
<button
|
||||
class="perm-chip"
|
||||
:class="{ 'is-on': pinOf(a.account, p.id, 'can_run') }"
|
||||
:title="
|
||||
pinOf(a.account, p.id, 'can_run') ? '已允许运行,点击关闭' : '点击允许运行'
|
||||
"
|
||||
:disabled="toggling"
|
||||
@click="toggle(a.account, p.id, 'can_run')"
|
||||
>
|
||||
▶
|
||||
</el-tag>
|
||||
运
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
<td v-if="!pagedColumns.length" align="center">—</td>
|
||||
</tr>
|
||||
<tr v-if="!rows.length">
|
||||
<td :colspan="pagedColumns.length + 1" align="center" class="py-8 text-gray-400 text-sm">
|
||||
无匹配账号
|
||||
<td :colspan="pagedColumns.length + 1" align="center" class="py-6">
|
||||
<el-empty description="没有匹配的账号" :image-size="60" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</el-scrollbar>
|
||||
|
||||
<div class="mt-2 text-xs text-gray-400">
|
||||
点击单元格内的 ⬇ / ▶ 徽标切换对应权限;下载与运行都关闭时自动撤销整条授权。点击插件列头可只看该插件;
|
||||
插件多时先用「插件分类」Tab 收窄,再按需翻页。
|
||||
绿底 = 下载与运行都已允许;黄底 = 只开了一项;白底 =
|
||||
未授权。点格子里的「下」「运」即时生效,两个都关掉即撤销该授权。
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -390,30 +523,62 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
z-index: 2;
|
||||
text-align: center;
|
||||
}
|
||||
/* 分组行固定在更上层,插件行紧随其后 */
|
||||
/* 分组行固定在更上层,插件行紧随其后下移 30px(重叠 1px 消缝) */
|
||||
.matrix-table thead .group-row th {
|
||||
top: 0;
|
||||
height: 26px;
|
||||
padding: 3px 10px;
|
||||
height: 30px;
|
||||
padding: 0 10px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: var(--el-text-color-secondary);
|
||||
letter-spacing: 0.3px;
|
||||
}
|
||||
.matrix-table thead tr:not(.group-row) th {
|
||||
top: 32px;
|
||||
cursor: pointer;
|
||||
.matrix-table.has-groups thead tr:not(.group-row) th {
|
||||
top: 29px;
|
||||
}
|
||||
.matrix-table .plugin-col {
|
||||
max-width: 132px;
|
||||
min-width: 96px;
|
||||
cursor: default;
|
||||
}
|
||||
.matrix-table .plugin-col .name {
|
||||
max-width: 116px;
|
||||
max-width: 104px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.matrix-table .plugin-col.is-pinned {
|
||||
background: var(--el-color-primary-light-9);
|
||||
}
|
||||
|
||||
/* 列头「只看」按钮:常显低透明度,悬停变亮,避免整列头点击误触 */
|
||||
.pin-btn {
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--el-text-color-placeholder);
|
||||
opacity: 0.55;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.matrix-table th:hover .pin-btn,
|
||||
.pin-btn.is-on {
|
||||
opacity: 1;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.pin-btn.is-on {
|
||||
background: var(--el-color-primary-light-8);
|
||||
}
|
||||
.pin-btn:hover {
|
||||
background: var(--el-color-primary-light-8);
|
||||
}
|
||||
|
||||
.matrix-table .sticky-col {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
@@ -448,10 +613,72 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
.matrix-table tbody tr:hover td.state-partial {
|
||||
background: var(--el-color-warning-light-8);
|
||||
}
|
||||
.cell-tag {
|
||||
font-size: 12px;
|
||||
padding: 0 7px;
|
||||
|
||||
/* 权限按钮:开=实心绿,关=灰色空心,中文单字不需要猜符号含义 */
|
||||
.perm-chip {
|
||||
width: 26px;
|
||||
height: 21px;
|
||||
padding: 0;
|
||||
border-radius: 5px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
background: var(--el-bg-color);
|
||||
color: var(--el-text-color-placeholder);
|
||||
font-size: 11px;
|
||||
line-height: 1;
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.perm-chip:hover:not(:disabled) {
|
||||
border-color: var(--el-color-primary);
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
.perm-chip.is-on {
|
||||
background: var(--el-color-success);
|
||||
border-color: var(--el-color-success);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
.perm-chip.is-on:hover:not(:disabled) {
|
||||
background: var(--el-color-success-dark-2);
|
||||
border-color: var(--el-color-success-dark-2);
|
||||
color: #fff;
|
||||
}
|
||||
.perm-chip:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.legend-chip {
|
||||
width: 22px;
|
||||
height: 18px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid var(--el-border-color);
|
||||
background: var(--el-bg-color);
|
||||
color: var(--el-text-color-placeholder);
|
||||
font-size: 10px;
|
||||
font-style: normal;
|
||||
display: inline-grid;
|
||||
place-items: center;
|
||||
}
|
||||
.legend-chip.is-on {
|
||||
background: var(--el-color-success);
|
||||
border-color: var(--el-color-success);
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.badge-off {
|
||||
font-size: 10px;
|
||||
line-height: 14px;
|
||||
padding: 0 4px;
|
||||
border-radius: 3px;
|
||||
background: var(--el-fill-color);
|
||||
color: var(--el-text-color-secondary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 紧凑模式:压窄列宽,塞下更多插件列 */
|
||||
.matrix-table.is-compact th,
|
||||
.matrix-table.is-compact td {
|
||||
@@ -462,11 +689,12 @@ async function toggle(account: string, pluginId: string, field: 'can_download' |
|
||||
min-width: 64px;
|
||||
}
|
||||
.matrix-table.is-compact .plugin-col .name {
|
||||
max-width: 66px;
|
||||
max-width: 52px;
|
||||
font-size: 12px;
|
||||
}
|
||||
.matrix-table.is-compact .cell-tag {
|
||||
padding: 0 4px;
|
||||
font-size: 11px;
|
||||
.matrix-table.is-compact .perm-chip {
|
||||
width: 22px;
|
||||
height: 18px;
|
||||
font-size: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 插件管理(37du 控制台)
|
||||
* 列表/搜索/上传发布/状态切换/删除,对接 /api/admin/plugins、/pkg、/plugin/patch、/plugin/delete
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
fetchPlugins, uploadPlugin, patchPlugin, deletePlugin,
|
||||
@@ -13,21 +13,39 @@ import {
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
const total = ref(0)
|
||||
const query = reactive({ page: 1, page_size: 10, q: '' })
|
||||
const query = reactive({
|
||||
page: 1,
|
||||
page_size: 10,
|
||||
q: '',
|
||||
status: '' as string, // 快捷状态:''/published/testing/disabled/revoked
|
||||
category: '', // 分类;__none__ = 未分类
|
||||
flags: [] as string[], // test=有在测版本 force=已设强制更新 granted=已授权 ungranted=未授权
|
||||
sort: 'id',
|
||||
order: 'asc'
|
||||
})
|
||||
|
||||
const statusMap: Record<string, { label: string; type: any }> = {
|
||||
published: { label: '已发布', type: 'success' },
|
||||
testing: { label: '测试中', type: 'primary' },
|
||||
disabled: { label: '已禁用', type: 'warning' },
|
||||
revoked: { label: '已下架', type: 'danger' }
|
||||
}
|
||||
/** 快捷筛选计数(后端按当前关键字/分类统计,用于按钮上的数字) */
|
||||
const stats = ref<Record<string, number>>({
|
||||
all: 0, published: 0, testing: 0, disabled: 0, revoked: 0,
|
||||
has_test: 0, force: 0, granted: 0, ungranted: 0
|
||||
})
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchPlugins(query)
|
||||
const r = await fetchPlugins({
|
||||
page: query.page,
|
||||
page_size: query.page_size,
|
||||
q: query.q,
|
||||
status: query.status,
|
||||
category: query.category,
|
||||
flags: query.flags.join(','),
|
||||
sort: query.sort,
|
||||
order: query.order
|
||||
})
|
||||
list.value = r.items || []
|
||||
total.value = r.total || 0
|
||||
if (r.stats) stats.value = { ...stats.value, ...r.stats }
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
@@ -38,6 +56,35 @@ function search() {
|
||||
load()
|
||||
}
|
||||
|
||||
function resetQuery() {
|
||||
Object.assign(query, { q: '', status: '', category: '', flags: [], sort: 'id', order: 'asc' })
|
||||
search()
|
||||
}
|
||||
|
||||
/** 是否处于任何筛选状态(用于显示「清空筛选」) */
|
||||
const filtered = computed(
|
||||
() => !!(query.q || query.status || query.category || query.flags.length)
|
||||
)
|
||||
|
||||
/** 「已授权 / 未授权」互斥:后勾选的那个生效,避免两个同时选中导致空列表 */
|
||||
function onFlagChange() {
|
||||
if (query.flags.includes('granted') && query.flags.includes('ungranted')) {
|
||||
const last = query.flags[query.flags.length - 1]
|
||||
query.flags = query.flags.filter(
|
||||
(f) => f === last || (f !== 'granted' && f !== 'ungranted')
|
||||
)
|
||||
}
|
||||
search()
|
||||
}
|
||||
|
||||
|
||||
const statusMap: Record<string, { label: string; type: any }> = {
|
||||
published: { label: '已发布', type: 'success' },
|
||||
testing: { label: '测试中', type: 'primary' },
|
||||
disabled: { label: '已禁用', type: 'warning' },
|
||||
revoked: { label: '已下架', type: 'danger' }
|
||||
}
|
||||
|
||||
// ---- 上传发布 ----
|
||||
const uploadOpen = ref(false)
|
||||
const uploading = ref(false)
|
||||
@@ -221,6 +268,13 @@ function fmtDeadline(s: string): string {
|
||||
return String(s || '').replace('T', ' ').slice(0, 16)
|
||||
}
|
||||
|
||||
/** 授权账号提示(最多列 10 个,避免 tooltip 过长) */
|
||||
function grantTip(row: any): string {
|
||||
const accs: any[] = row.accounts || []
|
||||
const head = accs.slice(0, 10).map((a) => `${a.account}${a.nickname ? `(${a.nickname})` : ''}`)
|
||||
return head.join('、') + (accs.length > 10 ? ` 等 ${accs.length} 个账号` : '')
|
||||
}
|
||||
|
||||
// ---- 删除 ----
|
||||
async function remove(row: any) {
|
||||
await ElMessageBox.confirm(`确认删除插件「${row.id}」?将连带删除版本与授权。`, '删除确认', {
|
||||
@@ -246,15 +300,58 @@ onMounted(() => {
|
||||
</template>
|
||||
</ArtPageHeader>
|
||||
|
||||
<!-- 搜索 -->
|
||||
<!-- 筛选 -->
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<!-- 状态快捷切换(含计数,点一下即筛) -->
|
||||
<div class="flex flex-wrap items-center gap-2 mb-3">
|
||||
<el-radio-group v-model="query.status" size="small" @change="search">
|
||||
<el-radio-button value="">全部 {{ stats.all }}</el-radio-button>
|
||||
<el-radio-button value="published">已发布 {{ stats.published }}</el-radio-button>
|
||||
<el-radio-button value="testing">测试中 {{ stats.testing }}</el-radio-button>
|
||||
<el-radio-button value="disabled">已禁用 {{ stats.disabled }}</el-radio-button>
|
||||
<el-radio-button value="revoked">已下架 {{ stats.revoked }}</el-radio-button>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<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-input v-model="query.q" placeholder="ID / 名称" clearable style="width: 200px" @keyup.enter="search" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类">
|
||||
<el-select
|
||||
v-model="query.category"
|
||||
clearable
|
||||
placeholder="全部分类"
|
||||
style="width: 160px"
|
||||
@change="search"
|
||||
>
|
||||
<el-option label="未分类" value="__none__" />
|
||||
<el-option v-for="c in categories" :key="c.id" :label="c.label" :value="c.label" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="快捷">
|
||||
<el-checkbox-group v-model="query.flags" @change="onFlagChange">
|
||||
<el-checkbox value="test">有在测版本 {{ stats.has_test }}</el-checkbox>
|
||||
<el-checkbox value="force">已设强制更新 {{ stats.force }}</el-checkbox>
|
||||
<el-checkbox value="granted">已授权 {{ stats.granted }}</el-checkbox>
|
||||
<el-checkbox value="ungranted">未授权 {{ stats.ungranted }}</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序">
|
||||
<el-select v-model="query.sort" style="width: 120px" @change="search">
|
||||
<el-option label="插件ID" value="id" />
|
||||
<el-option label="名称" value="name" />
|
||||
<el-option label="分类" value="category" />
|
||||
<el-option label="状态" value="status" />
|
||||
<el-option label="更新时间" value="updated_at" />
|
||||
</el-select>
|
||||
<el-select v-model="query.order" style="width: 90px" @change="search">
|
||||
<el-option label="升序" value="asc" />
|
||||
<el-option label="降序" value="desc" />
|
||||
</el-select>
|
||||
</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-button :disabled="!filtered" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
@@ -302,6 +399,19 @@ onMounted(() => {
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="授权账号" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tooltip
|
||||
v-if="row.accounts?.length"
|
||||
:content="grantTip(row)"
|
||||
placement="top"
|
||||
popper-class="max-w-[320px]"
|
||||
>
|
||||
<el-tag size="small" type="success" effect="plain">{{ row.accounts.length }} 个</el-tag>
|
||||
</el-tooltip>
|
||||
<span v-else class="text-gray-300 text-xs">未授权</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="强制更新" min-width="170">
|
||||
<template #default="{ row }">
|
||||
<el-tooltip
|
||||
@@ -348,8 +458,10 @@ onMounted(() => {
|
||||
v-model:current-page="query.page"
|
||||
v-model:page-size="query.page_size"
|
||||
:total="total"
|
||||
layout="total, prev, pager, next"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
@current-change="load"
|
||||
@size-change="search"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* SDK 管理(37du 控制台)
|
||||
* SDK = 执行机按插件 plugin.json.requires.sdks 自动下载并挂载到 sys.path 的纯 Python 运行库:
|
||||
* 不能单独运行、没有独立运行记录,因此这里只管「版本 + 通道 + 撤回」。
|
||||
* 对接 /api/admin/sdks、/sdk-pkg、/sdk/patch、/sdk-yank、/sdk/delete
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { fetchSdks, uploadSdk, patchSdk, yankSdk, deleteSdk } from '@/api/business'
|
||||
|
||||
const loading = ref(false)
|
||||
const list = ref<any[]>([])
|
||||
|
||||
const statusMap: Record<string, { label: string; type: any }> = {
|
||||
published: { label: '已发布', type: 'success' },
|
||||
testing: { label: '测试中', type: 'primary' },
|
||||
disabled: { label: '已禁用', type: 'warning' },
|
||||
revoked: { label: '已下架', type: 'danger' }
|
||||
}
|
||||
|
||||
const verStatusMap: Record<string, { label: string; type: any }> = {
|
||||
published: { label: '正式', type: 'success' },
|
||||
testing: { label: '在测', type: 'primary' },
|
||||
yanked: { label: '已撤回', type: 'danger' }
|
||||
}
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
const r = await fetchSdks()
|
||||
list.value = r.items || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function fmtSize(n: any): string {
|
||||
const v = Number(n || 0)
|
||||
if (!v) return '-'
|
||||
return v > 1024 * 1024 ? `${(v / 1024 / 1024).toFixed(1)} MB` : `${(v / 1024).toFixed(0)} KB`
|
||||
}
|
||||
|
||||
function shortSha(s: string): string {
|
||||
return s ? String(s).slice(0, 12) + '…' : '-'
|
||||
}
|
||||
|
||||
// ---- 上传发布 ----
|
||||
const uploadOpen = ref(false)
|
||||
const uploading = ref(false)
|
||||
const uploadForm = reactive({ sdk_id: '', name: '', version: '', channel: 'test', file: null as File | null })
|
||||
|
||||
function openUpload() {
|
||||
Object.assign(uploadForm, { sdk_id: '', name: '', version: '', channel: 'test', file: null })
|
||||
uploadOpen.value = true
|
||||
}
|
||||
|
||||
async function submitUpload() {
|
||||
if (!uploadForm.file || !uploadForm.sdk_id || !uploadForm.version) {
|
||||
ElMessage.warning('请填写 sdk_id / version 并选择安装包')
|
||||
return
|
||||
}
|
||||
uploading.value = true
|
||||
try {
|
||||
await uploadSdk(uploadForm.file, {
|
||||
sdk_id: uploadForm.sdk_id,
|
||||
name: uploadForm.name,
|
||||
version: uploadForm.version,
|
||||
channel: uploadForm.channel
|
||||
})
|
||||
ElMessage.success(
|
||||
uploadForm.channel === 'test' ? '测试版已上传(仅管理员账号可同步)' : '已直发正式版'
|
||||
)
|
||||
uploadOpen.value = false
|
||||
load()
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 状态切换 / 转正 ----
|
||||
async function setStatus(row: any, status: string) {
|
||||
await patchSdk(row.id, { status })
|
||||
ElMessage.success(statusMap[status]?.label || `状态已更新为 ${status}`)
|
||||
load()
|
||||
}
|
||||
|
||||
async function promote(row: any) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`确认把在测版本 v${row.test_version} 转正?转正后所有账号下次同步即升级到该版本(复用同一版本号,不重新打包)。`,
|
||||
'在测版本转正',
|
||||
{ type: 'warning', confirmButtonText: '转正发布', cancelButtonText: '取消' }
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
await patchSdk(row.id, { status: 'published' })
|
||||
ElMessage.success(`v${row.test_version} 已转正为正式版`)
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 撤回单个版本 ----
|
||||
async function yank(row: any, ver: any) {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`撤回 ${row.id} v${ver.version}?执行机下次同步会回落到最高可用版本;已装该版本的机器本地目录保留,但不会再被选中。`,
|
||||
'撤回版本',
|
||||
{ type: 'warning', confirmButtonText: '撤回', cancelButtonText: '取消' }
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
await yankSdk(row.id, ver.version)
|
||||
ElMessage.success(`v${ver.version} 已撤回`)
|
||||
load()
|
||||
}
|
||||
|
||||
// ---- 删除 ----
|
||||
async function remove(row: any) {
|
||||
await ElMessageBox.confirm(
|
||||
`确认删除 SDK「${row.id}」?将连带删除全部版本与磁盘包文件;依赖它的插件会因缺少 SDK 而无法运行。`,
|
||||
'删除确认',
|
||||
{ type: 'warning' }
|
||||
)
|
||||
await deleteSdk(row.id)
|
||||
ElMessage.success('已删除')
|
||||
load()
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-5 space-y-4">
|
||||
<ArtPageHeader
|
||||
title="SDK 管理"
|
||||
description="执行机按插件依赖自动下载的纯 Python 运行库:版本目录不可变,插件用 compat ^x.y 自动跟随"
|
||||
>
|
||||
<template #actions>
|
||||
<el-button type="primary" @click="openUpload">
|
||||
<ArtSvgIcon icon="ri:upload-2-line" class="mr-1" />上传发布
|
||||
</el-button>
|
||||
</template>
|
||||
</ArtPageHeader>
|
||||
|
||||
<el-alert type="info" :closable="false" show-icon>
|
||||
<template #title>
|
||||
SDK 只做版本下发,不能单独运行;执行机侧的挂载由插件 <code>requires.sdks</code> 决定。
|
||||
发布前请先本地跑 <code>tools/sdk_compat_check.py</code> 兼容预检(打包/发布命令已内置门禁)。
|
||||
</template>
|
||||
</el-alert>
|
||||
|
||||
<el-card shadow="never" class="rounded-xl">
|
||||
<el-table v-loading="loading" :data="list" border stripe row-key="id">
|
||||
<el-table-column type="expand">
|
||||
<template #default="{ row }">
|
||||
<div class="px-4 py-2">
|
||||
<el-table :data="row.versions || []" size="small" border>
|
||||
<el-table-column prop="version" label="版本" width="120" />
|
||||
<el-table-column label="版本状态" width="110">
|
||||
<template #default="{ row: v }">
|
||||
<el-tag :type="verStatusMap[v.status]?.type || 'info'" size="small">
|
||||
{{ verStatusMap[v.status]?.label || v.status }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="sha256" min-width="150">
|
||||
<template #default="{ row: v }">
|
||||
<span class="text-xs font-mono">{{ shortSha(v.sha256) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="大小" width="100">
|
||||
<template #default="{ row: v }">{{ fmtSize(v.size_bytes) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="uploaded_at" label="上传时间" min-width="160" />
|
||||
<el-table-column label="操作" width="90" fixed="right">
|
||||
<template #default="{ row: v }">
|
||||
<el-button
|
||||
v-if="v.status !== 'yanked'"
|
||||
link type="danger"
|
||||
@click="yank(row, v)"
|
||||
>撤回</el-button>
|
||||
<span v-else class="text-gray-300 text-xs">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<div v-if="!row.versions?.length" class="py-2 text-sm text-gray-400">暂无版本</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="id" label="SDK ID" min-width="150" />
|
||||
<el-table-column prop="name" label="名称" min-width="160" />
|
||||
<el-table-column label="正式版" width="100">
|
||||
<template #default="{ row }">{{ row.latest_version || '-' }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="在测版" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.test_version" size="small" type="primary">{{ row.test_version }}</el-tag>
|
||||
<span v-else class="text-gray-300 text-xs">-</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="实际下发" width="110">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.effective_version" size="small" effect="plain">
|
||||
{{ row.effective_version }}
|
||||
</el-tag>
|
||||
<span v-else class="text-gray-300 text-xs">无可用版本</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<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="90">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" type="info">{{ row.versions?.length || 0 }}</el-tag>
|
||||
</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 === 'testing' && row.test_version"
|
||||
link type="primary"
|
||||
@click="promote(row)"
|
||||
>转正</el-button>
|
||||
<el-button
|
||||
v-if="row.status === 'published' || row.status === 'testing'"
|
||||
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 v-if="!loading && !list.length" class="py-10 text-center text-sm text-gray-400">
|
||||
暂无 SDK。上传 <code>dist-sdk/<id>_v<版本>.zip</code> 即可(或用 <code>agent_cli.py sdk-publish</code>)。
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 上传发布弹窗 -->
|
||||
<el-dialog v-model="uploadOpen" title="上传发布 SDK" width="500px">
|
||||
<el-form label-width="90px">
|
||||
<el-form-item label="SDK ID" required>
|
||||
<el-input v-model="uploadForm.sdk_id" placeholder="如 hotel_report(与 sdk.json 内 id 一致)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="版本号" required>
|
||||
<el-input v-model="uploadForm.version" placeholder="如 0.2.0(测试版须高于当前正式版)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="名称">
|
||||
<el-input v-model="uploadForm.name" placeholder="留空则取 sdk.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-item label="发布通道">
|
||||
<el-radio-group v-model="uploadForm.channel">
|
||||
<el-radio value="test">测试版(仅管理员账号同步)</el-radio>
|
||||
<el-radio value="prod">正式版(立即全量生效)</el-radio>
|
||||
</el-radio-group>
|
||||
<div class="text-xs text-gray-400 leading-5 mt-1">
|
||||
测试版发布后状态为「测试中」:管理员账号同步到新版本,其他账号继续用当前正式版。
|
||||
人工验证通过后点列表里的「转正」即全量生效。
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="预检">
|
||||
<div class="text-xs text-gray-400 leading-5">
|
||||
发版前请在仓库执行 <code>tools/sdk_compat_check.py</code>(<code>sdk_pack</code> / <code>sdk-publish</code> 已内置门禁);
|
||||
本页只负责上传与通道切换。
|
||||
</div>
|
||||
</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>
|
||||
Reference in New Issue
Block a user