fix: 修复商品图片管理和缓存一致性问题

- 重构 ImageUpload 组件,使用 rawUrl 跟踪原始路径
- 新增 normalizeStorageImageUrl 避免存储绝对 URL
- 商品增删改后同步清除缓存和旧图片文件
- 修复秒杀活动列表商品图片为空的问题
This commit is contained in:
2026-03-14 21:05:42 +08:00
parent 0f67f6cc49
commit 098ea9ad02
10 changed files with 193 additions and 39 deletions

View File

@@ -16,7 +16,7 @@ import type {
AdminRecentOrderRow,
AdminUserRow,
} from '@/types/admin'
import { DEFAULT_PRODUCT_IMAGE, resolveImageUrl } from '@/utils/image'
import { DEFAULT_PRODUCT_IMAGE, normalizeStorageImageUrl, resolveImageUrl } from '@/utils/image'
const toNumber = (value: unknown, fallback = 0) => {
const result = Number(value)
@@ -280,7 +280,7 @@ export const normalizeAdminProduct = (product: Record<string, any>): AdminProduc
price: toNumber(product.price),
stock: toNumber(product.stock),
status: toNumber(product.status, 1),
imageUrl: resolveImageUrl(toString(product.imageUrl, '')),
imageUrl: normalizeStorageImageUrl(toString(product.imageUrl, '')),
createdAt: toIsoLikeString(product.createdAt),
updatedAt: product.updatedAt ? toIsoLikeString(product.updatedAt) : undefined,
totalSales: toNumber(product.totalSales),