优化(斗鱼履约): 提示客户只填写游戏角色名
This commit is contained in:
@@ -22,6 +22,7 @@ import type {
|
|||||||
DouyuCustomerSystem,
|
DouyuCustomerSystem,
|
||||||
} from '@/types/douyu-fulfillment'
|
} from '@/types/douyu-fulfillment'
|
||||||
import { formatAdminDateTime } from '@/utils/admin-time'
|
import { formatAdminDateTime } from '@/utils/admin-time'
|
||||||
|
import { DOUYU_ROLE_NAME_FORMAT_HINT, getDouyuRoleNameIssue } from '@/utils/douyu-role-name'
|
||||||
import { useRealtimeEvents } from '@/hooks/useRealtimeEvents'
|
import { useRealtimeEvents } from '@/hooks/useRealtimeEvents'
|
||||||
|
|
||||||
const BINDING_FAILURE_ISSUES = new Set([
|
const BINDING_FAILURE_ISSUES = new Set([
|
||||||
@@ -80,6 +81,7 @@ export default function DouyuFulfillmentPage() {
|
|||||||
const [nowMs, setNowMs] = useState(() => Date.now())
|
const [nowMs, setNowMs] = useState(() => Date.now())
|
||||||
const autoStartRef = useRef('')
|
const autoStartRef = useRef('')
|
||||||
const customerRoleRef = useRef('')
|
const customerRoleRef = useRef('')
|
||||||
|
const roleNameIssue = useMemo(() => getDouyuRoleNameIssue(roleName), [roleName])
|
||||||
|
|
||||||
const applyData = useCallback((next: DouyuCustomerFulfillment) => {
|
const applyData = useCallback((next: DouyuCustomerFulfillment) => {
|
||||||
const previousRole = customerRoleRef.current
|
const previousRole = customerRoleRef.current
|
||||||
@@ -257,6 +259,10 @@ export default function DouyuFulfillmentPage() {
|
|||||||
message.warning('请输入游戏角色名')
|
message.warning('请输入游戏角色名')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (roleNameIssue) {
|
||||||
|
message.warning(roleNameIssue)
|
||||||
|
return
|
||||||
|
}
|
||||||
setSaving(true)
|
setSaving(true)
|
||||||
try {
|
try {
|
||||||
const response = await saveDouyuProfile(orderNo, {
|
const response = await saveDouyuProfile(orderNo, {
|
||||||
@@ -405,7 +411,17 @@ export default function DouyuFulfillmentPage() {
|
|||||||
onChange={(event) => setRoleName(event.target.value)}
|
onChange={(event) => setRoleName(event.target.value)}
|
||||||
placeholder="请输入和平精英角色名"
|
placeholder="请输入和平精英角色名"
|
||||||
maxLength={100}
|
maxLength={100}
|
||||||
|
status={roleNameIssue ? 'warning' : undefined}
|
||||||
|
aria-describedby="douyu-role-name-help"
|
||||||
/>
|
/>
|
||||||
|
<p
|
||||||
|
id="douyu-role-name-help"
|
||||||
|
className={`customer-douyu-role-name-help${roleNameIssue ? ' is-warning' : ''}`}
|
||||||
|
aria-live="polite"
|
||||||
|
>
|
||||||
|
{roleNameIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
|
||||||
|
<span>{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}</span>
|
||||||
|
</p>
|
||||||
<Button
|
<Button
|
||||||
block
|
block
|
||||||
size="large"
|
size="large"
|
||||||
|
|||||||
@@ -555,6 +555,25 @@
|
|||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.customer-auth-page.is-douyu .customer-douyu-role-name-help {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 6px;
|
||||||
|
margin: -4px 2px 0;
|
||||||
|
color: #94a3b8;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.55;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-auth-page.is-douyu .customer-douyu-role-name-help .anticon {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
margin-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-auth-page.is-douyu .customer-douyu-role-name-help.is-warning {
|
||||||
|
color: #fbbf24;
|
||||||
|
}
|
||||||
|
|
||||||
.customer-auth-page.is-douyu .customer-collect-submit.ant-btn:hover,
|
.customer-auth-page.is-douyu .customer-collect-submit.ant-btn:hover,
|
||||||
.customer-auth-page.is-douyu .customer-collect-submit.ant-btn:focus-visible {
|
.customer-auth-page.is-douyu .customer-collect-submit.ant-btn:focus-visible {
|
||||||
color: #fff !important;
|
color: #fff !important;
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
export const DOUYU_ROLE_NAME_FORMAT_HINT =
|
||||||
|
'只填写游戏角色名,不要填写 UID、区服或微信/QQ;登录方式和设备系统请在上方选择。'
|
||||||
|
|
||||||
|
export const DOUYU_ROLE_NAME_MIXED_WARNING =
|
||||||
|
'这里只能填写游戏角色名。检测到 UID、区服或登录方式,请只保留角色名称,例如“花乔妖精”。'
|
||||||
|
|
||||||
|
const ROLE_NAME_SEPARATOR = /[\s,,、|/\\·::;;_-]+/u
|
||||||
|
const STANDALONE_UID = /^\d{6,}$/u
|
||||||
|
const LONG_NUMBER = /\d{8,}/u
|
||||||
|
const STANDALONE_LOGIN_OR_SYSTEM = /^(?:安卓区?|苹果区?|ios|android|微信|qq|q区|v区|手q)$/iu
|
||||||
|
|
||||||
|
export function getDouyuRoleNameIssue(value: string): string | null {
|
||||||
|
const roleName = String(value ?? '').trim()
|
||||||
|
if (!roleName) return null
|
||||||
|
|
||||||
|
const tokens = roleName.split(ROLE_NAME_SEPARATOR).filter(Boolean)
|
||||||
|
const hasStandaloneUid = tokens.some((token) => STANDALONE_UID.test(token))
|
||||||
|
const hasLongNumber = LONG_NUMBER.test(roleName)
|
||||||
|
const hasStandaloneLoginOrSystem = tokens.some((token) => STANDALONE_LOGIN_OR_SYSTEM.test(token))
|
||||||
|
|
||||||
|
return hasStandaloneUid || hasLongNumber || hasStandaloneLoginOrSystem
|
||||||
|
? DOUYU_ROLE_NAME_MIXED_WARNING
|
||||||
|
: null
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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'
|
||||||
|
|
||||||
|
import {
|
||||||
|
DOUYU_ROLE_NAME_MIXED_WARNING,
|
||||||
|
getDouyuRoleNameIssue,
|
||||||
|
} from '../src/utils/douyu-role-name.ts'
|
||||||
|
|
||||||
|
const root = dirname(fileURLToPath(import.meta.url))
|
||||||
|
const page = readFileSync(
|
||||||
|
join(root, '../src/pages/douyu-fulfillment/DouyuFulfillmentPage.tsx'),
|
||||||
|
'utf8',
|
||||||
|
)
|
||||||
|
|
||||||
|
test('斗鱼客户只填写角色名时通过校验', () => {
|
||||||
|
assert.equal(getDouyuRoleNameIssue('花乔妖精'), null)
|
||||||
|
assert.equal(getDouyuRoleNameIssue('狙神123'), null)
|
||||||
|
assert.equal(getDouyuRoleNameIssue('QQ战神'), null)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('识别角色名中混入的 UID、区服和登录方式', () => {
|
||||||
|
assert.equal(
|
||||||
|
getDouyuRoleNameIssue('花乔妖精 3379480446 安卓区 微信'),
|
||||||
|
DOUYU_ROLE_NAME_MIXED_WARNING,
|
||||||
|
)
|
||||||
|
assert.equal(getDouyuRoleNameIssue('花乔妖精 3379480446'), DOUYU_ROLE_NAME_MIXED_WARNING)
|
||||||
|
assert.equal(getDouyuRoleNameIssue('花乔妖精3379480446'), DOUYU_ROLE_NAME_MIXED_WARNING)
|
||||||
|
assert.equal(getDouyuRoleNameIssue('安卓区'), DOUYU_ROLE_NAME_MIXED_WARNING)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('客户填写时实时提示,并在提交前阻止混合资料', () => {
|
||||||
|
assert.ok(page.includes('const roleNameIssue = useMemo(() => getDouyuRoleNameIssue(roleName)'))
|
||||||
|
assert.ok(page.includes("status={roleNameIssue ? 'warning' : undefined}"))
|
||||||
|
assert.ok(page.includes('{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}'))
|
||||||
|
assert.ok(page.includes('if (roleNameIssue) {'))
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user