调整(虎牙客户资料): 增加游戏主页截图、UID 纯数字与角色名混入校验

- 迁移 191:semi_auto_tasks 增加客户游戏主页截图 5 个正式字段
  (object_key / url / thumbnail_url / filename / uploaded_at)。
- 新增 POST /customer-fulfillment/:orderNo/tasks/:taskId/homepage-screenshot
  (writeLimit + 单文件上传),场景 semi-auto-homepage-screenshot、
  归属 semi-auto-task-{taskId},与斗鱼同一套 file_assets 校验口径。
- 保存资料改为四要素必填:区服 / 游戏角色 UID / 角色名 / 游戏主页截图;
  截图须在同一事务内校验归属与类型,缺失或越权直接 400。
- 游戏角色 UID 改为 1..20 位纯数字校验(semi_auto_profile_role_id_invalid);
  角色名新增「不得混入 UID/区服/登录方式」校验,规则与斗鱼一致并在后端再实现一份。
- 客户页:UID 提示改为「请输入游戏角色 UID,纯数字uid」、只接受数字输入并实时提示;
  角色名加斗鱼同款提示与混入警告;新增「游戏主页截图(必填)」上传区 + 示例图 + 说明文案;
  已保存截图按 DTO 的 objectKey 回填预览,不再从文件链接反解。
- 角色名规则收敛到共享 game-role-name(删除 douyu-role-name 转发层,斗鱼页面与文案不变)。
- 「资料已完成」判断仍只看已保存三要素:截图在保存时强制,
  避免本次改造前已填好资料的历史任务被卡回第一步。
