修复:全局治理雪花ID精度问题

This commit is contained in:
xiaowang
2026-03-27 14:55:41 +08:00
parent 824e35366a
commit d2b63e0c71
34 changed files with 459 additions and 255 deletions
+11 -9
View File
@@ -53,13 +53,15 @@ import { ElMessage } from 'element-plus'
import { wishlistApi, type WishlistItem } from '@/api/wishlist'
import { cartApi } from '@/api/cart'
import { fileApi } from '@/api/file'
import type { IdType } from '@/utils/id'
import { sameId } from '@/utils/id'
const router = useRouter()
const updateCartCount = inject<() => Promise<void>>('updateCartCount', async () => {})
const wishlistItems = ref<WishlistItem[]>([])
const imageIdCache = ref<Record<string, string>>({})
const imageUrls = ref<Record<number, string[]>>({})
const imageUrls = ref<Record<string, string[]>>({})
const DEFAULT_PRODUCT_IMAGE = 'data:image/svg+xml;base64,PHN2ZyB3aW0dPSJodHRwOi8vd3d3Lm9yZy8yMDAwL3N2ZyI+Pjwvc3ZnPg=='
const handleBackClick = () => {
@@ -87,7 +89,7 @@ const loadImageUrls = async (items: WishlistItem[]) => {
if (id) {
try {
if (!imageIdCache.value[id]) {
const response = await fileApi.getSignedUrl(Number(id)) as any
const response = await fileApi.getSignedUrl(id.trim()) as any
imageIdCache.value[id] = response
}
if (imageIdCache.value[id]) {
@@ -100,18 +102,18 @@ const loadImageUrls = async (items: WishlistItem[]) => {
}
}
imageUrls.value[item.product.id] = urls
imageUrls.value[String(item.product.id)] = urls
} else {
imageUrls.value[item.product.id] = [DEFAULT_PRODUCT_IMAGE]
imageUrls.value[String(item.product.id)] = [DEFAULT_PRODUCT_IMAGE]
}
}
}
const getProductImages = (product: any): string[] => {
return imageUrls.value[product.id] || [DEFAULT_PRODUCT_IMAGE]
return imageUrls.value[String(product.id)] || [DEFAULT_PRODUCT_IMAGE]
}
const handleAddToCart = async (productId: number) => {
const handleAddToCart = async (productId: IdType) => {
try {
await cartApi.addToCart({ productId, quantity: 1 })
await updateCartCount()
@@ -122,10 +124,10 @@ const handleAddToCart = async (productId: number) => {
}
}
const handleRemoveItem = async (productId: number) => {
const handleRemoveItem = async (productId: IdType) => {
try {
await wishlistApi.removeFromWishlist(productId)
wishlistItems.value = wishlistItems.value.filter(item => item.productId !== productId)
wishlistItems.value = wishlistItems.value.filter(item => !sameId(item.productId, productId))
ElMessage.success('已从收藏中移除')
} catch (error) {
console.error('移除收藏失败:', error)
@@ -137,7 +139,7 @@ const handleBrowseProducts = () => {
router.push('/products')
}
const handleProductClick = (productId: number) => {
const handleProductClick = (productId: IdType) => {
router.push(`/product/${productId}`)
}