feat(cps): 新建淘宝活动支持上传/选择落地页图 + 列表缩略图

- ActivityFormModal 淘宝分支加 ImagePicker(上传新图 / 选已有 / 预览),必填
- 活动列表加落地页图缩略图列
- types: CpsActivity.image_url

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 21:32:12 +08:00
parent 654aca4c40
commit ecbce54e70
2 changed files with 103 additions and 8 deletions
+102 -8
View File
@@ -19,6 +19,7 @@ import {
Tabs,
Tag,
Typography,
Upload,
message,
} from 'antd';
import { api, errMsg } from '@/lib/api';
@@ -556,6 +557,17 @@ function ActivitiesTab() {
ellipsis: true,
render: (v: string | null) => v || '-',
},
{
title: '落地页图',
dataIndex: 'image_url',
width: 80,
render: (v: string | null) =>
v ? (
<img src={v} alt="" style={{ width: 36, height: 46, objectFit: 'cover', borderRadius: 4 }} />
) : (
'-'
),
},
{
title: '状态',
dataIndex: 'status',
@@ -587,13 +599,86 @@ function ActivitiesTab() {
showTotal: (t) => `${t} 个活动`,
onChange,
}}
scroll={{ x: 1000 }}
scroll={{ x: 1080 }}
/>
<ActivityFormModal open={createOpen} onClose={() => setCreateOpen(false)} onDone={reload} />
</div>
);
}
// 淘宝活动落地页图选择器:上传新图 或 点选已有图。受控组件(value = image_url 绝对 URL)。
function ImagePicker({ value, onChange }: { value?: string | null; onChange?: (v: string) => void }) {
const [existing, setExisting] = useState<string[]>([]);
const [uploading, setUploading] = useState(false);
useEffect(() => {
api
.get<{ images: string[] }>('/admin/api/cps/activity-images')
.then((r) => setExisting(r.data.images || []))
.catch(() => {});
}, []);
const upload = async (file: File) => {
setUploading(true);
try {
const fd = new FormData();
fd.append('file', file);
const r = await api.post<{ url: string }>('/admin/api/cps/upload-image', fd);
onChange?.(r.data.url);
setExisting((prev) => (prev.includes(r.data.url) ? prev : [r.data.url, ...prev]));
message.success('图片已上传');
} catch (e) {
message.error(errMsg(e, '上传失败'));
} finally {
setUploading(false);
}
};
const thumb = (u: string, w: number, selected: boolean) => (
<img
key={u}
src={u}
alt="落地页图"
onClick={() => onChange?.(u)}
style={{
width: w,
height: Math.round(w * 1.27),
objectFit: 'cover',
borderRadius: 6,
cursor: 'pointer',
border: selected ? '2px solid #ff4d4f' : '2px solid #f0f0f0',
}}
/>
);
return (
<div>
<Upload
accept="image/*"
showUploadList={false}
beforeUpload={(file) => {
upload(file);
return false; // 阻止 antd 默认上传,走我们自己的端点
}}
>
<Button loading={uploading}></Button>
</Upload>
{value && (
<div style={{ marginTop: 8, display: 'flex', alignItems: 'center', gap: 8 }}>
<span style={{ fontSize: 12, color: '#999' }}>:</span>
{thumb(value, 90, true)}
</div>
)}
{existing.length > 0 && (
<div style={{ marginTop: 10 }}>
<div style={{ fontSize: 12, color: '#999', marginBottom: 6 }}>:</div>
<Space wrap>{existing.map((u) => thumb(u, 56, u === value))}</Space>
</div>
)}
</div>
);
}
function ActivityFormModal({
open,
onClose,
@@ -655,13 +740,22 @@ function ActivityFormModal({
</>
)}
{platform === 'taobao' && (
<Form.Item
name="payload"
label="淘口令(整段,运营从淘宝联盟复制,落地页原样复制给用户)"
rules={[{ required: true, message: '请填淘口令' }]}
>
<Input.TextArea rows={4} placeholder="如:8¥abcXYZ¥ https://m.tb.cn/h.xxx 长按复制本条..." maxLength={4096} />
</Form.Item>
<>
<Form.Item
name="payload"
label="淘口令(整段,运营从淘宝联盟复制,落地页原样复制给用户)"
rules={[{ required: true, message: '请填淘口令' }]}
>
<Input.TextArea rows={4} placeholder="如:8¥abcXYZ¥ https://m.tb.cn/h.xxx 长按复制本条..." maxLength={4096} />
</Form.Item>
<Form.Item
name="image_url"
label="落地页图(用户点链接后看到的页面主图,上传新图或选已有)"
rules={[{ required: true, message: '请上传或选择落地页图' }]}
>
<ImagePicker />
</Form.Item>
</>
)}
{platform === 'jd' && (
<Form.Item
+1
View File
@@ -323,6 +323,7 @@ export interface CpsActivity {
act_id: string | null; // 美团活动物料 ID
product_view_sign: string | null;
payload: string | null; // 淘宝整段淘口令 / 京东链接
image_url: string | null; // 淘宝落地页主视觉图(绝对 URL)
status: string;
remark: string | null;
created_at: string;