From c275391ced7ffcfeaf7fef46ee37f1ef376815e8 Mon Sep 17 00:00:00 2001 From: ssw Date: Mon, 15 Jun 2026 10:17:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(user):=20=E6=96=B0=E5=A2=9E=20socials-unbi?= =?UTF-8?q?nd=20=E5=91=BD=E4=BB=A4=20(admin=20=E8=A7=A3=E7=BB=91=E7=A4=BE?= =?UTF-8?q?=E4=BA=A4=E8=B4=A6=E5=8F=B7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commands/user/socials-unbind.ts | 77 ++++++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/src/commands/user/socials-unbind.ts b/src/commands/user/socials-unbind.ts index 1a57d6c..9ed48ac 100644 --- a/src/commands/user/socials-unbind.ts +++ b/src/commands/user/socials-unbind.ts @@ -1,16 +1,79 @@ /** - * commands/user/socials-unbind.ts — 占位, Task 12 实现 + * commands/user/socials-unbind.ts — admin 解绑社交账号 + * + * API: + * 1) GET /api/permission/socials?userId={uid} 查绑定列表 + * 2) DELETE /api/permission/socials/{userId}/{socialsId} 解绑 + * + * web 端触发: SocialsBind.vue, handleDel(item.entity.id) */ 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 SocialsItem { + name?: string + description?: string + entity?: { id?: string } +} + +interface SocialsUnbindOpts { + userId: string + socialsId?: string + list?: boolean +} export function buildUserSocialsUnbindCommand(): Command { - const cmd = new Command('socials-unbind').description('TODO: implement in Task 12') - cmd.action(async () => { - log.warn('TODO: implement in Task 12') - process.exit(1) + const cmd = new Command('socials-unbind') + .description('解绑社交账号 (admin 操作)') + .requiredOption('--userId ', '用户 id') + .option('--socialsId ', '社交账号 entity.id (web 端 entity.id)') + .option('--list', '列出该用户的所有社交账号绑定, 不解绑', false) + .action(async (opts: SocialsUnbindOpts) => { + const c = await JnpfClient.fromToken() + + // Step 1: 查绑定列表 + const listRes = await c.get('/permission/socials', { + userId: opts.userId, + }) + if (listRes.code !== 200) { + log.error(`socials 列表失败 (code=${listRes.code}): ${listRes.msg}`) + process.exit(1) + } + const list = listRes.data || [] + if (opts.list || !opts.socialsId) { + log.info(`用户 id=${opts.userId} 共 ${list.length} 个社交账号绑定`) + for (const it of list) { + console.log(` ${it.entity?.id || '(无 entity)'} ${it.name} (${it.description || ''})`) + } + if (!opts.socialsId) { + log.info('用 --socialsId= 解绑指定账号') + } + return + } + + // Step 2: 解绑 + const r = await c.del(`/permission/socials/${opts.userId}/${opts.socialsId}`) + if (r.code !== 200) { + log.error(`socials-unbind 失败 (code=${r.code}): ${r.msg}`) + process.exit(1) + } + log.info(`✓ 用户 id=${opts.userId} 社交账号 socialsId=${opts.socialsId} 已解绑`) + }) + installAiHelpHook(cmd, { + purpose: '解绑社交账号 (admin 操作)', + required: { '--userId': '用户 id' }, + optional: { '--socialsId': '社交账号 entity.id (不传只列出)', '--list': '只列出不解绑' }, + example: 'dacli user socials-unbind --userId=1234567890 --socialsId=abc123', + source: { + web: 'web/apps/jnpf-web-apps-main/src/views/permission/user/SocialsBind.vue', + api: 'DELETE /api/permission/socials/{userId}/{socialsId}', + }, + notes: [ + '**先列后绑**: 不传 --socialsId 时只列, 传后才解绑 (二段式防误操作)', + '**实体 id**: 用 web 端 SocialsBind.vue 看到的 entity.id, 不是社交平台 userId', + ], }) - installAiHelpHook(cmd, { purpose: 'TODO' }) return cmd } \ No newline at end of file