consumer模块完成度95%,实现数据库多端注册登录,优化安卓端小程序bug
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,10 @@
|
||||
<text class="service-icon">👑</text>
|
||||
<text class="service-text">会员中心</text>
|
||||
</view>
|
||||
<view class="service-item" @click="goToSettings">
|
||||
<text class="service-icon">⚙️</text>
|
||||
<text class="service-text">设置</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -102,7 +106,7 @@
|
||||
<view class="order-shortcuts">
|
||||
<view class="section-header-row">
|
||||
<text class="section-title">我的订单</text>
|
||||
<text class="view-all" @click="goToOrders(currentOrderTab)">查看更多 ></text>
|
||||
<text class="view-all" @click="goToOrders(currentOrderTab)">查看更多 ❯</text>
|
||||
</view>
|
||||
<view class="order-tabs">
|
||||
<view class="order-tab" :class="{ active: currentOrderTab === 'all' }" @click="switchOrderTab('all')">
|
||||
@@ -144,7 +148,7 @@
|
||||
<view class="order-shop">
|
||||
<text class="shop-icon">🏪</text>
|
||||
<text class="shop-name">{{ getOrderShopName(order) }}</text>
|
||||
<text class="shop-arrow">›</text>
|
||||
<text class="shop-arrow"> › </text>
|
||||
</view>
|
||||
<view class="status-row">
|
||||
<text class="order-status-text" :class="getOrderStatusClass(order.status)">{{ getOrderStatusText(order.status) }}</text>
|
||||
|
||||
Reference in New Issue
Block a user