fix(semi-auto): 刷新绑定二维码 5 秒内复用当前码

This commit is contained in:
2026-11-19 12:34:55 +08:00
parent 87c7cc267c
commit 7f74772dab
4 changed files with 68 additions and 1 deletions
@@ -46,6 +46,8 @@ import { runWeiboYidunChallenge } from '@/utils/weibo-yidun'
import HuyaChallengeModal from './HuyaChallengeModal'
const POLL_INTERVAL_MS = 2000
// 刷新绑定二维码的冷却时间:避免连续点击频繁请求虎牙。
const BINDING_REFRESH_COOLDOWN_MS = 3_000
const SERVER_ZONE_OPTIONS = ['苹果Q区', '苹果V区', '安卓Q区', '安卓V区']
@@ -88,6 +90,7 @@ export default function CustomerFulfillmentPage({
const [profileSaving, setProfileSaving] = useState(false)
const [profileEditing, setProfileEditing] = useState(false)
const startingBindingRef = useRef(false)
const lastBindingRefreshAtRef = useRef(0)
const resettingBindingRef = useRef(false)
const hydratingBindingRef = useRef(false)
const autoOpenedRoleRef = useRef('')
@@ -176,6 +179,7 @@ export default function CustomerFulfillmentPage({
setBindingInfo(null)
setBindingConfirmOpen(false)
startingBindingRef.current = false
lastBindingRefreshAtRef.current = 0
hydratingBindingRef.current = false
autoOpenedRoleRef.current = ''
weiboBindingSyncRef.current = false
@@ -608,6 +612,12 @@ export default function CustomerFulfillmentPage({
async function handleRefreshBinding(forceRebind: boolean) {
if (!selectedTask) return
const now = Date.now()
if (now - lastBindingRefreshAtRef.current < BINDING_REFRESH_COOLDOWN_MS) {
message.warning('操作频繁,请稍后再试')
return
}
lastBindingRefreshAtRef.current = now
setBindingLoading(true)
try {
const response = await startCustomerBinding(orderNo, selectedTask.id, { forceRebind })
@@ -56,3 +56,18 @@ test('上一步修改资料会清空换绑状态并保留已填资料', () => {
// 重置失败不阻断客户修改资料。
assert.ok(source.includes('重置绑定状态失败,请稍后重试'))
})
test('刷新二维码有 3 秒冷却并提示操作频繁', () => {
assert.ok(source.includes('BINDING_REFRESH_COOLDOWN_MS = 3_000'))
assert.ok(source.includes('lastBindingRefreshAtRef'))
assert.ok(source.includes("message.warning('操作频繁,请稍后再试')"))
// 首次二维码出现不设置冷却,只有手动刷新才计时。
assert.ok(!source.includes('lastBindingRefreshAtRef.current = Date.now()'))
assert.ok(source.includes('lastBindingRefreshAtRef.current = now'))
// 冷却判断必须在真正发起 startCustomerBinding 之前。
const guardIndex = source.indexOf('操作频繁,请稍后再试')
const startIndex = source.indexOf(
'await startCustomerBinding(orderNo, selectedTask.id, { forceRebind })',
)
assert.ok(guardIndex > 0 && startIndex > guardIndex)
})