1947 lines
73 KiB
TypeScript
1947 lines
73 KiB
TypeScript
import {
|
||
CheckCircleFilled,
|
||
ExclamationCircleOutlined,
|
||
LoadingOutlined,
|
||
QrcodeOutlined,
|
||
ReloadOutlined,
|
||
} from '@ant-design/icons'
|
||
import { App, Alert, Button, Image, Input, Modal, Select, Space, Spin } from 'antd'
|
||
import QRCode from 'qrcode'
|
||
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||
import { useLocation, useNavigate, useParams } from 'react-router'
|
||
|
||
import {
|
||
confirmCustomerBinding,
|
||
fetchCustomerFulfillment,
|
||
loginCustomerHuyaSms,
|
||
loginCustomerWeiboSms,
|
||
markCustomerFulfillmentOpened,
|
||
pollCustomerBinding,
|
||
pollCustomerLogin,
|
||
pollCustomerWeiboQrLogin,
|
||
saveCustomerTaskProfile,
|
||
sendCustomerHuyaSmsCode,
|
||
sendCustomerWeiboSmsCode,
|
||
startCustomerBinding,
|
||
startCustomerLogin,
|
||
startCustomerWeiboQrLogin,
|
||
submitCustomerRebind,
|
||
verifyCustomerHuyaSmsChallenge,
|
||
type CustomerHuyaChallengeSolution,
|
||
type CustomerHuyaSmsChallenge,
|
||
} from '@/services/customer-fulfillment'
|
||
import type {
|
||
CustomerBindingInfo,
|
||
CustomerLoginInfo,
|
||
CustomerSemiAutoTask,
|
||
} from '@/types/customer-fulfillment'
|
||
import { formatAdminDateTime } from '@/utils/admin-time'
|
||
import {
|
||
buildCustomerFulfillmentPath,
|
||
resolveCustomerPlatformRedirect,
|
||
type CustomerFulfillmentPlatform,
|
||
} from '@/utils/customer-fulfillment-link'
|
||
import { runWeiboYidunChallenge } from '@/utils/weibo-yidun'
|
||
import HuyaChallengeModal from './HuyaChallengeModal'
|
||
|
||
const POLL_INTERVAL_MS = 2000
|
||
|
||
const SERVER_ZONE_OPTIONS = ['苹果Q区', '苹果V区', '安卓Q区', '安卓V区']
|
||
|
||
/** antd v6 语义化 classNames:让区服下拉弹层用页面深色样式 */
|
||
const SERVER_ZONE_SELECT_CLASS_NAMES = { popup: { root: 'customer-collect-dropdown' } }
|
||
|
||
export default function CustomerFulfillmentPage({
|
||
expectedPlatform,
|
||
}: {
|
||
expectedPlatform?: CustomerFulfillmentPlatform
|
||
}) {
|
||
const { message, modal } = App.useApp()
|
||
const { orderNo: routeOrderNo } = useParams<{ orderNo?: string }>()
|
||
const navigate = useNavigate()
|
||
const { search, hash } = useLocation()
|
||
const orderNo = String(routeOrderNo || '').trim()
|
||
const [loading, setLoading] = useState(true)
|
||
const [loadError, setLoadError] = useState('')
|
||
const [tasks, setTasks] = useState<CustomerSemiAutoTask[]>([])
|
||
const [selectedTaskId, setSelectedTaskId] = useState(0)
|
||
const [loginInfo, setLoginInfo] = useState<CustomerLoginInfo | null>(null)
|
||
const [loginQrImage, setLoginQrImage] = useState('')
|
||
const [loginMode, setLoginMode] = useState<'sms' | 'qr'>('sms')
|
||
const [mobile, setMobile] = useState('')
|
||
const [smsCode, setSmsCode] = useState('')
|
||
const [smsSending, setSmsSending] = useState(false)
|
||
const [smsLogging, setSmsLogging] = useState(false)
|
||
const [smsCountdown, setSmsCountdown] = useState(0)
|
||
const [smsMfaRequired, setSmsMfaRequired] = useState(false)
|
||
const [huyaChallenge, setHuyaChallenge] = useState<CustomerHuyaSmsChallenge | null>(null)
|
||
const [huyaChallengeLoading, setHuyaChallengeLoading] = useState(false)
|
||
const [bindingInfo, setBindingInfo] = useState<CustomerBindingInfo | null>(null)
|
||
const [bindingLoading, setBindingLoading] = useState(false)
|
||
const [bindingConfirmOpen, setBindingConfirmOpen] = useState(false)
|
||
const [bindingSecondsLeft, setBindingSecondsLeft] = useState(0)
|
||
const [bindingQrImage, setBindingQrImage] = useState('')
|
||
const [profileRoleName, setProfileRoleName] = useState('')
|
||
const [profileRoleId, setProfileRoleId] = useState('')
|
||
const [profileServerZone, setProfileServerZone] = useState('')
|
||
const [profileSaving, setProfileSaving] = useState(false)
|
||
const [profileEditing, setProfileEditing] = useState(false)
|
||
const [rebindFailureDismissed, setRebindFailureDismissed] = useState(false)
|
||
const startingBindingRef = useRef(false)
|
||
const hydratingBindingRef = useRef(false)
|
||
const autoOpenedRoleRef = useRef('')
|
||
const redirectingRef = useRef(false)
|
||
// Connector 重启或会话被回收后,绑定/确认接口会返回 huya_native_session_not_found。
|
||
const [bindingSessionExpired, setBindingSessionExpired] = useState(false)
|
||
const [bindingLoadError, setBindingLoadError] = useState('')
|
||
|
||
const selectedTask = useMemo(
|
||
() => tasks.find((task) => task.id === selectedTaskId) || tasks[0] || null,
|
||
[selectedTaskId, tasks],
|
||
)
|
||
const isWeibo = selectedTask?.platform === 'weibo'
|
||
|
||
const load = useCallback(
|
||
async (silent = false) => {
|
||
if (!orderNo) {
|
||
setLoadError('订单号无效,请确认订单号是否正确')
|
||
setLoading(false)
|
||
return
|
||
}
|
||
if (!silent) setLoading(true)
|
||
try {
|
||
const response = await fetchCustomerFulfillment(orderNo)
|
||
const nextTasks = response.data || []
|
||
const redirectPlatform = resolveCustomerPlatformRedirect(expectedPlatform, nextTasks)
|
||
if (redirectPlatform) {
|
||
const targetPath = buildCustomerFulfillmentPath(orderNo, redirectPlatform)
|
||
if (targetPath && !redirectingRef.current) {
|
||
redirectingRef.current = true
|
||
void navigate(`${targetPath}${search}${hash}`, { replace: true })
|
||
}
|
||
return
|
||
}
|
||
const visibleTasks = expectedPlatform
|
||
? nextTasks.filter((task) => task.platform === expectedPlatform)
|
||
: nextTasks
|
||
if (expectedPlatform && nextTasks.length > 0 && visibleTasks.length === 0) {
|
||
setTasks([])
|
||
setLoadError('当前链接与订单平台不匹配,请使用对应平台的客户链接')
|
||
return
|
||
}
|
||
setTasks(visibleTasks)
|
||
setLoadError('')
|
||
setSelectedTaskId((current) => {
|
||
if (visibleTasks.some((task) => task.id === current)) return current
|
||
return visibleTasks[0]?.id || 0
|
||
})
|
||
} catch (error) {
|
||
if (!silent) {
|
||
setTasks([])
|
||
setLoadError(error instanceof Error ? error.message : '读取订单履约信息失败')
|
||
}
|
||
} finally {
|
||
if (!silent) setLoading(false)
|
||
}
|
||
},
|
||
[expectedPlatform, hash, navigate, orderNo, search],
|
||
)
|
||
|
||
// 订单号或平台路由变化后允许重新判定跳转,避免复用组件时上一次的标记卡住。
|
||
useEffect(() => {
|
||
redirectingRef.current = false
|
||
}, [expectedPlatform, orderNo])
|
||
|
||
useEffect(() => {
|
||
void load()
|
||
}, [load])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask) return
|
||
setLoginMode('sms')
|
||
setMobile('')
|
||
setSmsCode('')
|
||
setSmsMfaRequired(false)
|
||
setSmsCountdown(0)
|
||
setHuyaChallenge(null)
|
||
setBindingInfo(null)
|
||
setBindingConfirmOpen(false)
|
||
startingBindingRef.current = false
|
||
hydratingBindingRef.current = false
|
||
autoOpenedRoleRef.current = ''
|
||
setBindingSessionExpired(false)
|
||
setBindingLoadError('')
|
||
setRebindFailureDismissed(false)
|
||
}, [selectedTask?.id])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask) return
|
||
void markCustomerFulfillmentOpened(orderNo, selectedTask.id).catch(() => undefined)
|
||
}, [orderNo, selectedTask?.id])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask || !orderNo) return
|
||
if (
|
||
selectedTask.executionStatus === 'completed' ||
|
||
selectedTask.executionStatus === 'cancelled'
|
||
) {
|
||
return
|
||
}
|
||
const timer = window.setInterval(() => {
|
||
void load(true)
|
||
}, POLL_INTERVAL_MS)
|
||
return () => window.clearInterval(timer)
|
||
}, [load, orderNo, selectedTask?.executionStatus, selectedTask?.id])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask) return
|
||
if (!['waiting_login', 'failed', 'expired'].includes(selectedTask.loginStatus)) return
|
||
setLoginInfo(null)
|
||
setSmsCode('')
|
||
setSmsMfaRequired(false)
|
||
setSmsCountdown(0)
|
||
setHuyaChallenge(null)
|
||
}, [selectedTask?.id, selectedTask?.loginStatus])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask) return
|
||
setProfileRoleName(selectedTask.customerGameRoleName || '')
|
||
setProfileRoleId(selectedTask.customerGameRoleId || '')
|
||
setProfileServerZone(selectedTask.customerServerZone || '')
|
||
setProfileEditing(false)
|
||
}, [
|
||
selectedTask?.id,
|
||
selectedTask?.customerGameRoleName,
|
||
selectedTask?.customerGameRoleId,
|
||
selectedTask?.customerServerZone,
|
||
])
|
||
|
||
useEffect(() => {
|
||
if (loginInfo?.qrImage) {
|
||
setLoginQrImage(loginInfo.qrImage)
|
||
return
|
||
}
|
||
if (!loginInfo?.qrContent) {
|
||
setLoginQrImage('')
|
||
return
|
||
}
|
||
void QRCode.toDataURL(loginInfo.qrContent, {
|
||
width: 300,
|
||
margin: 2,
|
||
color: { dark: '#111827', light: '#ffffff' },
|
||
}).then(setLoginQrImage)
|
||
}, [loginInfo?.qrContent, loginInfo?.qrImage])
|
||
|
||
useEffect(() => {
|
||
if (smsCountdown <= 0) return
|
||
const timer = window.setTimeout(() => setSmsCountdown((value) => value - 1), 1000)
|
||
return () => window.clearTimeout(timer)
|
||
}, [smsCountdown])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask || !orderNo) return
|
||
if (!['qr_pending', 'scanned'].includes(selectedTask.loginStatus)) return
|
||
const tick = async () => {
|
||
try {
|
||
const response =
|
||
selectedTask.platform === 'weibo'
|
||
? await pollCustomerWeiboQrLogin(orderNo, selectedTask.id)
|
||
: await pollCustomerLogin(orderNo, selectedTask.id)
|
||
if (response.data.task) {
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
}
|
||
if (response.data.login) setLoginInfo(response.data.login)
|
||
} catch {
|
||
// 短暂轮询失败不打断客户页面,下一轮继续。
|
||
}
|
||
}
|
||
const timer = window.setInterval(() => {
|
||
void tick()
|
||
}, POLL_INTERVAL_MS)
|
||
return () => window.clearInterval(timer)
|
||
}, [orderNo, selectedTask?.id, selectedTask?.loginStatus, selectedTask?.platform])
|
||
|
||
// 登录成功后自动进入绑定阶段;失败或过期时由客户点按钮重试,避免页面来回跳。
|
||
useEffect(() => {
|
||
if (!selectedTask || !orderNo || selectedTask.platform !== 'huya') return
|
||
if (selectedTask.loginStatus !== 'authenticated') return
|
||
if (selectedTask.bindingStatus === 'confirmed') return
|
||
if (selectedTask.bindingStatus !== 'not_started' || startingBindingRef.current) return
|
||
startingBindingRef.current = true
|
||
void startCustomerBinding(orderNo, selectedTask.id)
|
||
.then((response) => {
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
setBindingInfo(response.data.binding)
|
||
setBindingLoadError('')
|
||
})
|
||
.catch((error) => {
|
||
if (isHuyaSessionExpired(error)) {
|
||
setBindingSessionExpired(true)
|
||
return
|
||
}
|
||
const detail = error instanceof Error ? error.message : '创建绑定二维码失败'
|
||
setBindingLoadError(detail)
|
||
message.error(detail)
|
||
})
|
||
.finally(() => {
|
||
startingBindingRef.current = false
|
||
})
|
||
}, [
|
||
message,
|
||
orderNo,
|
||
selectedTask?.bindingStatus,
|
||
selectedTask?.id,
|
||
selectedTask?.loginStatus,
|
||
selectedTask?.platform,
|
||
])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask || !orderNo || selectedTask.platform !== 'huya') return
|
||
if (bindingSessionExpired) return
|
||
if (!['qr_pending', 'scanned'].includes(selectedTask.bindingStatus)) return
|
||
const tick = async () => {
|
||
try {
|
||
const response = await pollCustomerBinding(orderNo, selectedTask.id)
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
if (response.data.binding) setBindingInfo(response.data.binding)
|
||
setBindingLoadError('')
|
||
} catch (error) {
|
||
if (isHuyaSessionExpired(error)) {
|
||
setBindingSessionExpired(true)
|
||
setBindingConfirmOpen(false)
|
||
return
|
||
}
|
||
// 非会话错误不要静默:二维码区域会展示可重试的错误,避免一直转圈。
|
||
setBindingLoadError(error instanceof Error ? error.message : '刷新绑定状态失败')
|
||
}
|
||
}
|
||
// 先立即请求一次,会话已失效时不必等 3 秒轮询。
|
||
void tick()
|
||
const timer = window.setInterval(() => {
|
||
void tick()
|
||
}, POLL_INTERVAL_MS)
|
||
return () => window.clearInterval(timer)
|
||
}, [
|
||
bindingSessionExpired,
|
||
orderNo,
|
||
selectedTask?.bindingStatus,
|
||
selectedTask?.id,
|
||
selectedTask?.platform,
|
||
])
|
||
|
||
// 进入 role_ready 时补一次绑定详情,保证确认弹窗能拿到两侧角色 ID。
|
||
useEffect(() => {
|
||
if (!selectedTask || !orderNo || selectedTask.platform !== 'huya') return
|
||
if (bindingSessionExpired) return
|
||
if (selectedTask.bindingStatus !== 'role_ready' || bindingInfo || hydratingBindingRef.current)
|
||
return
|
||
hydratingBindingRef.current = true
|
||
void pollCustomerBinding(orderNo, selectedTask.id)
|
||
.then((response) => {
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
if (response.data.binding) setBindingInfo(response.data.binding)
|
||
setBindingLoadError('')
|
||
})
|
||
.catch((error) => {
|
||
if (isHuyaSessionExpired(error)) {
|
||
setBindingSessionExpired(true)
|
||
return
|
||
}
|
||
setBindingLoadError(error instanceof Error ? error.message : '刷新绑定状态失败')
|
||
})
|
||
.finally(() => {
|
||
hydratingBindingRef.current = false
|
||
})
|
||
}, [
|
||
bindingInfo,
|
||
bindingSessionExpired,
|
||
orderNo,
|
||
selectedTask?.bindingStatus,
|
||
selectedTask?.id,
|
||
selectedTask?.platform,
|
||
])
|
||
|
||
useEffect(() => {
|
||
if (!selectedTask || selectedTask.bindingStatus !== 'role_ready') return
|
||
if (!bindingInfo?.comparison) return
|
||
// 换绑后仍是原角色时只展示失败原因,不能自动弹出确认框。
|
||
if (bindingInfo.rebindUnchanged) return
|
||
// 识别到角色(含与资料不一致)都要弹出对比框,由客户选择修改资料或同步平台角色。
|
||
const key = `${selectedTask.id}:${bindingInfo.bindGameRoleId || ''}`
|
||
if (autoOpenedRoleRef.current === key) return
|
||
autoOpenedRoleRef.current = key
|
||
setBindingConfirmOpen(true)
|
||
}, [bindingInfo, selectedTask?.bindingStatus, selectedTask?.id])
|
||
|
||
useEffect(() => {
|
||
const url = bindingInfo?.qrUrl
|
||
if (!url) {
|
||
setBindingQrImage('')
|
||
return
|
||
}
|
||
void QRCode.toDataURL(url, {
|
||
width: 320,
|
||
margin: 2,
|
||
color: { dark: '#111827', light: '#ffffff' },
|
||
}).then(setBindingQrImage)
|
||
}, [bindingInfo?.qrUrl])
|
||
|
||
useEffect(() => {
|
||
const expiresAt = bindingInfo?.qrExpiresAt ? new Date(bindingInfo.qrExpiresAt).getTime() : 0
|
||
if (!expiresAt || Number.isNaN(expiresAt)) {
|
||
setBindingSecondsLeft(0)
|
||
return
|
||
}
|
||
const update = () => {
|
||
setBindingSecondsLeft(Math.max(0, Math.floor((expiresAt - Date.now()) / 1000)))
|
||
}
|
||
update()
|
||
const timer = window.setInterval(update, 1000)
|
||
return () => window.clearInterval(timer)
|
||
}, [bindingInfo?.qrExpiresAt])
|
||
|
||
async function handleStartLogin() {
|
||
if (!selectedTask) return
|
||
setLoading(true)
|
||
try {
|
||
const response =
|
||
selectedTask.platform === 'weibo'
|
||
? await startCustomerWeiboQrLogin(orderNo, selectedTask.id)
|
||
: await startCustomerLogin(orderNo, selectedTask.id)
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
setLoginInfo(response.data.login)
|
||
setBindingSessionExpired(false)
|
||
setBindingLoadError('')
|
||
setBindingInfo(null)
|
||
setBindingConfirmOpen(false)
|
||
setBindingSecondsLeft(0)
|
||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||
} catch (error) {
|
||
message.error(error instanceof Error ? error.message : '创建登录二维码失败')
|
||
} finally {
|
||
setLoading(false)
|
||
}
|
||
}
|
||
|
||
async function handleSendSms() {
|
||
if (!selectedTask) return
|
||
const phone = mobile.trim()
|
||
if (!isValidMainlandMobile(phone)) {
|
||
message.warning('请输入正确的手机号')
|
||
return
|
||
}
|
||
setSmsSending(true)
|
||
try {
|
||
if (selectedTask.platform === 'weibo') {
|
||
let response = await sendCustomerWeiboSmsCode(orderNo, selectedTask.id, phone, '86')
|
||
if (response.data.mfaRequired) {
|
||
setSmsMfaRequired(true)
|
||
if (!response.data.mfaId || !response.data.captchaId) {
|
||
throw new Error('微博返回的安全验证参数不完整')
|
||
}
|
||
await runWeiboYidunChallenge(response.data.mfaId, response.data.captchaId)
|
||
response = await sendCustomerWeiboSmsCode(
|
||
orderNo,
|
||
selectedTask.id,
|
||
phone,
|
||
'86',
|
||
response.data.mfaId,
|
||
)
|
||
if (response.data.mfaRequired) {
|
||
throw new Error('微博安全验证未通过,请重新获取验证码')
|
||
}
|
||
}
|
||
message.success(response.data.message || '验证码已发送,请注意查收')
|
||
} else {
|
||
const response = await sendCustomerHuyaSmsCode(orderNo, selectedTask.id, phone)
|
||
if (response.data.challenge) {
|
||
setHuyaChallenge(response.data.challenge)
|
||
message.info('请先完成滑块安全验证')
|
||
return
|
||
}
|
||
message.success(response.data.message || '验证码已发送,请注意查收')
|
||
}
|
||
setSmsMfaRequired(false)
|
||
setSmsCountdown(60)
|
||
} catch (error) {
|
||
message.error(error instanceof Error ? error.message : '发送验证码失败')
|
||
} finally {
|
||
setSmsSending(false)
|
||
}
|
||
}
|
||
|
||
async function handleLoginSms() {
|
||
if (!selectedTask) return
|
||
const phone = mobile.trim()
|
||
if (!isValidMainlandMobile(phone)) {
|
||
message.warning('请输入正确的手机号')
|
||
return
|
||
}
|
||
if (!smsCode.trim()) {
|
||
message.warning('请输入短信验证码')
|
||
return
|
||
}
|
||
setSmsLogging(true)
|
||
try {
|
||
const response =
|
||
selectedTask.platform === 'weibo'
|
||
? await loginCustomerWeiboSms(orderNo, selectedTask.id, {
|
||
mobile: phone,
|
||
code: smsCode.trim(),
|
||
countryCode: '86',
|
||
})
|
||
: await loginCustomerHuyaSms(orderNo, selectedTask.id, {
|
||
mobile: phone,
|
||
code: smsCode.trim(),
|
||
})
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
setLoginInfo(response.data.login)
|
||
setHuyaChallenge(null)
|
||
message.success(isWeibo ? '微博登录成功,等待客服处理' : '登录成功,请继续绑定游戏角色')
|
||
} catch (error) {
|
||
const errorCode = (error as { errorCode?: string } | null)?.errorCode || ''
|
||
if (errorCode === 'weibo_sms_mfa_required') {
|
||
setSmsMfaRequired(true)
|
||
message.warning('微博要求二次验证,请改用扫码登录')
|
||
return
|
||
}
|
||
message.error(error instanceof Error ? error.message : '短信登录失败')
|
||
} finally {
|
||
setSmsLogging(false)
|
||
}
|
||
}
|
||
|
||
async function handleVerifyHuyaChallenge(solution: CustomerHuyaChallengeSolution) {
|
||
if (!selectedTask || !huyaChallenge) return
|
||
setHuyaChallengeLoading(true)
|
||
try {
|
||
const response = await verifyCustomerHuyaSmsChallenge(orderNo, selectedTask.id, solution)
|
||
if (response.data.challenge) {
|
||
setHuyaChallenge(response.data.challenge)
|
||
message.warning('安全验证未通过,请重新完成')
|
||
return
|
||
}
|
||
setHuyaChallenge(null)
|
||
setSmsCountdown(60)
|
||
message.success(response.data.message || '验证码已发送,请注意查收')
|
||
} catch (error) {
|
||
message.error(error instanceof Error ? error.message : '虎牙安全验证失败')
|
||
} finally {
|
||
setHuyaChallengeLoading(false)
|
||
}
|
||
}
|
||
|
||
async function handleRefreshBinding(forceRebind: boolean) {
|
||
if (!selectedTask) return
|
||
setBindingLoading(true)
|
||
try {
|
||
const response = await startCustomerBinding(orderNo, selectedTask.id, { forceRebind })
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
setBindingInfo(response.data.binding)
|
||
setBindingLoadError('')
|
||
setBindingConfirmOpen(false)
|
||
} catch (error) {
|
||
if (isHuyaSessionExpired(error)) {
|
||
setBindingSessionExpired(true)
|
||
setBindingConfirmOpen(false)
|
||
message.warning('虎牙登录会话已过期,请重新登录')
|
||
return
|
||
}
|
||
const detail = error instanceof Error ? error.message : '创建绑定二维码失败'
|
||
setBindingLoadError(detail)
|
||
message.error(detail)
|
||
} finally {
|
||
setBindingLoading(false)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 二维码区的刷新/重新获取:换绑流程必须 forceRebind。
|
||
* 否则后端发现账号已有绑定角色会直接返回已有角色(role_ready),页面看起来像「返回上一步」。
|
||
*/
|
||
function handleRefreshBindingQr() {
|
||
void handleRefreshBinding(bindingInfo?.rebindRequested === true)
|
||
}
|
||
|
||
async function handlePollBindingNow(openConfirm = false) {
|
||
if (!selectedTask) return
|
||
setBindingLoading(true)
|
||
try {
|
||
const response = await pollCustomerBinding(orderNo, selectedTask.id)
|
||
const nextTask = response.data.task
|
||
const nextBinding = response.data.binding
|
||
setTasks((current) => current.map((task) => (task.id === nextTask.id ? nextTask : task)))
|
||
if (nextBinding) setBindingInfo(nextBinding)
|
||
setBindingLoadError('')
|
||
if (nextTask.bindingStatus === 'role_ready') {
|
||
if (nextBinding?.rebindUnchanged) {
|
||
setBindingConfirmOpen(false)
|
||
if (nextBinding.rebindConfirmState === 'rejected') {
|
||
message.error(nextBinding.message || '虎牙未接受本次换绑')
|
||
} else {
|
||
message.warning(nextBinding.message || '换绑未生效,请查看下方原因')
|
||
}
|
||
return
|
||
}
|
||
// 资料不一致同样打开对比框,客户可在弹窗内修改资料或同步平台角色。
|
||
setBindingConfirmOpen(true)
|
||
return
|
||
}
|
||
if (nextTask.bindingStatus === 'confirmed') {
|
||
setBindingConfirmOpen(false)
|
||
message.success('绑定已确认,等待客服处理')
|
||
return
|
||
}
|
||
// 弹窗内点「刷新」:角色不再是待确认状态时收起弹窗,避免展示过期比对。
|
||
if (openConfirm) setBindingConfirmOpen(false)
|
||
const detail = nextBinding?.message || ''
|
||
if (nextTask.bindingStatus === 'scanned') {
|
||
if (nextBinding?.rebindConfirmState === 'accepted') {
|
||
message.info('虎牙已受理换绑,正在等待角色生效')
|
||
return
|
||
}
|
||
message.info(detail || '已扫码,请选好角色后点「已选好角色,提交换绑」')
|
||
return
|
||
}
|
||
if (nextTask.bindingStatus === 'qr_pending') {
|
||
message.warning('还没有检测到扫码记录,请使用微信扫码完成绑定后再点击')
|
||
return
|
||
}
|
||
if (nextTask.bindingStatus === 'expired') {
|
||
message.warning('绑定二维码已过期,请点击「刷新二维码」重新获取')
|
||
return
|
||
}
|
||
if (nextTask.bindingStatus === 'failed') {
|
||
message.error(detail || '识别绑定角色失败,请点击「刷新二维码」重试')
|
||
return
|
||
}
|
||
message.info(detail || '绑定状态还没有更新,请稍后再试')
|
||
} catch (error) {
|
||
if (isHuyaSessionExpired(error)) {
|
||
setBindingSessionExpired(true)
|
||
setBindingConfirmOpen(false)
|
||
message.warning('虎牙登录会话已过期,请重新登录')
|
||
return
|
||
}
|
||
const detail = error instanceof Error ? error.message : '刷新绑定状态失败'
|
||
setBindingLoadError(detail)
|
||
message.error(detail)
|
||
} finally {
|
||
setBindingLoading(false)
|
||
}
|
||
}
|
||
|
||
async function handleSubmitRebind() {
|
||
if (!selectedTask) return
|
||
setBindingLoading(true)
|
||
try {
|
||
const response = await submitCustomerRebind(orderNo, selectedTask.id)
|
||
const nextTask = response.data.task
|
||
const nextBinding = response.data.binding
|
||
setTasks((current) => current.map((task) => (task.id === nextTask.id ? nextTask : task)))
|
||
if (nextBinding) setBindingInfo(nextBinding)
|
||
setBindingLoadError('')
|
||
setBindingConfirmOpen(false)
|
||
if (nextBinding?.rebindUnchanged || nextBinding?.rebindConfirmState === 'rejected') {
|
||
message.error(nextBinding.message || '虎牙未接受本次换绑')
|
||
return
|
||
}
|
||
if (nextTask.bindingStatus === 'role_ready') {
|
||
message.success('换绑已生效,请核对角色后确认绑定')
|
||
return
|
||
}
|
||
message.info('已向虎牙提交换绑,正在等待角色生效')
|
||
} catch (error) {
|
||
if (isHuyaSessionExpired(error)) {
|
||
setBindingSessionExpired(true)
|
||
setBindingConfirmOpen(false)
|
||
message.warning('虎牙登录会话已过期,请重新登录')
|
||
return
|
||
}
|
||
const detail = error instanceof Error ? error.message : '提交换绑失败'
|
||
setBindingLoadError(detail)
|
||
message.error(detail)
|
||
} finally {
|
||
setBindingLoading(false)
|
||
}
|
||
}
|
||
|
||
async function handleSyncBindingProfile() {
|
||
if (!selectedTask) return
|
||
const comparison = bindingInfo?.comparison
|
||
if (!comparison) return
|
||
const roleName = comparison.boundRoleName
|
||
const roleId = comparison.boundRoleId
|
||
const serverZone = comparison.boundZone
|
||
if (!roleName || !roleId || !/^\d+$/.test(roleId) || !serverZone) {
|
||
message.warning('平台角色信息不完整,请点「修改资料」手动填写')
|
||
return
|
||
}
|
||
setProfileSaving(true)
|
||
try {
|
||
const response = await saveCustomerTaskProfile(orderNo, selectedTask.id, {
|
||
roleName,
|
||
roleId,
|
||
serverZone,
|
||
})
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id)
|
||
if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding)
|
||
reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding)
|
||
message.success('资料已按平台角色同步,请核对后确认绑定')
|
||
} catch (error) {
|
||
message.error(error instanceof Error ? error.message : '同步角色资料失败')
|
||
} finally {
|
||
setProfileSaving(false)
|
||
}
|
||
}
|
||
|
||
async function handleConfirmBinding(acceptExistingRole = false) {
|
||
if (!selectedTask) return
|
||
setBindingLoading(true)
|
||
try {
|
||
const response = await confirmCustomerBinding(
|
||
orderNo,
|
||
selectedTask.id,
|
||
acceptExistingRole ? { acceptExistingRole: true } : {},
|
||
)
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
setBindingInfo(response.data.binding)
|
||
setBindingConfirmOpen(false)
|
||
message.success(
|
||
acceptExistingRole ? '已按原绑定角色确认,等待客服处理' : '绑定已确认,等待客服处理',
|
||
)
|
||
} catch (error) {
|
||
if (isHuyaSessionExpired(error)) {
|
||
setBindingSessionExpired(true)
|
||
setBindingConfirmOpen(false)
|
||
message.warning('虎牙登录会话已过期,请重新登录')
|
||
return
|
||
}
|
||
message.error(error instanceof Error ? error.message : '确认绑定失败')
|
||
} finally {
|
||
setBindingLoading(false)
|
||
}
|
||
}
|
||
|
||
/** 换绑被虎牙拒绝时的二次确认:客户可以选择继续使用原绑定角色。 */
|
||
function handleAcceptExistingRole() {
|
||
if (!selectedTask || bindingLoading) return
|
||
const reason = String(bindingInfo?.rebindConfirmMessage || '').trim()
|
||
modal.confirm({
|
||
title: '确认使用原角色?',
|
||
content: `本次换绑未成功${reason ? `(${reason})` : ''},平台仍返回原绑定角色「${
|
||
bindingRoleName || '当前角色'
|
||
}」。确认后本次换绑作废,直接使用该角色继续履约。`,
|
||
okText: '确认使用原角色',
|
||
cancelText: '先不确认',
|
||
onOk: () => handleConfirmBinding(true),
|
||
})
|
||
}
|
||
|
||
/** 资料变更后重新打开对比弹窗,让客户基于最新两侧信息再次核对。 */
|
||
function reopenBindingConfirm(
|
||
nextTask: CustomerSemiAutoTask,
|
||
nextBinding: CustomerBindingInfo | null | undefined,
|
||
) {
|
||
if (nextTask.bindingStatus !== 'role_ready') return false
|
||
if (!nextBinding?.comparison || nextBinding.rebindUnchanged) return false
|
||
autoOpenedRoleRef.current = `${nextTask.id}:${nextBinding.bindGameRoleId || ''}`
|
||
setBindingConfirmOpen(true)
|
||
return true
|
||
}
|
||
|
||
/** 从对比弹窗回到资料表单,保存成功后会自动重新打开对比。 */
|
||
function openProfileEditor() {
|
||
setBindingConfirmOpen(false)
|
||
setProfileEditing(true)
|
||
window.setTimeout(() => {
|
||
document
|
||
.getElementById('customer-profile-form')
|
||
?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||
}, 0)
|
||
}
|
||
|
||
async function handleSaveProfile() {
|
||
if (!selectedTask) return
|
||
if (!profileServerZone.trim() || !profileRoleId.trim() || !profileRoleName.trim()) {
|
||
message.warning('请完整填写区服、游戏编号和角色名')
|
||
return
|
||
}
|
||
if (!SERVER_ZONE_OPTIONS.includes(profileServerZone.trim())) {
|
||
message.warning('请选择区服')
|
||
return
|
||
}
|
||
setProfileSaving(true)
|
||
try {
|
||
const response = await saveCustomerTaskProfile(orderNo, selectedTask.id, {
|
||
roleName: profileRoleName.trim(),
|
||
roleId: profileRoleId.trim(),
|
||
serverZone: profileServerZone.trim(),
|
||
})
|
||
setTasks((current) =>
|
||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||
)
|
||
setProfileEditing(false)
|
||
let reopened = false
|
||
try {
|
||
const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id)
|
||
if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding)
|
||
reopened = reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding)
|
||
} catch {
|
||
// 绑定尚未开始时没有 binding,可忽略。
|
||
}
|
||
message.success(reopened ? '角色资料已保存,请重新核对绑定角色' : '角色资料已保存')
|
||
} catch (error) {
|
||
message.error(error instanceof Error ? error.message : '保存角色资料失败')
|
||
} finally {
|
||
setProfileSaving(false)
|
||
}
|
||
}
|
||
|
||
async function handleCopyBindingLink() {
|
||
const url = bindingInfo?.qrUrl || ''
|
||
if (!url) {
|
||
message.warning('当前二维码不支持复制链接,请长按二维码保存图片')
|
||
return
|
||
}
|
||
try {
|
||
await navigator.clipboard.writeText(url)
|
||
message.success('二维码链接已复制')
|
||
} catch {
|
||
message.error('复制失败,请长按二维码保存图片')
|
||
}
|
||
}
|
||
|
||
/** 缺角色 ID 时引导客户把订单号发给客服人工核实。 */
|
||
async function copyOrderNoForSupport() {
|
||
const text = String(orderNo || selectedTask?.orderNo || '').trim()
|
||
if (!text) {
|
||
message.warning('订单号为空,请直接联系客服')
|
||
return
|
||
}
|
||
try {
|
||
await navigator.clipboard.writeText(text)
|
||
message.success('订单号已复制,请联系客服核实角色ID')
|
||
} catch {
|
||
message.error('复制失败,请手动记录订单号后联系客服')
|
||
}
|
||
}
|
||
|
||
const config = selectedTask?.semiAutoConfig || {}
|
||
const displayTitle = isWeibo ? '微博账号登录授权' : '绑定游戏角色'
|
||
const loginQrVisible =
|
||
Boolean(selectedTask) && ['qr_pending', 'scanned'].includes(selectedTask.loginStatus)
|
||
const showBindingStage = Boolean(
|
||
selectedTask &&
|
||
selectedTask.platform === 'huya' &&
|
||
selectedTask.loginStatus === 'authenticated' &&
|
||
selectedTask.executionStatus !== 'completed' &&
|
||
selectedTask.executionStatus !== 'cancelled',
|
||
)
|
||
const bindingQrVisible = ['not_started', 'qr_pending', 'scanned'].includes(
|
||
selectedTask?.bindingStatus || '',
|
||
)
|
||
const bindingComparison = bindingInfo?.comparison || null
|
||
const bindingRoleId = bindingInfo?.bindGameRoleId || selectedTask?.bindGameRoleId || ''
|
||
// 虎牙 gameRole.roleId 是加密串,客户侧统一展示数值 UID(huyaUid)。
|
||
const bindingPendingUid = (() => {
|
||
const comparisonId = String(bindingComparison?.boundRoleId || '').trim()
|
||
if (/^\d+$/.test(comparisonId)) return comparisonId
|
||
const huyaUid = String(selectedTask?.huyaUid || '').trim()
|
||
return /^\d+$/.test(huyaUid) ? huyaUid : comparisonId
|
||
})()
|
||
const bindingRoleName = bindingInfo?.bindGameRole || selectedTask?.bindGameRole || ''
|
||
const rebindUnchanged = bindingInfo?.rebindUnchanged === true
|
||
// 换绑失败视图可返回「已识别角色 + 资料不一致」的核对界面;后端 rebindUnchanged 保持不变。
|
||
const showRebindFailure = rebindUnchanged && !rebindFailureDismissed
|
||
const rebindConfirmState = bindingInfo?.rebindConfirmState || 'idle'
|
||
const rebindRejected = rebindConfirmState === 'rejected'
|
||
const rebindAccepted = rebindConfirmState === 'accepted'
|
||
const bindConfirmState = bindingInfo?.bindConfirmState || 'idle'
|
||
const bindConfirmRejected = bindConfirmState === 'rejected'
|
||
const bindConfirmPending = bindConfirmState === 'submitting' || bindConfirmState === 'accepted'
|
||
const bindingRoleIdNumeric = /^\d+$/.test(String(bindingPendingUid || bindingRoleId || '').trim())
|
||
// 平台返回了绑定角色但没有可核对的角色ID:提示联系客服,不能直接确认或重新扫码。
|
||
const bindingRequiresSupport =
|
||
Boolean(bindingInfo) &&
|
||
(bindingInfo?.requiresSupport ??
|
||
(Boolean(bindingInfo?.bindGameRole || bindingRoleName) && !bindingRoleIdNumeric))
|
||
// 绑定阶段顶部状态条:按 bindingStatus 显式映射,已确认/已过期/失败不再显示(各自有卡片)。
|
||
const bindingBanner = (() => {
|
||
if (bindingSessionExpired) return null
|
||
if (bindingRequiresSupport && selectedTask?.bindingStatus !== 'confirmed') {
|
||
return {
|
||
tone: 'is-warning',
|
||
text: '已登录,但平台未返回可核对的角色ID,请联系客服人工核实',
|
||
}
|
||
}
|
||
if (showRebindFailure) {
|
||
return {
|
||
tone: 'is-warning',
|
||
text: rebindRejected ? '虎牙未接受本次换绑,请查看下方原因' : '换绑未生效,请查看下方原因',
|
||
}
|
||
}
|
||
if (selectedTask?.bindingStatus === 'role_ready') {
|
||
return { tone: 'is-info', text: '已识别绑定角色,请核对后确认' }
|
||
}
|
||
if (
|
||
selectedTask?.bindingStatus === 'confirmed' ||
|
||
selectedTask?.bindingStatus === 'expired' ||
|
||
selectedTask?.bindingStatus === 'failed'
|
||
) {
|
||
return null
|
||
}
|
||
if (bindingInfo?.hasExistingBinding === false) {
|
||
return {
|
||
tone: 'is-info',
|
||
text: '登录成功,该虎牙账号还没有绑定游戏角色,请扫码完成绑定',
|
||
}
|
||
}
|
||
return null
|
||
})()
|
||
const nextRebindText = bindingInfo?.nextRebindAt
|
||
? formatAdminDateTime(bindingInfo.nextRebindAt)
|
||
: ''
|
||
const comparisonMismatch =
|
||
selectedTask?.bindingStatus === 'role_ready' && bindingComparison?.verdict === 'mismatch'
|
||
const showProfileForm = showBindingStage && profileEditing
|
||
const bindingCustomerReady = Boolean(
|
||
bindingComparison?.customerRoleId || bindingComparison?.customerRoleName,
|
||
)
|
||
// 平台角色名、数字角色 ID、区服齐全时,才支持一键同步为平台角色。
|
||
const canSyncBindingProfile = Boolean(
|
||
bindingComparison?.boundRoleName &&
|
||
/^\d+$/.test(String(bindingComparison?.boundRoleId || '').trim()) &&
|
||
bindingComparison?.boundZone,
|
||
)
|
||
const needsProfileCollection = Boolean(
|
||
selectedTask &&
|
||
selectedTask.platform === 'huya' &&
|
||
selectedTask.executionStatus !== 'completed' &&
|
||
selectedTask.bindingStatus !== 'confirmed' &&
|
||
(!selectedTask.customerServerZone ||
|
||
!selectedTask.customerGameRoleId ||
|
||
!selectedTask.customerGameRoleName),
|
||
)
|
||
|
||
const renderLoginForm = (options: {
|
||
platformLabel: string
|
||
mobilePlaceholder: string
|
||
codePlaceholder: string
|
||
submitText: string
|
||
afterMobile?: ReactNode
|
||
footerNote?: ReactNode
|
||
}) => (
|
||
<div className="customer-login-form">
|
||
<p className="customer-login-hint">请使用你的「{options.platformLabel}」账号登录</p>
|
||
<div className="customer-login-mobile-row">
|
||
<Input
|
||
className="customer-login-mobile"
|
||
value={mobile}
|
||
onChange={(event) => setMobile(event.target.value)}
|
||
placeholder={options.mobilePlaceholder}
|
||
inputMode="numeric"
|
||
maxLength={11}
|
||
/>
|
||
<Button
|
||
className="customer-login-code-button"
|
||
loading={smsSending}
|
||
disabled={smsCountdown > 0}
|
||
onClick={() => void handleSendSms()}
|
||
>
|
||
{smsCountdown > 0 ? `${smsCountdown}s` : '获取验证码'}
|
||
</Button>
|
||
</div>
|
||
{options.afterMobile}
|
||
<Input
|
||
className="customer-login-code-input"
|
||
value={smsCode}
|
||
onChange={(event) => setSmsCode(event.target.value)}
|
||
placeholder={options.codePlaceholder}
|
||
maxLength={8}
|
||
inputMode="numeric"
|
||
onPressEnter={() => void handleLoginSms()}
|
||
/>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-login-submit"
|
||
loading={smsLogging}
|
||
onClick={() => void handleLoginSms()}
|
||
>
|
||
{options.submitText}
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-login-alt"
|
||
onClick={() => {
|
||
setLoginMode('qr')
|
||
void handleStartLogin()
|
||
}}
|
||
>
|
||
改用二维码登录
|
||
</Button>
|
||
{options.footerNote}
|
||
</div>
|
||
)
|
||
|
||
const huyaLoginForm = renderLoginForm({
|
||
platformLabel: '虎牙',
|
||
mobilePlaceholder: '请输入号码',
|
||
codePlaceholder: '6 位验证码',
|
||
submitText: '登录',
|
||
})
|
||
|
||
if (loading) {
|
||
return (
|
||
<CustomerAuthFrame title="正在读取订单信息">
|
||
<div className="customer-auth-loading">
|
||
<Spin indicator={<LoadingOutlined spin />} />
|
||
<span>正在读取订单履约信息...</span>
|
||
</div>
|
||
</CustomerAuthFrame>
|
||
)
|
||
}
|
||
|
||
if (loadError || tasks.length === 0) {
|
||
return (
|
||
<CustomerAuthFrame title="暂时无法打开订单">
|
||
<div className="customer-auth-state is-error">
|
||
<h2>订单信息读取失败</h2>
|
||
<p>{loadError || '该订单没有需要客户授权或绑定的任务。'}</p>
|
||
</div>
|
||
</CustomerAuthFrame>
|
||
)
|
||
}
|
||
|
||
if (selectedTask?.executionStatus === 'completed') {
|
||
return (
|
||
<CustomerAuthFrame platform={selectedTask.platform} title={displayTitle}>
|
||
<CustomerOrderCard task={selectedTask} />
|
||
<div className="customer-auth-state is-success">
|
||
<div className="customer-auth-state-icon">
|
||
<CheckCircleFilled />
|
||
</div>
|
||
<h2>履约已完成</h2>
|
||
<p>
|
||
{selectedTask.completionNote ||
|
||
(isWeibo
|
||
? '客服已完成本订单的微博发帖操作,请到微博账号中确认。'
|
||
: '客服已完成本订单的充值或赠送操作,请到平台账号中确认。')}
|
||
</p>
|
||
{selectedTask.completedAt ? (
|
||
<span className="customer-auth-state-time">
|
||
完成时间:{formatAdminDateTime(selectedTask.completedAt)}
|
||
</span>
|
||
) : null}
|
||
</div>
|
||
<CustomerPrivacyNote />
|
||
</CustomerAuthFrame>
|
||
)
|
||
}
|
||
|
||
if (needsProfileCollection && selectedTask) {
|
||
return (
|
||
<CustomerCollectStep
|
||
task={selectedTask}
|
||
onSaved={(task) =>
|
||
setTasks((current) => current.map((item) => (item.id === task.id ? task : item)))
|
||
}
|
||
/>
|
||
)
|
||
}
|
||
|
||
return (
|
||
<CustomerAuthFrame platform={selectedTask?.platform} title={displayTitle}>
|
||
<div className="customer-auth-content-stack">
|
||
{tasks.length > 1 ? (
|
||
<div className="customer-auth-task-switcher">
|
||
<span>本订单需要处理</span>
|
||
<div>
|
||
{tasks.map((task) => (
|
||
<Button
|
||
key={task.id}
|
||
type={task.id === selectedTask?.id ? 'primary' : 'default'}
|
||
onClick={() => {
|
||
setSelectedTaskId(task.id)
|
||
setLoginInfo(null)
|
||
}}
|
||
>
|
||
{task.productName || task.skuName} × {task.quantity}
|
||
</Button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
|
||
<CustomerOrderCard task={selectedTask} />
|
||
|
||
{selectedTask?.loginStatus === 'waiting_login' ||
|
||
selectedTask?.loginStatus === 'failed' ||
|
||
selectedTask?.loginStatus === 'expired' ||
|
||
(loginQrVisible && loginMode === 'sms') ? (
|
||
<section className="customer-auth-section">
|
||
{isWeibo
|
||
? renderLoginForm({
|
||
platformLabel: '微博',
|
||
mobilePlaceholder: '请输入微博绑定手机号',
|
||
codePlaceholder: '请输入短信验证码',
|
||
submitText: '登录微博',
|
||
afterMobile: smsMfaRequired ? (
|
||
<div className="customer-auth-note">
|
||
请在安全验证弹窗中完成验证,通过后会继续发送短信验证码。
|
||
</div>
|
||
) : null,
|
||
footerNote: (
|
||
<span className="customer-auth-form-hint">
|
||
如安全验证弹窗未出现,请检查浏览器是否拦截脚本。
|
||
</span>
|
||
),
|
||
})
|
||
: huyaLoginForm}
|
||
</section>
|
||
) : null}
|
||
|
||
{loginQrVisible && loginMode === 'qr' ? (
|
||
<section className="customer-auth-section">
|
||
<div className="customer-auth-section-heading">
|
||
<span className="customer-auth-section-icon">
|
||
<QrcodeOutlined />
|
||
</span>
|
||
<div>
|
||
<h2>{isWeibo ? '使用微博 App 扫码' : '使用虎牙 App 扫码'}</h2>
|
||
<p>二维码仅用于本次订单授权,请勿转发给他人。</p>
|
||
</div>
|
||
</div>
|
||
<div className="customer-auth-qr">
|
||
{loginQrImage ? (
|
||
<div className="customer-auth-qr-image">
|
||
<Image
|
||
src={loginQrImage}
|
||
alt={isWeibo ? '微博登录二维码' : '虎牙登录二维码'}
|
||
width={232}
|
||
preview={false}
|
||
/>
|
||
</div>
|
||
) : (
|
||
<div className="customer-auth-qr-placeholder">
|
||
<Spin />
|
||
<span>正在生成二维码...</span>
|
||
</div>
|
||
)}
|
||
<p>{loginInfo?.message || '等待扫码'}</p>
|
||
{selectedTask.loginStatus === 'scanned' ? (
|
||
<span className="customer-auth-status-pill is-scanned">
|
||
{isWeibo ? '已扫码,请在微博客户端确认登录' : '已扫码,请在 App 确认'}
|
||
</span>
|
||
) : null}
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-login-alt"
|
||
onClick={() => void handleStartLogin()}
|
||
>
|
||
重新获取二维码
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-login-alt"
|
||
onClick={() => setLoginMode('sms')}
|
||
>
|
||
改用手机号登录
|
||
</Button>
|
||
</div>
|
||
</section>
|
||
) : null}
|
||
|
||
{showBindingStage ? (
|
||
<section id="customer-binding-stage" className="customer-binding-stage">
|
||
<div className="customer-binding-info">
|
||
<h3>
|
||
绑定信息 <small>(已登录虎牙账号)</small>
|
||
</h3>
|
||
<div>
|
||
<span>登录账号</span>
|
||
<strong>
|
||
{bindingInfo?.bindGameAccount || selectedTask.bindGameAccount || '未获取'}
|
||
</strong>
|
||
</div>
|
||
<div>
|
||
<span>绑定角色</span>
|
||
<strong>{bindingRoleName || '未识别到角色'}</strong>
|
||
</div>
|
||
</div>
|
||
|
||
{bindingSessionExpired ? (
|
||
<div className="customer-binding-session-card">
|
||
<p className="customer-binding-session-title">虎牙登录会话已过期</p>
|
||
<p className="customer-binding-session-desc">
|
||
请返回登录重新扫码,已填写的订单资料和绑定状态不会丢失。
|
||
</p>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-next"
|
||
loading={loading}
|
||
onClick={() => void handleStartLogin()}
|
||
>
|
||
返回登录
|
||
</Button>
|
||
</div>
|
||
) : null}
|
||
|
||
{bindingBanner ? (
|
||
<div className={`customer-binding-alert ${bindingBanner.tone}`}>
|
||
{bindingBanner.text}
|
||
</div>
|
||
) : null}
|
||
|
||
{showProfileForm && !bindingSessionExpired ? (
|
||
<div className="customer-auth-profile" id="customer-profile-form">
|
||
<p>修改资料后会重新核对平台识别角色。</p>
|
||
<div className="customer-profile-form">
|
||
<label className="customer-collect-label">
|
||
区服 <span>*</span>
|
||
</label>
|
||
<Select
|
||
className="customer-collect-select"
|
||
classNames={SERVER_ZONE_SELECT_CLASS_NAMES}
|
||
value={profileServerZone || undefined}
|
||
onChange={(value) => setProfileServerZone(String(value))}
|
||
placeholder="请选择区服"
|
||
options={SERVER_ZONE_OPTIONS.map((value) => ({ value, label: value }))}
|
||
/>
|
||
<label className="customer-collect-label">
|
||
游戏编号 <span>*</span>
|
||
</label>
|
||
<Input
|
||
className="customer-collect-input"
|
||
value={profileRoleId}
|
||
onChange={(event) => setProfileRoleId(event.target.value)}
|
||
placeholder="请输入游戏编号"
|
||
maxLength={64}
|
||
inputMode="numeric"
|
||
/>
|
||
<label className="customer-collect-label">
|
||
角色名 <span>*</span>
|
||
</label>
|
||
<Input
|
||
className="customer-collect-input"
|
||
value={profileRoleName}
|
||
onChange={(event) => setProfileRoleName(event.target.value)}
|
||
placeholder="请输入角色名"
|
||
maxLength={100}
|
||
/>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-collect-submit"
|
||
loading={profileSaving}
|
||
onClick={() => void handleSaveProfile()}
|
||
>
|
||
提交资料
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
) : null}
|
||
|
||
{bindingQrVisible && !bindingSessionExpired ? (
|
||
<div className="customer-binding-qr-card">
|
||
<h3>游戏角色绑定二维码</h3>
|
||
{bindingInfo?.qrImage || bindingQrImage ? (
|
||
<Image
|
||
src={bindingInfo?.qrImage || bindingQrImage || ''}
|
||
alt="游戏角色绑定二维码"
|
||
width={260}
|
||
preview={false}
|
||
/>
|
||
) : bindingLoadError ? (
|
||
<div className="customer-binding-qr-error">
|
||
<p>绑定二维码加载失败</p>
|
||
<span>{bindingLoadError}</span>
|
||
<div className="customer-binding-qr-actions">
|
||
<Button type="primary" onClick={() => void handlePollBindingNow()}>
|
||
重试
|
||
</Button>
|
||
<Button loading={loading} onClick={() => void handleStartLogin()}>
|
||
返回登录
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="customer-auth-qr-placeholder">
|
||
<Spin />
|
||
<span>正在生成绑定二维码...</span>
|
||
</div>
|
||
)}
|
||
<p className="customer-binding-qr-hint">
|
||
{bindingInfo?.hasExistingBinding === false
|
||
? '该虎牙账号还没有绑定游戏角色,请用微信扫码完成绑定'
|
||
: '请使用微信APP扫码进行游戏角色绑定'}
|
||
</p>
|
||
<p className="customer-binding-qr-hint">
|
||
扫码后系统会核对平台角色与已填资料;不一致时可修改资料或同步平台角色。
|
||
</p>
|
||
<p className="customer-binding-qr-tip">
|
||
{selectedTask?.bindingStatus === 'scanned'
|
||
? rebindAccepted
|
||
? '已向虎牙提交换绑,正在等待角色生效,请稍候刷新。'
|
||
: bindConfirmPending
|
||
? '已向虎牙提交绑定,正在等待角色生效,请稍候刷新。'
|
||
: bindingInfo?.rebindRequested
|
||
? '扫码后请在虎牙弹窗中选中目标角色;选好后点下方「已选好角色,提交换绑」。'
|
||
: '请在微信中完成角色绑定确认,再点击下方按钮进入下一步。'
|
||
: '扫码后请在微信确认框中核对目标角色。'}
|
||
</p>
|
||
{nextRebindText ? (
|
||
<p className="customer-binding-qr-tip">
|
||
本次换绑成功后,下次可换绑:{nextRebindText}。
|
||
</p>
|
||
) : null}
|
||
<p className="customer-binding-qr-countdown">
|
||
{selectedTask?.bindingStatus === 'scanned'
|
||
? bindingInfo?.message || '已扫码,等待角色生效'
|
||
: `建议 ${formatCountdown(bindingSecondsLeft)} 内完成扫码`}
|
||
</p>
|
||
<div className="customer-binding-qr-actions">
|
||
<Button type="primary" onClick={() => void handleCopyBindingLink()}>
|
||
复制二维码链接
|
||
</Button>
|
||
<Button onClick={handleRefreshBindingQr} loading={bindingLoading}>
|
||
刷新二维码
|
||
</Button>
|
||
</div>
|
||
{selectedTask?.bindingStatus === 'scanned' &&
|
||
bindingInfo?.rebindRequested &&
|
||
!rebindAccepted ? (
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-next"
|
||
loading={bindingLoading}
|
||
onClick={() => void handleSubmitRebind()}
|
||
>
|
||
已选好角色,提交换绑
|
||
</Button>
|
||
) : (
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-next"
|
||
loading={bindingLoading}
|
||
onClick={() => void handlePollBindingNow()}
|
||
>
|
||
{rebindAccepted || bindConfirmPending
|
||
? '刷新绑定状态'
|
||
: '已扫码绑定,点击进入下一步'}
|
||
</Button>
|
||
)}
|
||
</div>
|
||
) : null}
|
||
|
||
{selectedTask?.bindingStatus === 'expired' ? (
|
||
<Alert
|
||
type="warning"
|
||
showIcon
|
||
message="绑定二维码已过期"
|
||
description="请重新获取绑定二维码后再扫码,已填写的订单资料不会丢失。"
|
||
action={
|
||
<Button size="small" onClick={handleRefreshBindingQr}>
|
||
重新获取
|
||
</Button>
|
||
}
|
||
/>
|
||
) : null}
|
||
|
||
{selectedTask?.bindingStatus === 'failed' ? (
|
||
<Alert
|
||
type="error"
|
||
showIcon
|
||
message={bindConfirmRejected ? '虎牙未接受本次绑定' : '绑定失败'}
|
||
description={
|
||
bindingInfo?.message || '请刷新二维码后重新扫码,如持续失败请联系客服。'
|
||
}
|
||
action={
|
||
<Button size="small" onClick={handleRefreshBindingQr}>
|
||
重新获取
|
||
</Button>
|
||
}
|
||
/>
|
||
) : null}
|
||
|
||
{selectedTask?.bindingStatus === 'role_ready' && !bindingSessionExpired ? (
|
||
<Space direction="vertical" size={12} style={{ width: '100%' }}>
|
||
{bindingRequiresSupport ? (
|
||
<Alert
|
||
type="warning"
|
||
showIcon
|
||
message="请联系客服人工核实绑定角色"
|
||
description={`平台未返回可核对的角色ID,无法自动核对。请复制订单号 ${
|
||
orderNo || selectedTask?.orderNo || ''
|
||
} 联系客服,核实完成前请不要确认绑定。`}
|
||
/>
|
||
) : showRebindFailure ? (
|
||
<Alert
|
||
type={rebindRejected ? 'error' : 'warning'}
|
||
showIcon
|
||
message={rebindRejected ? '虎牙未接受本次换绑' : '换绑未生效'}
|
||
description={
|
||
<Space direction="vertical" size={2}>
|
||
<span>
|
||
平台仍返回原绑定角色:
|
||
{bindingRoleName || '未识别到角色'}
|
||
</span>
|
||
{bindingInfo?.rebindConfirmMessage ? (
|
||
<span>虎牙原因:{bindingInfo.rebindConfirmMessage}</span>
|
||
) : null}
|
||
{nextRebindText ? <span>预计下次可换绑:{nextRebindText}</span> : null}
|
||
{Number(bindingInfo?.platformChangeBindDay || 0) > 0 ? (
|
||
<span>
|
||
虎牙规则:每 {bindingInfo?.platformChangeBindDay} 个自然日可换绑 1 次
|
||
</span>
|
||
) : null}
|
||
{!bindingInfo?.rebindConfirmMessage && !nextRebindText ? (
|
||
<span>请核对虎牙弹窗中选中的目标角色后重新提交。</span>
|
||
) : null}
|
||
</Space>
|
||
}
|
||
/>
|
||
) : (
|
||
<Alert
|
||
type="success"
|
||
showIcon
|
||
message={bindingRoleName ? `已识别角色:${bindingRoleName}` : '已识别绑定角色'}
|
||
description={[bindingInfo?.bindGameAccount, bindingInfo?.bindGameChannel]
|
||
.filter(Boolean)
|
||
.join(' · ')}
|
||
/>
|
||
)}
|
||
{!bindingRequiresSupport &&
|
||
!showRebindFailure &&
|
||
comparisonMismatch &&
|
||
bindingComparison ? (
|
||
<Alert
|
||
type="warning"
|
||
showIcon
|
||
message="平台识别的角色与已填资料不一致"
|
||
description={
|
||
<Space direction="vertical" size={2}>
|
||
<span>
|
||
平台角色:{bindingComparison.boundZone || '区服未知'} ·{' '}
|
||
{bindingComparison.boundRoleName || '角色未知'}(ID{' '}
|
||
{bindingComparison.boundRoleId || '未知'})
|
||
</span>
|
||
<span>
|
||
已填资料:{bindingComparison.customerZone || '区服未填'} ·{' '}
|
||
{bindingComparison.customerRoleName || '角色未填'}(ID{' '}
|
||
{bindingComparison.customerRoleId || '未填'})
|
||
</span>
|
||
<span>三项一致后才能提交确认;可一键同步平台角色。</span>
|
||
</Space>
|
||
}
|
||
/>
|
||
) : null}
|
||
{bindingRequiresSupport ? (
|
||
<div className="customer-binding-role-actions">
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-confirm"
|
||
onClick={() => void copyOrderNoForSupport()}
|
||
>
|
||
复制订单号联系客服
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-rebind"
|
||
icon={<ReloadOutlined />}
|
||
loading={bindingLoading}
|
||
onClick={() => {
|
||
setBindingLoading(true)
|
||
void load(true).finally(() => setBindingLoading(false))
|
||
}}
|
||
>
|
||
刷新状态
|
||
</Button>
|
||
</div>
|
||
) : showRebindFailure ? (
|
||
<div className="customer-binding-role-actions">
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-confirm"
|
||
loading={bindingLoading}
|
||
onClick={() => void handleSubmitRebind()}
|
||
>
|
||
重新提交换绑
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-rebind"
|
||
icon={<ReloadOutlined />}
|
||
loading={bindingLoading}
|
||
onClick={() => void handleRefreshBinding(true)}
|
||
>
|
||
重新扫码换绑
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-accept"
|
||
onClick={() => {
|
||
setRebindFailureDismissed(true)
|
||
window.setTimeout(() => {
|
||
document
|
||
.getElementById('customer-binding-stage')
|
||
?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||
}, 0)
|
||
}}
|
||
>
|
||
返回上一步
|
||
</Button>
|
||
</div>
|
||
) : comparisonMismatch ? (
|
||
<div className="customer-binding-role-actions">
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-confirm"
|
||
loading={profileSaving}
|
||
onClick={() => void handleSyncBindingProfile()}
|
||
>
|
||
同步平台角色并继续
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-rebind"
|
||
icon={<ExclamationCircleOutlined />}
|
||
loading={bindingLoading}
|
||
onClick={() => void handleRefreshBinding(true)}
|
||
>
|
||
角色不对,重新扫码换绑
|
||
</Button>
|
||
</div>
|
||
) : rebindUnchanged ? (
|
||
<div className="customer-binding-role-actions">
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-confirm"
|
||
loading={bindingLoading}
|
||
onClick={() => handleAcceptExistingRole()}
|
||
>
|
||
确认使用原角色
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-rebind"
|
||
icon={<ExclamationCircleOutlined />}
|
||
loading={bindingLoading}
|
||
onClick={() => void handleRefreshBinding(true)}
|
||
>
|
||
角色不对,重新扫码换绑
|
||
</Button>
|
||
</div>
|
||
) : (
|
||
<div className="customer-binding-role-actions">
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-confirm"
|
||
loading={bindingLoading}
|
||
onClick={() => setBindingConfirmOpen(true)}
|
||
>
|
||
确认绑定角色
|
||
</Button>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-binding-rebind"
|
||
icon={<ExclamationCircleOutlined />}
|
||
loading={bindingLoading}
|
||
onClick={() => void handleRefreshBinding(true)}
|
||
>
|
||
角色不对,重新扫码换绑
|
||
</Button>
|
||
</div>
|
||
)}
|
||
</Space>
|
||
) : null}
|
||
|
||
{selectedTask?.bindingStatus === 'confirmed' ? (
|
||
<div className="customer-binding-verify">
|
||
<p>绑定状态需要平台人工核实,请联系客服处理</p>
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-login-alt"
|
||
loading={bindingLoading}
|
||
onClick={() => {
|
||
setBindingLoading(true)
|
||
void load(true).finally(() => setBindingLoading(false))
|
||
}}
|
||
>
|
||
刷新绑定状态
|
||
</Button>
|
||
</div>
|
||
) : null}
|
||
</section>
|
||
) : null}
|
||
|
||
{isWeibo &&
|
||
selectedTask?.loginStatus === 'authenticated' &&
|
||
selectedTask.executionStatus !== 'completed' ? (
|
||
<div className="customer-auth-state is-waiting">
|
||
<div className="customer-auth-state-icon">
|
||
<LoadingOutlined spin />
|
||
</div>
|
||
<h2>客服正在安排</h2>
|
||
<p>请耐心等待</p>
|
||
<Button
|
||
className="customer-auth-secondary-button"
|
||
icon={<ReloadOutlined />}
|
||
onClick={() => void load()}
|
||
>
|
||
刷新状态
|
||
</Button>
|
||
</div>
|
||
) : null}
|
||
|
||
<Modal
|
||
open={
|
||
bindingConfirmOpen &&
|
||
selectedTask?.bindingStatus === 'role_ready' &&
|
||
!rebindUnchanged &&
|
||
!bindingRequiresSupport
|
||
}
|
||
title="确认绑定角色"
|
||
onCancel={() => {
|
||
if (!bindingLoading) setBindingConfirmOpen(false)
|
||
}}
|
||
footer={
|
||
<div className="customer-binding-modal-footer">
|
||
<div className="customer-binding-modal-actions">
|
||
<Button
|
||
onClick={() => {
|
||
if (!bindingLoading) setBindingConfirmOpen(false)
|
||
}}
|
||
>
|
||
取消
|
||
</Button>
|
||
<Button
|
||
type="primary"
|
||
loading={bindingLoading}
|
||
disabled={!bindingCustomerReady || bindingComparison?.verdict === 'mismatch'}
|
||
onClick={() => void handleConfirmBinding()}
|
||
>
|
||
确认绑定
|
||
</Button>
|
||
</div>
|
||
{bindingComparison?.verdict === 'mismatch' ? (
|
||
<div className="customer-binding-modal-actions is-mismatch">
|
||
<Button onClick={openProfileEditor}>修改资料</Button>
|
||
{canSyncBindingProfile ? (
|
||
<Button loading={profileSaving} onClick={() => void handleSyncBindingProfile()}>
|
||
同步平台角色
|
||
</Button>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
{bindingComparison?.verdict === 'mismatch' ? (
|
||
<p className="customer-binding-modal-error">
|
||
{bindingComparison?.message || '两侧角色信息不一致,无法确认绑定'}
|
||
</p>
|
||
) : bindingComparison?.verdict === 'unknown' ? (
|
||
<p className="customer-binding-modal-warning">两侧角色信息不完整,请联系客服核实</p>
|
||
) : null}
|
||
</div>
|
||
}
|
||
destroyOnClose
|
||
>
|
||
<Space direction="vertical" size={14} style={{ width: '100%' }}>
|
||
<p style={{ margin: 0 }}>检测到待确认的绑定角色,请核对两侧角色是否一致。</p>
|
||
<div className="customer-binding-compare">
|
||
<div className="customer-binding-compare-side">
|
||
<div className="customer-binding-compare-head">
|
||
<span>您填写的角色</span>
|
||
<Button type="link" size="small" onClick={openProfileEditor}>
|
||
编辑
|
||
</Button>
|
||
</div>
|
||
<strong>{bindingComparison?.customerRoleName || '未填写'}</strong>
|
||
<em>{bindingComparison?.customerRoleId || '未填写角色ID'}</em>
|
||
</div>
|
||
<div className="customer-binding-compare-side">
|
||
<div className="customer-binding-compare-head">
|
||
<span>待确认角色</span>
|
||
<Button
|
||
type="link"
|
||
size="small"
|
||
loading={bindingLoading}
|
||
onClick={() => void handlePollBindingNow(true)}
|
||
>
|
||
刷新
|
||
</Button>
|
||
</div>
|
||
<strong>{bindingComparison?.boundRoleName || '未识别到角色'}</strong>
|
||
<em>{bindingPendingUid || '未获取到角色ID'}</em>
|
||
</div>
|
||
</div>
|
||
</Space>
|
||
</Modal>
|
||
|
||
<HuyaChallengeModal
|
||
open={Boolean(huyaChallenge)}
|
||
challenge={huyaChallenge}
|
||
loading={huyaChallengeLoading}
|
||
onCancel={() => {
|
||
if (!huyaChallengeLoading) setHuyaChallenge(null)
|
||
}}
|
||
onSubmit={(solution) => void handleVerifyHuyaChallenge(solution)}
|
||
/>
|
||
|
||
{isWeibo ? <CustomerPrivacyNote /> : null}
|
||
</div>
|
||
</CustomerAuthFrame>
|
||
)
|
||
}
|
||
|
||
function CustomerAuthFrame(input: {
|
||
platform?: CustomerSemiAutoTask['platform']
|
||
title: string
|
||
children: ReactNode
|
||
}) {
|
||
const platformClass =
|
||
input.platform === 'weibo' ? 'is-weibo' : input.platform === 'huya' ? 'is-huya' : ''
|
||
return (
|
||
<div className={`customer-auth-page ${platformClass}`}>
|
||
<div className="customer-auth-shell">
|
||
<header className="customer-auth-hero">
|
||
<div className="customer-auth-brand">
|
||
<div>
|
||
<h1>{input.title}</h1>
|
||
</div>
|
||
</div>
|
||
</header>
|
||
{input.platform === 'weibo' ? (
|
||
<div className="customer-auth-warning">温馨提示:未成年人禁止下单</div>
|
||
) : null}
|
||
<main className="customer-auth-main">{input.children}</main>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
function CustomerOrderCard({ task }: { task: CustomerSemiAutoTask }) {
|
||
if (task.platform === 'weibo') {
|
||
return (
|
||
<section className="customer-order-card">
|
||
<h3>订单信息</h3>
|
||
<div>
|
||
<span>订单号</span>
|
||
<strong>{task.orderNo}</strong>
|
||
</div>
|
||
<div>
|
||
<span>商品</span>
|
||
<strong>
|
||
{task.productName || task.skuName} × {task.quantity}
|
||
</strong>
|
||
</div>
|
||
<div>
|
||
<span>平台</span>
|
||
<strong>{task.platformLabel || '微博'}</strong>
|
||
</div>
|
||
<div>
|
||
<span>状态</span>
|
||
<strong className="customer-order-status">{task.displayStatus.label}</strong>
|
||
</div>
|
||
</section>
|
||
)
|
||
}
|
||
const zone = task.customerServerZone
|
||
? /区$/.test(task.customerServerZone)
|
||
? task.customerServerZone
|
||
: `${task.customerServerZone}区`
|
||
: ''
|
||
const roleText = [zone, task.customerGameRoleName].filter(Boolean).join('-') || '未填写'
|
||
return (
|
||
<section className="customer-order-card">
|
||
<h3>订单信息</h3>
|
||
<div>
|
||
<span>游戏名称</span>
|
||
<strong>和平精英</strong>
|
||
</div>
|
||
<div>
|
||
<span>角色名称</span>
|
||
<strong>{roleText}</strong>
|
||
</div>
|
||
<div>
|
||
<span>购买物品</span>
|
||
<strong>{task.productName || task.skuName}</strong>
|
||
</div>
|
||
</section>
|
||
)
|
||
}
|
||
|
||
function CustomerCollectStep(input: {
|
||
task: CustomerSemiAutoTask
|
||
onSaved: (task: CustomerSemiAutoTask) => void
|
||
}) {
|
||
const { message } = App.useApp()
|
||
const [serverZone, setServerZone] = useState(input.task.customerServerZone || '')
|
||
const [roleId, setRoleId] = useState(input.task.customerGameRoleId || '')
|
||
const [roleName, setRoleName] = useState(input.task.customerGameRoleName || '')
|
||
const [saving, setSaving] = useState(false)
|
||
|
||
async function submit() {
|
||
if (!serverZone.trim() || !roleId.trim() || !roleName.trim()) {
|
||
message.warning('请完整填写区服、游戏编号和角色名')
|
||
return
|
||
}
|
||
if (!SERVER_ZONE_OPTIONS.includes(serverZone.trim())) {
|
||
message.warning('请选择区服')
|
||
return
|
||
}
|
||
if (!/^\d+$/.test(roleId.trim())) {
|
||
message.warning('游戏编号只能是数字')
|
||
return
|
||
}
|
||
setSaving(true)
|
||
try {
|
||
const response = await saveCustomerTaskProfile(input.task.orderNo, input.task.id, {
|
||
roleName: roleName.trim(),
|
||
roleId: roleId.trim(),
|
||
serverZone: serverZone.trim(),
|
||
})
|
||
input.onSaved(response.data.task)
|
||
message.success('资料已提交')
|
||
} catch (error) {
|
||
message.error(error instanceof Error ? error.message : '提交资料失败')
|
||
} finally {
|
||
setSaving(false)
|
||
}
|
||
}
|
||
|
||
return (
|
||
<div className="customer-collect-page">
|
||
<div className="customer-collect-hero">
|
||
<p className="customer-collect-warning">温馨提示:未成年人禁止下单</p>
|
||
</div>
|
||
<div className="customer-collect-body">
|
||
<label className="customer-collect-label">
|
||
订单号 <span>*</span>
|
||
</label>
|
||
<div className="customer-collect-readonly">{input.task.orderNo}</div>
|
||
|
||
<div className="customer-collect-card">
|
||
<div>
|
||
<span>商品</span>
|
||
<strong>{input.task.productName || input.task.skuName}</strong>
|
||
</div>
|
||
<div>
|
||
<span>游戏</span>
|
||
<strong>和平精英</strong>
|
||
</div>
|
||
<p>填完资料记得截图联系客服。</p>
|
||
</div>
|
||
|
||
<label className="customer-collect-label">
|
||
区服 <span>*</span>
|
||
</label>
|
||
<Select
|
||
className="customer-collect-select"
|
||
classNames={SERVER_ZONE_SELECT_CLASS_NAMES}
|
||
value={serverZone || undefined}
|
||
onChange={(value) => setServerZone(String(value))}
|
||
placeholder="请选择区服"
|
||
options={SERVER_ZONE_OPTIONS.map((value) => ({ value, label: value }))}
|
||
/>
|
||
|
||
<label className="customer-collect-label">
|
||
游戏编号 <span>*</span>
|
||
</label>
|
||
<Input
|
||
className="customer-collect-input"
|
||
value={roleId}
|
||
onChange={(event) => setRoleId(event.target.value)}
|
||
placeholder="请输入游戏编号"
|
||
maxLength={64}
|
||
inputMode="numeric"
|
||
/>
|
||
|
||
<label className="customer-collect-label">
|
||
角色名 <span>*</span>
|
||
</label>
|
||
<Input
|
||
className="customer-collect-input"
|
||
value={roleName}
|
||
onChange={(event) => setRoleName(event.target.value)}
|
||
placeholder="请输入角色名"
|
||
maxLength={100}
|
||
/>
|
||
|
||
<Button
|
||
block
|
||
size="large"
|
||
className="customer-collect-submit"
|
||
loading={saving}
|
||
onClick={() => void submit()}
|
||
>
|
||
提交资料
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
function CustomerPrivacyNote() {
|
||
return (
|
||
<div className="customer-auth-privacy">
|
||
资料仅用于本次订单履约,请勿向他人泄露验证码或账号信息。
|
||
</div>
|
||
)
|
||
}
|
||
|
||
/** Connector 重启或会话被回收时后端返回该错误码,需要引导客户重新登录。 */
|
||
function isHuyaSessionExpired(error: unknown) {
|
||
return (error as { errorCode?: string } | null)?.errorCode === 'huya_native_session_not_found'
|
||
}
|
||
|
||
function isValidMainlandMobile(value: string) {
|
||
const digits = value.replace(/\D/g, '')
|
||
if (!digits) return false
|
||
return /^1\d{10}$/.test(digits)
|
||
}
|
||
|
||
function formatCountdown(seconds: number) {
|
||
const safe = Math.max(0, Math.floor(seconds))
|
||
const minutes = Math.floor(safe / 60)
|
||
const rest = safe % 60
|
||
return `${minutes}:${String(rest).padStart(2, '0')}`
|
||
}
|