From 530844e57da4d077abce48e99744b0ad49492fd3 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: Sat, 27 Dec 2025 16:29:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81=E6=97=B6?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E5=8E=9F=E6=9C=89=E6=8E=92=E5=88=97=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index 1df2bb3..4d75c90 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -481,7 +481,7 @@ Page({ updatedGoods = newGoods } - const filteredGoods = this.applyFilters(updatedGoods) + const filteredGoods = this.applyFilters(updatedGoods, !isLoadMore) console.log('filteredGoods 数量:', filteredGoods.length) console.log('filteredGoods[0]:', filteredGoods[0]) console.log('filteredGoods[1]:', filteredGoods[1]) @@ -618,7 +618,7 @@ Page({ }, // 应用筛选条件 - applyFilters: function(goods) { + applyFilters: function(goods, shouldSort = true) { let filtered = [...goods] if (this.data.selectedCategory !== '全部') { @@ -640,19 +640,21 @@ Page({ filtered = filtered.filter(item => item.isAd || (item.region && item.region.includes(selectedRegion))) } - filtered.sort((a, b) => { - const reservedCountA = a.reservedCount || 0 - const reservedCountB = b.reservedCount || 0 - if (reservedCountB !== reservedCountA) return reservedCountB - reservedCountA - - const priceA = parseFloat(a.price || 0) - const priceB = parseFloat(b.price || 0) - if (!isNaN(priceB) && !isNaN(priceA) && priceA !== priceB) return priceA - priceB - - const createdAtA = new Date(a.createdAt || 0).getTime() - const createdAtB = new Date(b.createdAt || 0).getTime() - return createdAtB - createdAtA - }) + if (shouldSort) { + filtered.sort((a, b) => { + const reservedCountA = a.reservedCount || 0 + const reservedCountB = b.reservedCount || 0 + if (reservedCountB !== reservedCountA) return reservedCountB - reservedCountA + + const priceA = parseFloat(a.price || 0) + const priceB = parseFloat(b.price || 0) + if (!isNaN(priceB) && !isNaN(priceA) && priceA !== priceB) return priceA - priceB + + const createdAtA = new Date(a.createdAt || 0).getTime() + const createdAtB = new Date(b.createdAt || 0).getTime() + return createdAtB - createdAtA + }) + } return filtered },