build(desktop): 升级 electron-shell 版本至 1.6.3 并调整插件执行超时配置
- 插件执行超时默认延长至 6 小时,支持插件单独配置超时时间 - 新增插件根目录迁移逻辑,解决旧版权限问题 - 新增多个服务端实体、DTO、配置模块等基础代码 - 新增插件 UI 模板及相关静态资源
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
import { CoolController, BaseController } from '@cool-midway/core';
|
||||
import { Get, Headers, Inject, Provide } from '@midwayjs/core';
|
||||
import { InjectEntityModel } from '@midwayjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { AccountEntity } from '../../entity/account';
|
||||
import { CenterAuthService, ApiError } from '../../service/auth';
|
||||
|
||||
/**
|
||||
* 控制台业务菜单(RBAC 驱动)。
|
||||
* - GET /api/admin/me/menus:返回当前操作者的业务菜单树 + 权限标识集合。
|
||||
* 管理员(is_admin=1)返回全量;非管理员按 cool-admin 角色权限过滤(预留,2F 用户体系落地后生效)。
|
||||
* - 前端据此驱动动态路由与按钮权限("菜单要权限"落点)。
|
||||
*/
|
||||
|
||||
interface MenuNode {
|
||||
path: string;
|
||||
name: string;
|
||||
component: string;
|
||||
meta: {
|
||||
title: string;
|
||||
icon: string;
|
||||
perms: string[];
|
||||
roles?: string[];
|
||||
};
|
||||
children?: MenuNode[];
|
||||
}
|
||||
|
||||
/** 控制台菜单目录(path/component 与前端视图一一对应;perms 为按钮/页面权限标识) */
|
||||
const CONSOLE_MENUS: MenuNode[] = [
|
||||
{
|
||||
path: '/overview', name: 'Overview', component: '/overview/index',
|
||||
meta: { title: '概览', icon: 'ri:pie-chart-line', perms: ['center:overview:view'] },
|
||||
},
|
||||
{
|
||||
path: '/stats', name: 'Stats', component: '/stats/index',
|
||||
meta: { title: '数据看板', icon: 'ri:bar-chart-2-line', perms: ['center:stats:view'] },
|
||||
},
|
||||
{
|
||||
path: '/plugins', name: 'Plugins', component: '/plugins/index',
|
||||
meta: { title: '插件管理', icon: 'ri:box-3-line', perms: ['center:plugin:list'] },
|
||||
},
|
||||
{
|
||||
path: '/accounts', name: 'Accounts', component: '/accounts/index',
|
||||
meta: { title: '账号管理', icon: 'ri:user-3-line', perms: ['center:account:list'] },
|
||||
},
|
||||
{
|
||||
path: '/grants', name: 'Grants', component: '/grants/index',
|
||||
meta: { title: '权限授权', icon: 'ri:key-2-line', perms: ['center:grant:list'] },
|
||||
},
|
||||
{
|
||||
path: '/audit', name: 'Audit', component: '/audit/index',
|
||||
meta: { title: '审计报表', icon: 'ri:file-list-3-line', perms: ['center:audit:list'] },
|
||||
},
|
||||
{
|
||||
path: '/reports', name: 'Reports', component: '/reports/index',
|
||||
meta: { title: '运行记录', icon: 'ri:terminal-box-line', perms: ['center:report:list'] },
|
||||
},
|
||||
{
|
||||
path: '/devices', name: 'Devices', component: '/devices/index',
|
||||
meta: { title: '执行机设备', icon: 'ri:computer-line', perms: ['center:device:list'] },
|
||||
},
|
||||
{
|
||||
path: '/upgrade', name: 'Upgrade', component: '/upgrade/index',
|
||||
meta: { title: '升级进度', icon: 'ri:rocket-2-line', perms: ['center:device:summary'] },
|
||||
},
|
||||
{
|
||||
path: '/notify', name: 'Notify', component: '/notify/index',
|
||||
meta: { title: '通知推送', icon: 'ri:notification-3-line', perms: ['center:notify:list'] },
|
||||
},
|
||||
{
|
||||
path: '/creds', name: 'Creds', component: '/creds/index',
|
||||
meta: { title: '敏感凭证', icon: 'ri:shield-keyhole-line', perms: ['center:creds:list'] },
|
||||
},
|
||||
{
|
||||
path: '/file-sources', name: 'FileSources', component: '/file-sources/index',
|
||||
meta: { title: '大文件源', icon: 'ri:database-2-line', perms: ['center:fileSource:list'] },
|
||||
},
|
||||
{
|
||||
path: '/system', name: 'System', component: '/system/index',
|
||||
meta: { title: '系统管理', icon: 'ri:settings-3-line', perms: [] },
|
||||
children: [
|
||||
{ path: 'user', name: 'SysUser', component: '/system/user', meta: { title: '用户管理', icon: '', perms: ['center:sys:user'] } },
|
||||
{ path: 'role', name: 'SysRole', component: '/system/role', meta: { title: '角色管理', icon: '', perms: ['center:sys:role'] } },
|
||||
{ path: 'menu', name: 'SysMenu', component: '/system/menu', meta: { title: '菜单管理', icon: '', perms: ['center:sys:menu'] } },
|
||||
{ path: 'department', name: 'SysDept', component: '/system/department', meta: { title: '部门管理', icon: '', perms: ['center:sys:dept'] } },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
/** 全部权限标识集合(供按钮级 v-permission 使用) */
|
||||
function allPerms(nodes: MenuNode[]): string[] {
|
||||
const out: string[] = [];
|
||||
const walk = (ns: MenuNode[]) => ns.forEach(n => { out.push(...n.meta.perms); if (n.children) walk(n.children); });
|
||||
walk(nodes);
|
||||
return out;
|
||||
}
|
||||
|
||||
@Provide()
|
||||
@CoolController('/api/admin')
|
||||
export class AdminMenuController extends BaseController {
|
||||
@Inject()
|
||||
centerAuthService: CenterAuthService;
|
||||
|
||||
@InjectEntityModel(AccountEntity)
|
||||
accountRepo: Repository<AccountEntity>;
|
||||
|
||||
/** GET /api/admin/me/menus */
|
||||
@Get('/me/menus')
|
||||
async meMenus(
|
||||
@Headers('Authorization') authorization: string = '',
|
||||
@Headers('X-Admin-Token') xAdminToken: string = '',
|
||||
@Headers('X-API-Token') xApiToken: string = '',
|
||||
@Headers('X-Admin-User') xAdminUser: string = ''
|
||||
) {
|
||||
let account = '';
|
||||
try {
|
||||
account = await this.centerAuthService.identity(authorization, xAdminToken, xApiToken, xAdminUser);
|
||||
} catch (e) {
|
||||
account = '';
|
||||
}
|
||||
// 无效身份 → 401(触发前端自动登出,避免 200-空菜单被误判后跳 500)
|
||||
if (!account) throw new ApiError(401, '登录态无效或已过期,请重新登录');
|
||||
const row = await this.accountRepo.findOneBy({ account });
|
||||
if (!row || !Number(row.status)) throw new ApiError(401, '登录态无效或已过期,请重新登录');
|
||||
const isAdmin = !!Number(row.isAdmin);
|
||||
// 非管理员:按 cool-admin 角色权限过滤(2F 用户体系落地后生效;当前业务控制台仍以 is_admin 为准)
|
||||
if (isAdmin) {
|
||||
return { account, menus: CONSOLE_MENUS, perms: allPerms(CONSOLE_MENUS), is_admin: true };
|
||||
}
|
||||
return { account, menus: [], perms: [], is_admin: false };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user