diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 2dd76ca..52cb74c 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -26,63 +26,26 @@ function calculateDisplayPrice(price) { return String(price); } -// 格式化分享标题 - 按优先级: 地区、规格、数量、蛋黄颜色、蛋壳颜色 +// 格式化分享标题 - 只显示货源描述 function formatShareTitle(goodsDetail) { console.log('===== formatShareTitle 开始 ====='); console.log('goodsDetail:', JSON.stringify(goodsDetail, null, 2)); - const titleParts = []; - - // 1. 地区 (region) - const region = (goodsDetail.region || '').trim(); - console.log('region:', region); - if (region) { - titleParts.push(region); - } - - // 2. 规格 (specification/spec) - const specification = (goodsDetail.specification || goodsDetail.spec || goodsDetail.specs || '').trim(); - console.log('specification:', specification); - if (specification) { - titleParts.push(specification); - } - - // 3. 数量 (quantity) - const quantity = (goodsDetail.quantity || '').trim(); - console.log('quantity:', quantity); - if (quantity) { - titleParts.push(`${quantity}件`); - } - - // 4. 蛋黄颜色 (yolk) - const yolk = (goodsDetail.yolk || '').trim(); - console.log('yolk:', yolk); - if (yolk) { - titleParts.push(yolk); - } + // 优先使用货源描述 + const description = (goodsDetail.description || '').trim(); + console.log('description:', description); - // 5. 蛋壳颜色 (category) - const category = (goodsDetail.category || '').trim(); - console.log('category:', category); - if (category) { - titleParts.push(category); + if (description) { + console.log('最终标题:', description); + console.log('===== formatShareTitle 结束 ====='); + return description; } - // 过滤空值后组合标题 - const validParts = titleParts.filter(part => part && part.length > 0); - const result = validParts.join(' '); - - console.log('titleParts:', titleParts); - console.log('validParts:', validParts); - console.log('最终标题:', result); + // 如果没有货源描述,返回默认标题 + const defaultTitle = goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; + console.log('最终标题:', defaultTitle); console.log('===== formatShareTitle 结束 ====='); - - if (validParts.length > 0) { - return result; - } - - // 如果没有匹配的数据,返回默认标题 - return goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; + return defaultTitle; } // 构建商品分享消息内容