|
@@ -260,11 +260,28 @@ function formatPrice(price) {
|
|
|
return Number.isNaN(num) ? '0.00' : num.toFixed(2);
|
|
return Number.isNaN(num) ? '0.00' : num.toFixed(2);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 取第一张图:逗号分隔取首段,数组取首项,对象取 url/path/src(与 orderDetail 一致)
|
|
|
|
|
+function firstImage(val) {
|
|
|
|
|
+ if (val == null || val === '') return '';
|
|
|
|
|
+ if (Array.isArray(val)) {
|
|
|
|
|
+ const first = val[0];
|
|
|
|
|
+ if (first != null && first !== '') {
|
|
|
|
|
+ if (typeof first === 'object' && first !== null) return first.url ?? first.path ?? first.src ?? first.link ?? '';
|
|
|
|
|
+ return String(first).split(/[,,]/)[0].trim();
|
|
|
|
|
+ }
|
|
|
|
|
+ return '';
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof val === 'object') return val.url ?? val.path ?? val.src ?? val.link ?? '';
|
|
|
|
|
+ const str = String(val).trim();
|
|
|
|
|
+ return str ? str.split(/[,,]/)[0].trim() : '';
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function getItemImage(item) {
|
|
function getItemImage(item) {
|
|
|
if (Number(item?.id ?? item?.cuisineId) === -1) return '/static/utensilFee.png';
|
|
if (Number(item?.id ?? item?.cuisineId) === -1) return '/static/utensilFee.png';
|
|
|
- const raw = item?.image ?? item?.cuisineImage ?? item?.imageUrl ?? '';
|
|
|
|
|
- if (typeof raw === 'string' && (raw.startsWith('http') || raw.startsWith('//'))) return raw;
|
|
|
|
|
- return getFileUrl(raw || 'img/icon/shop.png');
|
|
|
|
|
|
|
+ const raw = item?.image ?? item?.cuisineImage ?? item?.imageUrl ?? item?.images ?? item?.pic ?? item?.cover ?? '';
|
|
|
|
|
+ const url = firstImage(raw) || (typeof raw === 'string' ? raw.split(/[,,]/)[0]?.trim() : '');
|
|
|
|
|
+ if (url && typeof url === 'string' && (url.startsWith('http') || url.startsWith('//'))) return url;
|
|
|
|
|
+ return getFileUrl(url || 'img/icon/shop.png');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 将 tags 统一为 [{ text, type }] 格式
|
|
// 将 tags 统一为 [{ text, type }] 格式
|
|
@@ -285,15 +302,16 @@ function normalizeTags(raw) {
|
|
|
}).filter((t) => t.text !== '' && t.text != null);
|
|
}).filter((t) => t.text !== '' && t.text != null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 接口订单项转列表项:图片取首张(逗号/数组/对象与 orderDetail 一致)
|
|
|
function normalizeOrderItem(item) {
|
|
function normalizeOrderItem(item) {
|
|
|
const rawTags = item?.tags ?? item?.tagList ?? item?.tagNames ?? item?.labels ?? item?.tag;
|
|
const rawTags = item?.tags ?? item?.tagList ?? item?.tagNames ?? item?.labels ?? item?.tag;
|
|
|
- const images = item?.images ?? item?.image;
|
|
|
|
|
- const imageUrl = Array.isArray(images) ? images[0] : images;
|
|
|
|
|
|
|
+ const rawImg = item?.images ?? item?.image ?? item?.cuisineImage ?? item?.imageUrl ?? item?.pic ?? item?.cover ?? '';
|
|
|
|
|
+ const imageUrl = firstImage(rawImg) || (typeof rawImg === 'string' ? rawImg.split(/[,,]/)[0]?.trim() : '') || 'img/icon/shop.png';
|
|
|
return {
|
|
return {
|
|
|
id: item?.id ?? item?.cuisineId,
|
|
id: item?.id ?? item?.cuisineId,
|
|
|
name: item?.cuisineName ?? item?.name ?? '',
|
|
name: item?.cuisineName ?? item?.name ?? '',
|
|
|
price: item?.totalPrice ?? item?.unitPrice ?? item?.price ?? 0,
|
|
price: item?.totalPrice ?? item?.unitPrice ?? item?.price ?? 0,
|
|
|
- image: imageUrl ?? item?.image ?? item?.cuisineImage ?? '',
|
|
|
|
|
|
|
+ image: imageUrl,
|
|
|
quantity: item?.quantity ?? 1,
|
|
quantity: item?.quantity ?? 1,
|
|
|
tags: normalizeTags(rawTags)
|
|
tags: normalizeTags(rawTags)
|
|
|
};
|
|
};
|