Browse Source

添加搜索功能调试信息

添加详细的调试日志来诊断搜索功能问题:
1. 搜索输入时的商品数量记录
2. 搜索执行时的商品数据示例
3. 筛选过程的每个步骤详细记录
4. 未匹配商品的详细信息

帮助定位搜索功能找不到数据的原因。
pull/3/head
徐飞洋 2 months ago
parent
commit
5e80b41ae4
  1. 67
      pages/index/index.js

67
pages/index/index.js

@ -933,20 +933,45 @@ Page({
// 应用筛选条件 // 应用筛选条件
applyFilters: function(goods, shouldSort = true) { applyFilters: function(goods, shouldSort = true) {
console.log('===== applyFilters 开始 =====');
console.log('输入商品数量:', goods.length);
console.log('搜索关键词:', this.data.searchKeyword);
console.log('选中分类:', this.data.selectedCategory);
let filtered = [...goods] let filtered = [...goods]
if (this.data.selectedCategory !== '全部') { if (this.data.selectedCategory !== '全部') {
const category = this.data.selectedCategory const category = this.data.selectedCategory
console.log('应用分类筛选:', category);
filtered = filtered.filter(item => item.isAd || (item.category === category)) filtered = filtered.filter(item => item.isAd || (item.category === category))
console.log('分类筛选后数量:', filtered.length);
} }
if (this.data.searchKeyword) { if (this.data.searchKeyword) {
const keyword = this.data.searchKeyword.toLowerCase() const keyword = this.data.searchKeyword.toLowerCase()
filtered = filtered.filter(item => console.log('应用关键词搜索:', keyword);
item.isAd || console.log('筛选前商品示例:', filtered.slice(0, 3).map(item => ({
(item.name || '').toLowerCase().includes(keyword) || name: item.name,
(item.region || '').toLowerCase().includes(keyword) productName: item.productName,
) spec: item.spec,
region: item.region
})));
const originalLength = filtered.length;
filtered = filtered.filter(item => {
const nameMatch = (item.name || '').toLowerCase().includes(keyword);
const productNameMatch = (item.productName || '').toLowerCase().includes(keyword);
const specMatch = (item.spec || '').toLowerCase().includes(keyword);
const regionMatch = (item.region || '').toLowerCase().includes(keyword);
const match = item.isAd || nameMatch || productNameMatch || specMatch || regionMatch;
if (!match && originalLength <= 5) { // 只为小数据集打印详细信息
console.log('商品未匹配:', item.name, '| name:', item.name, '| productName:', item.productName, '| spec:', item.spec, '| region:', item.region);
}
return match;
})
console.log('搜索筛选后数量:', filtered.length);
} }
if (this.data.selectedRegion !== '全国') { if (this.data.selectedRegion !== '全国') {
@ -1104,6 +1129,11 @@ Page({
// 搜索输入(带防抖) // 搜索输入(带防抖)
onSearchInput: function(e) { onSearchInput: function(e) {
const keyword = e.detail.value const keyword = e.detail.value
console.log('===== 搜索输入 =====');
console.log('搜索关键词:', keyword);
console.log('当前商品数量:', this.data.goods.length);
console.log('当前筛选商品数量:', this.data.filteredGoods.length);
this.setData({ this.setData({
searchKeyword: keyword searchKeyword: keyword
}) })
@ -1115,6 +1145,9 @@ Page({
// 设置新的定时器,300ms防抖 // 设置新的定时器,300ms防抖
const timer = setTimeout(() => { const timer = setTimeout(() => {
console.log('===== 执行搜索 =====');
console.log('搜索关键词:', this.data.searchKeyword);
console.log('商品数据:', this.data.goods.slice(0, 3)); // 只显示前3个商品用于调试
this.searchGoods() this.searchGoods()
}, 300) }, 300)
@ -2837,28 +2870,4 @@ Page({
}, },
// 跳转到鸡蛋估价页面
goToEvaluatePage() {
console.log('点击鸡蛋估价按钮,跳转到估价页面');
wx.switchTab({
url: '/pages/evaluate/index',
success: (res) => {
console.log('跳转到估价页面成功:', res);
},
fail: (err) => {
console.error('跳转到估价页面失败,尝试使用reLaunch:', err);
wx.reLaunch({
url: '/pages/evaluate/index',
success: (res) => {
console.log('reLaunch到估价页面成功:', res);
},
fail: (err) => {
console.error('reLaunch到估价页面也失败:', err);
}
});
}
});
},
}) })

Loading…
Cancel
Save