From d3ef343f5e9adbb811bf3e5a18305619af6ce277 Mon Sep 17 00:00:00 2001 From: Trae AI Date: Tue, 6 Jan 2026 13:54:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E6=A0=BC=E5=BC=8F=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=B4=A7=E6=BA=90=E6=8F=8F=E8=BF=B0=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods-detail/goods-detail.js | 102 +++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 0ac0378..ba8897a 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -11,6 +11,88 @@ function getSourceTypeColor(sourceType) { return colorMap[sourceType] || '#4d9dff'; } +// 格式化分享标题 - 按优先级: 规格、地区、数量(鸡场直销-三方货源)、蛋黄颜色、蛋壳颜色 +function formatShareTitle(goodsDetail) { + console.log('===== formatShareTitle 开始 ====='); + console.log('goodsDetail:', JSON.stringify(goodsDetail, null, 2)); + + const titleParts = []; + + // 1. 规格 (specification/spec) + const specification = (goodsDetail.specification || goodsDetail.spec || goodsDetail.specs || '').trim(); + console.log('specification:', specification); + if (specification) { + titleParts.push(specification); + } + + // 2. 地区 (region) + const region = (goodsDetail.region || '').trim(); + console.log('region:', region); + if (region) { + titleParts.push(region); + } + + // 3. 数量 + (鸡场直销-三方货源) + const quantity = (goodsDetail.quantity || '').trim(); + const sourceType = (goodsDetail.sourceType || '').trim(); + console.log('quantity:', quantity, 'sourceType:', sourceType); + if (quantity) { + const sourceLabel = sourceType ? `(${sourceType})` : ''; + titleParts.push(`${quantity}件${sourceLabel}`); + } else if (sourceType) { + titleParts.push(`(${sourceType})`); + } + + // 4. 蛋黄颜色 (yolk) + const yolk = (goodsDetail.yolk || '').trim(); + console.log('yolk:', yolk); + if (yolk) { + titleParts.push(yolk); + } + + // 5. 蛋壳颜色 (eggshell) - 使用品种(breed)作为备选 + const eggshell = (goodsDetail.eggshell || goodsDetail.shell || goodsDetail.breed || '').trim(); + console.log('eggshell:', eggshell); + if (eggshell) { + titleParts.push(eggshell); + } + + // 6. 货源描述 (description) + const description = (goodsDetail.description || goodsDetail.shareTitle || '').trim(); + console.log('description:', description); + if (description) { + titleParts.push(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); + console.log('===== formatShareTitle 结束 ====='); + + if (validParts.length > 0) { + return result; + } + + // 如果没有匹配的数据,返回默认标题 + return goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; +} + +// 获取适合分享的图片 - 优先使用正方形图片填满分享框 +function getShareImageUrl(goodsDetail) { + const imageUrls = goodsDetail.imageUrls || []; + + if (imageUrls.length > 0) { + // 返回第一张图片作为分享图片 + return imageUrls[0]; + } + + return '/images/你有好蛋.png'; +} + // 媒体类型判断函数 function isVideoUrl(url) { if (!url || typeof url !== 'string') { @@ -202,7 +284,7 @@ Page({ // 分享给朋友/群聊 onShareAppMessage() { const goodsDetail = this.data.goodsDetail || {}; - const title = goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; + const title = formatShareTitle(goodsDetail); // 获取联系人、电话号码和地区信息 const contactName = goodsDetail.product_contact || ''; @@ -235,14 +317,14 @@ Page({ return { title: title, path: sharePath, - imageUrl: goodsDetail.imageUrls && goodsDetail.imageUrls.length > 0 ? goodsDetail.imageUrls[0] : '/images/你有好蛋.png' + imageUrl: getShareImageUrl(goodsDetail) } }, // 分享到朋友圈 onShareTimeline() { const goodsDetail = this.data.goodsDetail || {}; - const title = goodsDetail.name ? `优质鸡蛋 - ${goodsDetail.name}` : '优质鸡蛋货源'; + const title = formatShareTitle(goodsDetail); // 获取联系人、电话号码和地区信息 const contactName = goodsDetail.product_contact || ''; @@ -272,7 +354,7 @@ Page({ return { title: title, query: contactQuery, - imageUrl: goodsDetail.imageUrls && goodsDetail.imageUrls.length > 0 ? goodsDetail.imageUrls[0] : '/images/你有好蛋.png' + imageUrl: getShareImageUrl(goodsDetail) } }, @@ -415,6 +497,18 @@ Page({ console.log('移除收藏状态变化事件监听'); } }, + + onReady: function () { + wx.updateShareMenu({ + withShareTicket: true, + success: () => { + console.log('分享菜单配置成功'); + }, + fail: (err) => { + console.log('分享菜单配置失败:', err); + } + }); + }, loadGoodsDetail: function (productId, preloadedData = null, contactFromShare = null) { // 首先显示预加载的数据,确保UI快速响应