xsh_1997 1 tydzień temu
rodzic
commit
5267559e91

+ 14 - 3
shop-app/components/cart/CartItemRow.vue

@@ -13,7 +13,13 @@
13 13
 			<image class="cart-item__pic" :src="item.displayPic" mode="aspectFill" />
14 14
 			<view class="cart-item__info">
15 15
 				<text class="cart-item__name">{{ item.goodsName }}</text>
16
-				<text class="cart-item__spec">{{ item.specText }}</text>
16
+				<view v-if="item.specList && item.specList.length" class="cart-item__specs">
17
+					<text
18
+						v-for="(spec, specIndex) in item.specList"
19
+						:key="specIndex"
20
+						class="cart-item__spec"
21
+					>{{ spec }}</text>
22
+				</view>
17 23
 				<view class="cart-item__price-row">
18 24
 					<text class="cart-item__price">¥{{ item.priceText }}</text>
19 25
 					<text v-if="item.invalidLabel" class="cart-item__tag">{{ item.invalidLabel }}</text>
@@ -117,11 +123,16 @@ function onPlus() {
117 123
 	-webkit-box-orient: vertical;
118 124
 	overflow: hidden;
119 125
 }
120
-.cart-item__spec {
121
-	display: block;
126
+.cart-item__specs {
122 127
 	margin-top: 8rpx;
128
+	display: flex;
129
+	flex-direction: column;
130
+	gap: 4rpx;
131
+}
132
+.cart-item__spec {
123 133
 	font-size: 24rpx;
124 134
 	color: #999;
135
+	line-height: 1.4;
125 136
 }
126 137
 .cart-item__price-row {
127 138
 	margin-top: 12rpx;

+ 6 - 0
shop-app/constants/cart.js

@@ -15,3 +15,9 @@ export const CART_MSG_CROSS_SHOP = '请选择同一店铺的商品结算'
15 15
 
16 16
 /** 确认订单预填数据缓存键(待确认订单页读取) */
17 17
 export const CART_CHECKOUT_STORAGE_KEY = 'cart_checkout_prepare'
18
+
19
+/**
20
+ * 加购时多条规格拼接、购物车展示拆分的专用分隔符
21
+ * 选用 §,正常规格文案里几乎不会出现
22
+ */
23
+export const CART_SPEC_SEPARATOR = '§'

+ 4 - 10
shop-app/utils/cartDisplay.js

@@ -10,16 +10,9 @@ import {
10 10
   CART_INVALID_SHOP_DELETED
11 11
 } from '@/constants/cart'
12 12
 import { SHOP_STATUS_CLOSED } from '@/constants/shop'
13
-const GOODS_PLACEHOLDER = '/static/logo.png'
13
+import { parseCartSpecText } from '@/utils/cartSpec'
14 14
 
15
-/** 纠正历史加购误用 join 产生的 [object Object] 文案 */
16
-function normalizeCartSpecText(specText) {
17
-  const text = (specText || '').trim()
18
-  if (!text || text.includes('[object Object]')) {
19
-    return '默认'
20
-  }
21
-  return text
22
-}
15
+const GOODS_PLACEHOLDER = '/static/logo.png'
23 16
 
24 17
 const INVALID_LABEL_MAP = {
25 18
   [CART_INVALID_OUT_OF_STOCK]: '缺货',
@@ -44,7 +37,8 @@ function mapCartItem(row) {
44 37
     goodsId: row.goodsId,
45 38
     goodsName: row.goodsName || '',
46 39
     displayPic: resolveFileUrl(row.mainPic) || GOODS_PLACEHOLDER,
47
-    specText: normalizeCartSpecText(row.specText),
40
+    specText: (row.specText || '').trim() || '默认',
41
+    specList: parseCartSpecText(row.specText),
48 42
     salePrice: row.salePrice,
49 43
     priceText: formatPrice(row.salePrice),
50 44
     quantity: Number(row.quantity) || 1,

+ 34 - 0
shop-app/utils/cartSpec.js

@@ -0,0 +1,34 @@
1
+import { CART_SPEC_SEPARATOR } from '@/constants/cart'
2
+
3
+/**
4
+ * 详情多条规格 → 加购 specText 字符串
5
+ * 例:「批次:2024春季§包装:袋装」
6
+ */
7
+export function joinCartSpecParts(parts) {
8
+  if (!Array.isArray(parts) || !parts.length) {
9
+    return '默认'
10
+  }
11
+  const list = parts.map((p) => (p != null ? String(p).trim() : '')).filter(Boolean)
12
+  return list.length ? list.join(CART_SPEC_SEPARATOR) : '默认'
13
+}
14
+
15
+/**
16
+ * 购物车 specText → 展示用数组
17
+ */
18
+export function parseCartSpecText(specText) {
19
+  const text = (specText || '').trim()
20
+  if (!text || text.includes('[object Object]')) {
21
+    return ['默认']
22
+  }
23
+  if (text === '默认') {
24
+    return ['默认']
25
+  }
26
+  if (text.includes(CART_SPEC_SEPARATOR)) {
27
+    return text.split(CART_SPEC_SEPARATOR).map((s) => s.trim()).filter(Boolean)
28
+  }
29
+  // 兼容旧数据用「 / 」拼接的规格
30
+  if (text.includes(' / ')) {
31
+    return text.split(' / ').map((s) => s.trim()).filter(Boolean)
32
+  }
33
+  return [text]
34
+}

+ 4 - 3
shop-app/utils/goodsDetail.js

@@ -1,6 +1,7 @@
1 1
 import { resolveFileUrl } from '@/utils/image'
2 2
 import { formatPrice } from '@/utils/format'
3 3
 import { PAGE_GOODS_DETAIL } from '@/utils/pageRoute'
4
+import { joinCartSpecParts } from '@/utils/cartSpec'
4 5
 
5 6
 const GOODS_PLACEHOLDER = '/static/logo.png'
6 7
 const SHOP_AVATAR_PLACEHOLDER = '/static/logo.png'
@@ -68,8 +69,8 @@ export function mapGoodsDetail(data) {
68 69
 }
69 70
 
70 71
 /**
71
- * 详情 specDisplay({ itemName, values[] })→ 加购/展示用文案
72
- * 例:「批次:2024春季 / 包装:袋装」
72
+ * 详情 specDisplay({ itemName, values[] })→ 加购 specText
73
+ * 多条规格用 CART_SPEC_SEPARATOR(§)拼接,购物车再拆开展示
73 74
  */
74 75
 export function formatSpecDisplayText(specDisplay) {
75 76
   if (!Array.isArray(specDisplay) || !specDisplay.length) {
@@ -91,7 +92,7 @@ export function formatSpecDisplayText(specDisplay) {
91 92
       return name || valText
92 93
     })
93 94
     .filter(Boolean)
94
-  return parts.length ? parts.join(' / ') : '默认'
95
+  return joinCartSpecParts(parts)
95 96
 }
96 97
 
97 98
 function mapService(row) {