feat(semi-auto): 客户链接按平台严格绑定,注入后统一由前端打开指定页
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
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 { useParams } from 'react-router'
|
||||
import { useLocation, useNavigate, useParams } from 'react-router'
|
||||
|
||||
import {
|
||||
confirmCustomerBinding,
|
||||
@@ -36,6 +36,11 @@ import type {
|
||||
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'
|
||||
|
||||
@@ -46,9 +51,15 @@ 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() {
|
||||
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('')
|
||||
@@ -79,6 +90,7 @@ export default function CustomerFulfillmentPage() {
|
||||
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('')
|
||||
@@ -100,11 +112,28 @@ export default function CustomerFulfillmentPage() {
|
||||
try {
|
||||
const response = await fetchCustomerFulfillment(orderNo)
|
||||
const nextTasks = response.data || []
|
||||
setTasks(nextTasks)
|
||||
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 (nextTasks.some((task) => task.id === current)) return current
|
||||
return nextTasks[0]?.id || 0
|
||||
if (visibleTasks.some((task) => task.id === current)) return current
|
||||
return visibleTasks[0]?.id || 0
|
||||
})
|
||||
} catch (error) {
|
||||
if (!silent) {
|
||||
@@ -115,9 +144,14 @@ export default function CustomerFulfillmentPage() {
|
||||
if (!silent) setLoading(false)
|
||||
}
|
||||
},
|
||||
[orderNo],
|
||||
[expectedPlatform, hash, navigate, orderNo, search],
|
||||
)
|
||||
|
||||
// 订单号或平台路由变化后允许重新判定跳转,避免复用组件时上一次的标记卡住。
|
||||
useEffect(() => {
|
||||
redirectingRef.current = false
|
||||
}, [expectedPlatform, orderNo])
|
||||
|
||||
useEffect(() => {
|
||||
void load()
|
||||
}, [load])
|
||||
|
||||
Reference in New Issue
Block a user