feat(semi-auto): 补充扫码角色对比入口并修复换绑二维码刷新
- 扫码识别角色后资料不一致也打开对比弹窗,支持修改资料/同步平台角色 - 保存资料或同步角色后自动重新打开对比弹窗 - 换绑流程刷新二维码传 forceRebind,避免直接返回已有角色
This commit is contained in:
@@ -340,8 +340,7 @@ export default function CustomerFulfillmentPage() {
|
|||||||
if (!bindingInfo?.comparison) return
|
if (!bindingInfo?.comparison) return
|
||||||
// 换绑后仍是原角色时只展示失败原因,不能自动弹出确认框。
|
// 换绑后仍是原角色时只展示失败原因,不能自动弹出确认框。
|
||||||
if (bindingInfo.rebindUnchanged) return
|
if (bindingInfo.rebindUnchanged) return
|
||||||
// 平台角色与已填资料不一致时先引导同步资料,不能直接弹确认框。
|
// 识别到角色(含与资料不一致)都要弹出对比框,由客户选择修改资料或同步平台角色。
|
||||||
if (bindingInfo.comparison.verdict === 'mismatch') return
|
|
||||||
const key = `${selectedTask.id}:${bindingInfo.bindGameRoleId || ''}`
|
const key = `${selectedTask.id}:${bindingInfo.bindGameRoleId || ''}`
|
||||||
if (autoOpenedRoleRef.current === key) return
|
if (autoOpenedRoleRef.current === key) return
|
||||||
autoOpenedRoleRef.current = key
|
autoOpenedRoleRef.current = key
|
||||||
@@ -536,6 +535,14 @@ export default function CustomerFulfillmentPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二维码区的刷新/重新获取:换绑流程必须 forceRebind。
|
||||||
|
* 否则后端发现账号已有绑定角色会直接返回已有角色(role_ready),页面看起来像「返回上一步」。
|
||||||
|
*/
|
||||||
|
function handleRefreshBindingQr() {
|
||||||
|
void handleRefreshBinding(bindingInfo?.rebindRequested === true)
|
||||||
|
}
|
||||||
|
|
||||||
async function handlePollBindingNow(openConfirm = false) {
|
async function handlePollBindingNow(openConfirm = false) {
|
||||||
if (!selectedTask) return
|
if (!selectedTask) return
|
||||||
setBindingLoading(true)
|
setBindingLoading(true)
|
||||||
@@ -556,13 +563,7 @@ export default function CustomerFulfillmentPage() {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (nextBinding?.comparison?.verdict === 'mismatch') {
|
// 资料不一致同样打开对比框,客户可在弹窗内修改资料或同步平台角色。
|
||||||
setBindingConfirmOpen(false)
|
|
||||||
message.warning(
|
|
||||||
nextBinding.comparison.message || '平台角色与已填资料不一致,请先同步资料',
|
|
||||||
)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setBindingConfirmOpen(true)
|
setBindingConfirmOpen(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -668,6 +669,7 @@ export default function CustomerFulfillmentPage() {
|
|||||||
)
|
)
|
||||||
const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id)
|
const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id)
|
||||||
if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding)
|
if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding)
|
||||||
|
reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding)
|
||||||
message.success('资料已按平台角色同步,请核对后确认绑定')
|
message.success('资料已按平台角色同步,请核对后确认绑定')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(error instanceof Error ? error.message : '同步角色资料失败')
|
message.error(error instanceof Error ? error.message : '同步角色资料失败')
|
||||||
@@ -721,6 +723,29 @@ export default function CustomerFulfillmentPage() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 资料变更后重新打开对比弹窗,让客户基于最新两侧信息再次核对。 */
|
||||||
|
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() {
|
async function handleSaveProfile() {
|
||||||
if (!selectedTask) return
|
if (!selectedTask) return
|
||||||
if (!profileServerZone.trim() || !profileRoleId.trim() || !profileRoleName.trim()) {
|
if (!profileServerZone.trim() || !profileRoleId.trim() || !profileRoleName.trim()) {
|
||||||
@@ -742,13 +767,15 @@ export default function CustomerFulfillmentPage() {
|
|||||||
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
|
||||||
)
|
)
|
||||||
setProfileEditing(false)
|
setProfileEditing(false)
|
||||||
|
let reopened = false
|
||||||
try {
|
try {
|
||||||
const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id)
|
const bindingResponse = await pollCustomerBinding(orderNo, selectedTask.id)
|
||||||
if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding)
|
if (bindingResponse.data.binding) setBindingInfo(bindingResponse.data.binding)
|
||||||
|
reopened = reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding)
|
||||||
} catch {
|
} catch {
|
||||||
// 绑定尚未开始时没有 binding,可忽略。
|
// 绑定尚未开始时没有 binding,可忽略。
|
||||||
}
|
}
|
||||||
message.success('角色资料已保存')
|
message.success(reopened ? '角色资料已保存,请重新核对绑定角色' : '角色资料已保存')
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(error instanceof Error ? error.message : '保存角色资料失败')
|
message.error(error instanceof Error ? error.message : '保存角色资料失败')
|
||||||
} finally {
|
} finally {
|
||||||
@@ -866,6 +893,12 @@ export default function CustomerFulfillmentPage() {
|
|||||||
const bindingCustomerReady = Boolean(
|
const bindingCustomerReady = Boolean(
|
||||||
bindingComparison?.customerRoleId || bindingComparison?.customerRoleName,
|
bindingComparison?.customerRoleId || bindingComparison?.customerRoleName,
|
||||||
)
|
)
|
||||||
|
// 平台角色名、数字角色 ID、区服齐全时,才支持一键同步为平台角色。
|
||||||
|
const canSyncBindingProfile = Boolean(
|
||||||
|
bindingComparison?.boundRoleName &&
|
||||||
|
/^\d+$/.test(String(bindingComparison?.boundRoleId || '').trim()) &&
|
||||||
|
bindingComparison?.boundZone,
|
||||||
|
)
|
||||||
const needsProfileCollection = Boolean(
|
const needsProfileCollection = Boolean(
|
||||||
selectedTask &&
|
selectedTask &&
|
||||||
selectedTask.platform === 'huya' &&
|
selectedTask.platform === 'huya' &&
|
||||||
@@ -1233,6 +1266,9 @@ export default function CustomerFulfillmentPage() {
|
|||||||
? '该虎牙账号还没有绑定游戏角色,请用微信扫码完成绑定'
|
? '该虎牙账号还没有绑定游戏角色,请用微信扫码完成绑定'
|
||||||
: '请使用微信APP扫码进行游戏角色绑定'}
|
: '请使用微信APP扫码进行游戏角色绑定'}
|
||||||
</p>
|
</p>
|
||||||
|
<p className="customer-binding-qr-hint">
|
||||||
|
扫码后系统会核对平台角色与已填资料;不一致时可修改资料或同步平台角色。
|
||||||
|
</p>
|
||||||
<p className="customer-binding-qr-tip">
|
<p className="customer-binding-qr-tip">
|
||||||
{selectedTask?.bindingStatus === 'scanned'
|
{selectedTask?.bindingStatus === 'scanned'
|
||||||
? rebindAccepted
|
? rebindAccepted
|
||||||
@@ -1258,7 +1294,7 @@ export default function CustomerFulfillmentPage() {
|
|||||||
<Button type="primary" onClick={() => void handleCopyBindingLink()}>
|
<Button type="primary" onClick={() => void handleCopyBindingLink()}>
|
||||||
复制二维码链接
|
复制二维码链接
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={() => void handleRefreshBinding(false)} loading={bindingLoading}>
|
<Button onClick={handleRefreshBindingQr} loading={bindingLoading}>
|
||||||
刷新二维码
|
刷新二维码
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -1297,7 +1333,7 @@ export default function CustomerFulfillmentPage() {
|
|||||||
message="绑定二维码已过期"
|
message="绑定二维码已过期"
|
||||||
description="请重新获取绑定二维码后再扫码,已填写的订单资料不会丢失。"
|
description="请重新获取绑定二维码后再扫码,已填写的订单资料不会丢失。"
|
||||||
action={
|
action={
|
||||||
<Button size="small" onClick={() => void handleRefreshBinding(false)}>
|
<Button size="small" onClick={handleRefreshBindingQr}>
|
||||||
重新获取
|
重新获取
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
@@ -1313,7 +1349,7 @@ export default function CustomerFulfillmentPage() {
|
|||||||
bindingInfo?.message || '请刷新二维码后重新扫码,如持续失败请联系客服。'
|
bindingInfo?.message || '请刷新二维码后重新扫码,如持续失败请联系客服。'
|
||||||
}
|
}
|
||||||
action={
|
action={
|
||||||
<Button size="small" onClick={() => void handleRefreshBinding(false)}>
|
<Button size="small" onClick={handleRefreshBindingQr}>
|
||||||
重新获取
|
重新获取
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
@@ -1592,6 +1628,16 @@ export default function CustomerFulfillmentPage() {
|
|||||||
确认绑定
|
确认绑定
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</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' ? (
|
{bindingComparison?.verdict === 'mismatch' ? (
|
||||||
<p className="customer-binding-modal-error">
|
<p className="customer-binding-modal-error">
|
||||||
{bindingComparison?.message || '两侧角色信息不一致,无法确认绑定'}
|
{bindingComparison?.message || '两侧角色信息不一致,无法确认绑定'}
|
||||||
@@ -1609,19 +1655,7 @@ export default function CustomerFulfillmentPage() {
|
|||||||
<div className="customer-binding-compare-side">
|
<div className="customer-binding-compare-side">
|
||||||
<div className="customer-binding-compare-head">
|
<div className="customer-binding-compare-head">
|
||||||
<span>您填写的角色</span>
|
<span>您填写的角色</span>
|
||||||
<Button
|
<Button type="link" size="small" onClick={openProfileEditor}>
|
||||||
type="link"
|
|
||||||
size="small"
|
|
||||||
onClick={() => {
|
|
||||||
setBindingConfirmOpen(false)
|
|
||||||
setProfileEditing(true)
|
|
||||||
window.setTimeout(() => {
|
|
||||||
document
|
|
||||||
.getElementById('customer-profile-form')
|
|
||||||
?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
|
||||||
}, 0)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
编辑
|
编辑
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2901,6 +2901,10 @@
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.customer-binding-modal-actions.is-mismatch {
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||||
|
}
|
||||||
|
|
||||||
.customer-binding-modal-error {
|
.customer-binding-modal-error {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
color: #dc2626;
|
color: #dc2626;
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import { dirname, join } from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import test from 'node:test'
|
||||||
|
|
||||||
|
const root = dirname(fileURLToPath(import.meta.url))
|
||||||
|
const source = readFileSync(
|
||||||
|
join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'),
|
||||||
|
'utf8',
|
||||||
|
)
|
||||||
|
const styles = readFileSync(join(root, '../src/styles/client.css'), 'utf8')
|
||||||
|
|
||||||
|
test('扫码识别角色后,资料不一致也打开对比弹窗', () => {
|
||||||
|
// 自动弹窗 effect 不再因 mismatch 提前 return。
|
||||||
|
assert.ok(source.includes('识别到角色(含与资料不一致)都要弹出对比框'))
|
||||||
|
assert.ok(!source.includes("if (bindingInfo.comparison.verdict === 'mismatch') return"))
|
||||||
|
// 手动刷新时 mismatch 同样打开弹窗,不再关闭并只弹提示。
|
||||||
|
assert.ok(source.includes('资料不一致同样打开对比框'))
|
||||||
|
assert.ok(!source.includes('平台角色与已填资料不一致,请先同步资料'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('对比弹窗在资料不一致时提供修改资料与同步平台角色入口', () => {
|
||||||
|
assert.ok(source.includes('修改资料'))
|
||||||
|
assert.ok(source.includes('同步平台角色'))
|
||||||
|
assert.ok(source.includes('canSyncBindingProfile'))
|
||||||
|
assert.ok(source.includes('onClick={openProfileEditor}'))
|
||||||
|
assert.ok(
|
||||||
|
source.includes(
|
||||||
|
"disabled={!bindingCustomerReady || bindingComparison?.verdict === 'mismatch'}",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert.ok(styles.includes('.customer-binding-modal-actions.is-mismatch'))
|
||||||
|
assert.ok(styles.includes('repeat(auto-fit, minmax(140px, 1fr))'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('保存资料或同步平台角色后会重新打开对比弹窗', () => {
|
||||||
|
assert.ok(source.includes('function reopenBindingConfirm('))
|
||||||
|
assert.ok(source.includes("if (nextTask.bindingStatus !== 'role_ready') return false"))
|
||||||
|
assert.ok(source.includes('reopened = reopenBindingConfirm('))
|
||||||
|
assert.ok(
|
||||||
|
source.includes(
|
||||||
|
'reopenBindingConfirm(bindingResponse.data.task, bindingResponse.data.binding)',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert.ok(source.includes('角色资料已保存,请重新核对绑定角色'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('资料不一致时仍保持后端严格比对:确认按钮禁用并显示原因', () => {
|
||||||
|
assert.ok(source.includes('两侧角色信息不一致,无法确认绑定'))
|
||||||
|
assert.ok(source.includes('customer-binding-modal-error'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('二维码区提示扫码后会核对平台角色与已填资料', () => {
|
||||||
|
assert.ok(source.includes('扫码后系统会核对平台角色与已填资料'))
|
||||||
|
})
|
||||||
|
|
||||||
|
test('换绑流程刷新二维码必须带 forceRebind,避免直接返回已有角色', () => {
|
||||||
|
assert.ok(source.includes('function handleRefreshBindingQr()'))
|
||||||
|
assert.ok(source.includes('handleRefreshBinding(bindingInfo?.rebindRequested === true)'))
|
||||||
|
// 三处刷新/重新获取入口都不能再固定传 false。
|
||||||
|
assert.ok(!source.includes('handleRefreshBinding(false)'))
|
||||||
|
assert.ok(source.includes('onClick={handleRefreshBindingQr}'))
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user