feat(user): 新增 baseinfo 命令 (self 通用字段更新)

This commit is contained in:
ssw committed 2026-06-15 10:26:35 +08:00
1 parent bb2f300ac9
commit cc684caa94
1 file changed
+48 -7
+48 -7
View File
@@ -1,16 +1,57 @@
/**
* commands/user/baseinfo.ts — 占位, Task 15 实现
* commands/user/baseinfo.ts — 用户自己改个人资料
*
* API: PUT /api/permission/Users/Current/BaseInfo
*
* web 端触发:
* - 个人中心 UserInfo.vue (整张表保存) → updateUserInfo(state.userForm)
* - 个人中心 Account/Form.vue (单字段 mobilePhone/email) → updateUserInfo(values)
*
* 通用入口: --fields JSON 传任意字段子集
*/
import { Command } from 'commander'
import { log } from '../../core/log.ts'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log } from '../../core/log.ts'
interface BaseinfoOpts {
fields: string
}
export function buildUserBaseinfoCommand(): Command {
const cmd = new Command('baseinfo').description('TODO: implement in Task 15')
cmd.action(async () => {
log.warn('TODO: implement in Task 15')
process.exit(1)
const cmd = new Command('baseinfo')
.description('修改当前用户个人资料 (self 操作, 任意字段子集)')
.requiredOption('--fields <json>', '要更新的字段 JSON, 如 {"mobilePhone":"138...","email":"x@y","realName":"新名"}')
.action(async (opts: BaseinfoOpts) => {
let fields: Record<string, unknown>
try {
fields = JSON.parse(opts.fields)
} catch (e) {
log.error(`JSON 解析失败: ${(e as Error).message}`)
process.exit(1)
}
const c = await JnpfClient.fromToken()
const r = await c.putJson('/permission/Users/Current/BaseInfo', fields)
if (r.code !== 200) {
log.error(`user baseinfo 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
log.info(`✓ 个人资料已更新: ${Object.keys(fields).map((k) => `${k}=${fields[k]}`).join(', ')}`)
})
installAiHelpHook(cmd, {
purpose: '修改当前用户个人资料 (self 操作, 通用入口)',
required: { '--fields': '字段 JSON, 支持 mobilePhone/email/realName/gender/nation/education/birthday/...' },
example:
'dacli user baseinfo --fields=\'{"mobilePhone":"13800000000","email":"[email protected]"}\'',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/_core/profile/components/UserInfo.vue + Account/Form.vue',
api: 'PUT /api/permission/Users/Current/BaseInfo',
},
notes: [
'**通用入口**: 单字段 (mobilePhone/email) 或多字段 (整张 UserInfo 表) 都用同一命令',
'**JSON**: --fields 必须合法 JSON, 失败会 exit(1)',
'**web 端**: web 端用两个表单 (单字段 vs 整张表), CLI 统一为 --fields',
],
})
installAiHelpHook(cmd, { purpose: 'TODO' })
return cmd
}