Files
order_site/apps/frontend/src/pages/admin/AdminDevMockPage.tsx
T

1074 lines
37 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
ApiOutlined,
BugOutlined,
CopyOutlined,
GiftOutlined,
LinkOutlined,
SearchOutlined,
ThunderboltOutlined,
WalletOutlined,
} from '@ant-design/icons'
import {
Alert,
App,
Button,
Card,
Col,
Divider,
Empty,
Form,
Input,
InputNumber,
Result,
Row,
Segmented,
Select,
Space,
Tabs,
Tag,
Typography,
} from 'antd'
import { useMutation, useQuery } from '@tanstack/react-query'
import { useMemo, useState } from 'react'
import { Link } from 'react-router'
import PageHeader from '@/components/admin/PageHeader'
import {
buildOpen91QueryDevMock,
createAffiliateDashDevMock,
createDouyuFulfillmentDevMock,
createKuaishouIndustryVoucherDevMock,
createSemiAutoDevMock,
createSemiAutoIntegrationDevMock,
fetchDevMockStatus,
type DevMockCreateResult,
type DevMockKuaishouIndustryVoucherResult,
type DevMockOpen91QueryResult,
type DevMockSemiAutoResult,
type DevDouyuFulfillmentMockResult,
type DevSemiAutoIntegrationResult,
} from '@/services/admin'
import { buildCustomerFulfillmentPath } from '@/utils/customer-fulfillment-link'
type MockTabKey = 'douyu' | 'semi-auto' | 'affiliate-dash' | 'kuaishou-voucher' | 'open91'
type SemiAutoMode = 'integration' | 'direct'
export default function AdminDevMockPage() {
const { message } = App.useApp()
const [activeTab, setActiveTab] = useState<MockTabKey>('douyu')
const [semiAutoMode, setSemiAutoMode] = useState<SemiAutoMode>('integration')
const [lastCreate, setLastCreate] = useState<DevMockCreateResult | null>(null)
const [lastVoucherCreate, setLastVoucherCreate] =
useState<DevMockKuaishouIndustryVoucherResult | null>(null)
const [lastQuery, setLastQuery] = useState<DevMockOpen91QueryResult | null>(null)
const [lastDouyuFulfillment, setLastDouyuFulfillment] =
useState<DevDouyuFulfillmentMockResult | null>(null)
const [lastSemiAuto, setLastSemiAuto] = useState<
DevMockSemiAutoResult | DevSemiAutoIntegrationResult | null
>(null)
const statusQuery = useQuery({
queryKey: ['admin-dev-mock-status'],
queryFn: () => fetchDevMockStatus(),
retry: false,
})
const status = statusQuery.data?.data
const enabled = Boolean(status?.enabled)
const affiliateDashMutation = useMutation({
mutationFn: createAffiliateDashDevMock,
onSuccess: (response) => {
setLastCreate(response.data)
message.success('affiliate-dash mock 已生成')
},
onError: (error) => {
message.error(error instanceof Error ? error.message : '生成失败')
},
})
const voucherMutation = useMutation({
mutationFn: createKuaishouIndustryVoucherDevMock,
onSuccess: (response) => {
setLastVoucherCreate(response.data)
message.success(`已生成 ${response.data.createdCount} 条电子凭证 Mock`)
},
onError: (error) => {
message.error(error instanceof Error ? error.message : '生成失败')
},
})
const open91Mutation = useMutation({
mutationFn: buildOpen91QueryDevMock,
onSuccess: (response) => {
setLastQuery(response.data)
message.success('91 查单请求已生成')
},
onError: (error) => {
message.error(error instanceof Error ? error.message : '生成失败')
},
})
const semiAutoMutation = useMutation({
mutationFn: createSemiAutoDevMock,
onSuccess: (response) => {
setLastSemiAuto(response.data)
message.success('半自动履约 Mock 已生成')
},
onError: (error) => {
message.error(error instanceof Error ? error.message : '生成失败')
},
})
const semiAutoIntegrationMutation = useMutation({
mutationFn: createSemiAutoIntegrationDevMock,
onSuccess: (response) => {
setLastSemiAuto(response.data)
message.success('半自动真实履约链路测试单已生成')
},
onError: (error) => {
message.error(error instanceof Error ? error.message : '生成失败')
},
})
const douyuFulfillmentMutation = useMutation({
mutationFn: createDouyuFulfillmentDevMock,
onSuccess: (response) => {
setLastDouyuFulfillment(response.data)
message.success('斗鱼直播账号履约测试单已生成')
},
onError: (error) => {
message.error(error instanceof Error ? error.message : '生成失败')
},
})
const defaultOrderNo = useMemo(() => lastCreate?.orderNo || '', [lastCreate?.orderNo])
const semiAutoCustomerPath = lastSemiAuto
? buildCustomerFulfillmentPath(lastSemiAuto.orderNo, lastSemiAuto.semiAutoPlatform) ||
lastSemiAuto.customerPath
: ''
const semiAutoCustomerUrl = semiAutoCustomerPath
? `${window.location.origin}${semiAutoCustomerPath}`
: ''
if (statusQuery.isLoading) {
return (
<section className="page-stack">
<PageHeader title="开发 Mock" description="加载中…" />
</section>
)
}
if (statusQuery.error || !enabled) {
return (
<section className="page-stack">
<PageHeader title="开发 Mock" description="仅开发环境可用。" />
<Result
status="403"
title="当前环境未开启开发 Mock"
subTitle={
statusQuery.error instanceof Error
? statusQuery.error.message
: '生产环境默认关闭。本地开发请使用 docker-compose.dev 或设置 ENABLE_DEV_MOCK=1。'
}
/>
</section>
)
}
return (
<section className="page-stack">
<PageHeader
title="开发 Mock"
description="按场景切换测试工具,只展示当前模块,减少长页面和误操作。"
extra={
<Space size={8}>
<Tag color="green">Mock 已开启</Tag>
<Typography.Text type="secondary">NODE_ENV={status?.nodeEnv || '-'}</Typography.Text>
</Space>
}
/>
<Alert
type="warning"
showIcon
icon={<BugOutlined />}
message="仅用于开发环境"
description="Mock 会向当前开发库写入真实订单和任务。请先确认当前环境,再切换对应业务模块生成测试数据。"
/>
<Tabs
className="dev-mock-tabs"
type="card"
activeKey={activeTab}
onChange={(key) => setActiveTab(key as MockTabKey)}
items={[
{
key: 'douyu',
label: (
<Space size={6}>
<ThunderboltOutlined />
斗鱼履约
</Space>
),
children: (
<Row gutter={[16, 16]}>
<Col xs={24} xl={14}>
<Card title="创建斗鱼履约测试单" extra={<Tag color="blue">正式订单链路</Tag>}>
<Alert
type="success"
showIcon
style={{ marginBottom: 16 }}
message="供 live-hub 直播账号履约工作台读取"
description="生成 manual + assigned 履约和内部 SKU 映射,不创建 huya/weibo 半自动任务。"
/>
<DouyuFulfillmentMockForm
loading={douyuFulfillmentMutation.isPending}
onSubmit={(values) => douyuFulfillmentMutation.mutate(values)}
/>
</Card>
</Col>
<Col xs={24} xl={10}>
<Space direction="vertical" size={16} style={{ width: '100%' }}>
{lastDouyuFulfillment ? (
<DouyuFulfillmentResultCard result={lastDouyuFulfillment} />
) : (
<MockResultEmpty description="生成后显示订单号、内部 SKU 和履约 ID" />
)}
<Card size="small" title="联调口径">
<ul style={{ margin: 0, paddingLeft: 18 }}>
<li>订单走正式 upsertOrderFromSource 入库。</li>
<li>工作台同步后使用返回的内部 SKU 配置斗鱼商品映射。</li>
<li>不生成半自动任务,客户绑定和人工兑换都在 live-hub 完成。</li>
</ul>
</Card>
</Space>
</Col>
</Row>
),
},
{
key: 'semi-auto',
label: (
<Space size={6}>
<ApiOutlined />
半自动履约
</Space>
),
children: (
<Space direction="vertical" size={16} style={{ width: '100%' }}>
<Segmented
block
value={semiAutoMode}
onChange={(value) => setSemiAutoMode(value as SemiAutoMode)}
options={[
{ label: '正式订单链路', value: 'integration' },
{ label: '直连 Mock', value: 'direct' },
]}
/>
<Row gutter={[16, 16]}>
<Col xs={24} xl={14}>
<Card
title={semiAutoMode === 'integration' ? '正式链路测试单' : '页面直连 Mock'}
extra={
<Tag color={semiAutoMode === 'integration' ? 'blue' : 'orange'}>
{semiAutoMode === 'integration' ? 'upsertOrderFromSource' : '直连造单'}
</Tag>
}
>
<Alert
type={semiAutoMode === 'integration' ? 'success' : 'warning'}
showIcon
style={{ marginBottom: 16 }}
message={
semiAutoMode === 'integration'
? '订单走正式订单、渠道和半自动任务链路'
: '仅适合半自动页面联调,不经过正式订单入口'
}
/>
<SemiAutoMockForm
loading={
semiAutoMode === 'integration'
? semiAutoIntegrationMutation.isPending
: semiAutoMutation.isPending
}
submitText={
semiAutoMode === 'integration' ? '生成真实链路测试单' : '生成直连 Mock'
}
integration={semiAutoMode === 'integration'}
defaultConnectorMode={status?.semiAuto?.defaultConnectorMode}
externalConnectorConfigured={status?.semiAuto?.externalConnectorConfigured}
mockConnectorAvailable={status?.semiAuto?.mockConnectorAvailable}
onSubmit={(values) => {
if (semiAutoMode === 'integration') {
semiAutoIntegrationMutation.mutate(values)
return
}
semiAutoMutation.mutate(values)
}}
/>
</Card>
</Col>
<Col xs={24} xl={10}>
<Space direction="vertical" size={16} style={{ width: '100%' }}>
{lastSemiAuto &&
(semiAutoMode === 'integration'
? 'pipeline' in lastSemiAuto
: !('pipeline' in lastSemiAuto)) ? (
<SemiAutoResultCard
result={lastSemiAuto}
customerUrl={semiAutoCustomerUrl}
/>
) : (
<MockResultEmpty description="当前模式生成后显示任务和客户履约入口" />
)}
<Card size="small" title="两种模式的区别">
<ul style={{ margin: 0, paddingLeft: 18 }}>
<li>正式订单链路会经过 SKU 映射、渠道判定和 Carrier 补偿。</li>
<li>直连 Mock 只用于半自动页面联调,验证页面和 Connector 状态。</li>
<li>微博固定使用内置 Connector,虎牙可按环境选择。</li>
</ul>
</Card>
</Space>
</Col>
</Row>
</Space>
),
},
{
key: 'affiliate-dash',
label: (
<Space size={6}>
<GiftOutlined />
affiliate-dash
</Space>
),
children: (
<Row gutter={[16, 16]}>
<Col xs={24} xl={14}>
<Card title="affiliate-dash 领取 Mock">
<Typography.Paragraph type="secondary">
生成领取订单、任务和二维码上下文,用于领取页的填写 UID、绑定、提交和完成流程。
</Typography.Paragraph>
<AffiliateDashMockForm
loading={affiliateDashMutation.isPending}
onSubmit={(values) => affiliateDashMutation.mutate(values)}
/>
</Card>
</Col>
<Col xs={24} xl={10}>
{lastCreate ? (
<AffiliateDashResultCard result={lastCreate} />
) : (
<MockResultEmpty description="生成后显示领取链接和操作提示" />
)}
</Col>
</Row>
),
},
{
key: 'kuaishou-voucher',
label: (
<Space size={6}>
<WalletOutlined />
快手凭证
</Space>
),
children: (
<Row gutter={[16, 16]}>
<Col xs={24} xl={14}>
<Card title="快手电子凭证测试数据">
<Typography.Paragraph type="secondary">
一次生成 6 条不同状态的测试券码,覆盖待使用、已核销、已销毁和回调异常。
</Typography.Paragraph>
<KuaishouIndustryVoucherMockForm
loading={voucherMutation.isPending}
onSubmit={(values) => voucherMutation.mutate(values)}
/>
</Card>
</Col>
<Col xs={24} xl={10}>
{lastVoucherCreate ? (
<KuaishouVoucherResultCard result={lastVoucherCreate} />
) : (
<MockResultEmpty description="生成后显示店铺和测试券码" />
)}
</Col>
</Row>
),
},
{
key: 'open91',
label: (
<Space size={6}>
<SearchOutlined />
91 查单
</Space>
),
children: (
<Row gutter={[16, 16]}>
<Col xs={24} xl={14}>
<Card title="模拟 91 查单">
<Form
layout="vertical"
initialValues={{ orderNo: defaultOrderNo, execute: '1' }}
key={defaultOrderNo}
onFinish={(values) =>
open91Mutation.mutate({
orderNo: values.orderNo,
execute: values.execute === '1',
})
}
>
<Row gutter={12}>
<Col xs={24} md={14}>
<Form.Item
label="orderNo"
name="orderNo"
rules={[{ required: true, message: '填写要查询的订单号' }]}
>
<Input placeholder="MOCK91…" />
</Form.Item>
</Col>
<Col xs={24} md={10}>
<Form.Item label="执行方式" name="execute">
<Select
options={[
{ value: '1', label: '生成并请求本机' },
{ value: '0', label: '仅生成请求体' },
]}
/>
</Form.Item>
</Col>
</Row>
<Typography.Paragraph type="secondary">
对应日志:POST /api/v1/open/91/orders/query。需配置 KAQUAN91_SECRET(32
位)。
</Typography.Paragraph>
<Button type="primary" htmlType="submit" loading={open91Mutation.isPending}>
模拟 91 查单
</Button>
</Form>
</Card>
</Col>
<Col xs={24} xl={10}>
{lastQuery ? (
<Open91ResultCard result={lastQuery} />
) : (
<MockResultEmpty description="生成后显示请求体、curl 和响应" />
)}
</Col>
</Row>
),
},
]}
/>
</section>
)
}
function MockResultEmpty({ description }: { description: string }) {
return (
<Card size="small" title="最近结果">
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={description} />
</Card>
)
}
function AffiliateDashResultCard({ result }: { result: DevMockCreateResult }) {
const { message } = App.useApp()
return (
<Card
size="small"
title="最近结果"
extra={
<Space>
<Link to={`/admin/orders/${result.orderId}`}>订单 #{result.orderId}</Link>
<Link to={`/admin/tasks/${result.taskId}`}>任务 #{result.taskId}</Link>
</Space>
}
>
<Space direction="vertical" size={12} style={{ width: '100%' }}>
<div>
<Typography.Text type="secondary">平台 / 步骤</Typography.Text>
<div>
<Typography.Text strong>
{result.platform} · {result.step}
</Typography.Text>
</div>
</div>
<div>
<Typography.Text type="secondary">订单号</Typography.Text>
<div>
<Typography.Text copyable>{result.orderNo}</Typography.Text>
</div>
</div>
<div>
<Typography.Text type="secondary">商品 / UID</Typography.Text>
<div>
{result.productName} · {result.expectedUid}
</div>
</div>
<div>
<Typography.Text type="secondary">领取链接</Typography.Text>
<Typography.Paragraph style={{ margin: '4px 0 0' }}>
<Typography.Link href={result.claimUrl} target="_blank" rel="noreferrer">
<LinkOutlined /> {result.claimUrl}
</Typography.Link>
</Typography.Paragraph>
</div>
<Space wrap>
<Button
icon={<CopyOutlined />}
onClick={async () => {
await navigator.clipboard.writeText(result.claimUrl)
message.success('已复制领取链接')
}}
>
复制链接
</Button>
<Button type="primary" href={result.claimUrl} target="_blank">
打开领取页
</Button>
</Space>
<Alert
type="success"
showIcon
message="操作提示"
description={
<ul style={{ margin: 0, paddingLeft: 18 }}>
{result.tips.map((tip) => (
<li key={tip}>{tip}</li>
))}
<li>{result.open91QueryHint}</li>
</ul>
}
/>
</Space>
</Card>
)
}
function DouyuFulfillmentResultCard({ result }: { result: DevDouyuFulfillmentMockResult }) {
const { message } = App.useApp()
const customerUrl = `${window.location.origin}${result.customerPath}`
return (
<Card size="small" title="最近结果" extra={<Link to={result.adminPath}>打开订单</Link>}>
<Row gutter={[12, 12]}>
<Col span={24}>
<Typography.Text type="secondary">订单号</Typography.Text>
<div>
<Typography.Text copyable strong>
{result.orderNo}
</Typography.Text>
</div>
</Col>
<Col span={24}>
<Typography.Text type="secondary">内部 SKU</Typography.Text>
<div>
<Typography.Text copyable>{result.skuKey}</Typography.Text>
</div>
</Col>
<Col span={12}>
<Typography.Text type="secondary">订单项</Typography.Text>
<div>#{result.orderItemId}</div>
</Col>
<Col span={12}>
<Typography.Text type="secondary">履约单</Typography.Text>
<div>#{result.fulfillmentId}</div>
</Col>
<Col span={24}>
<Typography.Text type="secondary">客户领取链接</Typography.Text>
<Typography.Paragraph style={{ margin: '4px 0 0' }}>
<Typography.Link href={customerUrl} target="_blank" rel="noreferrer">
<LinkOutlined /> {customerUrl}
</Typography.Link>
</Typography.Paragraph>
</Col>
<Col span={24}>
<Alert
type="success"
showIcon
message="下一步"
description={
<ul style={{ margin: 0, paddingLeft: 18 }}>
{result.tips.map((tip) => (
<li key={tip}>{tip}</li>
))}
</ul>
}
/>
</Col>
<Col span={24}>
<Space wrap>
<Button
icon={<CopyOutlined />}
onClick={async () => {
await navigator.clipboard.writeText(customerUrl)
message.success('斗鱼客户领取链接已复制')
}}
>
复制客户链接
</Button>
<Button type="primary" href={customerUrl} target="_blank">
打开客户领取页
</Button>
</Space>
</Col>
</Row>
</Card>
)
}
function SemiAutoResultCard({
result,
customerUrl,
}: {
result: DevMockSemiAutoResult | DevSemiAutoIntegrationResult
customerUrl: string
}) {
const { message } = App.useApp()
return (
<Card size="small" title="最近结果" extra={<Link to={result.adminPath}>打开后台任务</Link>}>
<Space direction="vertical" size={12} style={{ width: '100%' }}>
<div>
<Typography.Text type="secondary">订单号</Typography.Text>
<div>
<Typography.Text copyable strong>
{result.orderNo}
</Typography.Text>
</div>
</div>
<div>
<Typography.Text type="secondary">内部 SKU / 任务</Typography.Text>
<div>
{result.semiAutoPlatform === 'weibo' ? '微博' : '虎牙'} · {result.skuKey} · 任务 #
{result.taskId}
</div>
</div>
<div>
<Typography.Text type="secondary">客户履约入口</Typography.Text>
<Typography.Paragraph style={{ margin: '4px 0 0' }}>
<Typography.Link href={customerUrl} target="_blank" rel="noreferrer">
<LinkOutlined /> {customerUrl}
</Typography.Link>
</Typography.Paragraph>
</div>
<Space wrap>
<Button
icon={<CopyOutlined />}
onClick={async () => {
await navigator.clipboard.writeText(customerUrl)
message.success('已复制客户履约链接')
}}
>
复制客户链接
</Button>
<Button type="primary" href={customerUrl} target="_blank">
打开客户页
</Button>
</Space>
<Alert
type={
result.connectorMode === 'mock'
? 'warning'
: result.connectorConfigured
? 'success'
: 'error'
}
showIcon
message={
result.connectorMode === 'mock'
? '当前使用内置 Mock Connector'
: result.connectorConfigured
? result.connectorMode === 'external'
? '当前使用远程真实 Connector'
: '当前使用 order_site 内置真实 Connector'
: '当前选择远程真实 Connector,但尚未配置'
}
description={
<ul style={{ margin: 0, paddingLeft: 18 }}>
{result.tips.map((tip) => (
<li key={tip}>{tip}</li>
))}
</ul>
}
/>
</Space>
</Card>
)
}
function KuaishouVoucherResultCard({ result }: { result: DevMockKuaishouIndustryVoucherResult }) {
return (
<Card
size="small"
title="最近结果"
extra={<Link to="/admin/kuaishou-industry">查看电子凭证</Link>}
>
<Typography.Paragraph type="secondary">
已为店铺 {result.sellerId} 写入 {result.createdCount} 条测试券码。
</Typography.Paragraph>
<Space direction="vertical" size={6}>
{result.vouchers.map((voucher) => (
<Typography.Text key={voucher.voucherCode} copyable>
{voucher.status} · {voucher.voucherCode} · {voucher.oid}
</Typography.Text>
))}
</Space>
</Card>
)
}
function Open91ResultCard({ result }: { result: DevMockOpen91QueryResult }) {
return (
<Card size="small" title="查单结果">
<Space direction="vertical" size={12} style={{ width: '100%' }}>
<div>
<Typography.Text type="secondary">Endpoint</Typography.Text>
<div>
<Typography.Text code copyable>
{result.endpoint}
</Typography.Text>
</div>
</div>
<div>
<Typography.Text type="secondary">Request</Typography.Text>
<pre className="dev-mock-pre" style={{ marginTop: 6 }}>
{JSON.stringify(result.requestBody, null, 2)}
</pre>
</div>
<div>
<Typography.Text type="secondary">curl</Typography.Text>
<Typography.Paragraph style={{ margin: '4px 0 0' }}>
<Typography.Text code copyable>
{result.curl}
</Typography.Text>
</Typography.Paragraph>
</div>
{result.response ? (
<>
<Divider style={{ margin: 0 }} />
<div>
<Typography.Text type="secondary">Response</Typography.Text>
<pre className="dev-mock-pre" style={{ marginTop: 6 }}>
{JSON.stringify(result.response, null, 2)}
</pre>
</div>
</>
) : null}
</Space>
</Card>
)
}
function AffiliateDashMockForm({
loading,
onSubmit,
}: {
loading: boolean
onSubmit: (values: Record<string, unknown>) => void
}) {
const [form] = Form.useForm()
const step = Form.useWatch('step', form)
const uidRequired = step !== 'uid'
return (
<Form
form={form}
layout="vertical"
initialValues={{
step: 'bind',
uid: '166909256',
productName: '幸运币90个',
productSku: 'lucky_coin_x90',
}}
onFinish={onSubmit}
>
<Form.Item label="页面步骤" name="step">
<Select
options={[
{ value: 'uid', label: 'uid · 待填 UID(第一步)' },
{ value: 'bind', label: 'bind · 已填 UID + mock 绑定二维码(第二步,推荐)' },
{ value: 'submitted', label: 'submitted · 已绑定待提交发货(第三步)' },
{ value: 'completed', label: 'completed · 模拟发货成功(第四步)' },
{ value: 'failed', label: 'failed · 模拟发货失败' },
]}
/>
</Form.Item>
<Form.Item
label="游戏 UID"
name="uid"
required={uidRequired}
rules={
uidRequired
? [{ required: true, whitespace: true, message: '后续步骤请填写游戏 UID' }]
: []
}
extra={
step === 'uid'
? '「待填 UID」步骤可不填,打开领取页会停留在第一步让用户填写'
: '后续步骤用于模拟已提交的编号'
}
>
<Input allowClear placeholder="166909256" />
</Form.Item>
<Form.Item label="商品名" name="productName">
<Input />
</Form.Item>
<Form.Item label="affiliate-dash sku(可空)" name="productSku">
<Input placeholder="lucky_coin_x90" />
</Form.Item>
<Form.Item label="订单号 orderNo(可空)" name="orderNo">
<Input placeholder="留空自动 MOCKAD…" />
</Form.Item>
<Button type="primary" htmlType="submit" loading={loading} block>
生成 affiliate-dash Mock
</Button>
</Form>
)
}
function KuaishouIndustryVoucherMockForm({
loading,
onSubmit,
}: {
loading: boolean
onSubmit: (values: { sellerId?: string }) => void
}) {
return (
<Form layout="vertical" onFinish={onSubmit}>
<Form.Item
label="店铺 ID(可空)"
name="sellerId"
extra="留空时使用快手行业配置中的首个启用店铺;会生成 6 条不同状态的券码。"
>
<Input allowClear placeholder="留空自动选择测试店铺" />
</Form.Item>
<Button type="primary" htmlType="submit" loading={loading} block>
生成电子凭证 Mock
</Button>
</Form>
)
}
function DouyuFulfillmentMockForm({
loading,
onSubmit,
}: {
loading: boolean
onSubmit: (values: { orderNo?: string; skuName?: string }) => void
}) {
return (
<Form layout="vertical" onFinish={onSubmit}>
<Form.Item
label="内部 SKU 名称(可空)"
name="skuName"
extra="留空自动生成“斗鱼精英宝典联调-时间戳”;必须包含中文,live-hub 将用它配置斗鱼商品映射。"
>
<Input allowClear placeholder="斗鱼精英宝典联调" />
</Form.Item>
<Form.Item label="订单号 orderNo(可空)" name="orderNo" extra="留空自动生成 LIVEHUBDOUYU…">
<Input allowClear placeholder="LIVEHUBDOUYU…" />
</Form.Item>
<Button type="primary" htmlType="submit" loading={loading} block>
生成斗鱼履约测试单
</Button>
</Form>
)
}
function SemiAutoMockForm({
loading,
submitText,
integration = false,
defaultConnectorMode,
externalConnectorConfigured,
mockConnectorAvailable,
onSubmit,
}: {
loading: boolean
submitText?: string
integration?: boolean
defaultConnectorMode?: 'embedded' | 'external' | 'mock'
externalConnectorConfigured?: boolean
mockConnectorAvailable?: boolean
onSubmit: (values: {
platform: 'huya' | 'weibo'
orderNo?: string
skuName?: string
quantity?: number
pageTitle?: string
browserTargetUrl?: string
connectorMode?: 'embedded' | 'external' | 'mock'
}) => void
}) {
const [form] = Form.useForm()
const selectedPlatform =
(Form.useWatch('platform', form) as 'huya' | 'weibo' | undefined) || 'huya'
const defaultMode =
defaultConnectorMode === 'mock' && mockConnectorAvailable
? 'mock'
: defaultConnectorMode === 'external'
? 'external'
: 'embedded'
const selectedMode =
(Form.useWatch('connectorMode', form) as 'embedded' | 'external' | 'mock' | undefined) ||
defaultMode
return (
<Form
form={form}
layout="vertical"
initialValues={{
platform: 'huya',
quantity: 1,
pageTitle: '虎牙账号授权测试',
browserTargetUrl: 'https://www.huya.com/',
connectorMode: defaultMode,
}}
onFinish={onSubmit}
>
<Form.Item
label="履约平台"
name="platform"
extra="当前只负责客户登录和账号 CK 获取;客服在后台人工处理后续履约。"
>
<Select
options={[
{ value: 'huya', label: '虎牙(扫码登录 + 游戏角色绑定)' },
{ value: 'weibo', label: '微博(短信 / 扫码登录 + 游戏角色绑定)' },
]}
onChange={(value: 'huya' | 'weibo') => {
form.setFieldsValue({
pageTitle: value === 'weibo' ? '微博角色绑定测试' : '虎牙账号授权测试',
browserTargetUrl: value === 'weibo' ? 'https://weibo.com/' : 'https://www.huya.com/',
...(value === 'weibo' ? { connectorMode: 'embedded' } : {}),
})
}}
/>
</Form.Item>
{selectedPlatform === 'huya' ? (
<Form.Item
label={integration ? 'Connector 模式' : 'Mock 范围'}
name="connectorMode"
extra={
integration
? '订单始终走正式订单与履约链路,这里只选择登录和 CK 获取使用的 Connector。'
: '只 Mock 订单时,登录和 CK 获取可走内置真实 Connector,也可显式使用远程 Connector。'
}
>
<Select
options={[
{
value: 'embedded',
label: integration
? '内置真实 Connector'
: '仅 Mock 订单(内置真实登录 / CK 获取)',
},
{
value: 'external',
label: integration ? '远程真实 Connector' : '仅 Mock 订单(远程真实 Connector)',
},
{
value: 'mock',
label: integration
? '内置 Mock Connector(仅联调登录)'
: '订单 + 登录 CK 都 Mock(内置 Connector)',
disabled: mockConnectorAvailable === false,
},
]}
/>
</Form.Item>
) : (
<Alert
type="info"
showIcon
style={{ marginBottom: 12 }}
message="微博目前只支持内置 Connector,连接模式固定为 embedded。"
/>
)}
<Form.Item
label="内部 SKU 名称(可空)"
name="skuName"
extra={`留空自动生成“${
selectedPlatform === 'weibo' ? '微博半自动' : '虎牙半自动'
}测试-时间戳”;必须包含中文。`}
>
<Input
allowClear
placeholder={selectedPlatform === 'weibo' ? '微博半自动测试' : '虎牙半自动测试'}
/>
</Form.Item>
<Form.Item label="订单号 orderNo(可空)" name="orderNo">
<Input
allowClear
placeholder={
integration
? selectedPlatform === 'weibo'
? '留空自动 INTWB…'
: '留空自动 INTSA…'
: selectedPlatform === 'weibo'
? '留空自动 MOCKWB…'
: '留空自动 MOCKSA…'
}
/>
</Form.Item>
<Space size={12} style={{ display: 'flex' }}>
<Form.Item label="数量" name="quantity" style={{ flex: 1 }}>
<InputNumber min={1} max={10} style={{ width: '100%' }} />
</Form.Item>
<Form.Item label="客户页标题" name="pageTitle" style={{ flex: 2 }}>
<Input />
</Form.Item>
</Space>
<Form.Item
label="客服浏览器目标页"
name="browserTargetUrl"
extra="客服点击“打开浏览器登录态”时,扩展会注入到此页面。"
>
<Input
placeholder={
selectedPlatform === 'weibo' ? 'https://weibo.com/' : 'https://www.huya.com/'
}
/>
</Form.Item>
<Alert
type={
selectedPlatform === 'weibo'
? 'info'
: selectedMode === 'mock'
? 'warning'
: selectedMode === 'external' && !externalConnectorConfigured
? 'error'
: 'success'
}
showIcon
style={{ marginBottom: 12 }}
message={
selectedPlatform === 'weibo'
? '微博使用内置真实 Connector:短信验证码会真实发送到客户手机号,登录后还需客户通过微信或 QQ 扫码绑定游戏角色。'
: selectedMode === 'mock'
? integration
? '订单和履约链路是正式的,只有登录与 CK 获取使用内置 Mock Connector。'
: '登录和 CK 获取会使用内置 Mock Connector,仅用于联调页面。'
: selectedMode === 'external'
? externalConnectorConfigured
? integration
? '远程真实 Connector 已配置,订单走正式履约链路。'
: '远程真实 Connector 已配置;只有订单由 Mock 生成。'
: '远程真实 Connector 未配置:请设置 SEMI_AUTO_CONNECTOR_BASE_URL 和 API_KEY。'
: integration
? '使用 order_site 内置真实 Connector,订单走正式履约链路。'
: '使用 order_site 内置真实 Connector;无需启动 live-hub-py,只有订单由 Mock 生成。'
}
/>
<Button type="primary" htmlType="submit" loading={loading} block>
{submitText || '生成半自动履约 Mock'}
</Button>
</Form>
)
}