From f6abfa81f340b104e7549434181a240370711cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Mon, 26 Jan 2026 17:14:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api-response.json | 1 + pages/goods-detail/goods-detail.js | 120 +++++++++++++++++++++++---- pages/goods-detail/goods-detail.wxml | 6 +- 3 files changed, 108 insertions(+), 19 deletions(-) create mode 100644 api-response.json diff --git a/api-response.json b/api-response.json new file mode 100644 index 0000000..2a65fdb --- /dev/null +++ b/api-response.json @@ -0,0 +1 @@ +{"success":true,"code":200,"message":"获取商品列表成功","products":[{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E9%BB%91%E5%87%A4/image/dd4dc9ac5184f44038a91a1078f1acc2.jpeg"],"id":2385,"productId":"product_1769412832105_807","sellerId":"user_1763624963234_sa4y5rarm","productName":"黑凤","price":"100,200,300","costprice":"111,222,333","quantity":"11,22,33","grossWeight":"","yolk":"未知","specification":"净重46-47,净重45-46,净重44-45","created_at":"2026-01-26T07:33:52.000Z","updated_at":"2026-01-26T07:34:19.000Z","status":"published","region":"甘肃省 金昌市","sourceType":"鸡场直销","supplyStatus":"预售","category":"白壳","producting":"1*420枚新包装","description":"测试数据,不参考","frequency":8,"seller":{"userId":"user_1763624963234_sa4y5rarm","name":"微信用户","nickName":"刘琴","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"刘琴","sellerName":"刘琴"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BB%BF%E5%A3%B3/image/61ec55c3f04dc9031fd50c4df2d8306d.jpeg"],"id":2381,"productId":"product_1769393951492_146","sellerId":"user_1763534257815_09vv9nnfe","productName":"绿壳","price":"235","costprice":"227.5","quantity":"110","grossWeight":"","yolk":"红心","specification":"毛重48-49","created_at":"2026-01-26T02:19:12.000Z","updated_at":"2026-01-26T05:09:00.000Z","status":"published","region":"湖北省 随州市","sourceType":"鸡场直销","supplyStatus":"现货","category":"绿壳","producting":"1*420枚新包装","description":"新箱新托,420枚件装","frequency":1,"seller":{"userId":"user_1763534257815_09vv9nnfe","name":"微信用户","nickName":"李真音","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"李真音","sellerName":"李真音"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BB%BF%E5%A3%B3/image/d25c374223aa7365b86f44b678d04c59.jpeg","https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BB%BF%E5%A3%B3/image/51790f5daa1ed496bd72e8f52fc1259f.jpeg"],"id":2379,"productId":"product_1769392983344_47","sellerId":"user_1763534304462_47zwzrx5d","productName":"绿壳","price":"205,205,200","costprice":"192.5,197.5,192.5","quantity":"130,200,300","grossWeight":"","yolk":"双色","specification":"毛重42-43,毛重44-45,毛重40-41","created_at":"2026-01-26T02:03:03.000Z","updated_at":"2026-01-26T02:13:18.000Z","status":"published","region":"陕西省 渭南市","sourceType":"鸡场直销","supplyStatus":"现货","category":"绿壳","producting":"1*360枚新包装","description":"新箱新托","frequency":11,"seller":{"userId":"user_1763534304462_47zwzrx5d","name":"微信用户","nickName":"何佳芹","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"何佳芹","sellerName":"何佳芹"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BD%97%E6%9B%BC%E7%B2%89/image/57c84a5b478ddb1e6453f99e4614d149.jpeg"],"id":2378,"productId":"product_1769392387188_907","sellerId":"user_1763534215363_8svd1vyts","productName":"罗曼粉","price":null,"costprice":"3.95","quantity":"450","grossWeight":"","yolk":"双色","specification":"净重44-45","created_at":"2026-01-26T01:53:07.000Z","updated_at":null,"status":"published","region":"重庆市 重庆市","sourceType":"鸡场直销","supplyStatus":"现货","category":"粉壳","producting":"1*360枚新包装","description":"5.6扣5","frequency":0,"seller":{"userId":"user_1763534215363_8svd1vyts","name":"微信用户","nickName":"汤敏","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"汤敏","sellerName":"汤敏"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BD%97%E6%9B%BC%E7%B2%89/image/e20d9bf86dd2e18fc90e1fb355fa9bd7.jpeg","https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BD%97%E6%9B%BC%E7%B2%89/image/9c45b628a42e0f07013c0578ff7c3da6.jpeg"],"id":2377,"productId":"product_1769392357166_615","sellerId":"user_1763534215363_8svd1vyts","productName":"罗曼粉","price":null,"costprice":"3.9","quantity":"750","grossWeight":"","yolk":"红心","specification":"净重44-45","created_at":"2026-01-26T01:52:37.000Z","updated_at":null,"status":"published","region":"重庆市 重庆市","sourceType":"鸡场直销","supplyStatus":"现货","category":"粉壳","producting":"1*360枚新包装","description":"箱皮5扣4.8","frequency":0,"seller":{"userId":"user_1763534215363_8svd1vyts","name":"微信用户","nickName":"汤敏","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"汤敏","sellerName":"汤敏"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E6%B5%B7%E8%93%9D%E8%A4%90/image/2358f7cc79f2cf28c674fea00bc1289c.jpeg","https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E6%B5%B7%E8%93%9D%E8%A4%90/image/18980e9dfa994c8401e4c026f48920fd.jpeg"],"id":2376,"productId":"product_1769392326915_923","sellerId":"user_1763534304462_47zwzrx5d","productName":"海蓝褐","price":"183","costprice":"178","quantity":"300","grossWeight":"","yolk":"黄心","specification":"毛重50-51","created_at":"2026-01-26T01:52:07.000Z","updated_at":"2026-01-26T02:12:52.000Z","status":"published","region":"云南省 玉溪市","sourceType":"鸡场直销","supplyStatus":"现货","category":"褐壳","producting":"1*360枚新包装","description":"新箱新托","frequency":4,"seller":{"userId":"user_1763534304462_47zwzrx5d","name":"微信用户","nickName":"何佳芹","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"何佳芹","sellerName":"何佳芹"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BD%97%E6%9B%BC%E7%B2%89/image/1ce66dc28fe48bc5c5128ec125a2514a.jpeg","https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BD%97%E6%9B%BC%E7%B2%89/image/7b95d276041633de8992930aca740829.jpeg"],"id":2375,"productId":"product_1769392294531_916","sellerId":"user_1763534215363_8svd1vyts","productName":"罗曼粉","price":null,"costprice":"3.85,3.85,168","quantity":"85,770,480","grossWeight":"","yolk":"红心","specification":"净重42-43,净重43-44,净重40-41","created_at":"2026-01-26T01:51:35.000Z","updated_at":null,"status":"published","region":"四川省 凉山彝族自治州","sourceType":"鸡场直销","supplyStatus":"现货","category":"粉壳","producting":"1*360枚新包装","description":"5斤","frequency":0,"seller":{"userId":"user_1763534215363_8svd1vyts","name":"微信用户","nickName":"汤敏","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"汤敏","sellerName":"汤敏"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E5%A4%A7%E5%8D%88%E9%87%91%E5%87%A4/image/01dd7d0d3225b7d673c9afa2290af07f.jpeg","https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E5%A4%A7%E5%8D%88%E9%87%91%E5%87%A4/image/e2b44edd733bfee5d3b78cd65f3919b1.jpeg"],"id":2373,"productId":"product_1769392243606_532","sellerId":"user_1763624963234_sa4y5rarm","productName":"大午金凤","price":null,"costprice":"163,163","quantity":"450,500","grossWeight":"","yolk":"黄心","specification":"净重36-38,净重37-38","created_at":"2026-01-26T01:50:44.000Z","updated_at":null,"status":"published","region":"四川省 乐山市","sourceType":"鸡场直销","supplyStatus":"现货","category":"粉壳","producting":"1*420枚新包装","description":"420枚包装一车 360枚包装一车","frequency":0,"seller":{"userId":"user_1763624963234_sa4y5rarm","name":"微信用户","nickName":"刘琴","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"刘琴","sellerName":"刘琴"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BD%97%E6%9B%BC%E7%B2%89/image/128328c43217d72b8350453df164d1f9.jpeg","https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BD%97%E6%9B%BC%E7%B2%89/image/2473d908bd63c050dcdd99fb04eb19bc.jpeg"],"id":2372,"productId":"product_1769392068391_647","sellerId":"user_1763534227412_0y4f3wtxj","productName":"罗曼粉","price":null,"costprice":"164","quantity":"360","grossWeight":"","yolk":"红心","specification":"净重37-39","created_at":"2026-01-26T01:47:48.000Z","updated_at":"2026-01-26T01:48:36.000Z","status":"published","region":"四川省 乐山市","sourceType":"鸡场直销","supplyStatus":"现货","category":"粉壳","producting":"1*360枚新包装","description":"粉壳红心小码,净重37-39,350件","frequency":0,"seller":{"userId":"user_1763534227412_0y4f3wtxj","name":"微信用户","nickName":"吴海燕","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"吴海燕","sellerName":"吴海燕"},"reservedCount":0},{"imageUrls":["https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BB%BF%E5%A3%B3/image/69f5800a2daf9ac4f9bfd891280a61e3.jpeg","https://my-supplier-photos.oss-cn-chengdu.aliyuncs.com/products/%E7%BB%BF%E5%A3%B3/image/a39008eebe9cb514a0126fe3d6d27eb6.jpeg"],"id":2371,"productId":"product_1769392017962_941","sellerId":"user_1763534304462_47zwzrx5d","productName":"绿壳","price":"205,205,205","costprice":"198,198,198","quantity":"100,100,100","grossWeight":"","yolk":"红心","specification":"净重35-36,净重34-35,净重33-34","created_at":"2026-01-26T01:46:58.000Z","updated_at":"2026-01-26T02:12:04.000Z","status":"published","region":"湖北省 武汉市","sourceType":"鸡场直销","supplyStatus":"现货","category":"绿壳","producting":"1*360枚新包装","description":"旧箱新托","frequency":5,"seller":{"userId":"user_1763534304462_47zwzrx5d","name":"微信用户","nickName":"何佳芹","avatarUrl":"https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0","sellerNickName":"何佳芹","sellerName":"何佳芹"},"reservedCount":0}],"total":21,"page":1,"pageSize":10,"totalPages":3} diff --git a/pages/goods-detail/goods-detail.js b/pages/goods-detail/goods-detail.js index 3baa441..435059e 100644 --- a/pages/goods-detail/goods-detail.js +++ b/pages/goods-detail/goods-detail.js @@ -1854,8 +1854,8 @@ Page({ phoneNumber: phoneNumber // 添加用户标识信息,用于判断是否可以删除 }; - // 更新评论列表 - const comments = [newComment, ...this.data.comments]; + // 更新评论列表 - add new comment to the end + const comments = [...this.data.comments, newComment]; this.setData({ comments: comments, @@ -1882,10 +1882,80 @@ Page({ title: '网络错误,评论提交失败', icon: 'none' }); - }); + }); + }, + + // 20 default comments + getDefaultComments() { + return [ + "鸡蛋品相贼好无破损,规格统一超适合批发", + "个头匀溜大小一致,装箱发货一点不费劲", + "包装严实防震,整车运输下来个个完好", + "蛋液浓稠清亮,品相达标完全符合供货要求", + "性价比真绝了,新鲜度在线囤货超划算", + "农家散养蛋品相佳,蛋黄紧实供货超稳定", + "物流嗖嗖快,到货鸡蛋无磕碰超省心", + "蛋壳干净无污渍,分拣打包效率直接拉满", + "个个饱满无瘪壳,市场铺货回头客贼多", + "分量超足规格齐,商超供货完全没毛病", + "无抗生素达标蛋,走商超渠道妥妥放心", + "蛋壳硬度够,装卸搬运全程零损耗", + "防震包装太贴心,长途运输损耗率超低", + "保鲜期够长,放一周品相依旧很能打", + "蛋体完整无瑕疵,分拣挑拣省超多功夫", + "品质稳定没色差,长期合作完全没问题", + "货源稳定供货及时,补货节奏卡得刚刚好", + "发货快包装硬,对接商超渠道超靠谱", + "蛋黄蛋清分层好,加工拿货性价比拉满", + "品质远超预期,后续订单必须锁定这家" + ]; + }, + + // Seeded random number generator for consistent results + seededRandom(seed) { + // Improved seeded random using a linear congruential generator + const a = 1103515245; + const c = 12345; + const m = Math.pow(2, 31); + const nextSeed = (a * seed + c) % m; + return nextSeed / m; + }, + + // Get consistent random comments based on product ID + getConsistentRandomComments(productId, count = 2) { + const defaultComments = this.getDefaultComments(); + // Generate order-dependent seed by multiplying character codes with their positions + const seed = productId.toString().split('').reduce((sum, char, index) => sum + (char.charCodeAt(0) * (index + 1)), 0); + + // Create an array of comment objects with their original indices + const commentsWithIndices = defaultComments.map((comment, index) => ({ + comment, + index + })); + + // Create a shuffled array based on the seed and comment index + const shuffled = [...commentsWithIndices].sort((a, b) => { + const rand1 = this.seededRandom(seed + a.index); + const rand2 = this.seededRandom(seed + b.index); + return rand1 - rand2; + }); + + // Return the first 'count' comments + return shuffled.slice(0, count).map((item, index) => ({ + id: `default_comment_${productId}_${index}`, + nickname: '匿名用户', + avatar: 'https://via.placeholder.com/40', + comments: item.comment, + like: Math.floor(this.seededRandom(seed + index) * 50), + hate: Math.floor(this.seededRandom(seed + index + 100) * 5), + liked: false, + hated: false, + replies: [], + phoneNumber: '', + isDefault: true + })); }, - // 加载商品评论 loadComments: function(productId) { console.log('开始加载商品评论,商品ID:', productId); @@ -1921,17 +1991,33 @@ Page({ commentsData = []; } - // 检查返回的评论是否都属于当前用户 - const allCommentsBelongToCurrentUser = commentsData.every(comment => - comment.phoneNumber === this.data.currentUserPhone - ); - console.log('所有评论是否都属于当前用户:', allCommentsBelongToCurrentUser); + // Remove duplicate comments + const uniqueComments = []; + const seenComments = new Set(); + commentsData.forEach(comment => { + const commentKey = comment.comments + (comment.phoneNumber || ''); + if (!seenComments.has(commentKey)) { + seenComments.add(commentKey); + uniqueComments.push(comment); + } + }); + commentsData = uniqueComments; - // 如果所有评论都属于当前用户,可能服务器没有返回所有评论 - if (allCommentsBelongToCurrentUser && commentsData.length > 0) { - console.warn('所有评论都属于当前用户,可能服务器没有返回所有评论'); - console.warn('当前用户手机号:', this.data.currentUserPhone); - } + // Always add default comments at the beginning + const defaultComments = this.getConsistentRandomComments(productId, 2); + commentsData = [...defaultComments, ...commentsData]; + + // 检查返回的评论是否都属于当前用户 + const allCommentsBelongToCurrentUser = commentsData.every(comment => + comment.phoneNumber === this.data.currentUserPhone + ); + console.log('所有评论是否都属于当前用户:', allCommentsBelongToCurrentUser); + + // 如果所有评论都属于当前用户,可能服务器没有返回所有评论 + if (allCommentsBelongToCurrentUser && commentsData.length > 0) { + console.warn('所有评论都属于当前用户,可能服务器没有返回所有评论'); + console.warn('当前用户手机号:', this.data.currentUserPhone); + } // 格式化评论时间为相对时间 const formattedComments = commentsData.map(comment => ({ @@ -1952,9 +2038,11 @@ Page({ .catch(err => { console.error('获取评论失败:', err); console.error('错误详情:', JSON.stringify(err, null, 2)); - // 加载失败时设置空数组,触发空评论状态的显示 + // 加载失败时使用默认评论 + console.log('使用默认评论'); + const defaultComments = this.getConsistentRandomComments(productId, 2); this.setData({ - comments: [] + comments: defaultComments }); }); }, diff --git a/pages/goods-detail/goods-detail.wxml b/pages/goods-detail/goods-detail.wxml index a6f61f9..8a4a0cf 100644 --- a/pages/goods-detail/goods-detail.wxml +++ b/pages/goods-detail/goods-detail.wxml @@ -210,10 +210,10 @@ {{item.nickname || '匿名用户'}} - {{item.time || '刚刚'}} + {{item.time || '刚刚'}} - - + + 删除