refactor(v0.11+): log login/operate 改走 webapi 镜像 (loadLog)

响应用户: '前面做的那些是不是也有问题, 应该走 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 <[email protected]>
This commit is contained in:
sswandClaude committed 2026-06-25 15:32:21 +08:00
1 parent d1284c45cb
commit 27cf29b12b
2 files changed
+27 -20

No files matched your search

+13 -11
View File
@@ -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 <k>', '按账号/姓名模糊搜索')
.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<string, unknown>[] }>('/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<string, unknown>[] }
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
}
+14 -9
View File
@@ -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 <k>', '按账号/姓名模糊搜索')
.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<string, unknown>[] }>('/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<string, unknown>[] }
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
}