From 27cf29b12bffe987d33e5b0583f2eb57fd07ea8c Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 25 Jun 2026 15:32:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor(v0.11+):=20log=20login/operate=20?= =?UTF-8?q?=E6=94=B9=E8=B5=B0=20webapi=20=E9=95=9C=E5=83=8F=20(loadLog)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 响应用户: '前面做的那些是不是也有问题, 应该走 webapi' - log/login: c.get → loadLog.getLogList(category=1) - log/operate: c.get → loadLog.getLogList(category=3) log 4 子命令全部走 webapi 镜像 (login/operate/exception/request) Co-Authored-By: Claude --- src/commands/log/login.ts | 24 +++++++++++++----------- src/commands/log/operate.ts | 23 ++++++++++++++--------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/commands/log/login.ts b/src/commands/log/login.ts index ebc8cc8..9b2b06f 100644 --- a/src/commands/log/login.ts +++ b/src/commands/log/login.ts @@ -1,13 +1,14 @@ /** * commands/log/login.ts — 登录日志 * - * 注: JNPF 登录日志走 GET /api/system/Log (LogType 区分: login/operate/异常/请求) - * 这里用 logType 字段过滤 + * v0.11+ Phase 2: webapi 化 (loadLog.getLogList + category=1) + * 替代 v0.10 直接 c.get */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { initWebapi, loadLog } from '../../webapi/log.ts' interface ListOpts { keyword?: string @@ -16,26 +17,26 @@ interface ListOpts { export function buildLogLoginCommand(): Command { const cmd = new Command('login') - .description('登录日志 (近 30 天)') + .description('登录日志 (近 30 天, v0.11+ webapi)') .option('--keyword ', '按账号/姓名模糊搜索') .option('--json', '原始 JSON 输出', false) .action(async (opts: ListOpts) => { const c = await JnpfClient.fromToken() + await initWebapi(c) // JNPF 登录日志 = Log + category='1' (web/src/views/sysLog/loginLog/index.vue:20 category:'1') - // 后端 BindException: category 必须是 int 字符串 ("1" 登录 / "3" 操作 / "4" 异常 / "5" 请求), 不能是 'login' 字面量 - const r = await c.get<{ list: Record[] }>('/system/Log', { + const r = (await loadLog.getLogList({ category: '1', keyword: opts.keyword, currentPage: 1, pageSize: 20, - }) - if (r.code !== 200) { - log.error(`log login 失败: ${r.msg}`) + })) as { list?: Record[] } + if (!r || (r as { code?: number }).code !== 200 && (r as { code?: number }).code !== undefined) { + log.error(`log login 失败: ${(r as { msg?: string }).msg}`) process.exit(1) } - const list = r.data?.list || [] + const list = r.list || [] if (opts.json) { - printJson(r.data) + printJson(r) return } log.info(`登录日志 ${list.length} 条`) @@ -50,8 +51,9 @@ export function buildLogLoginCommand(): Command { source: { web: 'web/apps/jnpf-web-apps-main/src/views/sysLog/loginLog/index.vue', api: 'GET /api/system/Log?category=1', - ref: 'doc/v0.8-endpoints.md §3.2', + ref: 'web/.../api/system/log.ts getLogList()', }, + notes: ['v0.11+ 改用 webapi 镜像 (loadLog.getLogList + category=1)'], }) return cmd } diff --git a/src/commands/log/operate.ts b/src/commands/log/operate.ts index 5f65759..501f9a1 100644 --- a/src/commands/log/operate.ts +++ b/src/commands/log/operate.ts @@ -1,10 +1,14 @@ /** * commands/log/operate.ts — 操作日志 + * + * v0.11+ Phase 2: webapi 化 (loadLog.getLogList + category=3) + * 替代 v0.10 直接 c.get */ import { Command } from 'commander' import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' +import { initWebapi, loadLog } from '../../webapi/log.ts' interface ListOpts { keyword?: string @@ -13,26 +17,26 @@ interface ListOpts { export function buildLogOperateCommand(): Command { const cmd = new Command('operate') - .description('操作日志') + .description('操作日志 (v0.11+ webapi)') .option('--keyword ', '按账号/姓名模糊搜索') .option('--json', '原始 JSON 输出', false) .action(async (opts: ListOpts) => { const c = await JnpfClient.fromToken() + await initWebapi(c) // JNPF 操作日志 = Log + category='3' (web/src/views/sysLog/operateLog/index.vue:23 category:'3') - // 后端 BindException: category 必须是 int 字符串 ("1" 登录 / "3" 操作 / "4" 异常 / "5" 请求), 不能是 'operate' 字面量 - const r = await c.get<{ list: Record[] }>('/system/Log', { + const r = (await loadLog.getLogList({ category: '3', keyword: opts.keyword, currentPage: 1, pageSize: 20, - }) - if (r.code !== 200) { - log.error(`log operate 失败: ${r.msg}`) + })) as { list?: Record[] } + if (!r || (r as { code?: number }).code !== 200 && (r as { code?: number }).code !== undefined) { + log.error(`log operate 失败: ${(r as { msg?: string }).msg}`) process.exit(1) } - const list = r.data?.list || [] + const list = r.list || [] if (opts.json) { - printJson(r.data) + printJson(r) return } log.info(`操作日志 ${list.length} 条`) @@ -47,8 +51,9 @@ export function buildLogOperateCommand(): Command { source: { web: 'web/apps/jnpf-web-apps-main/src/views/sysLog/operateLog/index.vue', api: 'GET /api/system/Log?category=3', - ref: 'doc/v0.8-endpoints.md §3.2', + ref: 'web/.../api/system/log.ts getLogList()', }, + notes: ['v0.11+ 改用 webapi 镜像 (loadLog.getLogList + category=3)'], }) return cmd }