From 64281aefb028e7fd6626a0122ef214d0fb99511d Mon Sep 17 00:00:00 2001 From: zhaoxing <2558691827@qq.com> Date: Mon, 16 Nov 2026 14:46:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(semi-auto):=20=E6=8D=A2=E7=BB=91=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E5=8D=A1=E9=80=8F=E5=87=BA=E8=99=8E=E7=89=99=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=E4=B8=8E=E4=B8=8B=E6=AC=A1=E6=8D=A2=E7=BB=91=E6=97=B6?= =?UTF-8?q?=E9=97=B4=EF=BC=8C=E4=BC=9A=E8=AF=9D=E8=BF=87=E6=9C=9F=E5=8F=AF?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1) 下次换绑时间改按虎牙日界口径:changeBindTime 是绑定日次日 00:00,(日界 + changeBindDay - 1) 天;11-16 绑定 → 2026-11-23,与虎牙绑定页一致(原 +7 天会显示 11-24)。 2) 客户页换绑失败卡同时展示虎牙原文原因、预计下次可换绑时间与「每 7 个自然日可换绑 1 次」规则。 3) 绑定会话失效时给出整行「返回登录」入口;二维码加载失败可重试;告警标题统一为亮色不再黑字;提交类按钮统一 56px 蓝色主按钮。 --- .../huya-native/huya-native-connector.ts | 16 ++- .../huya-native/rebind-cooldown.test.ts | 12 ++ .../CustomerFulfillmentPage.tsx | 124 +++++++++++++----- apps/frontend/src/styles/client.css | 88 +++++++++++-- 4 files changed, 194 insertions(+), 46 deletions(-) diff --git a/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts b/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts index 8744bf0b..18f54be0 100644 --- a/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts +++ b/apps/backend/src/services/semi-auto/huya-native/huya-native-connector.ts @@ -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: '' } } diff --git a/apps/backend/src/services/semi-auto/huya-native/rebind-cooldown.test.ts b/apps/backend/src/services/semi-auto/huya-native/rebind-cooldown.test.ts index 0cbfb5d3..f99df006 100644 --- a/apps/backend/src/services/semi-auto/huya-native/rebind-cooldown.test.ts +++ b/apps/backend/src/services/semi-auto/huya-native/rebind-cooldown.test.ts @@ -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( { diff --git a/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx b/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx index 93af3c9d..726e089b 100644 --- a/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx +++ b/apps/frontend/src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx @@ -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() { {bindingSessionExpired ? ( - { - setBindingSessionExpired(false) - void handleStartLogin() - }} - > - 重新登录 - - } - /> +
+

虎牙登录会话已过期

+

+ 请返回登录重新扫码,已填写的订单资料和绑定状态不会丢失。 +

+ +
) : null} {!bindingSessionExpired ? ( @@ -1154,6 +1200,19 @@ export default function CustomerFulfillmentPage() { width={260} preview={false} /> + ) : bindingLoadError ? ( +
+

绑定二维码加载失败

+ {bindingLoadError} +
+ + +
+
) : (
@@ -1259,11 +1318,16 @@ export default function CustomerFulfillmentPage() { {bindingInfo?.rebindConfirmMessage ? ( 虎牙原因:{bindingInfo.rebindConfirmMessage} - ) : nextRebindText ? ( - 预计下次可换绑:{nextRebindText}。 - ) : ( + ) : null} + {nextRebindText ? 预计下次可换绑:{nextRebindText} : null} + {Number(bindingInfo?.platformChangeBindDay || 0) > 0 ? ( + + 虎牙规则:每 {bindingInfo?.platformChangeBindDay} 个自然日可换绑 1 次 + + ) : null} + {!bindingInfo?.rebindConfirmMessage && !nextRebindText ? ( 请核对虎牙弹窗中选中的目标角色后重新提交。 - )} + ) : null} } /> diff --git a/apps/frontend/src/styles/client.css b/apps/frontend/src/styles/client.css index a4101b0d..a45756e8 100644 --- a/apps/frontend/src/styles/client.css +++ b/apps/frontend/src/styles/client.css @@ -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; }