832 lines
29 KiB
TypeScript
832 lines
29 KiB
TypeScript
import {
|
||
CheckCircleOutlined,
|
||
ChromeOutlined,
|
||
CopyOutlined,
|
||
KeyOutlined,
|
||
ReloadOutlined,
|
||
SendOutlined,
|
||
UserSwitchOutlined,
|
||
} from '@ant-design/icons'
|
||
import {
|
||
Alert,
|
||
App,
|
||
Button,
|
||
Card,
|
||
Descriptions,
|
||
Drawer,
|
||
Form,
|
||
Input,
|
||
InputNumber,
|
||
Modal,
|
||
Select,
|
||
Space,
|
||
Tag,
|
||
Timeline,
|
||
Typography,
|
||
} from 'antd'
|
||
import type { TableColumnsType } from 'antd'
|
||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||
import { useEffect, useMemo, useState } from 'react'
|
||
|
||
import ImageUpload from '@/components/files/ImageUpload'
|
||
import PageHeader from '@/components/admin/PageHeader'
|
||
import PercentTable from '@/components/common/PercentTable'
|
||
import {
|
||
cancelAdminSemiAutoTask,
|
||
claimAdminSemiAutoTask,
|
||
completeAdminSemiAutoTask,
|
||
createAdminSemiAutoBrowserSession,
|
||
exportAdminSemiAutoCredential,
|
||
fetchAdminSemiAutoTask,
|
||
fetchAdminSemiAutoTasks,
|
||
requestAdminSemiAutoCustomerReauth,
|
||
syncAdminSemiAutoTask,
|
||
} from '@/services/admin/semi-auto'
|
||
import type { SemiAutoTask } from '@/types/admin/semi-auto'
|
||
import type { UploadedFile } from '@/types/worker-platform'
|
||
import { formatAdminDateTime } from '@/utils/admin-time'
|
||
|
||
const { Text } = Typography
|
||
|
||
const STATUS_COLORS: Record<string, string> = {
|
||
waiting_customer: 'blue',
|
||
waiting_login: 'blue',
|
||
login_scanned: 'cyan',
|
||
waiting_binding: 'gold',
|
||
binding_confirm: 'orange',
|
||
binding_expired: 'red',
|
||
binding_failed: 'red',
|
||
waiting_operator: 'volcano',
|
||
credential_expired: 'red',
|
||
processing: 'processing',
|
||
completed: 'success',
|
||
failed: 'error',
|
||
cancelled: 'default',
|
||
}
|
||
|
||
const PLATFORM_LABELS: Record<string, string> = {
|
||
huya: '虎牙',
|
||
weibo: '微博',
|
||
}
|
||
|
||
const BINDING_STATUS_LABELS: Record<string, string> = {
|
||
not_started: '未开始',
|
||
qr_pending: '待扫码',
|
||
scanned: '已扫码',
|
||
role_ready: '待确认角色',
|
||
confirmed: '已确认',
|
||
failed: '失败',
|
||
expired: '已过期',
|
||
}
|
||
|
||
type CompleteFormValues = {
|
||
note?: string
|
||
externalOrderNo?: string
|
||
costYuan?: number
|
||
}
|
||
|
||
export default function AdminSemiAutoTasksPage() {
|
||
const { message, modal } = App.useApp()
|
||
const queryClient = useQueryClient()
|
||
const [keyword, setKeyword] = useState('')
|
||
const [platform, setPlatform] = useState('')
|
||
const [status, setStatus] = useState('')
|
||
const [page, setPage] = useState(1)
|
||
const [pageSize, setPageSize] = useState(20)
|
||
const [detailTaskId, setDetailTaskId] = useState<number | null>(null)
|
||
const [completeTask, setCompleteTask] = useState<SemiAutoTask | null>(null)
|
||
const [completeFiles, setCompleteFiles] = useState<UploadedFile[]>([])
|
||
const [completeForm] = Form.useForm<CompleteFormValues>()
|
||
|
||
const params = useMemo(
|
||
() => ({
|
||
page,
|
||
pageSize,
|
||
keyword: keyword.trim() || undefined,
|
||
platform: platform || undefined,
|
||
status: status || undefined,
|
||
}),
|
||
[keyword, page, pageSize, platform, status],
|
||
)
|
||
|
||
const listQuery = useQuery({
|
||
queryKey: ['admin-semi-auto-tasks', params],
|
||
queryFn: () => fetchAdminSemiAutoTasks(params),
|
||
refetchInterval: 3000,
|
||
})
|
||
const detailQuery = useQuery({
|
||
queryKey: ['admin-semi-auto-task', detailTaskId],
|
||
queryFn: () => fetchAdminSemiAutoTask(Number(detailTaskId)),
|
||
enabled: Boolean(detailTaskId),
|
||
refetchInterval: detailTaskId ? 3000 : false,
|
||
})
|
||
const list = listQuery.data?.data?.items || []
|
||
const pagination = listQuery.data?.data?.pagination
|
||
const detail = detailQuery.data?.data
|
||
|
||
useEffect(() => {
|
||
if (detailTaskId && listQuery.data && !list.some((item) => item.id === detailTaskId)) {
|
||
setDetailTaskId(null)
|
||
}
|
||
}, [detailTaskId, list, listQuery.data])
|
||
|
||
useEffect(() => {
|
||
const handleResult = (event: Event) => {
|
||
const detail = (event as CustomEvent<string>).detail
|
||
if (typeof detail !== 'string') return
|
||
try {
|
||
const result = JSON.parse(detail) as {
|
||
ok?: boolean
|
||
written?: number
|
||
error?: string
|
||
}
|
||
if (!result || typeof result !== 'object') return
|
||
if (result.ok) {
|
||
message.success(`浏览器登录态已注入(${Number(result.written || 0)} 个 Cookie)`)
|
||
} else {
|
||
message.error(result.error || '浏览器登录态注入失败')
|
||
}
|
||
} catch {
|
||
// 忽略其他页面事件
|
||
}
|
||
}
|
||
window.addEventListener('huya-exchange-result', handleResult)
|
||
return () => window.removeEventListener('huya-exchange-result', handleResult)
|
||
}, [message])
|
||
|
||
const syncMutation = useMutation({
|
||
mutationFn: (taskId: number) => syncAdminSemiAutoTask(taskId),
|
||
onSuccess: () => {
|
||
message.success('状态已刷新')
|
||
void refreshAll()
|
||
},
|
||
onError: (error) => message.error(error instanceof Error ? error.message : '刷新失败'),
|
||
})
|
||
|
||
const claimMutation = useMutation({
|
||
mutationFn: (taskId: number) => claimAdminSemiAutoTask(taskId),
|
||
onSuccess: () => {
|
||
message.success('任务已领取')
|
||
void refreshAll()
|
||
},
|
||
onError: (error) => message.error(error instanceof Error ? error.message : '领取失败'),
|
||
})
|
||
|
||
const injectionMutation = useMutation({
|
||
mutationFn: (task: SemiAutoTask) =>
|
||
createAdminSemiAutoBrowserSession(task.id, firstTargetUrl(task)),
|
||
onSuccess: (response) => {
|
||
const ticket = String(response.data?.ticket || '').trim()
|
||
if (!ticket) {
|
||
message.error('注入票据生成失败')
|
||
return
|
||
}
|
||
window.postMessage({ type: 'ORDER_SITE_SEMI_AUTO_INJECT', ticket }, window.location.origin)
|
||
message.info('正在注入浏览器登录态,请稍候')
|
||
void refreshAll()
|
||
},
|
||
onError: (error) =>
|
||
message.error(error instanceof Error ? error.message : '打开浏览器登录态失败'),
|
||
})
|
||
|
||
const credentialExportMutation = useMutation({
|
||
mutationFn: (taskId: number) => exportAdminSemiAutoCredential(taskId),
|
||
onSuccess: (response) => {
|
||
const text =
|
||
String(response.data?.cookieHeader || '').trim() ||
|
||
(response.data?.cookies || []).map((cookie) => `${cookie.name}=${cookie.value}`).join('; ')
|
||
if (!text) {
|
||
message.error('当前任务没有可复制的 CK')
|
||
return
|
||
}
|
||
void navigator.clipboard
|
||
.writeText(text)
|
||
.then(() => message.success('最终 CK 已复制'))
|
||
.catch(() => message.error('复制失败,请检查浏览器剪贴板权限'))
|
||
},
|
||
onError: (error) => message.error(error instanceof Error ? error.message : '复制账号 CK 失败'),
|
||
})
|
||
|
||
const reauthMutation = useMutation({
|
||
mutationFn: (task: SemiAutoTask) => requestAdminSemiAutoCustomerReauth(task.id),
|
||
onSuccess: async (response, task) => {
|
||
const copied = await copyCustomerLink(response.data?.task || task, '')
|
||
message.success(
|
||
copied ? '已重新发起授权,客户链接已复制' : '已重新发起授权,请手动复制客户链接',
|
||
)
|
||
await refreshAll()
|
||
},
|
||
onError: (error) =>
|
||
message.error(error instanceof Error ? error.message : '重新发起客户授权失败'),
|
||
})
|
||
|
||
const completeMutation = useMutation({
|
||
mutationFn: async (values: CompleteFormValues) => {
|
||
if (!completeTask) throw new Error('任务不存在')
|
||
const costFen =
|
||
values.costYuan !== undefined && values.costYuan !== null
|
||
? Math.round(Number(values.costYuan) * 100)
|
||
: undefined
|
||
return completeAdminSemiAutoTask(completeTask.id, {
|
||
note: values.note || '',
|
||
externalOrderNo: values.externalOrderNo || '',
|
||
...(costFen !== undefined ? { costFen } : {}),
|
||
screenshots: completeFiles.map((file) => ({ ...file })),
|
||
})
|
||
},
|
||
onSuccess: () => {
|
||
message.success('半自动履约已完成')
|
||
setCompleteTask(null)
|
||
setCompleteFiles([])
|
||
completeForm.resetFields()
|
||
void refreshAll()
|
||
},
|
||
onError: (error) => message.error(error instanceof Error ? error.message : '完成履约失败'),
|
||
})
|
||
|
||
const cancelMutation = useMutation({
|
||
mutationFn: ({ taskId, reason }: { taskId: number; reason: string }) =>
|
||
cancelAdminSemiAutoTask(taskId, reason),
|
||
onSuccess: () => {
|
||
message.success('任务已取消')
|
||
void refreshAll()
|
||
},
|
||
onError: (error) => message.error(error instanceof Error ? error.message : '取消失败'),
|
||
})
|
||
|
||
async function refreshAll() {
|
||
await Promise.all([
|
||
queryClient.invalidateQueries({ queryKey: ['admin-semi-auto-tasks'] }),
|
||
detailTaskId
|
||
? queryClient.invalidateQueries({ queryKey: ['admin-semi-auto-task', detailTaskId] })
|
||
: Promise.resolve(),
|
||
])
|
||
}
|
||
|
||
async function copyCustomerLink(task: SemiAutoTask, successMessage = '客户授权链接已复制') {
|
||
const url = `${window.location.origin}/c/${encodeURIComponent(task.orderNo)}`
|
||
try {
|
||
await navigator.clipboard.writeText(url)
|
||
if (successMessage) message.success(successMessage)
|
||
return true
|
||
} catch {
|
||
message.error('复制失败,请手动复制客户链接')
|
||
return false
|
||
}
|
||
}
|
||
|
||
function confirmReauth(task: SemiAutoTask) {
|
||
modal.confirm({
|
||
title: '重新发送客户授权',
|
||
content: '当前登录状态会失效,客户需要打开新的授权链接重新登录。原授权记录会保留。',
|
||
okText: '重新发送并复制链接',
|
||
cancelText: '取消',
|
||
onOk: () => reauthMutation.mutateAsync(task),
|
||
})
|
||
}
|
||
|
||
function confirmCopyCredential(task: SemiAutoTask) {
|
||
modal.confirm({
|
||
title: '复制最终 CK',
|
||
content: 'CK 等同于平台登录态。复制后请勿发给无关人员,也不要保存到聊天记录或工单备注。',
|
||
okText: '确认复制',
|
||
okButtonProps: { danger: true },
|
||
cancelText: '取消',
|
||
onOk: () => credentialExportMutation.mutateAsync(task.id),
|
||
})
|
||
}
|
||
|
||
function openComplete(task: SemiAutoTask) {
|
||
setCompleteTask(task)
|
||
setCompleteFiles([])
|
||
completeForm.resetFields()
|
||
}
|
||
|
||
function confirmCancel(task: SemiAutoTask) {
|
||
let reason = ''
|
||
modal.confirm({
|
||
title: '取消半自动履约任务',
|
||
content: (
|
||
<Input.TextArea
|
||
rows={3}
|
||
placeholder="请填写取消原因(可选)"
|
||
onChange={(event) => {
|
||
reason = event.target.value
|
||
}}
|
||
/>
|
||
),
|
||
okText: '确认取消',
|
||
okButtonProps: { danger: true },
|
||
cancelText: '返回',
|
||
onOk: () => cancelMutation.mutateAsync({ taskId: task.id, reason }),
|
||
})
|
||
}
|
||
|
||
const columns: TableColumnsType<SemiAutoTask> = [
|
||
{
|
||
title: '订单 / 商品',
|
||
key: 'order',
|
||
width: 260,
|
||
render: (_, task) => (
|
||
<Space direction="vertical" size={2}>
|
||
<Text strong>{task.orderNo}</Text>
|
||
<Text>{task.productName || task.skuName || task.skuCode}</Text>
|
||
<Text type="secondary">SKU:{task.skuCode || '-'}</Text>
|
||
</Space>
|
||
),
|
||
},
|
||
{
|
||
title: '平台',
|
||
dataIndex: 'platform',
|
||
width: 120,
|
||
render: (value: string, task) => (
|
||
<Space direction="vertical" size={4}>
|
||
<Tag color="purple">{PLATFORM_LABELS[value] || value}</Tag>
|
||
<Tag color={task.connectorMode === 'mock' ? 'orange' : 'green'}>
|
||
{task.connectorMode === 'mock' ? 'Mock' : '真实'}
|
||
</Tag>
|
||
</Space>
|
||
),
|
||
},
|
||
{
|
||
title: '客户登录',
|
||
key: 'login',
|
||
width: 180,
|
||
render: (_, task) => (
|
||
<Space direction="vertical" size={2}>
|
||
<Tag>{task.displayStatus.label}</Tag>
|
||
<Text type="secondary">{task.huyaUid ? `UID ${task.huyaUid}` : '未获取 UID'}</Text>
|
||
<Text type="secondary">
|
||
{task.platform === 'huya'
|
||
? `绑定:${BINDING_STATUS_LABELS[task.bindingStatus] || task.bindingStatus}`
|
||
: '微博登录即授权'}
|
||
</Text>
|
||
{task.platform === 'huya' && (task.bindGameRole || task.bindGameRoleId) ? (
|
||
<Text type="secondary">
|
||
{`角色:${task.bindGameRole || '-'}${task.bindGameRoleId ? `(${task.bindGameRoleId})` : '(无角色ID)'}`}
|
||
</Text>
|
||
) : null}
|
||
<Text type="secondary">
|
||
CK:
|
||
{task.credentialStatus === 'valid'
|
||
? '有效'
|
||
: task.credentialStatus === 'invalid'
|
||
? '失效'
|
||
: task.credentialStatus === 'error'
|
||
? '检测异常'
|
||
: '未保存'}
|
||
</Text>
|
||
</Space>
|
||
),
|
||
},
|
||
{
|
||
title: '账号凭证',
|
||
key: 'credential',
|
||
width: 190,
|
||
render: (_, task) => (
|
||
<Space direction="vertical" size={2}>
|
||
<Text strong>{task.platformNickname || task.huyaUid || '未获取账号'}</Text>
|
||
<Text type="secondary">
|
||
{task.credentialSource
|
||
? `${task.credentialSource} · ${formatAdminDateTime(task.credentialUpdatedAt)}`
|
||
: '尚无 CK'}
|
||
</Text>
|
||
</Space>
|
||
),
|
||
},
|
||
{
|
||
title: '客服',
|
||
dataIndex: 'assignedAdminName',
|
||
width: 110,
|
||
render: (value: string) => value || '未领取',
|
||
},
|
||
{
|
||
title: '更新时间',
|
||
dataIndex: 'updatedAt',
|
||
width: 155,
|
||
render: (value: string) => formatAdminDateTime(value),
|
||
},
|
||
{
|
||
title: '操作',
|
||
key: 'actions',
|
||
width: 520,
|
||
render: (_, task) => (
|
||
<Space direction="vertical" size={6} style={{ width: '100%' }}>
|
||
<Space wrap>
|
||
<Button size="small" onClick={() => setDetailTaskId(task.id)}>
|
||
详情
|
||
</Button>
|
||
{taskNeedsCustomerReauth(task) ? (
|
||
<Button
|
||
size="small"
|
||
type="primary"
|
||
icon={<SendOutlined />}
|
||
loading={reauthMutation.isPending}
|
||
onClick={() => confirmReauth(task)}
|
||
>
|
||
重发授权
|
||
</Button>
|
||
) : null}
|
||
<Button
|
||
size="small"
|
||
icon={<KeyOutlined />}
|
||
disabled={!task.credentialReady}
|
||
loading={credentialExportMutation.isPending}
|
||
onClick={() => confirmCopyCredential(task)}
|
||
>
|
||
复制 CK
|
||
</Button>
|
||
<Button
|
||
size="small"
|
||
icon={<ChromeOutlined />}
|
||
disabled={!taskCanUseCredential(task)}
|
||
loading={injectionMutation.isPending}
|
||
onClick={() => injectionMutation.mutate(task)}
|
||
>
|
||
注入浏览器
|
||
</Button>
|
||
</Space>
|
||
<Space wrap>
|
||
<Button
|
||
size="small"
|
||
icon={<CopyOutlined />}
|
||
onClick={() => void copyCustomerLink(task)}
|
||
>
|
||
客户链接
|
||
</Button>
|
||
<Button
|
||
size="small"
|
||
icon={<ReloadOutlined />}
|
||
loading={syncMutation.isPending}
|
||
onClick={() => syncMutation.mutate(task.id)}
|
||
>
|
||
刷新
|
||
</Button>
|
||
{!task.assignedAdminUserId ? (
|
||
<Button
|
||
size="small"
|
||
icon={<UserSwitchOutlined />}
|
||
loading={claimMutation.isPending}
|
||
onClick={() => claimMutation.mutate(task.id)}
|
||
>
|
||
领取
|
||
</Button>
|
||
) : null}
|
||
{task.executionStatus !== 'completed' &&
|
||
task.executionStatus !== 'cancelled' &&
|
||
!taskNeedsCustomerReauth(task) ? (
|
||
<Button
|
||
size="small"
|
||
type="primary"
|
||
icon={<CheckCircleOutlined />}
|
||
disabled={!taskCanUseCredential(task)}
|
||
onClick={() => openComplete(task)}
|
||
>
|
||
完成
|
||
</Button>
|
||
) : null}
|
||
{task.executionStatus !== 'completed' && task.executionStatus !== 'cancelled' ? (
|
||
<Button size="small" danger onClick={() => confirmCancel(task)}>
|
||
取消
|
||
</Button>
|
||
) : null}
|
||
</Space>
|
||
</Space>
|
||
),
|
||
},
|
||
]
|
||
|
||
return (
|
||
<section className="page-stack">
|
||
<PageHeader
|
||
title="半自动履约"
|
||
description="人工客服渠道下的平台账号授权、扫码绑定和浏览器辅助履约。"
|
||
/>
|
||
<Card size="small">
|
||
<Space wrap style={{ marginBottom: 16 }}>
|
||
<Input.Search
|
||
allowClear
|
||
placeholder="订单号 / 商品 / UID / 角色"
|
||
value={keyword}
|
||
onChange={(event) => {
|
||
setKeyword(event.target.value)
|
||
setPage(1)
|
||
}}
|
||
style={{ width: 280 }}
|
||
/>
|
||
<Select
|
||
allowClear
|
||
placeholder="全部平台"
|
||
value={platform || undefined}
|
||
onChange={(value) => {
|
||
setPlatform(value || '')
|
||
setPage(1)
|
||
}}
|
||
options={[
|
||
{ value: 'huya', label: '虎牙' },
|
||
{ value: 'weibo', label: '微博' },
|
||
]}
|
||
style={{ width: 130 }}
|
||
/>
|
||
<Select
|
||
allowClear
|
||
placeholder="全部状态"
|
||
value={status || undefined}
|
||
onChange={(value) => {
|
||
setStatus(value || '')
|
||
setPage(1)
|
||
}}
|
||
options={[
|
||
{ value: 'waiting_customer', label: '等待客户' },
|
||
{ value: 'waiting_operator', label: '等待客服' },
|
||
{ value: 'processing', label: '处理中' },
|
||
{ value: 'completed', label: '已完成' },
|
||
{ value: 'failed', label: '失败' },
|
||
{ value: 'cancelled', label: '已取消' },
|
||
]}
|
||
style={{ width: 130 }}
|
||
/>
|
||
<Button icon={<ReloadOutlined />} onClick={() => void listQuery.refetch()}>
|
||
刷新
|
||
</Button>
|
||
</Space>
|
||
<PercentTable<SemiAutoTask>
|
||
rowKey="id"
|
||
loading={listQuery.isLoading}
|
||
columns={columns}
|
||
dataSource={list}
|
||
scroll={{ x: 1400 }}
|
||
pagination={{
|
||
current: pagination?.page || page,
|
||
pageSize: pagination?.pageSize || pageSize,
|
||
total: pagination?.total || 0,
|
||
showSizeChanger: true,
|
||
onChange: (nextPage, nextPageSize) => {
|
||
setPage(nextPage)
|
||
setPageSize(nextPageSize)
|
||
},
|
||
}}
|
||
/>
|
||
</Card>
|
||
|
||
<Drawer
|
||
open={Boolean(detailTaskId)}
|
||
width={720}
|
||
title={detail?.task ? `半自动履约 · ${detail.task.orderNo}` : '半自动履约详情'}
|
||
onClose={() => setDetailTaskId(null)}
|
||
>
|
||
{detailQuery.isLoading ? (
|
||
<Text type="secondary">加载中...</Text>
|
||
) : detail?.task ? (
|
||
<Space direction="vertical" size={16} style={{ width: '100%' }}>
|
||
<Descriptions bordered size="small" column={2}>
|
||
<Descriptions.Item label="商品" span={2}>
|
||
{detail.task.productName}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="平台">
|
||
{PLATFORM_LABELS[detail.task.platform] || detail.task.platform}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="Connector">
|
||
<Tag color={detail.task.connectorMode === 'mock' ? 'orange' : 'green'}>
|
||
{detail.task.connectorMode === 'mock'
|
||
? '内置 Mock'
|
||
: detail.task.connectorMode === 'external'
|
||
? '远程真实'
|
||
: '内置真实'}
|
||
</Tag>
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="当前状态">
|
||
<Tag color={STATUS_COLORS[detail.task.displayStatus.key] || 'default'}>
|
||
{detail.task.displayStatus.label}
|
||
</Tag>
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label={detail.task.platform === 'weibo' ? '微博 UID' : '虎牙 UID'}>
|
||
{detail.task.huyaUid || '-'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="平台昵称">
|
||
{detail.task.platformNickname || '-'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="账号 CK">
|
||
<Space size={6}>
|
||
<Tag
|
||
color={
|
||
detail.task.credentialStatus === 'valid'
|
||
? 'green'
|
||
: detail.task.credentialStatus === 'invalid'
|
||
? 'red'
|
||
: 'default'
|
||
}
|
||
>
|
||
{detail.task.credentialStatus === 'valid'
|
||
? '有效'
|
||
: detail.task.credentialStatus === 'invalid'
|
||
? '失效'
|
||
: detail.task.credentialStatus === 'error'
|
||
? '检测异常'
|
||
: '未保存'}
|
||
</Tag>
|
||
<Text type="secondary">
|
||
{detail.task.credentialSource
|
||
? `${detail.task.credentialSource} · ${formatAdminDateTime(detail.task.credentialUpdatedAt)}`
|
||
: '-'}
|
||
</Text>
|
||
</Space>
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="平台昵称">
|
||
{detail.task.platformNickname || '-'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="登录状态">
|
||
{detail.task.loginStatus === 'authenticated' ? 'CK 已获取' : '等待客户登录'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="绑定状态">
|
||
{detail.task.platform === 'weibo'
|
||
? '微博登录即授权'
|
||
: BINDING_STATUS_LABELS[detail.task.bindingStatus] || detail.task.bindingStatus}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="绑定角色">
|
||
{detail.task.bindGameRole
|
||
? `${detail.task.bindGameRole}${detail.task.bindGameRoleId ? `(${detail.task.bindGameRoleId})` : '(无角色ID)'}`
|
||
: '-'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="客户填写角色">
|
||
{detail.task.customerGameRoleName
|
||
? `${detail.task.customerGameRoleName}${detail.task.customerGameRoleId ? `(${detail.task.customerGameRoleId})` : ''}`
|
||
: '-'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="区服">
|
||
{detail.task.customerServerZone || '-'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="客服">
|
||
{detail.task.assignedAdminName || '未领取'}
|
||
</Descriptions.Item>
|
||
<Descriptions.Item label="更新时间">
|
||
{formatAdminDateTime(detail.task.updatedAt)}
|
||
</Descriptions.Item>
|
||
</Descriptions>
|
||
{taskNeedsCustomerReauth(detail.task) ? (
|
||
<Alert
|
||
type="warning"
|
||
showIcon
|
||
message="客户登录状态需要更新"
|
||
description="平台 CK 已失效或任务登录失败。重新发送后,客户需要重新打开链接完成登录。"
|
||
/>
|
||
) : null}
|
||
{detail.task.lastError ? (
|
||
<Card size="small" title="最近错误">
|
||
<Text type="danger">{detail.task.lastError}</Text>
|
||
</Card>
|
||
) : null}
|
||
<Card size="small" title="操作">
|
||
<Space wrap>
|
||
{taskNeedsCustomerReauth(detail.task) ? (
|
||
<Button
|
||
type="primary"
|
||
icon={<SendOutlined />}
|
||
loading={reauthMutation.isPending}
|
||
onClick={() => confirmReauth(detail.task)}
|
||
>
|
||
重新发送授权
|
||
</Button>
|
||
) : null}
|
||
<Button icon={<CopyOutlined />} onClick={() => void copyCustomerLink(detail.task)}>
|
||
复制客户链接
|
||
</Button>
|
||
<Button
|
||
icon={<ReloadOutlined />}
|
||
loading={syncMutation.isPending}
|
||
onClick={() => syncMutation.mutate(detail.task.id)}
|
||
>
|
||
刷新客户状态
|
||
</Button>
|
||
<Button
|
||
icon={<KeyOutlined />}
|
||
disabled={!detail.task.credentialReady}
|
||
loading={credentialExportMutation.isPending}
|
||
onClick={() => confirmCopyCredential(detail.task)}
|
||
>
|
||
复制 CK
|
||
</Button>
|
||
<Button
|
||
icon={<ChromeOutlined />}
|
||
disabled={!taskCanUseCredential(detail.task)}
|
||
loading={injectionMutation.isPending}
|
||
onClick={() => injectionMutation.mutate(detail.task)}
|
||
>
|
||
注入浏览器
|
||
</Button>
|
||
</Space>
|
||
</Card>
|
||
<Card size="small" title="时间线">
|
||
<Timeline
|
||
items={(detail.events || []).map((event) => ({
|
||
color: event.eventType.includes('failed') ? 'red' : 'blue',
|
||
children: (
|
||
<Space direction="vertical" size={2}>
|
||
<Text strong>{event.eventType}</Text>
|
||
<Text type="secondary">
|
||
{formatAdminDateTime(event.createdAt)} · {event.actorType}
|
||
{event.actorId ? ` ${event.actorId}` : ''}
|
||
</Text>
|
||
{event.eventType === 'binding_status_changed' && event.detail?.message ? (
|
||
<Text
|
||
type={
|
||
event.detail.rebindUnchanged === true ||
|
||
Number(event.detail.rebindCooldownDays || 0) > 0
|
||
? 'warning'
|
||
: 'secondary'
|
||
}
|
||
>
|
||
{String(event.detail.message)}
|
||
{Number(event.detail.rebindCooldownDays || 0) > 0 &&
|
||
event.detail.nextRebindAt
|
||
? ` · 下次可换绑 ${formatAdminDateTime(
|
||
String(event.detail.nextRebindAt),
|
||
)}`
|
||
: ''}
|
||
</Text>
|
||
) : null}
|
||
</Space>
|
||
),
|
||
}))}
|
||
/>
|
||
</Card>
|
||
</Space>
|
||
) : (
|
||
<Text type="secondary">暂无任务详情</Text>
|
||
)}
|
||
</Drawer>
|
||
|
||
<Modal
|
||
open={Boolean(completeTask)}
|
||
title="确认完成半自动履约"
|
||
okText="确认完成"
|
||
cancelText="取消"
|
||
confirmLoading={completeMutation.isPending}
|
||
onCancel={() => {
|
||
setCompleteTask(null)
|
||
setCompleteFiles([])
|
||
completeForm.resetFields()
|
||
}}
|
||
onOk={() => {
|
||
void completeForm.validateFields().then((values) => completeMutation.mutate(values))
|
||
}}
|
||
>
|
||
<Form<CompleteFormValues> form={completeForm} layout="vertical">
|
||
<Form.Item name="externalOrderNo" label="外部订单号 / 流水号(可选)">
|
||
<Input maxLength={200} />
|
||
</Form.Item>
|
||
<Form.Item name="note" label="备注(可选)">
|
||
<Input.TextArea rows={3} maxLength={1000} showCount />
|
||
</Form.Item>
|
||
<Form.Item
|
||
name="costYuan"
|
||
label="本次实际成本(元,可选)"
|
||
extra="成本不固定的 SKU 可在这里填写;固定成本不需要填写。"
|
||
>
|
||
<InputNumber min={0} precision={2} style={{ width: '100%' }} />
|
||
</Form.Item>
|
||
<Form.Item label="完成截图(可选)">
|
||
<ImageUpload
|
||
value={completeFiles}
|
||
onChange={setCompleteFiles}
|
||
scene="semi-auto-evidence"
|
||
scope="admin"
|
||
maxCount={6}
|
||
showPasteHint
|
||
captureGlobalPaste
|
||
/>
|
||
</Form.Item>
|
||
</Form>
|
||
</Modal>
|
||
</section>
|
||
)
|
||
}
|
||
|
||
function firstTargetUrl(task: SemiAutoTask) {
|
||
const targets = Array.isArray(task.semiAutoConfig?.browserTargets)
|
||
? task.semiAutoConfig.browserTargets
|
||
: []
|
||
return String(targets.find((item) => item?.url)?.url || '')
|
||
}
|
||
|
||
function taskNeedsCustomerReauth(task: SemiAutoTask) {
|
||
if (task.executionStatus === 'completed' || task.executionStatus === 'cancelled') return false
|
||
return (
|
||
task.credentialStatus === 'invalid' ||
|
||
task.credentialStatus === 'error' ||
|
||
task.executionStatus === 'failed' ||
|
||
task.loginStatus === 'failed' ||
|
||
task.loginStatus === 'expired'
|
||
)
|
||
}
|
||
|
||
function taskCanUseCredential(task: SemiAutoTask) {
|
||
return (
|
||
task.loginStatus === 'authenticated' &&
|
||
(task.platform === 'weibo' || task.bindingStatus === 'confirmed') &&
|
||
task.credentialReady &&
|
||
task.credentialStatus !== 'invalid' &&
|
||
task.credentialStatus !== 'error'
|
||
)
|
||
}
|