优化一些问题
This commit is contained in:
@@ -73,10 +73,9 @@ const imageIdCache = ref<Record<string, string>>({})
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await orderApi.getOrderList()
|
||||
orders.value = data
|
||||
const response = await orderApi.getOrderList() as any
|
||||
orders.value = response || []
|
||||
|
||||
// 加载商品图片的临时加签链接
|
||||
await loadProductImages(orders.value)
|
||||
} catch (error) {
|
||||
message.error('获取订单列表失败')
|
||||
@@ -91,29 +90,22 @@ const loadProductImages = async (orders: any[]) => {
|
||||
if (order.items && order.items.length > 0) {
|
||||
for (const item of order.items) {
|
||||
if (item.productImage) {
|
||||
// 过滤掉HTML标签
|
||||
const cleanImageUrl = item.productImage.replace(/<[^>]*>/g, '')
|
||||
|
||||
// 从cleanImageUrl中提取图片ID
|
||||
// 假设图片URL的格式为 '/api/file/get/123'
|
||||
const match = cleanImageUrl.match(/\/api\/file\/get\/(\d+)/)
|
||||
if (match && match[1]) {
|
||||
const imageId = match[1]
|
||||
try {
|
||||
// 检查缓存
|
||||
if (!imageIdCache.value[imageId]) {
|
||||
const signedUrl = await fileApi.getSignedUrl(Number(imageId))
|
||||
imageIdCache.value[imageId] = signedUrl
|
||||
const response = await fileApi.getSignedUrl(Number(imageId)) as any
|
||||
imageIdCache.value[imageId] = response
|
||||
}
|
||||
// 更新商品图片为临时加签链接
|
||||
item.productImage = imageIdCache.value[imageId]
|
||||
} catch (error) {
|
||||
console.error('获取图片签名链接失败:', error)
|
||||
// 如果获取签名链接失败,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
} else {
|
||||
// 如果不是有效的图片URL格式,清除无效的图片URL
|
||||
item.productImage = ''
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user