feat(fulfillment): 优化斗鱼商品映射管理界面

- 表格压缩为无横向滚动,操作收进更多菜单,删除/归档随时可见
- 新建和编辑改为右侧抽屉表单,不再占用列表顶部
- 增加 SKU 搜索、销售模式过滤、归档开关和刷新
- 表格合并活动批次/商品 ID 到次要信息,减少列宽
This commit is contained in:
yml
2026-11-24 17:08:37 +08:00
parent c6e6e66f2d
commit 751a45782f
+287 -182
View File
@@ -2,8 +2,8 @@ import { useCallback, useEffect, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import dayjs from 'dayjs';
import type { Dayjs } from 'dayjs';
import { Alert, Button, Card, Col, DatePicker, Descriptions, Drawer, Empty, Input, InputNumber, Modal, QRCode, Row, Segmented, Select, Space, Switch, Table, Tabs, Tag, Timeline, Typography } from 'antd';
import { CheckCircleOutlined, CopyOutlined, CreditCardOutlined, DownloadOutlined, GiftOutlined, LinkOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons';
import { Alert, Button, Card, Col, DatePicker, Descriptions, Drawer, Dropdown, Empty, Input, InputNumber, Modal, QRCode, Row, Segmented, Select, Space, Switch, Table, Tag, Timeline, Typography } from 'antd';
import { CheckCircleOutlined, CopyOutlined, CreditCardOutlined, DownloadOutlined, GiftOutlined, LinkOutlined, MoreOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons';
import type { ColumnsType } from 'antd/es/table';
import { douyuApi, platformFulfillmentApi } from '../api/modules';
import type { DouyuGoodsItem, DouyuTaskItem, PlatformFulfillmentBindingLog, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentSettings, PlatformFulfillmentTask } from '../api/modules';
@@ -482,6 +482,9 @@ export default function PlatformFulfillmentPage() {
const [bindingQrImage, setBindingQrImage] = useState('');
const [bindingQrLoading, setBindingQrLoading] = useState(false);
const [mappingOpen, setMappingOpen] = useState(false);
const [mappingEditorOpen, setMappingEditorOpen] = useState(false);
const [mappingSaving, setMappingSaving] = useState(false);
const [mappingKeyword, setMappingKeyword] = useState('');
const [mappingSku, setMappingSku] = useState('');
const [mappingEditingId, setMappingEditingId] = useState<number | null>(null);
const [mappingCampaignKey, setMappingCampaignKey] = useState('douyu-current');
@@ -1020,7 +1023,7 @@ export default function PlatformFulfillmentPage() {
};
const loadMappingRows = async (
keyword = mappingSku.trim(),
keyword = mappingKeyword.trim(),
mode = mappingFilterMode,
includeArchived = mappingIncludeArchived,
) => {
@@ -1035,12 +1038,15 @@ export default function PlatformFulfillmentPage() {
const openMapping = async (task?: PlatformFulfillmentTask) => {
resetMappingForm(task);
setMappingOpen(true);
if (task) setMappingEditorOpen(true);
setMappingGoodsLoading(true);
try {
const keyword = task?.internalSkuKey || '';
setMappingKeyword(keyword);
const [goodsRows, mappingRows] = await Promise.all([
douyuApi.listLiveGoods(),
platformFulfillmentApi.listMappings({
keyword: task?.internalSkuKey || '',
keyword,
sale_mode: mappingFilterMode || undefined,
include_archived: mappingIncludeArchived,
}),
@@ -1057,7 +1063,13 @@ export default function PlatformFulfillmentPage() {
}
};
const openMappingCreate = () => {
resetMappingForm();
setMappingEditorOpen(true);
};
const editMapping = (row: PlatformFulfillmentMapping) => {
setMappingEditorOpen(true);
setMappingEditingId(row.id);
setMappingSku(row.internalSkuKey);
setMappingCampaignKey(row.campaignKey || 'douyu-current');
@@ -1141,6 +1153,7 @@ export default function PlatformFulfillmentPage() {
};
const saveMapping = async () => {
if (mappingSaving) return;
if (!mappingSku.trim() || !mappingCampaignKey.trim() || !mappingGoodsId || !mappingSaleMode) {
message.warning('请填写内部 SKU、活动批次、销售模式并选择斗鱼商品');
return;
@@ -1163,17 +1176,21 @@ export default function PlatformFulfillmentPage() {
available_until: mappingAvailableUntil?.toISOString() || null,
enabled: mappingEnabled,
};
setMappingSaving(true);
if (mappingEditingId) {
await platformFulfillmentApi.updateMapping(mappingEditingId, payload);
} else {
await platformFulfillmentApi.createMapping(payload);
}
message.success('商品映射已保存');
setMappingEditorOpen(false);
resetMappingForm();
await loadMappingRows();
await loadTasks();
} catch (error) {
message.error(getErrorMessage(error));
} finally {
setMappingSaving(false);
}
};
@@ -2456,196 +2473,284 @@ export default function PlatformFulfillmentPage() {
<Modal
open={mappingOpen}
title="斗鱼商品映射管理"
width={1120}
okText="保存映射"
onOk={() => void saveMapping()}
onCancel={() => setMappingOpen(false)}
width={1080}
footer={null}
onCancel={() => {
setMappingOpen(false);
setMappingEditorOpen(false);
}}
>
<Space direction="vertical" size={14} style={{ width: '100%' }}>
<Space wrap>
<Select
value={mappingFilterMode}
options={[
{ value: '', label: '全部销售模式' },
...Object.entries(SALE_MODE_LABELS).map(([value, label]) => ({ value, label })),
]}
onChange={(value) => {
setMappingFilterMode(value);
void loadMappingRows(mappingSku.trim(), value).catch((error) => message.error(getErrorMessage(error)));
}}
style={{ width: 160 }}
/>
<Space>
<Text>显示已归档</Text>
<Switch
checked={mappingIncludeArchived}
onChange={(checked) => {
setMappingIncludeArchived(checked);
void platformFulfillmentApi.listMappings({
keyword: mappingSku.trim(),
sale_mode: mappingFilterMode || undefined,
include_archived: checked,
}).then(setMappings).catch((error) => message.error(getErrorMessage(error)));
<Space direction="vertical" size={12} style={{ width: '100%' }}>
<Space wrap style={{ width: '100%', justifyContent: 'space-between' }}>
<Space wrap>
<Input.Search
allowClear
value={mappingKeyword}
placeholder="搜索内部 SKU / 商品"
style={{ width: 260 }}
onChange={(event) => setMappingKeyword(event.target.value)}
onSearch={(value) => {
setMappingKeyword(value);
void loadMappingRows(value).catch((error) => message.error(getErrorMessage(error)));
}}
/>
<Select
value={mappingFilterMode}
options={[
{ value: '', label: '全部销售模式' },
...Object.entries(SALE_MODE_LABELS).map(([value, label]) => ({ value, label })),
]}
onChange={(value) => {
setMappingFilterMode(value);
void loadMappingRows(mappingKeyword.trim(), value).catch((error) => message.error(getErrorMessage(error)));
}}
style={{ width: 150 }}
/>
<Space size={6}>
<Text type="secondary">显示已归档</Text>
<Switch
checked={mappingIncludeArchived}
onChange={(checked) => {
setMappingIncludeArchived(checked);
void loadMappingRows(mappingKeyword.trim(), mappingFilterMode, checked).catch((error) => message.error(getErrorMessage(error)));
}}
/>
</Space>
</Space>
<Space>
<Button icon={<ReloadOutlined />} onClick={() => void loadMappingRows().catch((error) => message.error(getErrorMessage(error)))}>
刷新
</Button>
<Button type="primary" onClick={openMappingCreate}>
新建映射
</Button>
</Space>
<Button onClick={() => resetMappingForm()}>
新建映射
</Button>
</Space>
<Space wrap style={{ width: '100%' }}>
<Input placeholder="内部 SKU,例如 套装-兔兔白日梦" value={mappingSku} onChange={(event) => setMappingSku(event.target.value)} style={{ width: 260 }} />
<Input placeholder="活动批次,例如 douyu-2026-11-return" value={mappingCampaignKey} onChange={(event) => setMappingCampaignKey(event.target.value)} style={{ width: 260 }} />
<Input placeholder="活动名称,例如 11 月返场" value={mappingCampaignName} onChange={(event) => setMappingCampaignName(event.target.value)} style={{ width: 220 }} />
</Space>
<Space.Compact style={{ width: '100%' }}>
<Select
showSearch
optionFilterProp="label"
loading={mappingGoodsLoading}
placeholder={mappingGoodsLoading ? '正在加载斗鱼活动商品…' : '选择斗鱼精英宝典商品'}
value={mappingGoodsId || undefined}
onChange={selectGoods}
options={[
...goods.map((item) => ({
value: item.commodity_id,
label: `${item.name || item.commodity_id} · ${item.score ?? '-'} 积分`,
})),
...(mappingGoodsId && !goods.some((item) => item.commodity_id === mappingGoodsId)
? [{
value: mappingGoodsId,
label: `${mappingGoodsName || mappingGoodsId} · 当前已缓存`,
}]
: []),
]}
notFoundContent={mappingGoodsLoading ? null : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无活动商品" />}
style={{ flex: 1 }}
/>
<Button icon={<ReloadOutlined />} loading={mappingGoodsLoading} onClick={() => void reloadMappingGoods()}>
刷新商品
</Button>
</Space.Compact>
<Space wrap>
<Text>销售模式</Text>
<Select
value={mappingSaleMode}
options={Object.entries(SALE_MODE_LABELS).map(([value, label]) => ({ value, label }))}
onChange={setMappingSaleMode}
style={{ width: 140 }}
/>
<Text>所需积分</Text>
<InputNumber min={0} value={mappingPoints} onChange={(value) => setMappingPoints(value)} />
<Text>启用</Text>
<Switch checked={mappingEnabled} onChange={setMappingEnabled} />
</Space>
<Space wrap>
<Text>商品开放时间</Text>
<DatePicker
showTime
value={mappingAvailableFrom}
onChange={setMappingAvailableFrom}
placeholder="开始时间"
/>
<Text>至</Text>
<DatePicker
showTime
value={mappingAvailableUntil}
onChange={setMappingAvailableUntil}
placeholder="结束时间"
/>
</Space>
<Tabs
items={[
<Text type="secondary" style={{ fontSize: 12 }}>
共 {mappings.length} 条映射;编辑、停用、归档、删除都在“更多”里,不需要横向滚动。
</Text>
<Table<PlatformFulfillmentMapping>
rowKey="id"
size="small"
tableLayout="fixed"
pagination={{ pageSize: 10, hideOnSinglePage: true, showSizeChanger: false }}
dataSource={mappings}
columns={[
{
key: 'current',
label: '当前映射',
children: (
<Table<PlatformFulfillmentMapping>
rowKey="id"
size="small"
pagination={false}
dataSource={mappings}
columns={[
{ title: '内部 SKU', dataIndex: 'internalSkuKey', width: 150 },
{
title: '活动批次',
key: 'campaign',
width: 170,
render: (_: unknown, row) => (
<Space direction="vertical" size={0}>
<Text>{row.campaignName || row.campaignKey}</Text>
<Text type="secondary" style={{ fontSize: 12 }}>{row.campaignKey}</Text>
</Space>
),
},
{ title: '商品', dataIndex: 'goodsName', width: 150 },
{ title: '商品 ID', dataIndex: 'commodityId', width: 180 },
{
title: '分类',
key: 'saleMode',
width: 130,
render: (_: unknown, row) => (
<Space direction="vertical" size={2}>
<Tag color={row.saleMode === 'presale' ? 'gold' : row.saleMode === 'direct' ? 'green' : 'default'}>
{SALE_MODE_LABELS[row.saleMode] || row.saleMode}
</Tag>
<Tag>{AVAILABILITY_LABELS[row.availabilityState] || row.availabilityState}</Tag>
</Space>
),
},
{ title: '积分', dataIndex: 'requiredPoints', width: 80 },
{ title: '影响任务', dataIndex: 'affectedTasks', width: 90 },
{
title: '状态',
dataIndex: 'enabled',
width: 100,
render: (value: boolean, row) => (
<Tag color={row.archivedAt ? 'default' : value ? 'green' : 'orange'}>
{row.archivedAt ? '已归档' : value ? '启用' : '停用'}
</Tag>
),
},
{
title: '操作',
key: 'actions',
width: 310,
render: (_: unknown, row) => (
<Space wrap size={4}>
<Button size="small" disabled={Boolean(row.archivedAt)} onClick={() => editMapping(row)}>
编辑
</Button>
{row.archivedAt ? (
<Button size="small" onClick={() => runMappingAction(row, 'restore')}>
恢复
</Button>
) : (
<>
<Button
size="small"
onClick={() => runMappingAction(row, row.enabled ? 'disable' : 'enable')}
>
{row.enabled ? '停用' : '启用'}
</Button>
<Button size="small" onClick={() => runMappingAction(row, 'archive')}>
归档
</Button>
</>
)}
<Button size="small" danger onClick={() => removeMapping(row)}>
删除
</Button>
</Space>
),
},
]}
scroll={{ x: 1300 }}
/>
title: '内部 SKU',
dataIndex: 'internalSkuKey',
width: 170,
ellipsis: true,
render: (value: string, row) => (
<Space direction="vertical" size={0} style={{ maxWidth: '100%' }}>
<Text strong ellipsis style={{ maxWidth: '100%' }}>{value}</Text>
<Text type="secondary" style={{ fontSize: 12 }} ellipsis>
{row.campaignName || row.campaignKey || '-'}
</Text>
</Space>
),
},
{
title: '商品',
dataIndex: 'goodsName',
width: 250,
ellipsis: true,
render: (value: string, row) => (
<Space direction="vertical" size={0} style={{ maxWidth: '100%' }}>
<Text ellipsis style={{ maxWidth: '100%' }}>{value || row.commodityId || '-'}</Text>
<Text type="secondary" style={{ fontSize: 12 }} ellipsis>
{row.commodityId}
</Text>
</Space>
),
},
{
title: '分类',
key: 'saleMode',
width: 110,
render: (_: unknown, row) => (
<Space direction="vertical" size={2}>
<Tag color={row.saleMode === 'presale' ? 'gold' : row.saleMode === 'direct' ? 'green' : 'default'}>
{SALE_MODE_LABELS[row.saleMode] || row.saleMode}
</Tag>
<Tag>{AVAILABILITY_LABELS[row.availabilityState] || row.availabilityState}</Tag>
</Space>
),
},
{ title: '积分', dataIndex: 'requiredPoints', width: 70 },
{ title: '影响任务', dataIndex: 'affectedTasks', width: 80 },
{
title: '状态',
dataIndex: 'enabled',
width: 80,
render: (value: boolean, row) => (
<Tag color={row.archivedAt ? 'default' : value ? 'green' : 'orange'}>
{row.archivedAt ? '已归档' : value ? '启用' : '停用'}
</Tag>
),
},
{
title: '操作',
key: 'actions',
width: 150,
render: (_: unknown, row) => (
<Space size={4}>
<Button size="small" disabled={Boolean(row.archivedAt)} onClick={() => editMapping(row)}>
编辑
</Button>
<Dropdown
menu={{
items: [
...(row.archivedAt
? [{ key: 'restore', label: '恢复' }]
: [
{ key: 'toggle', label: row.enabled ? '停用' : '启用' },
{ key: 'archive', label: '归档' },
]),
{ type: 'divider' as const },
{ key: 'delete', label: '删除', danger: true },
],
onClick: ({ key }) => {
if (key === 'toggle') {
runMappingAction(row, row.enabled ? 'disable' : 'enable');
} else if (key === 'archive') {
runMappingAction(row, 'archive');
} else if (key === 'restore') {
runMappingAction(row, 'restore');
} else if (key === 'delete') {
removeMapping(row);
}
},
}}
>
<Button size="small" icon={<MoreOutlined />}>
更多
</Button>
</Dropdown>
</Space>
),
},
]}
/>
</Space>
</Modal>
<Drawer
title={mappingEditingId ? '编辑商品映射' : '新建商品映射'}
open={mappingEditorOpen}
width={560}
onClose={() => setMappingEditorOpen(false)}
extra={
<Space>
<Button onClick={() => setMappingEditorOpen(false)}>取消</Button>
<Button type="primary" loading={mappingSaving} onClick={() => void saveMapping()}>
保存映射
</Button>
</Space>
}
>
<Space direction="vertical" size={14} style={{ width: '100%' }}>
<div>
<Text strong>内部 SKU</Text>
<Input
value={mappingSku}
placeholder="例如 套装-兔兔白日梦"
onChange={(event) => setMappingSku(event.target.value)}
style={{ marginTop: 6 }}
/>
</div>
<Row gutter={12}>
<Col span={12}>
<Text strong>活动批次</Text>
<Input
value={mappingCampaignKey}
placeholder="douyu-current"
onChange={(event) => setMappingCampaignKey(event.target.value)}
style={{ marginTop: 6 }}
/>
</Col>
<Col span={12}>
<Text strong>活动名称</Text>
<Input
value={mappingCampaignName}
placeholder="例如 11 月返场"
onChange={(event) => setMappingCampaignName(event.target.value)}
style={{ marginTop: 6 }}
/>
</Col>
</Row>
<div>
<Text strong>斗鱼精英宝典商品</Text>
<Space.Compact style={{ width: '100%', marginTop: 6 }}>
<Select
showSearch
optionFilterProp="label"
loading={mappingGoodsLoading}
placeholder={mappingGoodsLoading ? '正在加载斗鱼活动商品…' : '选择斗鱼精英宝典商品'}
value={mappingGoodsId || undefined}
onChange={selectGoods}
options={[
...goods.map((item) => ({
value: item.commodity_id,
label: `${item.name || item.commodity_id} · ${item.score ?? '-'} 积分`,
})),
...(mappingGoodsId && !goods.some((item) => item.commodity_id === mappingGoodsId)
? [{
value: mappingGoodsId,
label: `${mappingGoodsName || mappingGoodsId} · 当前已缓存`,
}]
: []),
]}
notFoundContent={mappingGoodsLoading ? null : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description="暂无活动商品" />}
style={{ flex: 1 }}
/>
<Button icon={<ReloadOutlined />} loading={mappingGoodsLoading} onClick={() => void reloadMappingGoods()}>
刷新
</Button>
</Space.Compact>
</div>
<Row gutter={12}>
<Col span={9}>
<Text strong>销售模式</Text>
<Select
value={mappingSaleMode}
options={Object.entries(SALE_MODE_LABELS).map(([value, label]) => ({ value, label }))}
onChange={setMappingSaleMode}
style={{ width: '100%', marginTop: 6 }}
/>
</Col>
<Col span={8}>
<Text strong>所需积分</Text>
<InputNumber
min={0}
value={mappingPoints}
onChange={(value) => setMappingPoints(value)}
style={{ width: '100%', marginTop: 6 }}
/>
</Col>
<Col span={7}>
<Text strong>启用</Text>
<div style={{ marginTop: 6 }}>
<Switch checked={mappingEnabled} onChange={setMappingEnabled} />
</div>
</Col>
</Row>
<div>
<Text strong>商品开放时间</Text>
<Space wrap style={{ width: '100%', marginTop: 6 }}>
<DatePicker showTime value={mappingAvailableFrom} onChange={setMappingAvailableFrom} placeholder="开始时间" />
<Text>至</Text>
<DatePicker showTime value={mappingAvailableUntil} onChange={setMappingAvailableUntil} placeholder="结束时间" />
</Space>
</div>
<Alert
type={mappingEditingId ? 'info' : 'success'}
showIcon
message={mappingEditingId ? '修改后会同步影响订单选号和兑换资格判断' : '保存后会立即进入商品映射列表'}
description="内部 SKU 必须和 order_site 订单商品一致;商品 ID 来自斗鱼精英宝典活动。"
/>
</Space>
</Drawer>
</Space>
);
}