修复虎牙绑定角色识别
This commit is contained in:
@@ -214,6 +214,10 @@ function hasMiniQrcode(task: HuyaTaskItem): boolean {
|
||||
return task.task_type === 'get_bind_qr' && Boolean(resultText(task.result, 'mini_qrcode_image'));
|
||||
}
|
||||
|
||||
function bindReadyForConfirm(task: HuyaTaskItem | null | undefined): boolean {
|
||||
return task?.task_type === 'get_bind_qr' && task.result?.bind_ready_for_confirm === true;
|
||||
}
|
||||
|
||||
function hasPaymentQrcode(task: HuyaTaskItem): boolean {
|
||||
return task.task_type === 'create_recharge_order' && Boolean(resultText(task.result, 'pay_url'));
|
||||
}
|
||||
@@ -430,6 +434,12 @@ export default function HuyaTasksPage() {
|
||||
if (latest !== payTask) setPayTask(latest);
|
||||
}, [payTask, tasks]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!qrTask) return;
|
||||
const latest = tasks.find((task) => task.id === qrTask.id);
|
||||
if (latest && latest !== qrTask) setQrTask(latest);
|
||||
}, [qrTask, tasks]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!accountContextMenu) return;
|
||||
const close = () => setAccountContextMenu(null);
|
||||
@@ -757,6 +767,26 @@ export default function HuyaTasksPage() {
|
||||
const failedCount = tasks.filter((task) => ['failed', 'error'].includes(task.status)).length;
|
||||
const qrResult = qrTask?.result || null;
|
||||
const qrImage = resultText(qrResult, 'mini_qrcode_image');
|
||||
const qrBindPhase = resultText(qrResult, 'bind_phase');
|
||||
const qrBindReady = bindReadyForConfirm(qrTask);
|
||||
const qrWaitingRole = qrTask?.status === 'running' && !qrBindReady;
|
||||
const qrGameTitle = resultText(qrResult, 'game_title');
|
||||
const qrRoleName = resultText(qrResult, 'role_name');
|
||||
const qrGameRole = resultObject(qrResult, 'game_role');
|
||||
const qrRoleArea = typeof qrGameRole?.area_name === 'string' ? qrGameRole.area_name : '';
|
||||
const qrRolePlat = typeof qrGameRole?.plat_name === 'string' ? qrGameRole.plat_name : '';
|
||||
const qrRoleLine = qrBindReady ? [qrRolePlat, qrRoleArea, qrRoleName].filter(Boolean).join(' - ') : '';
|
||||
const qrStatusText = qrBindReady
|
||||
? '已识别角色,待确认'
|
||||
: qrBindPhase === 'role_timeout'
|
||||
? '未检测到角色'
|
||||
: qrBindPhase === 'qrcode_completed'
|
||||
? '等待角色同步'
|
||||
: qrBindPhase === 'qrcode_scanned'
|
||||
? '已扫码'
|
||||
: qrBindPhase === 'qrcode_expired'
|
||||
? '二维码已失效'
|
||||
: '等待绑定';
|
||||
const qrAccountName = qrTask
|
||||
? resultProfileNick(qrResult) || qrTask.account_nickname || qrTask.account_uid || `#${qrTask.account_id}`
|
||||
: '';
|
||||
@@ -779,10 +809,34 @@ export default function HuyaTasksPage() {
|
||||
const exchangeRecordsAccountName = exchangeRecordsTask
|
||||
? exchangeRecordsTask.account_nickname || exchangeRecordsTask.account_uid || `#${exchangeRecordsTask.account_id}`
|
||||
: '';
|
||||
const confirmQrBind = () => {
|
||||
if (!qrTask || !qrBindReady) return;
|
||||
const accountId = qrTask.account_id;
|
||||
setQrTask(null);
|
||||
void startTask('confirm_bind', [accountId]);
|
||||
};
|
||||
const queryQrRole = () => {
|
||||
if (!qrTask) return;
|
||||
const accountId = qrTask.account_id;
|
||||
setQrTask(null);
|
||||
void startTask('query_game_name', [accountId]);
|
||||
};
|
||||
|
||||
const renderTaskResult = (value: Record<string, unknown> | null, record: HuyaTaskItem) => {
|
||||
const bindQrImage = resultText(value, 'mini_qrcode_image');
|
||||
if (bindQrImage) {
|
||||
if (bindReadyForConfirm(record)) {
|
||||
const roleName = resultText(value, 'role_name');
|
||||
return (
|
||||
<Space size={6}>
|
||||
<Tag color="gold">待确认</Tag>
|
||||
{roleName ? <Text>{roleName}</Text> : null}
|
||||
<Button size="small" icon={<QrcodeOutlined />} onClick={() => openQrTask(record)}>
|
||||
查看
|
||||
</Button>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Button size="small" icon={<QrcodeOutlined />} onClick={() => openQrTask(record)}>
|
||||
查看二维码
|
||||
@@ -1686,11 +1740,19 @@ export default function HuyaTasksPage() {
|
||||
open={!!qrTask}
|
||||
onCancel={() => setQrTask(null)}
|
||||
footer={null}
|
||||
width={360}
|
||||
width={400}
|
||||
>
|
||||
{qrTask && (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 12, padding: '8px 0 12px' }}>
|
||||
<Text strong style={{ maxWidth: '100%', textAlign: 'center' }}>{qrAccountName}</Text>
|
||||
<Space direction="vertical" size={4} style={{ width: '100%', textAlign: 'center' }}>
|
||||
<Text strong>{qrAccountName}</Text>
|
||||
<Tag
|
||||
color={qrBindReady ? 'gold' : qrBindPhase === 'role_timeout' ? 'orange' : 'processing'}
|
||||
style={{ alignSelf: 'center', marginInlineEnd: 0 }}
|
||||
>
|
||||
{qrStatusText}
|
||||
</Tag>
|
||||
</Space>
|
||||
{qrImage ? (
|
||||
<div
|
||||
style={{
|
||||
@@ -1716,6 +1778,32 @@ export default function HuyaTasksPage() {
|
||||
) : (
|
||||
<Text type="secondary">暂无二维码</Text>
|
||||
)}
|
||||
{qrRoleLine ? (
|
||||
<Space direction="vertical" size={2} style={{ width: '100%', textAlign: 'center' }}>
|
||||
{qrGameTitle ? <Text type="secondary">{qrGameTitle}</Text> : null}
|
||||
<Text strong>{qrRoleLine}</Text>
|
||||
</Space>
|
||||
) : null}
|
||||
<Space size={8}>
|
||||
<Button onClick={() => setQrTask(null)}>关闭</Button>
|
||||
<Button
|
||||
icon={<SearchOutlined />}
|
||||
disabled={!canTask || starting || qrWaitingRole}
|
||||
loading={starting}
|
||||
onClick={queryQrRole}
|
||||
>
|
||||
查询角色
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<CheckCircleOutlined />}
|
||||
disabled={!qrBindReady || !canTask || starting}
|
||||
loading={starting}
|
||||
onClick={confirmQrBind}
|
||||
>
|
||||
确认绑定
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user