fix(semi-auto): 换绑失败卡透出虎牙原因与下次换绑时间,会话过期可返回登录

1) 下次换绑时间改按虎牙日界口径:changeBindTime 是绑定日次日 00:00,(日界 + changeBindDay - 1) 天;11-16 绑定 → 2026-11-23,与虎牙绑定页一致(原 +7 天会显示 11-24)。

2) 客户页换绑失败卡同时展示虎牙原文原因、预计下次可换绑时间与「每 7 个自然日可换绑 1 次」规则。

3) 绑定会话失效时给出整行「返回登录」入口;二维码加载失败可重试;告警标题统一为亮色不再黑字;提交类按钮统一 56px 蓝色主按钮。
This commit is contained in:
2026-11-16 14:46:17 +08:00
parent ad59c87e13
commit 64281aefb0
4 changed files with 194 additions and 46 deletions
@@ -209,10 +209,18 @@ export function resolveRebindCooldown(
if (!response || (response.status !== undefined && response.status !== 200)) {
return { days: 0, nextRebindAt: '' }
}
const changeBindDay = Number(response.changeBindDay || 0)
const hasPlatformWindow =
Number.isFinite(changeBindDay) && changeBindDay > 0 && changeBindDay <= 30
const windowDays = hasPlatformWindow ? Math.round(changeBindDay) : REBIND_WINDOW_DAYS
const changeBindTime = Number(response.accountData?.changeBindTime || 0)
if (Number.isFinite(changeBindTime) && changeBindTime > 0) {
const changedAtMs = changeBindTime > 1e12 ? changeBindTime : changeBindTime * 1000
const nextRebindMs = changedAtMs + REBIND_WINDOW_DAYS * DAY_MS
// 虎牙把「本次绑定日」记成次日 00:00 的日界:11-16 绑定 → changeBindTime = 2026-11-17 00:00,
// 配合 changeBindDay = 7,绑定页提示「预计下次换绑时间 2026/11/23」。
// 因此下次可换绑 = 日界 + (窗口天数 - 1) 天;不能用 +7 天,否则会显示成 11-24。
const offsetDays = hasPlatformWindow ? Math.max(windowDays - 1, 0) : REBIND_WINDOW_DAYS
const nextRebindMs = changedAtMs + offsetDays * DAY_MS
if (nextRebindMs > now) {
return {
days: Math.ceil((nextRebindMs - now) / DAY_MS),
@@ -220,10 +228,8 @@ export function resolveRebindCooldown(
}
}
}
const changeBindDay = Number(response.changeBindDay || 0)
if (Number.isFinite(changeBindDay) && changeBindDay > 0 && changeBindDay <= 30) {
const days = Math.round(changeBindDay)
return { days, nextRebindAt: iso(now + days * DAY_MS) }
if (hasPlatformWindow) {
return { days: windowDays, nextRebindAt: iso(now + windowDays * DAY_MS) }
}
return { days: 0, nextRebindAt: '' }
}
@@ -20,6 +20,18 @@ test('换绑冷却:changeBindTime 为初次绑定时间时,下次换绑为 7
assert.equal(result.nextRebindAt.slice(0, 10), '2026-11-23')
})
test('换绑冷却:按虎牙日界推算(11-16 绑定 → 11-23 才能换绑)', () => {
// 实测 task 34:changeBindTime = 1794844800 = 2026-11-17 00:00 +08:00,changeBindDay = 7。
const now = Date.UTC(2026, 10, 16, 6, 31) // 2026-11-16 14:31 +08:00
const result = resolveRebindCooldown(
{ status: 200, changeBindDay: 7, accountData: { changeBindTime: 1794844800 } },
now,
)
assert.equal(result.days, 7)
// 2026-11-23 00:00 +08:00,与虎牙绑定页「预计下次换绑时间 2026/11/23」一致。
assert.equal(result.nextRebindAt, '2026-11-22T16:00:00.000Z')
})
test('换绑冷却:changeBindTime 已超过 7 天时不再限制', () => {
const result = resolveRebindCooldown(
{
@@ -82,6 +82,7 @@ export default function CustomerFulfillmentPage() {
const autoOpenedRoleRef = useRef('')
// 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,
@@ -137,6 +138,7 @@ export default function CustomerFulfillmentPage() {
hydratingBindingRef.current = false
autoOpenedRoleRef.current = ''
setBindingSessionExpired(false)
setBindingLoadError('')
}, [selectedTask?.id])
useEffect(() => {
@@ -241,13 +243,16 @@ export default function CustomerFulfillmentPage() {
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
}
message.error(error instanceof Error ? error.message : '创建绑定二维码失败')
const detail = error instanceof Error ? error.message : '创建绑定二维码失败'
setBindingLoadError(detail)
message.error(detail)
})
.finally(() => {
startingBindingRef.current = false
@@ -263,6 +268,7 @@ export default function CustomerFulfillmentPage() {
useEffect(() => {
if (!selectedTask || !orderNo || selectedTask.platform !== 'huya') return
if (bindingSessionExpired) return
if (!['qr_pending', 'scanned'].includes(selectedTask.bindingStatus)) return
const tick = async () => {
try {
@@ -271,19 +277,35 @@ export default function CustomerFulfillmentPage() {
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
)
if (response.data.binding) setBindingInfo(response.data.binding)
} catch {
// 短暂轮询失败不打断客户页面,下一轮继续。
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)
}, [orderNo, selectedTask?.bindingStatus, selectedTask?.id, selectedTask?.platform])
}, [
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
@@ -293,14 +315,26 @@ export default function CustomerFulfillmentPage() {
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)
if (isHuyaSessionExpired(error)) {
setBindingSessionExpired(true)
return
}
setBindingLoadError(error instanceof Error ? error.message : '刷新绑定状态失败')
})
.finally(() => {
hydratingBindingRef.current = false
})
}, [bindingInfo, orderNo, selectedTask?.bindingStatus, selectedTask?.id, selectedTask?.platform])
}, [
bindingInfo,
bindingSessionExpired,
orderNo,
selectedTask?.bindingStatus,
selectedTask?.id,
selectedTask?.platform,
])
useEffect(() => {
if (!selectedTask || selectedTask.bindingStatus !== 'role_ready') return
@@ -355,6 +389,11 @@ export default function CustomerFulfillmentPage() {
)
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 {
@@ -481,6 +520,7 @@ export default function CustomerFulfillmentPage() {
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)) {
@@ -489,7 +529,9 @@ export default function CustomerFulfillmentPage() {
message.warning('虎牙登录会话已过期,请重新登录')
return
}
message.error(error instanceof Error ? error.message : '创建绑定二维码失败')
const detail = error instanceof Error ? error.message : '创建绑定二维码失败'
setBindingLoadError(detail)
message.error(detail)
} finally {
setBindingLoading(false)
}
@@ -504,6 +546,7 @@ export default function CustomerFulfillmentPage() {
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)
@@ -560,7 +603,9 @@ export default function CustomerFulfillmentPage() {
message.warning('虎牙登录会话已过期,请重新登录')
return
}
message.error(error instanceof Error ? error.message : '刷新绑定状态失败')
const detail = error instanceof Error ? error.message : '刷新绑定状态失败'
setBindingLoadError(detail)
message.error(detail)
} finally {
setBindingLoading(false)
}
@@ -575,6 +620,7 @@ export default function CustomerFulfillmentPage() {
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 || '虎牙未接受本次换绑')
@@ -592,7 +638,9 @@ export default function CustomerFulfillmentPage() {
message.warning('虎牙登录会话已过期,请重新登录')
return
}
message.error(error instanceof Error ? error.message : '提交换绑失败')
const detail = error instanceof Error ? error.message : '提交换绑失败'
setBindingLoadError(detail)
message.error(detail)
} finally {
setBindingLoading(false)
}
@@ -1056,23 +1104,21 @@ export default function CustomerFulfillmentPage() {
</div>
{bindingSessionExpired ? (
<Alert
type="warning"
showIcon
message="虎牙登录会话已过期"
description="请重新登录后再扫码绑定游戏角色,已填写的订单资料不会丢失。"
action={
<Button
size="small"
onClick={() => {
setBindingSessionExpired(false)
void handleStartLogin()
}}
>
重新登录
</Button>
}
/>
<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}
{!bindingSessionExpired ? (
@@ -1154,6 +1200,19 @@ export default function CustomerFulfillmentPage() {
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 />
@@ -1259,11 +1318,16 @@ export default function CustomerFulfillmentPage() {
</span>
{bindingInfo?.rebindConfirmMessage ? (
<span>虎牙原因:{bindingInfo.rebindConfirmMessage}</span>
) : nextRebindText ? (
<span>预计下次可换绑:{nextRebindText}。</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>
}
/>
+77 -11
View File
@@ -2431,13 +2431,20 @@
}
.customer-login-submit.ant-btn {
height: 52px;
border-radius: 8px;
background: #0aa53a !important;
border-color: #0aa53a !important;
height: 56px;
border-radius: 14px;
background: #2563eb !important;
border-color: #2563eb !important;
color: #fff !important;
font-size: 17px;
font-weight: 600;
}
.customer-login-submit.ant-btn:hover,
.customer-login-submit.ant-btn:focus-visible {
background: #1d4ed8 !important;
border-color: #1d4ed8 !important;
color: #fff !important;
font-size: 18px;
font-weight: 700;
}
.customer-login-alt.ant-btn {
@@ -2498,6 +2505,53 @@
padding: 16px;
}
.customer-binding-session-card {
display: flex;
flex-direction: column;
gap: 10px;
padding: 18px;
border: 1px solid #78350f;
border-radius: 12px;
background: rgba(120, 53, 15, 0.22);
}
.customer-binding-session-title {
margin: 0;
color: #fbbf24;
font-size: 16px;
font-weight: 700;
}
.customer-binding-session-desc {
margin: 0 0 4px;
color: #fcd34d;
font-size: 13px;
line-height: 1.6;
}
.customer-binding-qr-error {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
padding: 24px 12px;
text-align: center;
}
.customer-binding-qr-error p {
margin: 0;
color: #fca5a5;
font-size: 15px;
font-weight: 600;
}
.customer-binding-qr-error span {
color: #cbd5e1;
font-size: 13px;
line-height: 1.6;
overflow-wrap: anywhere;
}
/* antd Alert 在绑定阶段统一走深色卡片,避免浅色块破坏整体深色风格 */
.customer-binding-stage .ant-alert {
align-items: flex-start;
@@ -2513,6 +2567,14 @@
font-weight: 600;
}
/* antd v6 的标题节点是 .ant-alert-title(v5 为 .ant-alert-message) */
.customer-binding-stage .ant-alert .ant-alert-title {
color: #e2e8f0;
font-size: 14px;
font-weight: 600;
line-height: 1.5;
}
.customer-binding-stage .ant-alert .ant-alert-description {
color: #cbd5e1;
font-size: 13px;
@@ -2525,7 +2587,8 @@
}
.customer-binding-stage .ant-alert-warning .ant-alert-icon,
.customer-binding-stage .ant-alert-warning .ant-alert-message {
.customer-binding-stage .ant-alert-warning .ant-alert-message,
.customer-binding-stage .ant-alert-warning .ant-alert-title {
color: #fbbf24;
}
@@ -2539,7 +2602,8 @@
}
.customer-binding-stage .ant-alert-error .ant-alert-icon,
.customer-binding-stage .ant-alert-error .ant-alert-message {
.customer-binding-stage .ant-alert-error .ant-alert-message,
.customer-binding-stage .ant-alert-error .ant-alert-title {
color: #fca5a5;
}
@@ -2553,7 +2617,8 @@
}
.customer-binding-stage .ant-alert-success .ant-alert-icon,
.customer-binding-stage .ant-alert-success .ant-alert-message {
.customer-binding-stage .ant-alert-success .ant-alert-message,
.customer-binding-stage .ant-alert-success .ant-alert-title {
color: #6ee7b7;
}
@@ -2739,12 +2804,13 @@
.customer-binding-next.ant-btn {
width: 100%;
height: 46px;
height: 56px;
margin-top: 6px;
border-radius: 8px;
border-radius: 14px;
background: #2563eb !important;
border-color: #2563eb !important;
color: #fff !important;
font-size: 17px;
font-weight: 600;
}