feat: 重构控制台为37du自动化平台,新增权限授权与通知中心功能
- 更新系统名称、登录页宣传文案为37du平台相关内容 - 移除聊天功能相关代码与配置 - 新增客户端版本上报字段与设备统计接口 - 新增通知中心功能(60s轮询、localStorage已读标记) - 新增权限授权工作台相关接口与页面 - 新增统一页头组件ArtPageHeader - 调整快速入口配置指向真实功能页面 - 修复控制面地址为内网生产库
This commit is contained in:
@@ -21,6 +21,8 @@ interface MenuNode {
|
||||
icon: string;
|
||||
perms: string[];
|
||||
roles?: string[];
|
||||
/** 侧栏隐藏(如个人中心,仅从用户菜单进入) */
|
||||
isHide?: boolean;
|
||||
};
|
||||
children?: MenuNode[];
|
||||
}
|
||||
@@ -76,13 +78,17 @@ const CONSOLE_MENUS: MenuNode[] = [
|
||||
meta: { title: '大文件源', icon: 'ri:database-2-line', perms: ['center:fileSource:list'] },
|
||||
},
|
||||
{
|
||||
path: '/system', name: 'System', component: '/system/index',
|
||||
// 嵌套菜单的父级 component 必须是布局容器(RoutesAlias.Layout='/index/index'),
|
||||
// 否则一级带 children 的路由不会包 Layout,子页面渲染不出(空白页)
|
||||
path: '/system', name: 'System', component: '/index/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'] } },
|
||||
// 个人中心:从头像下拉进入,不在侧栏显示(自助改密 + 头像)
|
||||
{ path: 'user-center', name: 'UserCenter', component: '/system/user-center', meta: { title: '个人中心', icon: '', perms: [], isHide: true } },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -222,7 +222,7 @@ export class AdminOpsController extends BaseController {
|
||||
const total: any = (await m.query('SELECT COUNT(*) AS c FROM devices'))[0];
|
||||
const rows: any[] = await m.query(
|
||||
`SELECT device_id, account, hostname, os, ip, chrome_installed, chrome_version, chrome_ok,
|
||||
last_seen, status, created_at, updated_at
|
||||
client_version, last_seen, status, created_at, updated_at
|
||||
FROM devices ORDER BY last_seen DESC LIMIT ? OFFSET ?`, [limit, offset]);
|
||||
return { items: rows.map((r: any) => ({ ...r, last_seen: fmtStr(r.last_seen), created_at: fmtStr(r.created_at), updated_at: fmtStr(r.updated_at) })), total: Number(total.c || 0) };
|
||||
}
|
||||
@@ -235,17 +235,66 @@ export class AdminOpsController extends BaseController {
|
||||
await this.centerAuthService.requireAdmin(xAdminToken, xApiToken);
|
||||
const m = this.deviceRepo.manager;
|
||||
const total: any = (await m.query('SELECT COUNT(*) AS c FROM devices'))[0];
|
||||
const byVersion: any[] = await m.query(
|
||||
`SELECT COALESCE(NULLIF(client_version, ''), '未知') AS client_version, COUNT(*) AS count
|
||||
FROM devices GROUP BY client_version ORDER BY count DESC`);
|
||||
const byAccount: any[] = await m.query(
|
||||
'SELECT account, COUNT(*) AS device_count, MAX(last_seen) AS last_seen FROM devices GROUP BY account ORDER BY account');
|
||||
`SELECT account, COALESCE(NULLIF(client_version, ''), '未知') AS client_version,
|
||||
COUNT(*) AS device_count, MAX(last_seen) AS last_seen
|
||||
FROM devices GROUP BY account, client_version ORDER BY account`);
|
||||
const statusRows: any[] = await m.query(
|
||||
`SELECT status, COUNT(*) AS c FROM devices GROUP BY status`);
|
||||
const chromeRows: any[] = await m.query(
|
||||
`SELECT COALESCE(SUM(chrome_ok = 1), 0) AS ok, COUNT(*) AS c FROM devices`);
|
||||
const nick: Record<string, [string, string]> = {};
|
||||
for (const a of await this.accountRepo.find()) nick[a.account] = [a.nickname || '', a.dept || ''];
|
||||
// 最新壳子版本(与 /api/shell/version 同源:file_sources category=shell 优先,其次 SHELL_DIR/version.json)
|
||||
const latestShell = await this.latestShellVersion();
|
||||
return {
|
||||
total: Number(total.c || 0),
|
||||
by_version: [],
|
||||
by_account: byAccount.map((r: any) => ({ ...r, nickname: nick[r.account]?.[0] || '', dept: nick[r.account]?.[1] || '' })),
|
||||
online: Number(statusRows.find((r: any) => Number(r.status) === 1)?.c || 0),
|
||||
offline: Number(statusRows.find((r: any) => Number(r.status) === 0)?.c || 0),
|
||||
chrome_ok: Number(chromeRows[0]?.ok || 0),
|
||||
chrome_total: Number(chromeRows[0]?.c || 0),
|
||||
latest_shell_version: latestShell.version || '',
|
||||
by_version: byVersion.map((r: any) => ({ client_version: String(r.client_version || '未知'), count: Number(r.count) })),
|
||||
by_account: byAccount.map((r: any) => ({
|
||||
...r,
|
||||
client_version: String(r.client_version || '未知'),
|
||||
device_count: Number(r.device_count),
|
||||
last_seen: fmtStr(r.last_seen),
|
||||
nickname: nick[r.account]?.[0] || '',
|
||||
dept: nick[r.account]?.[1] || '',
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/** 最新壳子版本(shellSourceUrl 优先 / version.json 兜底;与 /api/shell/version 同语义) */
|
||||
private async latestShellVersion(): Promise<{ version: string; available: boolean }> {
|
||||
try {
|
||||
const rows = await this.fileSourceRepo
|
||||
.createQueryBuilder('f')
|
||||
.select(['f.version'])
|
||||
.where('f.category = :c', { c: 'shell' })
|
||||
.andWhere('f.enabled = 1')
|
||||
.orderBy('f.id', 'DESC')
|
||||
.getMany();
|
||||
if (rows.length && rows[0].version) return { version: rows[0].version, available: true };
|
||||
} catch (e) {
|
||||
/* fallthrough */
|
||||
}
|
||||
try {
|
||||
const vf = path.join(SHELL_DIR, 'version.json');
|
||||
if (fs.existsSync(vf)) {
|
||||
const d = JSON.parse(fs.readFileSync(vf, 'utf-8').replace(/^\uFEFF/, ''));
|
||||
if (d?.version) return { version: String(d.version), available: true };
|
||||
}
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
return { version: '', available: false };
|
||||
}
|
||||
|
||||
/** POST /api/admin/shell-release — 发布壳子新版 */
|
||||
@Post('/shell-release')
|
||||
async shellRelease(
|
||||
@@ -407,6 +456,26 @@ export class AdminOpsController extends BaseController {
|
||||
}
|
||||
|
||||
/** 通知管理 CRUD */
|
||||
@Get('/notifications/latest')
|
||||
async notifLatest(
|
||||
@Query('limit') limit: number = 15,
|
||||
@Headers('X-Admin-Token') xAdminToken: string = '', @Headers('X-API-Token') xApiToken: string = ''
|
||||
) {
|
||||
await this.centerAuthService.requireAdmin(xAdminToken, xApiToken);
|
||||
const n = Math.max(1, Math.min(50, Number(limit) || 15));
|
||||
const rows: any[] = await this.notificationRepo.manager.query(
|
||||
`SELECT id, title, content, level, target, account, created_at, expires_at
|
||||
FROM notifications
|
||||
WHERE active = 1 AND (expires_at IS NULL OR expires_at > NOW())
|
||||
ORDER BY id DESC LIMIT ${n}`
|
||||
);
|
||||
const items = rows.map((r: any) => ({
|
||||
id: r.id, title: r.title, content: r.content, level: r.level,
|
||||
target: r.target, account: r.account, created_at: fmtStr(r.created_at),
|
||||
}));
|
||||
return { items };
|
||||
}
|
||||
|
||||
@Get('/notifications')
|
||||
async notifList(
|
||||
@Query('page') page: number = 1, @Query('page_size') pageSize: number = 20,
|
||||
|
||||
@@ -263,6 +263,139 @@ export class AdminPluginController extends BaseController {
|
||||
platforms: platforms.map((r: any) => r.platform_id),
|
||||
};
|
||||
}
|
||||
|
||||
// ==================== 双向批量授权(新 UI 专用;旧 /account_plugins 契约保持不动供 agent_cli 使用) ====================
|
||||
|
||||
/** GET /api/admin/plugin_grants?plugin_id= — 插件维度:该插件已授权账号列表(含昵称/部门/权限/授权时间) */
|
||||
@Get('/plugin_grants')
|
||||
async pluginGrants(
|
||||
@Query('plugin_id') pluginId: string = '',
|
||||
@Headers('X-Admin-Token') xAdminToken: string = '',
|
||||
@Headers('X-API-Token') xApiToken: string = ''
|
||||
) {
|
||||
await this.centerAuthService.requireAdmin(xAdminToken, xApiToken);
|
||||
pluginId = (pluginId || '').trim();
|
||||
if (!pluginId) throw new ApiError(400, 'plugin_id 不能为空');
|
||||
const pl = await this.pluginRepo.findOneBy({ id: pluginId });
|
||||
if (!pl) throw new ApiError(404, `插件 ${pluginId} 不存在`);
|
||||
const rows: any[] = await this.accountPluginRepo.manager.query(
|
||||
`SELECT ap.account, a.nickname, a.dept, ap.can_download, ap.can_run, ap.granted_at, ap.updated_at
|
||||
FROM account_plugins ap LEFT JOIN accounts a ON a.account = ap.account
|
||||
WHERE ap.plugin_id = ? ORDER BY ap.account`,
|
||||
[pluginId]
|
||||
);
|
||||
return {
|
||||
plugin: { id: pl.id, name: pl.name, status: pl.status, latest_version: pl.latestVersion },
|
||||
items: rows.map(r => ({
|
||||
account: r.account,
|
||||
nickname: r.nickname || '',
|
||||
dept: r.dept || '',
|
||||
can_download: !!Number(r.can_download),
|
||||
can_run: !!Number(r.can_run),
|
||||
granted_at: fmtStr(r.granted_at),
|
||||
updated_at: fmtStr(r.updated_at),
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
/** POST /api/admin/plugin_grants/batch — 批量授权/更新(事务 upsert) */
|
||||
@Post('/plugin_grants/batch')
|
||||
async pluginGrantsBatch(
|
||||
@Body() b: any,
|
||||
@Headers('X-Admin-Token') xAdminToken: string = '',
|
||||
@Headers('X-API-Token') xApiToken: string = ''
|
||||
) {
|
||||
const login = await this.centerAuthService.requireAdmin(xAdminToken, xApiToken);
|
||||
const pluginId = String(b?.plugin_id || '').trim();
|
||||
const items: any[] = Array.isArray(b?.items) ? b.items : [];
|
||||
if (!pluginId) throw new ApiError(400, 'plugin_id 不能为空');
|
||||
if (!items.length) throw new ApiError(400, 'items 不能为空');
|
||||
const pl = await this.pluginRepo.findOneBy({ id: pluginId });
|
||||
if (!pl) throw new ApiError(404, `插件 ${pluginId} 不存在`);
|
||||
const accounts: string[] = [];
|
||||
for (const it of items) {
|
||||
const acc = String(it?.account || '').trim();
|
||||
if (acc) accounts.push(acc);
|
||||
}
|
||||
if (!accounts.length) throw new ApiError(400, 'items 中无有效 account');
|
||||
const existRows: any[] = await this.pluginRepo.manager.query(
|
||||
`SELECT account FROM accounts WHERE account IN (${accounts.map(() => '?').join(',')})`,
|
||||
accounts
|
||||
);
|
||||
const existSet = new Set(existRows.map(r => String(r.account)));
|
||||
const unknown = accounts.filter(a => !existSet.has(a));
|
||||
if (unknown.length) throw new ApiError(400, `账号不存在:${unknown.slice(0, 5).join(', ')}${unknown.length > 5 ? ' ...' : ''}`);
|
||||
await this.pluginRepo.manager.transaction(async (em) => {
|
||||
for (const it of items) {
|
||||
const acc = String(it.account || '').trim();
|
||||
const dl = it?.can_download === undefined ? 1 : Number(!!it.can_download);
|
||||
const rn = it?.can_run === undefined ? 1 : Number(!!it.can_run);
|
||||
await em.query(
|
||||
`INSERT INTO account_plugins(account, plugin_id, can_download, can_run, granted_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, NOW(), NOW())
|
||||
ON DUPLICATE KEY UPDATE can_download = VALUES(can_download), can_run = VALUES(can_run), updated_at = NOW()`,
|
||||
[acc, pluginId, dl, rn]
|
||||
);
|
||||
}
|
||||
});
|
||||
await this.centerAuthService.audit(login, 'grant-batch', pluginId, JSON.stringify({ accounts, count: items.length }));
|
||||
return { ok: true, plugin_id: pluginId, count: items.length };
|
||||
}
|
||||
|
||||
/** POST /api/admin/plugin_grants/revoke — 批量撤销 */
|
||||
@Post('/plugin_grants/revoke')
|
||||
async pluginGrantsRevoke(
|
||||
@Body() b: any,
|
||||
@Headers('X-Admin-Token') xAdminToken: string = '',
|
||||
@Headers('X-API-Token') xApiToken: string = ''
|
||||
) {
|
||||
const login = await this.centerAuthService.requireAdmin(xAdminToken, xApiToken);
|
||||
const pluginId = String(b?.plugin_id || '').trim();
|
||||
const accounts: string[] = Array.isArray(b?.accounts) ? b.accounts.map((a: any) => String(a || '').trim()).filter(Boolean) : [];
|
||||
if (!pluginId) throw new ApiError(400, 'plugin_id 不能为空');
|
||||
if (!accounts.length) throw new ApiError(400, 'accounts 不能为空');
|
||||
const res = await this.accountPluginRepo
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.where('plugin_id = :pid', { pid: pluginId })
|
||||
.andWhere('account IN (:...accounts)', { accounts })
|
||||
.execute();
|
||||
await this.centerAuthService.audit(login, 'grant-revoke-batch', pluginId, JSON.stringify({ accounts, count: accounts.length }));
|
||||
return { ok: true, plugin_id: pluginId, removed: Number(res?.affected || 0) };
|
||||
}
|
||||
|
||||
/** GET /api/admin/grants/matrix — 授权矩阵总览(账号 × 插件 + 平台白名单) */
|
||||
@Get('/grants/matrix')
|
||||
async grantsMatrix(
|
||||
@Headers('X-Admin-Token') xAdminToken: string = '',
|
||||
@Headers('X-API-Token') xApiToken: string = ''
|
||||
) {
|
||||
await this.centerAuthService.requireAdmin(xAdminToken, xApiToken);
|
||||
const m = this.accountPluginRepo.manager;
|
||||
const plugins: any[] = await m.query(`SELECT id, name, status, latest_version FROM plugins ORDER BY id`);
|
||||
const accounts: any[] = await m.query(
|
||||
`SELECT account, nickname, dept, status, is_admin FROM accounts ORDER BY account`
|
||||
);
|
||||
const grants: any[] = await m.query(
|
||||
`SELECT account, plugin_id, can_download, can_run FROM account_plugins`
|
||||
);
|
||||
const platforms: any[] = await m.query(`SELECT account, platform_id FROM account_platforms`);
|
||||
return {
|
||||
plugins: plugins.map(p => ({ id: p.id, name: p.name, status: p.status, latest_version: p.latest_version })),
|
||||
accounts: accounts.map(a => ({
|
||||
account: a.account, nickname: a.nickname || '', dept: a.dept || '',
|
||||
status: Number(a.status), is_admin: !!Number(a.is_admin),
|
||||
})),
|
||||
grants: grants.map(g => ({
|
||||
account: g.account, plugin_id: g.plugin_id,
|
||||
can_download: !!Number(g.can_download), can_run: !!Number(g.can_run),
|
||||
})),
|
||||
platforms: platforms.reduce((acc: Record<string, string[]>, r) => {
|
||||
(acc[String(r.account)] ||= []).push(String(r.platform_id));
|
||||
return acc;
|
||||
}, {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function fmt(d: Date | null): string {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { CenterAuthService, ApiError } from '../../service/auth';
|
||||
|
||||
/**
|
||||
* 运行上报 + 设备上报(对齐旧 FastAPI apis/plugins.py /api/runtime/report、/api/device/report)
|
||||
* 注意:现网 devices 表无 client_version 列(以现网 schema 为准),上报仅 upsert 现有列
|
||||
* devices.client_version:壳子心跳携带的客户端版本号(老库迁移已含该列),供升级进度统计
|
||||
*/
|
||||
@Provide()
|
||||
@CoolController('/api')
|
||||
@@ -45,12 +45,13 @@ export class ApiDeviceController extends BaseController {
|
||||
const deviceId = (b?.device_id || '').trim();
|
||||
if (!deviceId) throw new ApiError(400, 'device_id 不能为空');
|
||||
await this.deviceRepo.manager.query(
|
||||
`INSERT INTO devices(device_id, account, hostname, os, ip, chrome_installed, chrome_version, chrome_ok, last_seen, status)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)
|
||||
`INSERT INTO devices(device_id, account, hostname, os, ip, chrome_installed, chrome_version, chrome_ok, client_version, last_seen, status)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
account = VALUES(account), hostname = VALUES(hostname), os = VALUES(os),
|
||||
ip = VALUES(ip), chrome_installed = VALUES(chrome_installed),
|
||||
chrome_version = VALUES(chrome_version), chrome_ok = VALUES(chrome_ok),
|
||||
client_version = VALUES(client_version),
|
||||
last_seen = VALUES(last_seen), status = VALUES(status)`,
|
||||
[
|
||||
deviceId,
|
||||
@@ -61,6 +62,7 @@ export class ApiDeviceController extends BaseController {
|
||||
Number(!!b?.chrome_installed),
|
||||
(b?.chrome_version || '').trim(),
|
||||
Number(!!b?.chrome_ok),
|
||||
(b?.client_version || '').trim(),
|
||||
Number(!!b?.status),
|
||||
]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user