|
|
@@ -21,8 +21,8 @@
|
|
|
<view class="food-item__info">
|
|
|
<view class="food-item__name">{{ item.name }}</view>
|
|
|
<view class="food-item__desc" v-if="item.tags && item.tags.length > 0">
|
|
|
- <text v-for="(tag, tagIndex) in item.tags" :key="tagIndex" class="food-item__tag">
|
|
|
- {{ tag.text }}<text v-if="tagIndex < item.tags.length - 1">,</text>
|
|
|
+ <text v-for="(tag, tagIndex) in item.tags" :key="tagIndex" class="food-item__tag"
|
|
|
+ :class="tag.type">{{ tag.text }}<text v-if="tagIndex < item.tags.length - 1">,</text>
|
|
|
</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -157,11 +157,28 @@ const formatPrice = (price) => {
|
|
|
return Number.isNaN(num) ? '0.00' : num.toFixed(2);
|
|
|
};
|
|
|
|
|
|
+// 将 tags 统一为 [{ text, type }] 格式
|
|
|
+function normalizeTags(raw) {
|
|
|
+ if (raw == null) return [];
|
|
|
+ let arr = [];
|
|
|
+ if (Array.isArray(raw)) arr = raw;
|
|
|
+ else if (typeof raw === 'string') {
|
|
|
+ const t = raw.trim();
|
|
|
+ if (t.startsWith('[')) { try { arr = JSON.parse(t); if (!Array.isArray(arr)) arr = []; } catch { arr = t ? [t] : []; } }
|
|
|
+ else arr = t ? t.split(/[,,、\s]+/).map(s => s.trim()).filter(Boolean) : [];
|
|
|
+ } else if (raw && typeof raw === 'object') arr = Array.isArray(raw.list) ? raw.list : Array.isArray(raw.items) ? raw.items : [];
|
|
|
+ return arr.map((it) => {
|
|
|
+ if (it == null) return { text: '', type: '' };
|
|
|
+ if (typeof it === 'string') return { text: it, type: '' };
|
|
|
+ if (typeof it === 'number') return { text: String(it), type: '' };
|
|
|
+ return { text: it.text ?? it.tagName ?? it.name ?? it.label ?? it.title ?? '', type: it.type ?? it.tagType ?? '' };
|
|
|
+ }).filter((t) => t.text !== '' && t.text != null);
|
|
|
+}
|
|
|
+
|
|
|
// 将接口订单项转为列表项
|
|
|
function normalizeOrderItem(item) {
|
|
|
- const tags = item?.tags ?? [];
|
|
|
- const tagArr = Array.isArray(tags) ? tags : [];
|
|
|
- const images = item?.images;
|
|
|
+ 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;
|
|
|
return {
|
|
|
id: item?.id ?? item?.cuisineId,
|
|
|
@@ -169,7 +186,7 @@ function normalizeOrderItem(item) {
|
|
|
price: item?.totalPrice ?? item?.unitPrice ?? item?.price ?? 0,
|
|
|
image: imageUrl ?? item?.image ?? item?.cuisineImage ?? 'img/icon/shop.png',
|
|
|
quantity: item?.quantity ?? 1,
|
|
|
- tags: tagArr.map((t) => (typeof t === 'string' ? { text: t } : { text: t?.text ?? t?.tagName ?? '' }))
|
|
|
+ tags: normalizeTags(rawTags)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -360,6 +377,12 @@ onLoad(async (e) => {
|
|
|
&__tag {
|
|
|
font-size: 24rpx;
|
|
|
color: #666666;
|
|
|
+ &.signature {
|
|
|
+ color: #FC793D;
|
|
|
+ }
|
|
|
+ &.spicy {
|
|
|
+ color: #2E2E2E;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
&__right {
|