- 权威文档同步虎牙资料四要素、UID 纯数字、角色名混入校验与截图用途,并补迁移 191 记录。
This commit is contained in:
yml
2026-12-01 00:52:15 +08:00
parent 4e5001b608
commit 366df12c9d
23 changed files with 993 additions and 61 deletions
@@ -11,6 +11,7 @@ import QRCode from 'qrcode'
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
import { useLocation, useNavigate, useParams } from 'react-router'
import ImageUpload from '@/components/files/ImageUpload'
import {
confirmCustomerBinding,
fetchCustomerFulfillment,
@@ -28,6 +29,7 @@ import {
startCustomerLogin,
startCustomerWeiboQrLogin,
submitCustomerRebind,
uploadCustomerTaskHomepageScreenshot,
verifyCustomerHuyaSmsChallenge,
type CustomerHuyaChallengeSolution,
type CustomerHuyaSmsChallenge,
@@ -37,12 +39,20 @@ import type {
CustomerLoginInfo,
CustomerSemiAutoTask,
} from '@/types/customer-fulfillment'
import type { UploadedFile } from '@/types/worker-platform'
import { formatAdminDateTime } from '@/utils/admin-time'
import {
CUSTOMER_SERVER_ZONE_OPTIONS,
GAME_ROLE_ID_PLACEHOLDER,
getGameRoleIdIssue,
validateCustomerProfileSubmit,
} from '@/utils/customer-fulfillment-profile'
import {
buildCustomerFulfillmentPath,
resolveCustomerPlatformRedirect,
type CustomerFulfillmentPlatform,
} from '@/utils/customer-fulfillment-link'
import { GAME_ROLE_NAME_FORMAT_HINT, getGameRoleNameIssue } from '@/utils/game-role-name'
import { formatHuyaBindingDecisionMessage } from '@/utils/semi-auto-binding-decision'
import { runWeiboYidunChallenge } from '@/utils/weibo-yidun'
import HuyaChallengeModal from './HuyaChallengeModal'
@@ -51,7 +61,7 @@ const POLL_INTERVAL_MS = 2000
// 刷新绑定二维码的冷却时间:避免连续点击频繁请求虎牙。
const BINDING_REFRESH_COOLDOWN_MS = 3_000
const SERVER_ZONE_OPTIONS = ['苹果Q区', '苹果V区', '安卓Q区', '安卓V区']
const SERVER_ZONE_OPTIONS = CUSTOMER_SERVER_ZONE_OPTIONS
/** antd v6 语义化 classNames:让区服下拉弹层用页面深色样式 */
const SERVER_ZONE_SELECT_CLASS_NAMES = { popup: { root: 'customer-collect-dropdown' } }
@@ -88,6 +98,7 @@ export default function CustomerFulfillmentPage({
const [profileRoleName, setProfileRoleName] = useState('')
const [profileRoleId, setProfileRoleId] = useState('')
const [profileServerZone, setProfileServerZone] = useState('')
const [profileHomepageScreenshot, setProfileHomepageScreenshot] = useState<UploadedFile[]>([])
const [profileSaving, setProfileSaving] = useState(false)
const [profileEditing, setProfileEditing] = useState(false)
const startingBindingRef = useRef(false)
@@ -115,13 +126,19 @@ export default function CustomerFulfillmentPage({
),
)
const isWeibo = selectedTask?.platform === 'weibo'
// 虎牙流程:填写资料(区服/UID/角色名)→ 登录 → 绑定角色。
// 资料齐全前不生成绑定二维码,避免客户在资料缺失时先绑错角色。
// 虎牙流程:填写资料 → 登录 → 绑定角色。
// 这里只判断**已保存**的三要素:截图是保存时的必填项(后端强校验),
// 但不能拿它当「资料已完成」的门禁,否则本次改造前已填好资料的老任务会被卡回第一步。
const profileComplete = Boolean(
String(selectedTask?.customerServerZone || '').trim() &&
String(selectedTask?.customerGameRoleId || '').trim() &&
String(selectedTask?.customerGameRoleName || '').trim(),
)
const profileRoleIdIssue = useMemo(() => getGameRoleIdIssue(profileRoleId), [profileRoleId])
const profileRoleNameIssue = useMemo(
() => getGameRoleNameIssue(profileRoleName),
[profileRoleName],
)
const load = useCallback(
async (silent = false) => {
@@ -242,12 +259,31 @@ export default function CustomerFulfillmentPage({
setProfileRoleName(selectedTask.customerGameRoleName || '')
setProfileRoleId(selectedTask.customerGameRoleId || '')
setProfileServerZone(selectedTask.customerServerZone || '')
setProfileHomepageScreenshot(
String(selectedTask.homepageScreenshotUrl || '').trim()
? [
{
objectKey: selectedTask.homepageScreenshotObjectKey || '',
url: selectedTask.homepageScreenshotUrl,
thumbnailUrl:
selectedTask.homepageScreenshotThumbnailUrl || selectedTask.homepageScreenshotUrl,
mediumUrl: selectedTask.homepageScreenshotUrl,
filename: selectedTask.homepageScreenshotFilename || '',
contentType: '',
size: 0,
},
]
: [],
)
setProfileEditing(false)
}, [
selectedTask?.id,
selectedTask?.customerGameRoleName,
selectedTask?.customerGameRoleId,
selectedTask?.customerServerZone,
selectedTask?.homepageScreenshotUrl,
selectedTask?.homepageScreenshotThumbnailUrl,
selectedTask?.homepageScreenshotFilename,
])
useEffect(() => {
@@ -896,12 +932,15 @@ export default function CustomerFulfillmentPage({
async function handleSaveProfile() {
if (!selectedTask) return
if (!profileServerZone.trim() || !profileRoleId.trim() || !profileRoleName.trim()) {
message.warning('请完整填写区服、游戏角色 UID 和角色名')
return
}
if (!SERVER_ZONE_OPTIONS.includes(profileServerZone.trim())) {
message.warning('请选择区服')
const homepageScreenshotObjectKey = String(profileHomepageScreenshot[0]?.objectKey || '').trim()
const issue = validateCustomerProfileSubmit({
serverZone: profileServerZone,
roleId: profileRoleId,
roleName: profileRoleName,
homepageScreenshotObjectKey,
})
if (issue) {
message.warning(issue.message)
return
}
setProfileSaving(true)
@@ -910,6 +949,7 @@ export default function CustomerFulfillmentPage({
roleName: profileRoleName.trim(),
roleId: profileRoleId.trim(),
serverZone: profileServerZone.trim(),
homepageScreenshotObjectKey,
})
setTasks((current) =>
current.map((task) => (task.id === response.data.task.id ? response.data.task : task)),
@@ -1174,7 +1214,7 @@ export default function CustomerFulfillmentPage({
<p>
{profileComplete
? '修改资料后会重新核对平台角色;角色名、区服和平台信息一致后才能确认绑定。'
: '第一步:请填写区服、游戏角色 UID 和角色名。UID 只做资料留档,不参与绑定核验。'}
: '第一步:请填写区服、游戏角色 UID、角色名和游戏主页截图。UID 只做资料留档,不参与绑定核验。'}
</p>
<div className="customer-profile-form">
<label className="customer-collect-label">
@@ -1192,23 +1232,79 @@ export default function CustomerFulfillmentPage({
游戏角色 UID <span>*</span>
</label>
<Input
className="customer-collect-input"
className={`customer-collect-input${profileRoleIdIssue ? ' is-warning' : ''}`}
value={profileRoleId}
onChange={(event) => setProfileRoleId(event.target.value)}
placeholder="请输入游戏角色 UID,仅作资料留档"
maxLength={64}
onChange={(event) => setProfileRoleId(event.target.value.replace(/\D/g, ''))}
placeholder={GAME_ROLE_ID_PLACEHOLDER}
maxLength={20}
inputMode="numeric"
aria-invalid={Boolean(profileRoleIdIssue)}
aria-describedby="customer-profile-role-id-help"
/>
<p
id="customer-profile-role-id-help"
className={`customer-field-help${profileRoleIdIssue ? ' is-error' : ''}`}
aria-live="polite"
>
{profileRoleIdIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
<span>{profileRoleIdIssue || '只能填写数字,例如 4212063544'}</span>
</p>
<label className="customer-collect-label">
角色名 <span>*</span>
</label>
<Input
className="customer-collect-input"
className={`customer-collect-input${profileRoleNameIssue ? ' is-warning' : ''}`}
value={profileRoleName}
onChange={(event) => setProfileRoleName(event.target.value)}
placeholder="请输入角色名"
maxLength={100}
aria-invalid={Boolean(profileRoleNameIssue)}
aria-describedby="customer-profile-role-name-help"
/>
<p
id="customer-profile-role-name-help"
className={`customer-field-help${profileRoleNameIssue ? ' is-warning' : ''}`}
aria-live="polite"
>
{profileRoleNameIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
<span>{profileRoleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}</span>
</p>
<label className="customer-collect-label">
游戏主页截图 <span>*</span>
</label>
<div className="customer-douyu-screenshot-row">
<div className="customer-douyu-screenshot-upload">
<ImageUpload
scene="semi-auto-homepage-screenshot"
scope="collect"
maxCount={1}
showPasteHint
value={profileHomepageScreenshot}
onChange={setProfileHomepageScreenshot}
uploader={async (file) => {
const response = await uploadCustomerTaskHomepageScreenshot(
orderNo,
selectedTask?.id || 0,
file,
)
return response.data.file
}}
/>
</div>
<div className="customer-douyu-screenshot-example">
<Image
src="/images/game-home-example.webp"
alt="游戏主页截图示例"
width={150}
height={140}
style={{ objectFit: 'cover', borderRadius: 8, border: '1px solid #334155' }}
/>
<span>示例:需能看到游戏名字和游戏 UID</span>
</div>
</div>
<p className="customer-field-help">
请上传游戏主页截图,需能看到游戏名字/昵称和游戏 UID(编号);用于客服核对绑定是否正确。
</p>
<Button
block
size="large"
@@ -26,7 +26,7 @@ import type {
DouyuCustomerSystem,
} from '@/types/douyu-fulfillment'
import { formatAdminDateTime } from '@/utils/admin-time'
import { DOUYU_ROLE_NAME_FORMAT_HINT, getDouyuRoleNameIssue } from '@/utils/douyu-role-name'
import { GAME_ROLE_NAME_FORMAT_HINT, getGameRoleNameIssue } from '@/utils/game-role-name'
import { useRealtimeEvents } from '@/hooks/useRealtimeEvents'
const BINDING_FAILURE_ISSUES = new Set([
@@ -85,7 +85,7 @@ export default function DouyuFulfillmentPage() {
const [bindingQrExpanded, setBindingQrExpanded] = useState(false)
const [nowMs, setNowMs] = useState(() => Date.now())
const customerRoleRef = useRef('')
const roleNameIssue = useMemo(() => getDouyuRoleNameIssue(roleName), [roleName])
const roleNameIssue = useMemo(() => getGameRoleNameIssue(roleName), [roleName])
const applyData = useCallback((next: DouyuCustomerFulfillment) => {
const previousRole = customerRoleRef.current
@@ -426,7 +426,7 @@ export default function DouyuFulfillmentPage() {
aria-live="polite"
>
{roleNameIssue ? <ExclamationCircleOutlined aria-hidden="true" /> : null}
<span>{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}</span>
<span>{roleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}</span>
</p>
<label className="customer-collect-label">游戏主页截图(必填)</label>
<div className="customer-douyu-screenshot-row">
@@ -1,4 +1,6 @@
import { apiGet, apiPost } from '@/lib/http'
import { apiGet, apiPost, apiPostForm } from '@/lib/http'
import { optimizeImageForUpload } from '@/utils/image-upload'
import type { UploadedFile } from '@/types/worker-platform'
import type {
CustomerBindingInfo,
CustomerLoginInfo,
@@ -21,7 +23,12 @@ export function markCustomerFulfillmentOpened(orderNo: string, taskId: number) {
export function saveCustomerTaskProfile(
orderNo: string,
taskId: number,
input: { roleName: string; roleId: string; serverZone: string },
input: {
roleName: string
roleId: string
serverZone: string
homepageScreenshotObjectKey: string
},
) {
return apiPost<{ task: CustomerSemiAutoTask }>(
`/api/v1/customer-fulfillment/${encodeURIComponent(orderNo)}/tasks/${taskId}/profile`,
@@ -29,6 +36,21 @@ export function saveCustomerTaskProfile(
)
}
/** 客户游戏主页截图:与斗鱼一致,先压缩再上传,服务端按任务归属校验。 */
export async function uploadCustomerTaskHomepageScreenshot(
orderNo: string,
taskId: number,
file: File,
) {
const optimized = await optimizeImageForUpload(file, 'semi-auto-homepage-screenshot')
const form = new FormData()
form.append('file', optimized)
return apiPostForm<{ file: UploadedFile }>(
`/api/v1/customer-fulfillment/${encodeURIComponent(orderNo)}/tasks/${taskId}/homepage-screenshot`,
form,
)
}
export function startCustomerLogin(orderNo: string, taskId: number) {
return apiPost<{ task: CustomerSemiAutoTask; login: CustomerLoginInfo }>(
`/api/v1/customer-fulfillment/${encodeURIComponent(orderNo)}/tasks/${taskId}/login/start`,
@@ -232,3 +232,28 @@
border-color: #1d4ed8 !important;
color: #fff !important;
}
/* 客户资料字段提示:虎牙资料表单与斗鱼共用同一套提示位置和配色。 */
.customer-field-help {
display: flex;
align-items: flex-start;
gap: 6px;
margin: -4px 2px 0;
color: #94a3b8;
font-size: 12px;
line-height: 1.55;
}
.customer-field-help .anticon {
flex: 0 0 auto;
margin-top: 2px;
}
/* 格式不合法(例如 UID 非纯数字)用红字,混入资料用警示色。 */
.customer-field-help.is-error {
color: #f87171;
}
.customer-field-help.is-warning {
color: #fbbf24;
}
@@ -58,6 +58,13 @@ export type CustomerSemiAutoTask = {
customerGameRoleId: string
customerGameRoleName: string
customerServerZone: string
/** 客户上传的游戏主页截图(客服核对绑定使用);未上传时为空串。 */
/** 已上传截图的存储 key;改资料时原样回传,后端不再解析 URL。 */
homepageScreenshotObjectKey: string
homepageScreenshotUrl: string
homepageScreenshotThumbnailUrl: string
homepageScreenshotFilename: string
homepageScreenshotUploadedAt: string | null
completedAt: string | null
completionNote: string
semiAutoConfig: {
@@ -0,0 +1,59 @@
import { getGameRoleNameIssue, isValidGameRoleId } from './game-role-name.ts'
/** 虎牙客户资料区服枚举,与后端 `normalizeCustomerProfile` 的集合一致。 */
export const CUSTOMER_SERVER_ZONE_OPTIONS = ['苹果Q区', '苹果V区', '安卓Q区', '安卓V区'] as const
/** 游戏角色 UID 输入框提示,与后端 `semi_auto_profile_role_id_invalid` 口径一致。 */
export const GAME_ROLE_ID_PLACEHOLDER = '请输入游戏角色 UID,纯数字uid'
export const GAME_ROLE_ID_INVALID_HINT = '游戏角色 UID 只能填写纯数字(1-20 位)'
/** 输入过程中的实时提示:为空不提示(提交时再统一拦截)。 */
export function getGameRoleIdIssue(value: string): string | null {
const roleId = String(value ?? '').trim()
if (!roleId) return null
return isValidGameRoleId(roleId) ? null : GAME_ROLE_ID_INVALID_HINT
}
export type CustomerProfileSubmitField = 'serverZone' | 'roleId' | 'roleName' | 'homepageScreenshot'
export type CustomerProfileSubmitIssue = {
field: CustomerProfileSubmitField
message: string
}
/**
* 客户提交虎牙资料前的纯函数校验,顺序与后端 `normalizeCustomerProfile` / `savePublicTaskProfile` 一致:
* 必填 → 区服枚举 → UID 纯数字 → 角色名不混入 UID/区服/登录方式 → 主页截图必填。
*/
export function validateCustomerProfileSubmit(input: {
serverZone: string
roleId: string
roleName: string
homepageScreenshotObjectKey: string
}): CustomerProfileSubmitIssue | null {
const serverZone = String(input.serverZone ?? '').trim()
const roleId = String(input.roleId ?? '').trim()
const roleName = String(input.roleName ?? '').trim()
const homepageScreenshotObjectKey = String(input.homepageScreenshotObjectKey ?? '').trim()
if (!serverZone || !roleId || !roleName) {
return {
field: !serverZone ? 'serverZone' : !roleId ? 'roleId' : 'roleName',
message: '请完整填写区服、游戏角色 UID 和角色名',
}
}
if (!(CUSTOMER_SERVER_ZONE_OPTIONS as readonly string[]).includes(serverZone)) {
return { field: 'serverZone', message: '请选择区服' }
}
if (!isValidGameRoleId(roleId)) {
return { field: 'roleId', message: GAME_ROLE_ID_INVALID_HINT }
}
const roleNameIssue = getGameRoleNameIssue(roleName)
if (roleNameIssue) {
return { field: 'roleName', message: roleNameIssue }
}
if (!homepageScreenshotObjectKey) {
return { field: 'homepageScreenshot', message: '请上传游戏主页截图' }
}
return null
}
@@ -1,7 +1,7 @@
export const DOUYU_ROLE_NAME_FORMAT_HINT =
export const GAME_ROLE_NAME_FORMAT_HINT =
'只填写游戏角色名,不要填写 UID、区服或微信/QQ;登录方式和设备系统请在上方选择。'
export const DOUYU_ROLE_NAME_MIXED_WARNING =
export const GAME_ROLE_NAME_MIXED_WARNING =
'这里只能填写游戏角色名。检测到 UID、区服或登录方式,请只保留角色名称,例如“花乔妖精”。'
const ROLE_NAME_SEPARATOR = /[\s,,、|/\\·::;;_-]+/u
@@ -9,7 +9,11 @@ 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 {
/** 游戏角色 UID 只接受 1..20 位纯数字,与后端校验保持一致。 */
export const GAME_ROLE_ID_MAX_LENGTH = 20
const GAME_ROLE_ID_PATTERN = /^\d+$/u
export function getGameRoleNameIssue(value: string): string | null {
const roleName = String(value ?? '').trim()
if (!roleName) return null
@@ -19,6 +23,20 @@ export function getDouyuRoleNameIssue(value: string): string | null {
const hasStandaloneLoginOrSystem = tokens.some((token) => STANDALONE_LOGIN_OR_SYSTEM.test(token))
return hasStandaloneUid || hasLongNumber || hasStandaloneLoginOrSystem
? DOUYU_ROLE_NAME_MIXED_WARNING
? GAME_ROLE_NAME_MIXED_WARNING
: null
}
export function isValidGameRoleId(value: string) {
const roleId = String(value ?? '').trim()
return (
roleId.length > 0 &&
roleId.length <= GAME_ROLE_ID_MAX_LENGTH &&
GAME_ROLE_ID_PATTERN.test(roleId)
)
}
/** 输入框只保留数字,避免把字母/空格带进 UID。 */
export function sanitizeGameRoleIdInput(value: string) {
return String(value ?? '').replace(/\D/g, '')
}
@@ -53,18 +53,22 @@ test('虎牙客户页固定先填写资料,再登录并绑定角色', () => {
assert.ok(source.includes('(isWeibo || profileComplete) &&'))
})
test('资料完整要求区服、角色名和 UID,但 UID 不做格式校验', () => {
test('资料完整只判断已保存的三要素,截图由提交校验强制', () => {
const profileStart = source.indexOf('const profileComplete = Boolean(')
const profileEnd = source.indexOf('\n\n const load =', profileStart)
const profileSource = source.slice(profileStart, profileEnd)
assert.ok(profileSource.includes('customerServerZone'))
assert.ok(profileSource.includes('customerGameRoleId'))
assert.ok(profileSource.includes('customerGameRoleName'))
assert.ok(source.includes('请完整填写区服、游戏角色 UID 和角色名'))
// 截图是保存时的必填项,但不能当「资料已完成」门禁,否则老任务会被卡回第一步。
assert.ok(!profileSource.includes('homepageScreenshotUrl'))
// 必填与格式校验统一收敛到纯函数,页面只负责展示提示。
assert.ok(source.includes('validateCustomerProfileSubmit({'))
assert.ok(source.includes('UID 只做资料留档,不参与绑定核验'))
assert.ok(source.includes('游戏角色 UID <span>*</span>'))
assert.ok(!source.includes('游戏角色 UID 只能是数字'))
assert.ok(!source.includes('!/^\\d+$/.test(profileRoleId.trim())'))
assert.ok(source.includes('游戏主页截图 <span>*</span>'))
assert.ok(source.includes("event.target.value.replace(/\\D/g, '')"))
assert.ok(source.includes('maxLength={20}'))
})
test('登录和绑定专用同步阶段暂停整单轮询', () => {
@@ -0,0 +1,92 @@
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 {
GAME_ROLE_ID_INVALID_HINT,
GAME_ROLE_ID_PLACEHOLDER,
getGameRoleIdIssue,
validateCustomerProfileSubmit,
} from '../src/utils/customer-fulfillment-profile.ts'
import { GAME_ROLE_NAME_MIXED_WARNING } from '../src/utils/game-role-name.ts'
const root = dirname(fileURLToPath(import.meta.url))
const page = readFileSync(
join(root, '../src/pages/customer-fulfillment/CustomerFulfillmentPage.tsx'),
'utf8',
)
const validProfile = {
serverZone: '安卓Q区',
roleId: '4212063544',
roleName: '花乔妖精',
homepageScreenshotObjectKey: 'semi-auto-homepage-screenshot/2026/11/a.png',
}
test('资料完整时允许提交', () => {
assert.equal(validateCustomerProfileSubmit(validProfile), null)
})
test('必填项缺失时提示完整填写', () => {
assert.equal(
validateCustomerProfileSubmit({ ...validProfile, serverZone: '' })?.message,
'请完整填写区服、游戏角色 UID 和角色名',
)
assert.equal(validateCustomerProfileSubmit({ ...validProfile, roleId: '' })?.field, 'roleId')
assert.equal(
validateCustomerProfileSubmit({ ...validProfile, roleName: ' ' })?.field,
'roleName',
)
})
test('游戏角色 UID 必须是纯数字,且不超过 20 位', () => {
assert.deepEqual(validateCustomerProfileSubmit({ ...validProfile, roleId: 'uid-not-number' }), {
field: 'roleId',
message: GAME_ROLE_ID_INVALID_HINT,
})
assert.deepEqual(
validateCustomerProfileSubmit({
...validProfile,
roleId: '123456789012345678901',
}),
{ field: 'roleId', message: GAME_ROLE_ID_INVALID_HINT },
)
assert.equal(getGameRoleIdIssue('4212063544'), null)
assert.equal(getGameRoleIdIssue('4212063544a'), GAME_ROLE_ID_INVALID_HINT)
assert.equal(getGameRoleIdIssue(''), null)
})
test('角色名混入 UID、区服或登录方式时阻止提交', () => {
assert.deepEqual(
validateCustomerProfileSubmit({ ...validProfile, roleName: '花乔妖精 4212063544' }),
{ field: 'roleName', message: GAME_ROLE_NAME_MIXED_WARNING },
)
assert.deepEqual(
validateCustomerProfileSubmit({ ...validProfile, roleName: '花乔妖精 安卓区' }),
{ field: 'roleName', message: GAME_ROLE_NAME_MIXED_WARNING },
)
})
test('未上传游戏主页截图时阻止提交', () => {
assert.deepEqual(
validateCustomerProfileSubmit({ ...validProfile, homepageScreenshotObjectKey: '' }),
{ field: 'homepageScreenshot', message: '请上传游戏主页截图' },
)
})
test('虎牙资料表单按斗鱼同款接入 UID 与主页截图', () => {
assert.equal(GAME_ROLE_ID_PLACEHOLDER, '请输入游戏角色 UID,纯数字uid')
assert.ok(page.includes('placeholder={GAME_ROLE_ID_PLACEHOLDER}'))
assert.ok(page.includes("event.target.value.replace(/\\D/g, '')"))
assert.ok(page.includes('maxLength={20}'))
assert.ok(page.includes('{profileRoleIdIssue || '))
assert.ok(page.includes('{profileRoleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}'))
assert.ok(page.includes('scene="semi-auto-homepage-screenshot"'))
assert.ok(page.includes('src="/images/game-home-example.webp"'))
assert.ok(page.includes('示例:需能看到游戏名字和游戏 UID'))
assert.ok(page.includes('用于客服核对绑定是否正确'))
assert.ok(page.includes('uploadCustomerTaskHomepageScreenshot'))
assert.ok(page.includes('const issue = validateCustomerProfileSubmit({'))
})
@@ -39,7 +39,7 @@ test('取消直接使用原角色的快捷确认路径', () => {
test('点击上一步修改资料会回到第一步并隐藏绑定区', () => {
// 步骤条把编辑资料视为第一步,即使资料原本已完整。
assert.ok(source.includes('profileEditing || !profileComplete'))
assert.ok(source.includes("'第一步:请填写区服、游戏角色 UID 和角色名"))
assert.ok(source.includes("'第一步:请填写区服、游戏角色 UID、角色名和游戏主页截图"))
assert.ok(source.includes('返回绑定角色'))
// 资料步骤隐藏二维码、失败提示和比对操作,避免与第二步混在一起。
assert.ok(source.includes('!profileEditing'))
@@ -5,9 +5,10 @@ import { fileURLToPath } from 'node:url'
import test from 'node:test'
import {
DOUYU_ROLE_NAME_MIXED_WARNING,
getDouyuRoleNameIssue,
} from '../src/utils/douyu-role-name.ts'
GAME_ROLE_NAME_FORMAT_HINT,
GAME_ROLE_NAME_MIXED_WARNING,
getGameRoleNameIssue,
} from '../src/utils/game-role-name.ts'
const root = dirname(fileURLToPath(import.meta.url))
const page = readFileSync(
@@ -16,28 +17,28 @@ const page = readFileSync(
)
test('斗鱼客户只填写角色名时通过校验', () => {
assert.equal(getDouyuRoleNameIssue('花乔妖精'), null)
assert.equal(getDouyuRoleNameIssue('狙神123'), null)
assert.equal(getDouyuRoleNameIssue('QQ战神'), null)
assert.equal(getGameRoleNameIssue('花乔妖精'), null)
assert.equal(getGameRoleNameIssue('狙神123'), null)
assert.equal(getGameRoleNameIssue('QQ战神'), null)
})
test('识别角色名中混入的 UID、区服和登录方式', () => {
assert.equal(
getDouyuRoleNameIssue('花乔妖精 3379480446 安卓区 微信'),
DOUYU_ROLE_NAME_MIXED_WARNING,
getGameRoleNameIssue('花乔妖精 3379480446 安卓区 微信'),
GAME_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)
assert.equal(getGameRoleNameIssue('花乔妖精 3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
assert.equal(getGameRoleNameIssue('花乔妖精3379480446'), GAME_ROLE_NAME_MIXED_WARNING)
assert.equal(getGameRoleNameIssue('安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
})
test('客户填写时实时提示,并在提交前阻止混合资料', () => {
assert.ok(page.includes('const roleNameIssue = useMemo(() => getDouyuRoleNameIssue(roleName)'))
assert.ok(page.includes('const roleNameIssue = useMemo(() => getGameRoleNameIssue(roleName)'))
assert.ok(
page.includes("className={`customer-collect-input${roleNameIssue ? ' is-warning' : ''}`}"),
)
assert.ok(page.includes('aria-invalid={Boolean(roleNameIssue)}'))
assert.ok(!page.includes("status={roleNameIssue ? 'warning' : undefined}"))
assert.ok(page.includes('{roleNameIssue || DOUYU_ROLE_NAME_FORMAT_HINT}'))
assert.ok(page.includes('{roleNameIssue || GAME_ROLE_NAME_FORMAT_HINT}'))
assert.ok(page.includes('if (roleNameIssue) {'))
})
@@ -0,0 +1,56 @@
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 {
GAME_ROLE_NAME_FORMAT_HINT,
GAME_ROLE_NAME_MIXED_WARNING,
getGameRoleNameIssue,
isValidGameRoleId,
sanitizeGameRoleIdInput,
} from '../src/utils/game-role-name.ts'
const root = dirname(fileURLToPath(import.meta.url))
test('斗鱼客户页与虎牙共用同一份角色名规则', () => {
const douyuPage = readFileSync(
join(root, '../src/pages/douyu-fulfillment/DouyuFulfillmentPage.tsx'),
'utf8',
)
assert.ok(douyuPage.includes("from '@/utils/game-role-name'"))
assert.ok(douyuPage.includes('getGameRoleNameIssue'))
assert.ok(douyuPage.includes('GAME_ROLE_NAME_FORMAT_HINT'))
})
test('虎牙角色名只填写名称时通过', () => {
assert.equal(getGameRoleNameIssue('花乔妖精'), null)
assert.equal(getGameRoleNameIssue('狙神123'), null)
assert.equal(getGameRoleNameIssue('QQ战神'), null)
assert.equal(getGameRoleNameIssue(''), null)
})
test('虎牙角色名混入 UID、区服或登录方式时提示', () => {
assert.equal(getGameRoleNameIssue('花乔妖精 4212063544'), GAME_ROLE_NAME_MIXED_WARNING)
assert.equal(getGameRoleNameIssue('花乔妖精4212063544'), GAME_ROLE_NAME_MIXED_WARNING)
assert.equal(getGameRoleNameIssue('花乔妖精 安卓区'), GAME_ROLE_NAME_MIXED_WARNING)
assert.equal(getGameRoleNameIssue('花乔妖精 微信'), GAME_ROLE_NAME_MIXED_WARNING)
assert.equal(getGameRoleNameIssue('花乔妖精 QQ'), GAME_ROLE_NAME_MIXED_WARNING)
})
test('游戏角色 UID 只接受 1..20 位纯数字', () => {
assert.equal(isValidGameRoleId('4212063544'), true)
assert.equal(isValidGameRoleId(' 4212063544 '), true)
assert.equal(isValidGameRoleId('12345678901234567890'), true)
assert.equal(isValidGameRoleId('123456789012345678901'), false)
assert.equal(isValidGameRoleId('UID-not-number'), false)
assert.equal(isValidGameRoleId('4212063544a'), false)
assert.equal(isValidGameRoleId(''), false)
})
test('UID 输入框只保留数字', () => {
assert.equal(sanitizeGameRoleIdInput(' 421 206 3544 '), '4212063544')
assert.equal(sanitizeGameRoleIdInput('uid-4212063544'), '4212063544')
assert.equal(sanitizeGameRoleIdInput(''), '')
})
+3
View File
@@ -16,6 +16,9 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
// 前端单测用 `node --experimental-strip-types` 直接跑源码,Node ESM 要求相对导入带显式后缀。
// 目前只有 src/utils/customer-fulfillment-profile.ts 一处运行时导入,Vite 构建不受影响。
"allowImportingTsExtensions": true,
"jsx": "react-jsx",
"baseUrl": ".",
"paths": {