From cef5ea014050f6b6a07f258a763aabc51ff9a497 Mon Sep 17 00:00:00 2001 From: marco Date: Wed, 17 Jun 2026 22:13:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(cps):=20=E6=B4=BB=E5=8A=A8=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E6=94=AF=E6=8C=81=E7=BC=96=E8=BE=91=20+=20=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=A0=E7=BC=96=E8=BE=91=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ActivityFormModal 改 create+edit 双模式(回填字段, 编辑走 PATCH, 加状态切换) - 活动列表操作列加「编辑」 Co-Authored-By: Claude Opus 4.8 --- src/app/(main)/cps/page.tsx | 72 +++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/src/app/(main)/cps/page.tsx b/src/app/(main)/cps/page.tsx index b82f8b4..2231e7a 100644 --- a/src/app/(main)/cps/page.tsx +++ b/src/app/(main)/cps/page.tsx @@ -556,6 +556,7 @@ function ActivitiesTab() { ); const canManage = canDo(['operator']); const [createOpen, setCreateOpen] = useState(false); + const [editing, setEditing] = useState(null); const delActivity = async (a: CpsActivity) => { try { @@ -613,17 +614,20 @@ function ActivitiesTab() { title: '操作', key: 'op', fixed: 'right' as const, - width: 80, + width: 120, render: (_: unknown, a: CpsActivity) => ( - delActivity(a)} - > - 删除 - + + setEditing(a)}>编辑 + delActivity(a)} + > + 删除 + + ), }, ] as ColumnsType) @@ -652,9 +656,10 @@ function ActivitiesTab() { showTotal: (t) => `共 ${t} 个活动`, onChange, }} - scroll={{ x: 1160 }} + scroll={{ x: 1200 }} /> - setCreateOpen(false)} onDone={reload} /> + setCreateOpen(false)} onDone={reload} /> + setEditing(null)} onDone={reload} /> ); } @@ -734,22 +739,38 @@ function ImagePicker({ value, onChange }: { value?: string | null; onChange?: (v function ActivityFormModal({ open, + activity, onClose, onDone, }: { open: boolean; + activity: CpsActivity | null; onClose: () => void; onDone: () => void; }) { const [form] = Form.useForm(); + const isEdit = !!activity; const platform = (Form.useWatch('platform', form) as string | undefined) || 'meituan'; useEffect(() => { if (open) { - form.resetFields(); - form.setFieldsValue({ platform: 'meituan' }); + if (activity) { + form.setFieldsValue({ + name: activity.name, + platform: activity.platform, + act_id: activity.act_id, + product_view_sign: activity.product_view_sign, + payload: activity.payload, + image_url: activity.image_url, + remark: activity.remark, + status: activity.status, + }); + } else { + form.resetFields(); + form.setFieldsValue({ platform: 'meituan' }); + } } - }, [open, form]); + }, [open, activity, form]); const submit = async () => { const v = await form.validateFields(); @@ -763,8 +784,13 @@ function ActivityFormModal({ return; } try { - await api.post('/admin/api/cps/activities', v); - message.success('已新建活动'); + if (isEdit && activity) { + await api.patch(`/admin/api/cps/activities/${activity.id}`, v); + message.success('已更新活动'); + } else { + await api.post('/admin/api/cps/activities', v); + message.success('已新建活动'); + } onClose(); onDone(); } catch (e) { @@ -773,7 +799,7 @@ function ActivityFormModal({ }; return ( - +
@@ -823,6 +849,16 @@ function ActivityFormModal({ + {isEdit && ( + +