完善微博半自动凭证与本地开发环境
This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
CheckCircleOutlined,
|
||||
ChromeOutlined,
|
||||
CopyOutlined,
|
||||
KeyOutlined,
|
||||
ReloadOutlined,
|
||||
UserSwitchOutlined,
|
||||
} from '@ant-design/icons'
|
||||
@@ -34,12 +35,14 @@ import {
|
||||
claimAdminSemiAutoTask,
|
||||
completeAdminSemiAutoTask,
|
||||
createAdminSemiAutoBrowserSession,
|
||||
exportAdminSemiAutoCredential,
|
||||
fetchAdminSemiAutoTask,
|
||||
fetchAdminSemiAutoTasks,
|
||||
syncAdminSemiAutoTask,
|
||||
} from '@/services/admin/semi-auto'
|
||||
import type { SemiAutoTask } from '@/types/admin/semi-auto'
|
||||
import type { SemiAutoCredentialExport, 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'
|
||||
|
||||
const { Text } = Typography
|
||||
@@ -79,6 +82,7 @@ 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(
|
||||
@@ -172,6 +176,18 @@ export default function AdminSemiAutoTasksPage() {
|
||||
message.error(error instanceof Error ? error.message : '打开浏览器登录态失败'),
|
||||
})
|
||||
|
||||
const credentialExportMutation = useMutation({
|
||||
mutationFn: (taskId: number) => exportAdminSemiAutoCredential(taskId),
|
||||
onSuccess: (response) => {
|
||||
if (!response.data) {
|
||||
message.error('账号 CK 导出失败')
|
||||
return
|
||||
}
|
||||
setCredentialExport(response.data)
|
||||
},
|
||||
onError: (error) => message.error(error instanceof Error ? error.message : '导出账号 CK 失败'),
|
||||
})
|
||||
|
||||
const completeMutation = useMutation({
|
||||
mutationFn: async (values: CompleteFormValues) => {
|
||||
if (!completeTask) throw new Error('任务不存在')
|
||||
@@ -223,6 +239,25 @@ export default function AdminSemiAutoTasksPage() {
|
||||
.catch(() => message.error('复制失败,请手动复制'))
|
||||
}
|
||||
|
||||
function copyCredentialText(text: string, label: string) {
|
||||
void navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => message.success(`${label}已复制`))
|
||||
.catch(() => message.error('复制失败,请手动选择文本'))
|
||||
}
|
||||
|
||||
function confirmExportCredential(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([])
|
||||
@@ -281,11 +316,21 @@ export default function AdminSemiAutoTasksPage() {
|
||||
{
|
||||
title: '客户登录',
|
||||
key: 'login',
|
||||
width: 150,
|
||||
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">
|
||||
CK:
|
||||
{task.credentialStatus === 'valid'
|
||||
? '有效'
|
||||
: task.credentialStatus === 'invalid'
|
||||
? '失效'
|
||||
: task.credentialStatus === 'error'
|
||||
? '检测异常'
|
||||
: '未保存'}
|
||||
</Text>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
@@ -487,6 +532,32 @@ export default function AdminSemiAutoTasksPage() {
|
||||
<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.platform === 'weibo' ? '微博昵称' : '游戏账号'}>
|
||||
{detail.task.bindGameAccount || '-'}
|
||||
</Descriptions.Item>
|
||||
@@ -536,6 +607,17 @@ export default function AdminSemiAutoTasksPage() {
|
||||
>
|
||||
注入浏览器
|
||||
</Button>
|
||||
{detail.task.credentialReady &&
|
||||
hasAdminPermission('semi_auto.credential.export') ? (
|
||||
<Button
|
||||
danger
|
||||
icon={<KeyOutlined />}
|
||||
loading={credentialExportMutation.isPending}
|
||||
onClick={() => confirmExportCredential(detail.task)}
|
||||
>
|
||||
导出 CK
|
||||
</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
</Card>
|
||||
<Card size="small" title="时间线">
|
||||
@@ -560,6 +642,65 @@ 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="确认完成半自动履约"
|
||||
|
||||
Reference in New Issue
Block a user