fix(pdd-ui): 优化拼多多管理面板UI布局与表格操作列自适应

This commit is contained in:
yml2213
2026-09-12 15:08:35 +08:00
parent cf9ca25a12
commit 121c2a452c
@@ -4,30 +4,40 @@
*/ */
import { import {
ApiOutlined,
CheckCircleOutlined, CheckCircleOutlined,
CloseCircleOutlined, CloseCircleOutlined,
DeleteOutlined, DeleteOutlined,
EditOutlined, EditOutlined,
FieldTimeOutlined,
GlobalOutlined,
PlusOutlined, PlusOutlined,
ReloadOutlined, ReloadOutlined,
SafetyCertificateOutlined,
SaveOutlined, SaveOutlined,
ShopOutlined,
ThunderboltOutlined, ThunderboltOutlined,
} from '@ant-design/icons' } from '@ant-design/icons'
import { import {
Alert, Alert,
Badge,
Button, Button,
Card, Card,
Col,
Divider,
Form, Form,
Input, Input,
InputNumber, InputNumber,
Modal, Modal,
Popconfirm, Popconfirm,
Row,
Space, Space,
Spin, Spin,
Statistic,
Switch, Switch,
Table, Table,
Tag, Tag,
Tooltip,
Typography, Typography,
} from 'antd' } from 'antd'
import type { TableColumnsType } from 'antd' import type { TableColumnsType } from 'antd'
@@ -52,6 +62,14 @@ import type {
const { Text, Paragraph } = Typography const { Text, Paragraph } = Typography
/**
* Extended test result with execution timestamp
* 带时间戳的 CK 校验结果结构
*/
interface ExtendedTestResult extends AdminPddTestCookieResult {
testedAt?: string
}
export function PddPlatformPanel() { export function PddPlatformPanel() {
const [loading, setLoading] = useState(true) const [loading, setLoading] = useState(true)
const [saving, setSaving] = useState(false) const [saving, setSaving] = useState(false)
@@ -61,15 +79,16 @@ export function PddPlatformPanel() {
stores: [], stores: [],
}) })
// Action loading states // Action loading states / 各操作加载状态
const [syncingAll, setSyncingAll] = useState(false) const [syncingAll, setSyncingAll] = useState(false)
const [testingShopId, setTestingShopId] = useState<string | null>(null) const [testingShopId, setTestingShopId] = useState<string | null>(null)
const [syncingShopId, setSyncingShopId] = useState<string | null>(null) const [syncingShopId, setSyncingShopId] = useState<string | null>(null)
const [togglingShopId, setTogglingShopId] = useState<string | null>(null)
// Test results cache by shopId // Test results cache by shopId / 店铺 CK 校验结果缓存
const [testResults, setTestResults] = useState<Record<string, AdminPddTestCookieResult>>({}) const [testResults, setTestResults] = useState<Record<string, ExtendedTestResult>>({})
// Modal State // Modal State / 弹窗表单状态
const [modalVisible, setModalVisible] = useState(false) const [modalVisible, setModalVisible] = useState(false)
const [isEditing, setIsEditing] = useState(false) const [isEditing, setIsEditing] = useState(false)
const [form] = Form.useForm<AdminPddStoreItem>() const [form] = Form.useForm<AdminPddStoreItem>()
@@ -80,6 +99,10 @@ export function PddPlatformPanel() {
void loadConfig() void loadConfig()
}, []) }, [])
/**
* Load PDD platform config
* 读取拼多多子服务配置
*/
async function loadConfig() { async function loadConfig() {
setLoading(true) setLoading(true)
try { try {
@@ -94,14 +117,19 @@ export function PddPlatformPanel() {
} }
} }
async function handleSaveGlobalConfig() { /**
* Save global configuration
* 保存全局同步调度配置
*/
async function handleSaveGlobalConfig(overrideConfig?: AdminPddConfig) {
setSaving(true) setSaving(true)
const targetConfig = overrideConfig || config
try { try {
const response = await saveAdminPddConfig(config) const response = await saveAdminPddConfig(targetConfig)
if (response && response.data) { if (response && response.data) {
setConfig(response.data) setConfig(response.data)
} }
showSuccess('拼多多全局配置已保存') showSuccess('拼多多全局调度配置已保存')
} catch (err) { } catch (err) {
showError(err instanceof Error ? err.message : '保存拼多多全局配置失败') showError(err instanceof Error ? err.message : '保存拼多多全局配置失败')
} finally { } finally {
@@ -109,6 +137,10 @@ export function PddPlatformPanel() {
} }
} }
/**
* Trigger order synchronization for all enabled stores
* 触发所有已启用店铺的手动拉单
*/
async function handleSyncAll() { async function handleSyncAll() {
setSyncingAll(true) setSyncingAll(true)
try { try {
@@ -118,10 +150,10 @@ export function PddPlatformPanel() {
const totalFetched = data.results.reduce((acc, r) => acc + (r.fetchedCount || 0), 0) const totalFetched = data.results.reduce((acc, r) => acc + (r.fetchedCount || 0), 0)
const totalUpserted = data.results.reduce((acc, r) => acc + (r.upsertedCount || 0), 0) const totalUpserted = data.results.reduce((acc, r) => acc + (r.upsertedCount || 0), 0)
showSuccess( showSuccess(
`全部店铺同步完成:共拉取 ${totalFetched} 笔订单,成功入库/更新 ${totalUpserted} 笔`, `全量店铺同步完成:共抓取 ${totalFetched} 笔,入库/更新 ${totalUpserted} 笔待发货订单`,
) )
} else { } else {
showSuccess('同步完成') showSuccess('全量店铺同步完成')
} }
} catch (err) { } catch (err) {
showError(err instanceof Error ? err.message : '触发全店铺同步失败') showError(err instanceof Error ? err.message : '触发全店铺同步失败')
@@ -130,6 +162,10 @@ export function PddPlatformPanel() {
} }
} }
/**
* Trigger order synchronization for a single store
* 单店铺手动触发拉单
*/
async function handleSyncSingleStore(store: AdminPddStoreItem) { async function handleSyncSingleStore(store: AdminPddStoreItem) {
setSyncingShopId(store.shopId) setSyncingShopId(store.shopId)
try { try {
@@ -137,7 +173,7 @@ export function PddPlatformPanel() {
const data = response?.data as AdminPddSyncResult | undefined const data = response?.data as AdminPddSyncResult | undefined
if (data) { if (data) {
showSuccess( showSuccess(
`店铺【${store.shopName}】同步完成:拉取 ${data.fetchedCount} 笔,入库/更新 ${data.upsertedCount} 笔`, `店铺【${store.shopName}】同步完成:抓取 ${data.fetchedCount} 笔,入库/更新 ${data.upsertedCount} 笔`,
) )
} else { } else {
showSuccess(`店铺【${store.shopName}】同步已触发`) showSuccess(`店铺【${store.shopName}】同步已触发`)
@@ -149,8 +185,13 @@ export function PddPlatformPanel() {
} }
} }
/**
* Live test MMS Cookie validity for a store
* 针对指定店铺实时测试 Cookie 有效性
*/
async function handleTestCookie(store: AdminPddStoreItem) { async function handleTestCookie(store: AdminPddStoreItem) {
setTestingShopId(store.shopId) setTestingShopId(store.shopId)
const nowStr = new Date().toLocaleTimeString('zh-CN', { hour12: false })
try { try {
const response = await testAdminPddCookie({ const response = await testAdminPddCookie({
shopId: store.shopId, shopId: store.shopId,
@@ -159,10 +200,13 @@ export function PddPlatformPanel() {
}) })
const result = response?.data const result = response?.data
if (result) { if (result) {
setTestResults((prev) => ({ ...prev, [store.shopId]: result })) setTestResults((prev) => ({
...prev,
[store.shopId]: { ...result, testedAt: nowStr },
}))
if (result.valid) { if (result.valid) {
showSuccess( showSuccess(
`【${store.shopName}】Cookie 校验通过,店铺在线订单总数: ${result.totalOrders ?? 0}`, `【${store.shopName}】Cookie 校验通过,在线待发货订单数: ${result.totalOrders ?? 0}`,
) )
} else { } else {
showError(`【${store.shopName}】Cookie 校验未通过: ${result.message}`) showError(`【${store.shopName}】Cookie 校验未通过: ${result.message}`)
@@ -175,18 +219,44 @@ export function PddPlatformPanel() {
} }
} }
/**
* Delete store configuration
* 删除店铺配置
*/
async function handleDeleteStore(shopId: string) { async function handleDeleteStore(shopId: string) {
try { try {
const response = await deleteAdminPddStore(shopId) const response = await deleteAdminPddStore(shopId)
if (response && response.data) { if (response && response.data) {
setConfig(response.data) setConfig(response.data)
} }
showSuccess('拼多多店铺已删除') showSuccess('拼多多店铺已安全移除')
} catch (err) { } catch (err) {
showError(err instanceof Error ? err.message : '删除拼多多店铺失败') showError(err instanceof Error ? err.message : '删除拼多多店铺失败')
} }
} }
/**
* Toggle store enabled state
* 快捷切换店铺启用状态
*/
async function handleToggleStoreEnabled(record: AdminPddStoreItem, checked: boolean) {
setTogglingShopId(record.shopId)
try {
const updated = { ...record, enabled: checked }
await saveAdminPddStore(record.shopId, updated)
await loadConfig()
showSuccess(`已${checked ? '启用' : '停用'}店铺【${record.shopName}】`)
} catch (err) {
showError(err instanceof Error ? err.message : '切换店铺状态失败')
} finally {
setTogglingShopId(null)
}
}
/**
* Open modal for adding a new store
* 打开添加店铺弹窗
*/
function handleOpenAddModal() { function handleOpenAddModal() {
setIsEditing(false) setIsEditing(false)
setModalTestResult(null) setModalTestResult(null)
@@ -202,6 +272,10 @@ export function PddPlatformPanel() {
setModalVisible(true) setModalVisible(true)
} }
/**
* Open modal for editing existing store
* 打开编辑店铺弹窗
*/
function handleOpenEditModal(store: AdminPddStoreItem) { function handleOpenEditModal(store: AdminPddStoreItem) {
setIsEditing(true) setIsEditing(true)
setModalTestResult(null) setModalTestResult(null)
@@ -217,11 +291,15 @@ export function PddPlatformPanel() {
setModalVisible(true) setModalVisible(true)
} }
/**
* Test Cookie inside Modal before saving
* 弹窗内免保存即时验证 Cookie
*/
async function handleModalTestCookie() { async function handleModalTestCookie() {
const values = form.getFieldsValue() const values = form.getFieldsValue()
const cookie = String(values.cookie || '').trim() const cookie = String(values.cookie || '').trim()
if (!cookie) { if (!cookie) {
showError('请先在下方输入或粘贴待测试的 Cookie 字符串') showError('请先在输入框中粘贴待测试的 Cookie 字符串')
return return
} }
@@ -251,6 +329,10 @@ export function PddPlatformPanel() {
} }
} }
/**
* Submit store Add/Edit form
* 提交店铺保存表单
*/
async function handleModalSubmit() { async function handleModalSubmit() {
try { try {
const values = await form.validateFields() const values = await form.validateFields()
@@ -267,86 +349,149 @@ export function PddPlatformPanel() {
} }
} }
// Calculate statistics / 计算统计数据
const totalStores = config.stores.length
const enabledStores = config.stores.filter((s) => s.enabled).length
const validStores = Object.values(testResults).filter((r) => r.valid).length
// Table columns definition / 表格列配置
const columns: TableColumnsType<AdminPddStoreItem> = [ const columns: TableColumnsType<AdminPddStoreItem> = [
{ {
title: '店铺 ID', title: '店铺标识 (ID)',
dataIndex: 'shopId', dataIndex: 'shopId',
key: 'shopId', key: 'shopId',
width: 140, width: 150,
render: (val: string) => <Tag color="blue">{val}</Tag>, render: (val: string) => (
<Tooltip title="点击复制标识">
<Tag
color="geekblue"
style={{ fontFamily: 'monospace', fontWeight: 500, cursor: 'pointer' }}
onClick={() => {
void navigator.clipboard.writeText(val)
showSuccess(`已复制: ${val}`)
}}
>
{val}
</Tag>
</Tooltip>
),
}, },
{ {
title: '店铺名称', title: '店铺名称',
dataIndex: 'shopName', dataIndex: 'shopName',
key: 'shopName', key: 'shopName',
width: 160, width: 180,
render: (val: string) => <Text strong>{val}</Text>, render: (val: string, record) => (
<Space direction="vertical" size={2}>
<Space size={6}>
<ShopOutlined style={{ color: '#ff6a00', fontSize: '15px' }} />
<Text strong style={{ fontSize: '14px' }}>
{val}
</Text>
</Space>
{record.proxy ? (
<Tag color="purple" style={{ fontSize: '11px', margin: 0 }}>
<GlobalOutlined /> 独立代理
</Tag>
) : null}
</Space>
),
}, },
{ {
title: 'Cookie 凭据', title: '商家凭证 (Cookie)',
dataIndex: 'cookie', dataIndex: 'cookie',
key: 'cookie', key: 'cookie',
ellipsis: true, width: 220,
render: (cookie: string) => { render: (cookie: string) => {
if (!cookie) return <Tag color="error">未配置</Tag> if (!cookie) return <Tag color="error">未配置</Tag>
const preview = const preview =
cookie.length > 30 ? `${cookie.slice(0, 15)}...${cookie.slice(-15)}` : cookie cookie.length > 26 ? `${cookie.slice(0, 12)}...${cookie.slice(-10)}` : cookie
return ( return (
<Space size="small"> <Space size={6} wrap={false}>
<Text code copyable={{ text: cookie }}> <Text
code
copyable={{ text: cookie }}
style={{ fontSize: '12px', wordBreak: 'keep-all' }}
>
{preview} {preview}
</Text> </Text>
<Tag color="cyan">{cookie.length} 字符</Tag> <Tag color="cyan" style={{ fontSize: '11px', margin: 0 }}>
{cookie.length} 字符
</Tag>
</Space> </Space>
) )
}, },
}, },
{ {
title: '状态', title: '自动拉单',
dataIndex: 'enabled', dataIndex: 'enabled',
key: 'enabled', key: 'enabled',
width: 100, width: 110,
render: (enabled: boolean, record) => ( render: (enabled: boolean, record) => (
<Space direction="vertical" size={2} align="start">
<Switch <Switch
checked={enabled} checked={enabled}
onChange={async (checked) => { loading={togglingShopId === record.shopId}
const updated = { ...record, enabled: checked } onChange={(checked) => handleToggleStoreEnabled(record, checked)}
await saveAdminPddStore(record.shopId, updated)
await loadConfig()
showSuccess(`已${checked ? '启用' : '停用'}店铺【${record.shopName}】`)
}}
/> />
<Badge
status={enabled ? 'processing' : 'default'}
text={
<Text type={enabled ? 'success' : 'secondary'} style={{ fontSize: '12px' }}>
{enabled ? '调度中' : '已暂停'}
</Text>
}
/>
</Space>
), ),
}, },
{ {
title: 'CK 校验结果', title: 'Cookie 校验状态',
key: 'testStatus', key: 'testStatus',
width: 180, width: 190,
render: (_, record) => { render: (_, record) => {
const testRes = testResults[record.shopId] const testRes = testResults[record.shopId]
if (!testRes) { if (!testRes) {
return <Text type="secondary">未校验</Text> return <Badge status="default" text={<Text type="secondary">未校验</Text>} />
} }
if (testRes.valid) { if (testRes.valid) {
return ( return (
<Space direction="vertical" size={2}>
<Tag icon={<CheckCircleOutlined />} color="success"> <Tag icon={<CheckCircleOutlined />} color="success">
有效 (订单数: {testRes.totalOrders ?? '-'}) 有效 (待发货: {testRes.totalOrders ?? 0})
</Tag> </Tag>
{testRes.testedAt && (
<Text type="secondary" style={{ fontSize: '11px' }}>
{testRes.testedAt} 测活
</Text>
)}
</Space>
) )
} }
return ( return (
<Tag icon={<CloseCircleOutlined />} color="error" title={testRes.message}> <Space direction="vertical" size={2}>
失效 <Tooltip title={testRes.message || 'Cookie 失效或风控拦截'}>
<Tag icon={<CloseCircleOutlined />} color="error" style={{ cursor: 'pointer' }}>
失效 (点击查看)
</Tag> </Tag>
</Tooltip>
{testRes.testedAt && (
<Text type="secondary" style={{ fontSize: '11px' }}>
{testRes.testedAt} 测活
</Text>
)}
</Space>
) )
}, },
}, },
{ {
title: '操作', title: '操作',
key: 'action', key: 'action',
width: 280, width: 300,
fixed: 'right',
render: (_, record) => ( render: (_, record) => (
<Space size="small"> <Space size={6} wrap={false}>
<Tooltip title="通过 Pure TS 0as 引擎实时测试 MMS 商家 Cookie 有效性">
<Button <Button
size="small" size="small"
icon={<ThunderboltOutlined />} icon={<ThunderboltOutlined />}
@@ -355,6 +500,8 @@ export function PddPlatformPanel() {
> >
测试CK 测试CK
</Button> </Button>
</Tooltip>
<Tooltip title="立即从拼多多 MMS 抓取待发货订单并同步至总平台">
<Button <Button
size="small" size="small"
icon={<ReloadOutlined />} icon={<ReloadOutlined />}
@@ -363,12 +510,13 @@ export function PddPlatformPanel() {
> >
立即拉单 立即拉单
</Button> </Button>
</Tooltip>
<Button size="small" icon={<EditOutlined />} onClick={() => handleOpenEditModal(record)}> <Button size="small" icon={<EditOutlined />} onClick={() => handleOpenEditModal(record)}>
编辑 编辑
</Button> </Button>
<Popconfirm <Popconfirm
title="确认删除此店铺配置?" title="确认删除此店铺配置?"
description="删除后将停止此店铺的自动拉单,已入库订单不会被删除。" description="删除后将停止此店铺的自动拉单,已入库的历史订单不受影响。"
onConfirm={() => handleDeleteStore(record.shopId)} onConfirm={() => handleDeleteStore(record.shopId)}
okText="删除" okText="删除"
cancelText="取消" cancelText="取消"
@@ -386,64 +534,236 @@ export function PddPlatformPanel() {
if (loading) { if (loading) {
return ( return (
<Card> <Card>
<div style={{ textAlign: 'center', padding: '40px 0' }}> <div style={{ textAlign: 'center', padding: '48px 0' }}>
<Spin tip="加载拼多多店铺配置中..." /> <Spin tip="正在加载拼多多子服务配置..." />
</div> </div>
</Card> </Card>
) )
} }
return ( return (
<Space direction="vertical" size="large" style={{ width: '100%' }}> <section className="platform-panel-stack">
{/* Global Sync Settings */} {/* Metrics Dashboard / 状态指标概览卡片 */}
<Row gutter={[16, 16]}>
<Col xs={24} sm={12} lg={6}>
<Card <Card
title="拼多多子服务全局配置" size="small"
style={{
borderRadius: 8,
borderLeft: '4px solid #ff6a00',
boxShadow: '0 1px 2px rgba(0,0,0,0.04)',
}}
>
<Statistic
title={<span style={{ color: '#64748b' }}>服务运行状态</span>}
value={config.enabled ? '运行中' : '已暂停'}
valueStyle={{
color: config.enabled ? '#52c41a' : '#8c8c8c',
fontWeight: 600,
fontSize: 20,
}}
prefix={config.enabled ? <CheckCircleOutlined /> : <CloseCircleOutlined />}
/>
<div
style={{
marginTop: 8,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text type="secondary" style={{ fontSize: 12 }}>
后台错峰自动拉单
</Text>
<Switch
size="small"
checked={config.enabled}
loading={saving}
onChange={(checked) => {
const next = { ...config, enabled: checked }
setConfig(next)
void handleSaveGlobalConfig(next)
}}
/>
</div>
</Card>
</Col>
<Col xs={24} sm={12} lg={6}>
<Card
size="small"
style={{
borderRadius: 8,
borderLeft: '4px solid #1677ff',
boxShadow: '0 1px 2px rgba(0,0,0,0.04)',
}}
>
<Statistic
title={<span style={{ color: '#64748b' }}>接入店铺总数</span>}
value={totalStores}
suffix={<span style={{ fontSize: 14, color: '#8c8c8c' }}>家</span>}
valueStyle={{ color: '#1677ff', fontWeight: 600, fontSize: 20 }}
prefix={<ShopOutlined />}
/>
<div
style={{
marginTop: 8,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text type="secondary" style={{ fontSize: 12 }}>
已启用 <strong style={{ color: '#52c41a' }}>{enabledStores}</strong> 家 / 待机{' '}
{totalStores - enabledStores} 家
</Text>
{validStores > 0 && (
<Tag color="success" style={{ margin: 0, fontSize: 11 }}>
CK 有效 {validStores}
</Tag>
)}
</div>
</Card>
</Col>
<Col xs={24} sm={12} lg={6}>
<Card
size="small"
style={{
borderRadius: 8,
borderLeft: '4px solid #722ed1',
boxShadow: '0 1px 2px rgba(0,0,0,0.04)',
}}
>
<Statistic
title={<span style={{ color: '#64748b' }}>错峰轮询频次</span>}
value={config.pollIntervalSeconds}
suffix={<span style={{ fontSize: 14, color: '#8c8c8c' }}>秒 / 轮</span>}
valueStyle={{ color: '#722ed1', fontWeight: 600, fontSize: 20 }}
prefix={<FieldTimeOutlined />}
/>
<div
style={{
marginTop: 8,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text type="secondary" style={{ fontSize: 12 }}>
多店铺平滑均摊时间片
</Text>
</div>
</Card>
</Col>
<Col xs={24} sm={12} lg={6}>
<Card
size="small"
style={{
borderRadius: 8,
borderLeft: '4px solid #13c2c2',
boxShadow: '0 1px 2px rgba(0,0,0,0.04)',
}}
>
<Statistic
title={<span style={{ color: '#64748b' }}>算法驱动核心</span>}
value="0as Pure TS"
valueStyle={{ color: '#13c2c2', fontWeight: 600, fontSize: 20 }}
prefix={<SafetyCertificateOutlined />}
/>
<div
style={{
marginTop: 8,
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text type="secondary" style={{ fontSize: 12 }}>
零浏览器依赖 · 毫秒级抗风控
</Text>
</div>
</Card>
</Col>
</Row>
{/* Global Sync Settings Card / 全局同步调度配置卡片 */}
<Card
title={
<Space>
<ApiOutlined style={{ color: '#ff6a00' }} />
<Text strong style={{ fontSize: '15px' }}>
拼多多子服务同步调度配置
</Text>
</Space>
}
extra={ extra={
<Space> <Space>
<Button <Button
type="primary" type="primary"
icon={<SaveOutlined />} icon={<SaveOutlined />}
loading={saving} loading={saving}
onClick={handleSaveGlobalConfig} onClick={() => handleSaveGlobalConfig()}
> >
保存全局配置 保存调度配置
</Button> </Button>
<Button icon={<ReloadOutlined />} loading={syncingAll} onClick={handleSyncAll}> <Button icon={<ReloadOutlined />} loading={syncingAll} onClick={handleSyncAll}>
全部店铺立即拉单 全量店铺立即拉单
</Button> </Button>
</Space> </Space>
} }
> >
<Space size="large" wrap align="center"> <Row gutter={[24, 16]} align="middle">
<Col xs={24} sm={8}>
<Space direction="vertical" size={4}>
<Text strong>自动拉单调度状态</Text>
<Space align="center"> <Space align="center">
<Text strong>启用拼多多同步:</Text>
<Switch <Switch
checked={config.enabled} checked={config.enabled}
onChange={(checked) => setConfig((prev) => ({ ...prev, enabled: checked }))} onChange={(checked) => setConfig((prev) => ({ ...prev, enabled: checked }))}
/> />
<Tag color={config.enabled ? 'success' : 'default'}>
{config.enabled ? '已开启自动同步' : '同步已暂停'}
</Tag>
</Space> </Space>
</Space>
</Col>
<Space align="center"> <Col xs={24} sm={16}>
<Text strong>错峰轮询间隔 (秒):</Text> <Space direction="vertical" size={4} style={{ width: '100%' }}>
<Text strong>错峰轮询间隔</Text>
<Space align="center" wrap>
<InputNumber <InputNumber
min={10} min={10}
max={3600} max={3600}
addonAfter="秒"
value={config.pollIntervalSeconds} value={config.pollIntervalSeconds}
onChange={(val) => onChange={(val) =>
setConfig((prev) => ({ ...prev, pollIntervalSeconds: Number(val || 20) })) setConfig((prev) => ({
...prev,
pollIntervalSeconds: Number(val || 20),
}))
} }
/> />
<Text type="secondary">(建议 15~30 秒,多店铺将自动错峰拉取待发货订单)</Text> <Text type="secondary" style={{ fontSize: 12 }}>
(建议 15~30 秒。多店铺自动平滑错峰拉取待发货订单,保证准实时入库且防止高频风控)
</Text>
</Space> </Space>
</Space> </Space>
</Col>
</Row>
</Card> </Card>
{/* Stores CRUD Table */} {/* Stores CRUD Table Card / 拼多多店铺管理表格卡片 */}
<Card <Card
title={ title={
<Space> <Space>
<span>拼多多店铺列表</span> <ShopOutlined style={{ color: '#ff6a00' }} />
<Tag color="processing">{config.stores.length} 个店铺</Tag> <Text strong style={{ fontSize: '15px' }}>
拼多多店铺配置与凭据
</Text>
<Tag color="orange">{totalStores} 家店铺</Tag>
</Space> </Space>
} }
extra={ extra={
@@ -457,25 +777,46 @@ export function PddPlatformPanel() {
columns={columns} columns={columns}
dataSource={config.stores} dataSource={config.stores}
pagination={false} pagination={false}
locale={{ emptyText: '暂未添加拼多多店铺,请点击右上角“添加店铺”' }} scroll={{ x: 1100 }}
locale={{
emptyText: (
<div style={{ padding: '24px 0', textAlign: 'center' }}>
<Text type="secondary">暂未添加拼多多店铺,请点击右上角“添加店铺”按钮接入店铺</Text>
</div>
),
}}
/> />
</Card> </Card>
{/* Add / Edit Store Modal */} {/* Add / Edit Store Modal / 添加与编辑店铺弹窗 */}
<Modal <Modal
title={isEditing ? '编辑拼多多店铺' : '添加拼多多店铺'} title={
<Space>
<ShopOutlined style={{ color: '#ff6a00' }} />
<span>{isEditing ? '编辑拼多多店铺' : '添加拼多多店铺'}</span>
</Space>
}
open={modalVisible} open={modalVisible}
onCancel={() => setModalVisible(false)} onCancel={() => setModalVisible(false)}
onOk={handleModalSubmit} onOk={handleModalSubmit}
okText="保存" okText="保存店铺"
cancelText="取消" cancelText="取消"
width={680} width={720}
destroyOnClose destroyOnClose
> >
<Form form={form} layout="vertical" initialValues={{ enabled: true }}> <Form form={form} layout="vertical" initialValues={{ enabled: true }}>
<Divider
titlePlacement="left"
style={{ margin: '4px 0 16px', fontSize: '13px', color: '#64748b' }}
>
1. 店铺基本信息 (Basic Information)
</Divider>
<Row gutter={16}>
<Col span={12}>
<Form.Item <Form.Item
name="shopId" name="shopId"
label="店铺标识 (shopId)" label="店铺唯一标识 (shopId)"
rules={[ rules={[
{ required: true, message: '请输入店铺唯一英文标识' }, { required: true, message: '请输入店铺唯一英文标识' },
{ {
@@ -483,76 +824,148 @@ export function PddPlatformPanel() {
message: '只允许输入英文、数字、下划线或连字符', message: '只允许输入英文、数字、下划线或连字符',
}, },
]} ]}
extra="系统内唯一标识,例如:store_pdd_01" extra="系统内唯一英文标识,例如:store_pdd_01"
> >
<Input placeholder="例如:store_pdd_01" disabled={isEditing} /> <Input placeholder="例如:store_pdd_01" disabled={isEditing} />
</Form.Item> </Form.Item>
</Col>
<Col span={12}>
<Form.Item <Form.Item
name="shopName" name="shopName"
label="店铺名称 (shopName)" label="店铺展示名称 (shopName)"
rules={[{ required: true, message: '请输入店铺展示名称' }]} rules={[{ required: true, message: '请输入店铺展示名称' }]}
extra="用于打手大厅与工单详情展示的中文名称,例如:和平精英专营1号店" extra="用于打手大厅与工单详情展示的中文名称"
> >
<Input placeholder="例如:和平精英专营1号店" /> <Input placeholder="例如:木狼数娱专卖店" />
</Form.Item> </Form.Item>
</Col>
</Row>
<Divider
titlePlacement="left"
style={{ margin: '4px 0 16px', fontSize: '13px', color: '#64748b' }}
>
2. 商家后台凭证与即时测活 (MMS Credentials & Testing)
</Divider>
<Form.Item <Form.Item
name="cookie" name="cookie"
label="商家后台 Cookie" label="MMS 商家后台完整 Cookie"
rules={[{ required: true, message: '请输入商家后台 Cookie' }]} rules={[{ required: true, message: '请输入商家后台 Cookie' }]}
extra={ extra={
<Paragraph style={{ fontSize: '12px', margin: 0 }}> <Paragraph style={{ fontSize: '12px', margin: '4px 0 0', color: '#64748b' }}>
登录 MMS 商家后台(mms.pinduoduo.com),按 F12 复制包含 <Text code>_nano_fp</Text>、 登录 MMS 商家后台(<Text code>mms.pinduoduo.com</Text>),按 F12 复制包含{' '}
<Text code>PASS_ID</Text>、<Text code>api_uid</Text> 的完整 Cookie。 <Text code>_nano_fp</Text>、<Text code>PASS_ID</Text>、<Text code>api_uid</Text>{' '}
的完整 Cookie。
</Paragraph> </Paragraph>
} }
> >
<Input.TextArea rows={4} placeholder="api_uid=...; _nano_fp=...; PASS_ID=...;" /> <Input.TextArea
rows={4}
placeholder="api_uid=...; _nano_fp=...; PASS_ID=...;"
style={{ fontFamily: 'monospace', fontSize: '12px' }}
/>
</Form.Item> </Form.Item>
{/* Test Cookie Action inside Modal */} {/* Dedicated Live Verification Area / 实时 Cookie 测活区域 */}
<div style={{ marginBottom: 18 }}> <Card
size="small"
style={{
marginBottom: 20,
background: '#f8fafc',
border: '1px dashed #cbd5e1',
borderRadius: 8,
}}
>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: modalTestResult ? 10 : 0,
}}
>
<Space> <Space>
<Button <Button
type="dashed"
icon={<ThunderboltOutlined />} icon={<ThunderboltOutlined />}
loading={modalTesting} loading={modalTesting}
onClick={handleModalTestCookie} onClick={handleModalTestCookie}
> >
测试此 Cookie 有效性 一键测试此 Cookie 有效性
</Button> </Button>
<Text type="secondary">无需先保存,可即时验证此 Cookie 是否能连通 MMS API</Text> <Text type="secondary" style={{ fontSize: 12 }}>
无需先保存,可即时检测是否能通过 0as 纯算防风控并连通 MMS 官方 API
</Text>
</Space> </Space>
</div>
{modalTestResult && ( {modalTestResult && (
<div style={{ marginTop: 10 }}>
<Alert <Alert
type={modalTestResult.valid ? 'success' : 'error'} type={modalTestResult.valid ? 'success' : 'error'}
showIcon showIcon
message={modalTestResult.valid ? 'Cookie 验证成功' : 'Cookie 验证失败'} message={modalTestResult.valid ? 'Cookie 验证通过' : 'Cookie 验证失败'}
description={modalTestResult.message} description={
/> <div>
<div>{modalTestResult.message}</div>
{modalTestResult.totalOrders !== undefined && (
<div style={{ marginTop: 4, fontWeight: 500 }}>
当前在线待发货订单数: {modalTestResult.totalOrders} 笔
</div> </div>
)} )}
</div> </div>
}
/>
)}
</Card>
<Form.Item name="userAgent" label="浏览器 User-Agent (选填)"> <Divider
<Input placeholder="留空则自动使用现实拟真 Chrome User-Agent" /> titlePlacement="left"
</Form.Item> style={{ margin: '4px 0 16px', fontSize: '13px', color: '#64748b' }}
>
3. 网络隔离与防关联 (Network & Isolation - 选填)
</Divider>
<Row gutter={16}>
<Col span={12}>
<Form.Item <Form.Item
name="proxy" name="proxy"
label="店铺独立代理 (选填)" label="店铺独立代理 (Proxy)"
extra="如有多店铺防关联需求,可填写 HTTP/SOCKS5 代理地址,格式:http://user:pass@ip:port" extra="如有多店铺防关联需求,可填写 HTTP/SOCKS5 代理地址"
> >
<Input placeholder="例如:http://127.0.0.1:7890" /> <Input placeholder="例如:http://user:pass@127.0.0.1:7890" />
</Form.Item> </Form.Item>
</Col>
<Form.Item name="enabled" label="启用店铺拉单" valuePropName="checked"> <Col span={12}>
<Form.Item
name="userAgent"
label="浏览器 User-Agent"
extra="留空则自动使用系统内置真实 Chrome User-Agent"
>
<Input placeholder="留空使用默认 Chrome UA" />
</Form.Item>
</Col>
</Row>
<Divider
titlePlacement="left"
style={{ margin: '4px 0 16px', fontSize: '13px', color: '#64748b' }}
>
4. 运行调度 (Schedule)
</Divider>
<Form.Item
name="enabled"
label="启用此店铺自动拉单"
valuePropName="checked"
style={{ marginBottom: 0 }}
>
<Switch /> <Switch />
</Form.Item> </Form.Item>
</Form> </Form>
</Modal> </Modal>
</Space> </section>
) )
} }