fix(admin): keep all batch-uploaded images when saving packages

Serialize multi-file uploads and reload package list after save so imageUrls persist.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-07 21:13:31 +08:00
parent 8f83624ffe
commit df546ff39f
3 changed files with 73 additions and 16 deletions
@@ -101,11 +101,11 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
usableTime: item.usableTime?.trim() || null,
otherNotes: item.otherNotes?.trim() || null,
imageUrl: imageUrls[0] ?? null,
imageUrls: imageUrls.length ? imageUrls : null,
imageUrls,
sortOrder: index,
};
})
.filter((item) => item.name || item.dishes || item.price || (item.imageUrls?.length ?? 0) > 0);
.filter((item) => item.name || item.dishes || item.price || item.imageUrls.length > 0);
for (let i = 0; i < filled.length; i++) {
const item = filled[i];
@@ -130,13 +130,27 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
setSaving(true);
try {
await request(`/admin/stores/${storeId}/packages`, {
const data = await request<{ live: PackageRow[] }>(`/admin/stores/${storeId}/packages`, {
method: 'PUT',
body: JSON.stringify({
packages: filled.map((p) => ({ ...p, price: Number(p.price).toFixed(2) })),
}),
});
message.success('套餐已保存并生效');
setItems(
data.live?.length
? data.live.map((p, i) => {
const imageUrls = normalizeStorePackageImageUrls(p);
return {
...p,
price: String(p.price),
imageUrl: imageUrls[0] ?? '',
imageUrls,
sortOrder: i,
};
})
: [emptyRow()],
);
} catch (e) {
message.error(e instanceof Error ? e.message : '保存失败');
} finally {
@@ -271,7 +285,7 @@ export default function AdminStorePackagesSection({ storeId }: { storeId: string
) : null}
<Typography.Paragraph type="secondary" style={{ marginBottom: 12 }}>
C
</Typography.Paragraph>
<Button type="primary" loading={saving} onClick={() => void save()}>