完善半自动履约凭证与客户重新授权流程
统一虎牙和微博账号级 CK 保存与导出;CK 失效后回到客户重新登录,后台支持重发授权;客户授权页改为统一深色布局并收敛开发迁移配置。
This commit is contained in:
@@ -2,16 +2,22 @@ import {
|
||||
CheckCircleOutlined,
|
||||
ChromeOutlined,
|
||||
CopyOutlined,
|
||||
DownOutlined,
|
||||
KeyOutlined,
|
||||
LinkOutlined,
|
||||
MoreOutlined,
|
||||
ReloadOutlined,
|
||||
SendOutlined,
|
||||
UserSwitchOutlined,
|
||||
} from '@ant-design/icons'
|
||||
import {
|
||||
Alert,
|
||||
App,
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Drawer,
|
||||
Dropdown,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
@@ -29,7 +35,6 @@ 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 { uploadFile } from '@/services/files'
|
||||
import {
|
||||
cancelAdminSemiAutoTask,
|
||||
claimAdminSemiAutoTask,
|
||||
@@ -38,9 +43,10 @@ import {
|
||||
exportAdminSemiAutoCredential,
|
||||
fetchAdminSemiAutoTask,
|
||||
fetchAdminSemiAutoTasks,
|
||||
requestAdminSemiAutoCustomerReauth,
|
||||
syncAdminSemiAutoTask,
|
||||
} from '@/services/admin/semi-auto'
|
||||
import type { SemiAutoCredentialExport, SemiAutoTask } from '@/types/admin/semi-auto'
|
||||
import type { SemiAutoTask } from '@/types/admin/semi-auto'
|
||||
import type { UploadedFile } from '@/types/worker-platform'
|
||||
import { hasAdminPermission } from '@/utils/admin-auth'
|
||||
import { formatAdminDateTime } from '@/utils/admin-time'
|
||||
@@ -54,6 +60,7 @@ const STATUS_COLORS: Record<string, string> = {
|
||||
waiting_binding: 'gold',
|
||||
binding_confirm: 'orange',
|
||||
waiting_operator: 'volcano',
|
||||
credential_expired: 'red',
|
||||
processing: 'processing',
|
||||
completed: 'success',
|
||||
failed: 'error',
|
||||
@@ -82,7 +89,6 @@ export default function AdminSemiAutoTasksPage() {
|
||||
const [detailTaskId, setDetailTaskId] = useState<number | null>(null)
|
||||
const [completeTask, setCompleteTask] = useState<SemiAutoTask | null>(null)
|
||||
const [completeFiles, setCompleteFiles] = useState<UploadedFile[]>([])
|
||||
const [credentialExport, setCredentialExport] = useState<SemiAutoCredentialExport | null>(null)
|
||||
const [completeForm] = Form.useForm<CompleteFormValues>()
|
||||
|
||||
const params = useMemo(
|
||||
@@ -169,7 +175,7 @@ export default function AdminSemiAutoTasksPage() {
|
||||
return
|
||||
}
|
||||
window.postMessage({ type: 'ORDER_SITE_SEMI_AUTO_INJECT', ticket }, window.location.origin)
|
||||
message.info('正在通过虎牙履约助手注入登录态,请稍候')
|
||||
message.info('正在注入浏览器登录态,请稍候')
|
||||
void refreshAll()
|
||||
},
|
||||
onError: (error) =>
|
||||
@@ -179,13 +185,32 @@ export default function AdminSemiAutoTasksPage() {
|
||||
const credentialExportMutation = useMutation({
|
||||
mutationFn: (taskId: number) => exportAdminSemiAutoCredential(taskId),
|
||||
onSuccess: (response) => {
|
||||
if (!response.data) {
|
||||
message.error('账号 CK 导出失败')
|
||||
const text =
|
||||
String(response.data?.cookieHeader || '').trim() ||
|
||||
(response.data?.cookies || []).map((cookie) => `${cookie.name}=${cookie.value}`).join('; ')
|
||||
if (!text) {
|
||||
message.error('当前任务没有可复制的 CK')
|
||||
return
|
||||
}
|
||||
setCredentialExport(response.data)
|
||||
void navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => message.success('最终 CK 已复制'))
|
||||
.catch(() => message.error('复制失败,请检查浏览器剪贴板权限'))
|
||||
},
|
||||
onError: (error) => message.error(error instanceof Error ? error.message : '导出账号 CK 失败'),
|
||||
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({
|
||||
@@ -231,33 +256,114 @@ export default function AdminSemiAutoTasksPage() {
|
||||
])
|
||||
}
|
||||
|
||||
function copyCustomerLink(task: SemiAutoTask) {
|
||||
async function copyCustomerLink(task: SemiAutoTask, successMessage = '客户授权链接已复制') {
|
||||
const url = `${window.location.origin}/c/${encodeURIComponent(task.orderNo)}`
|
||||
void navigator.clipboard
|
||||
.writeText(url)
|
||||
.then(() => message.success('客户授权链接已复制'))
|
||||
.catch(() => message.error('复制失败,请手动复制'))
|
||||
try {
|
||||
await navigator.clipboard.writeText(url)
|
||||
if (successMessage) message.success(successMessage)
|
||||
return true
|
||||
} catch {
|
||||
message.error('复制失败,请手动复制客户链接')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
function copyCredentialText(text: string, label: string) {
|
||||
void navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => message.success(`${label}已复制`))
|
||||
.catch(() => message.error('复制失败,请手动选择文本'))
|
||||
}
|
||||
|
||||
function confirmExportCredential(task: SemiAutoTask) {
|
||||
function confirmReauth(task: SemiAutoTask) {
|
||||
modal.confirm({
|
||||
title: '导出账号 CK',
|
||||
content:
|
||||
'CK 等同于平台登录态。导出后会显示在当前页面,请勿发给无关人员;关闭弹窗后不会保留在页面状态中。',
|
||||
okText: '确认导出',
|
||||
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 credentialMenu(task: SemiAutoTask) {
|
||||
const canExport = hasAdminPermission('semi_auto.credential.export')
|
||||
return {
|
||||
items: [
|
||||
...(canExport
|
||||
? [
|
||||
{
|
||||
key: 'copy',
|
||||
icon: <KeyOutlined />,
|
||||
label: '复制最终 CK',
|
||||
disabled: !task.credentialReady || credentialExportMutation.isPending,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
key: 'inject',
|
||||
icon: <ChromeOutlined />,
|
||||
label: '注入浏览器',
|
||||
disabled: task.bindingStatus !== 'confirmed' || injectionMutation.isPending,
|
||||
},
|
||||
],
|
||||
onClick: ({ key }: { key: string }) => {
|
||||
if (key === 'copy') {
|
||||
confirmCopyCredential(task)
|
||||
return
|
||||
}
|
||||
if (key === 'inject') injectionMutation.mutate(task)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function taskMenu(task: SemiAutoTask) {
|
||||
const active = task.executionStatus !== 'completed' && task.executionStatus !== 'cancelled'
|
||||
return {
|
||||
items: [
|
||||
{
|
||||
key: 'copy',
|
||||
icon: <LinkOutlined />,
|
||||
label: '复制客户链接',
|
||||
},
|
||||
{
|
||||
key: 'sync',
|
||||
icon: <ReloadOutlined />,
|
||||
label: '刷新客户状态',
|
||||
disabled: syncMutation.isPending,
|
||||
},
|
||||
...(!task.assignedAdminUserId
|
||||
? [
|
||||
{
|
||||
key: 'claim',
|
||||
icon: <UserSwitchOutlined />,
|
||||
label: '领取任务',
|
||||
disabled: claimMutation.isPending,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(active
|
||||
? [
|
||||
{
|
||||
key: 'cancel',
|
||||
danger: true,
|
||||
label: '取消任务',
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
onClick: ({ key }: { key: string }) => {
|
||||
if (key === 'copy') void copyCustomerLink(task)
|
||||
if (key === 'sync') syncMutation.mutate(task.id)
|
||||
if (key === 'claim') claimMutation.mutate(task.id)
|
||||
if (key === 'cancel') confirmCancel(task)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function openComplete(task: SemiAutoTask) {
|
||||
setCompleteTask(task)
|
||||
setCompleteFiles([])
|
||||
@@ -300,17 +406,14 @@ export default function AdminSemiAutoTasksPage() {
|
||||
{
|
||||
title: '平台',
|
||||
dataIndex: 'platform',
|
||||
width: 90,
|
||||
render: (value: string) => <Tag color="purple">{PLATFORM_LABELS[value] || value}</Tag>,
|
||||
},
|
||||
{
|
||||
title: 'Connector',
|
||||
dataIndex: 'connectorMode',
|
||||
width: 110,
|
||||
render: (value: string) => (
|
||||
<Tag color={value === 'mock' ? 'orange' : 'green'}>
|
||||
{value === 'mock' ? '内置 Mock' : '真实'}
|
||||
</Tag>
|
||||
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>
|
||||
),
|
||||
},
|
||||
{
|
||||
@@ -365,58 +468,46 @@ export default function AdminSemiAutoTasksPage() {
|
||||
{
|
||||
title: '操作',
|
||||
key: 'actions',
|
||||
width: 360,
|
||||
width: 340,
|
||||
render: (_, task) => (
|
||||
<Space wrap>
|
||||
<Button size="small" onClick={() => setDetailTaskId(task.id)}>
|
||||
详情
|
||||
</Button>
|
||||
<Button size="small" icon={<CopyOutlined />} onClick={() => copyCustomerLink(task)}>
|
||||
客户链接
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ReloadOutlined />}
|
||||
loading={syncMutation.isPending}
|
||||
onClick={() => syncMutation.mutate(task.id)}
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
{!task.assignedAdminUserId ? (
|
||||
{taskNeedsCustomerReauth(task) ? (
|
||||
<Button
|
||||
size="small"
|
||||
icon={<UserSwitchOutlined />}
|
||||
loading={claimMutation.isPending}
|
||||
onClick={() => claimMutation.mutate(task.id)}
|
||||
type="primary"
|
||||
icon={<SendOutlined />}
|
||||
loading={reauthMutation.isPending}
|
||||
onClick={() => confirmReauth(task)}
|
||||
>
|
||||
领取
|
||||
重发授权
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
size="small"
|
||||
icon={<ChromeOutlined />}
|
||||
disabled={task.bindingStatus !== 'confirmed'}
|
||||
loading={injectionMutation.isPending}
|
||||
onClick={() => injectionMutation.mutate(task)}
|
||||
>
|
||||
注入浏览器
|
||||
</Button>
|
||||
{task.executionStatus !== 'completed' && task.executionStatus !== 'cancelled' ? (
|
||||
<>
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
icon={<CheckCircleOutlined />}
|
||||
disabled={task.bindingStatus !== 'confirmed'}
|
||||
onClick={() => openComplete(task)}
|
||||
>
|
||||
完成
|
||||
</Button>
|
||||
<Button size="small" danger onClick={() => confirmCancel(task)}>
|
||||
取消
|
||||
</Button>
|
||||
</>
|
||||
<Dropdown menu={credentialMenu(task)} trigger={['click']}>
|
||||
<Button size="small" icon={<KeyOutlined />}>
|
||||
CK 操作 <DownOutlined />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
{task.executionStatus !== 'completed' &&
|
||||
task.executionStatus !== 'cancelled' &&
|
||||
!taskNeedsCustomerReauth(task) ? (
|
||||
<Button
|
||||
size="small"
|
||||
type="primary"
|
||||
icon={<CheckCircleOutlined />}
|
||||
disabled={task.bindingStatus !== 'confirmed'}
|
||||
onClick={() => openComplete(task)}
|
||||
>
|
||||
完成
|
||||
</Button>
|
||||
) : null}
|
||||
<Dropdown menu={taskMenu(task)} trigger={['click']}>
|
||||
<Button size="small" icon={<MoreOutlined />}>
|
||||
更多
|
||||
</Button>
|
||||
</Dropdown>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
@@ -582,6 +673,14 @@ export default function AdminSemiAutoTasksPage() {
|
||||
{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>
|
||||
@@ -589,7 +688,17 @@ export default function AdminSemiAutoTasksPage() {
|
||||
) : null}
|
||||
<Card size="small" title="操作">
|
||||
<Space wrap>
|
||||
<Button icon={<CopyOutlined />} onClick={() => copyCustomerLink(detail.task)}>
|
||||
{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
|
||||
@@ -599,25 +708,11 @@ export default function AdminSemiAutoTasksPage() {
|
||||
>
|
||||
刷新客户状态
|
||||
</Button>
|
||||
<Button
|
||||
icon={<ChromeOutlined />}
|
||||
disabled={detail.task.bindingStatus !== 'confirmed'}
|
||||
loading={injectionMutation.isPending}
|
||||
onClick={() => injectionMutation.mutate(detail.task)}
|
||||
>
|
||||
注入浏览器
|
||||
</Button>
|
||||
{detail.task.credentialReady &&
|
||||
hasAdminPermission('semi_auto.credential.export') ? (
|
||||
<Button
|
||||
danger
|
||||
icon={<KeyOutlined />}
|
||||
loading={credentialExportMutation.isPending}
|
||||
onClick={() => confirmExportCredential(detail.task)}
|
||||
>
|
||||
导出 CK
|
||||
<Dropdown menu={credentialMenu(detail.task)} trigger={['click']}>
|
||||
<Button icon={<KeyOutlined />}>
|
||||
CK 操作 <DownOutlined />
|
||||
</Button>
|
||||
) : null}
|
||||
</Dropdown>
|
||||
</Space>
|
||||
</Card>
|
||||
<Card size="small" title="时间线">
|
||||
@@ -642,65 +737,6 @@ export default function AdminSemiAutoTasksPage() {
|
||||
)}
|
||||
</Drawer>
|
||||
|
||||
<Modal
|
||||
open={Boolean(credentialExport)}
|
||||
title={
|
||||
credentialExport
|
||||
? `账号 CK · ${credentialExport.platform === 'weibo' ? '微博' : '平台'} ${credentialExport.platformUid}`
|
||||
: '账号 CK'
|
||||
}
|
||||
width={760}
|
||||
footer={null}
|
||||
onCancel={() => setCredentialExport(null)}
|
||||
>
|
||||
{credentialExport ? (
|
||||
<Space direction="vertical" size={14} style={{ width: '100%' }}>
|
||||
<Text type="danger">
|
||||
以下内容包含平台登录态,仅用于本次受控操作。关闭弹窗后请勿在聊天、日志或工单中留存。
|
||||
</Text>
|
||||
<Space direction="vertical" size={6} style={{ width: '100%' }}>
|
||||
<Space style={{ width: '100%', justifyContent: 'space-between' }}>
|
||||
<Text strong>{credentialExport.targetUrl || 'Cookie Header'}</Text>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() => copyCredentialText(credentialExport.cookieHeader, 'Cookie Header')}
|
||||
>
|
||||
复制 Header
|
||||
</Button>
|
||||
</Space>
|
||||
<Input.TextArea
|
||||
value={credentialExport.cookieHeader}
|
||||
readOnly
|
||||
autoSize={{ minRows: 3, maxRows: 6 }}
|
||||
/>
|
||||
</Space>
|
||||
<Space direction="vertical" size={6} style={{ width: '100%' }}>
|
||||
<Space style={{ width: '100%', justifyContent: 'space-between' }}>
|
||||
<Text strong>完整域名 Cookie</Text>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() =>
|
||||
copyCredentialText(
|
||||
JSON.stringify(credentialExport.cookies, null, 2),
|
||||
'完整 Cookie JSON',
|
||||
)
|
||||
}
|
||||
>
|
||||
复制 JSON
|
||||
</Button>
|
||||
</Space>
|
||||
<Input.TextArea
|
||||
value={JSON.stringify(credentialExport.cookies, null, 2)}
|
||||
readOnly
|
||||
autoSize={{ minRows: 10, maxRows: 18 }}
|
||||
/>
|
||||
</Space>
|
||||
</Space>
|
||||
) : null}
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
open={Boolean(completeTask)}
|
||||
title="确认完成半自动履约"
|
||||
@@ -753,3 +789,14 @@ function firstTargetUrl(task: SemiAutoTask) {
|
||||
: []
|
||||
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'
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user