consumer模块完成度95%,实现数据库多端注册登录,优化安卓端小程序bug

This commit is contained in:
cyh666666
2026-03-10 17:08:20 +08:00
parent 2262d1bfd9
commit 5517c93666
1010 changed files with 1688 additions and 4919 deletions

View File

@@ -334,35 +334,55 @@ const updateRecommendList = (recommends: Product[]) => {
const refreshRecommend = async () => {
try {
// 鷻加随机偏移量, const randomOffset = Math.floor(Math.random() * 1000)
const hotResp = await supabaseService.searchProducts('', recommendPage.value, 6, 'sales')
const recommends = hotResp.data
// 1. 模拟市面加载感,锁定按钮防止连续快速点击
if (loading.value) return
loading.value = true
// 如果新页码没有数据,重置为第一页再试一次
if (recommends.length === 0 && recommendPage.value > 1) {
recommendPage.value = 1
const firstPageResp = await supabaseService.searchProducts('', 1, 6, 'sales')
const firstRecommends = firstPageResp.data
if (firstRecommends.length > 0) {
updateRecommendList(firstRecommends)
uni.showToast({
title: '已重置推荐',
icon: 'none'
})
}
return
uni.showLoading({
title: '正在挑选...',
mask: true
})
// 2. 模拟市面“随机性”逻辑:
// 淘宝京东不会按顺序翻页,而是跳跃选取页码,并打乱排序规则
const maxOffsetPages = 20 // 假设数据库中至少有 20 页热推商品
const sorts = ['sales', 'price_asc', 'rating']
// 随机页码 + 随机排序 = 每次点击都有新发现
const nextRandomPage = Math.floor(Math.random() * maxOffsetPages) + 1
const randomSort = sorts[Math.floor(Math.random() * sorts.length)]
console.log(`[refreshRecommend] 换一批: 随机页=${nextRandomPage}, 随机排=${randomSort}`)
const hotResp = await supabaseService.searchProducts('', nextRandomPage, 6, randomSort)
let recommends = hotResp.data
// 3. 兜底逻辑:如果随机到的页码没数据,回退到第 1 页
if (recommends.length === 0) {
const fallbackResp = await supabaseService.searchProducts('', 1, 6, 'sales')
recommends = fallbackResp.data
}
// 4. 前端打乱 (Shuffle):即使是同一页数据,乱序排布也会增加“新鲜感”
if (recommends.length > 0) {
recommends.sort(() => Math.random() - 0.5)
updateRecommendList(recommends)
uni.hideLoading()
uni.showToast({
title: '已更新推荐',
icon: 'none'
title: '已为你换一批好物',
icon: 'none',
duration: 1000
})
} else {
uni.hideLoading()
}
} catch (error) {
uni.hideLoading()
console.error('刷新推荐失败:', error)
uni.showToast({ title: '加载失败,请重试', icon: 'none' })
} finally {
loading.value = false
}
}