feat(huya): 精英宝典工作台支持导入外部 CK

- 新增 POST /api/huya/workbench-accounts/import-cookies(huya:task + huya:import):
  外部 CK 复用现有解析入库后直接加入当前用户的工作台集合,导入完即可在工作台执行
  「生成开通支付码/绑定二维码/查询角色/刷新积分」等操作
- 新账号自动 assigned_to=导入者:客服的账号列表按归属过滤,不设归属会「导入成功但看不到」
- import_huya_cookies_detailed 返回账号对象供工作台复用,原 import_huya_cookies 行为不变
- 工作台账号卡片新增「导入外部 CK」入口(huya:import 权限控制)与导入弹窗

验证:新增 tests/test_huya_workbench_import_ck.py(入库、归属、工作台集合、重复导入幂等、
全脏数据不建记录);按 AGENTS.md 做了反向验证(关掉归属赋值后该用例变红,还原后恢复)。
前端 tsc -b 与全量 pytest 通过。
This commit is contained in:
yml2213
2026-10-15 14:56:58 +08:00
parent f540dcfc29
commit 4ce30e5c26
10 changed files with 304 additions and 9 deletions
@@ -0,0 +1,96 @@
import { useEffect, useState } from 'react';
import { Alert, Input, Modal, Select, Space, Typography } from 'antd';
import { huyaApi, type HuyaExternalCkImportResult, type HuyaWorkbenchScope } from '../api/modules';
import { getErrorMessage } from '../utils/error';
import { message } from '../utils/antdMessage';
const { Text } = Typography;
export interface HuyaExternalCkImportModalProps {
open: boolean;
onClose: () => void;
/** 已有标签,供下拉选择 */
tags: string[];
defaultTag?: string;
scope?: HuyaWorkbenchScope;
/** 导入成功后回调(带完整的工作台账号集合) */
onImported: (result: HuyaExternalCkImportResult) => void;
}
/** 工作台「导入外部 CK」:粘贴外部 Cookie,入库并直接加入工作台,随后可在工作台操作 */
export default function HuyaExternalCkImportModal({
open, onClose, tags, defaultTag, scope = 'elite', onImported,
}: HuyaExternalCkImportModalProps) {
const [text, setText] = useState('');
const [tag, setTag] = useState(defaultTag || '');
const [importing, setImporting] = useState(false);
const [result, setResult] = useState<HuyaExternalCkImportResult | null>(null);
useEffect(() => {
if (!open) return;
setResult(null);
setTag(defaultTag || '');
}, [defaultTag, open]);
const submit = async () => {
const value = text.trim();
if (!value) { message.warning('请先粘贴 CK,每行一条'); return; }
setImporting(true);
try {
const saved = await huyaApi.importWorkbenchCookies({ text: value, tag, handbook_scope: scope });
setResult(saved);
message.success(saved.message || `已导入 ${saved.count} 条`);
onImported(saved);
} catch (error) {
message.error(getErrorMessage(error));
} finally {
setImporting(false);
}
};
return (
<Modal
open={open}
title="导入外部 CK 到工作台"
width={640}
onCancel={onClose}
onOk={() => void submit()}
confirmLoading={importing}
okText="导入"
cancelText="取消"
>
<Space direction="vertical" size={8} style={{ width: '100%' }}>
<Input.TextArea
rows={8}
value={text}
onChange={(event) => setText(event.target.value)}
placeholder={'每行一条 CK,支持 N 行批量导入\n支持格式:纯 CK 或 账号----密码----CK'}
/>
<Space size={8}>
<Text type="secondary">标签</Text>
<Select
allowClear
showSearch
optionFilterProp="label"
placeholder="可选"
value={tag || undefined}
onChange={(value) => setTag(value || '')}
options={tags.map((item) => ({ value: item, label: item }))}
style={{ width: 220 }}
/>
</Space>
<Text type="secondary" style={{ fontSize: 12 }}>
导入后账号会直接加入当前工作台,可照常执行「生成开通支付码 / 绑定二维码 / 查询角色 / 刷新积分」等操作。
</Text>
{result && (
<Alert
type={result.count ? 'success' : 'warning'}
showIcon
message={result.message}
description={`成功 ${result.count} 条,跳过 ${result.skipped} 条;工作台现有 ${result.account_ids.length} 个账号`}
/>
)}
</Space>
</Modal>
);
}