consumer模块完成度95%,安卓端大部分页面能正常获取数据,页面样式显示基本正常,逐渐完善;消费者端的积分、余额、评价、优惠券等小模块正在完善

This commit is contained in:
cyh666666
2026-03-02 17:21:19 +08:00
parent df84fd8642
commit 7e74b88e1e
34 changed files with 17088 additions and 1751 deletions

View File

@@ -174,7 +174,7 @@
</view>
</view> -->
<!-- 热销药品专区 -->
<!-- 热销药品专区 -->
<view class="hot-products">
<view class="section-header">
<view class="title-section">
@@ -285,10 +285,12 @@ const hasMore = ref(true)
const activeSort = ref('recommend') // 默认展示智能推荐
const activeFilter = ref('recommend')
const currentPage = ref(1)
const priceAscending = ref(true) // 价格排序方向true=升序false=降序
// 数据源
const hotProducts = ref<Product[]>([])
const recommendedProducts = ref<Product[]>([])
const hotKeywords = ref<string[]>([])
// 屏幕尺寸检测
const isMobile = ref(false)
@@ -367,7 +369,10 @@ const loadCategories = async (): Promise<void> => {
// 获取二级分类数据
const loadSubCategories = async (parentId: string): Promise<void> => {
try {
console.log('[loadSubCategories] 开始加载二级分类, parentId:', parentId)
const subData = await supabaseService.getSubCategories(parentId)
console.log('[loadSubCategories] 获取到二级分类数量:', subData.length)
console.log('[loadSubCategories] 二级分类数据:', JSON.stringify(subData))
subCategories.value = subData
} catch (error) {
console.error('加载子分类数据失败:', error)
@@ -377,18 +382,31 @@ const loadSubCategories = async (parentId: string): Promise<void> => {
// 点击一级分类
const onParentCategoryClick = async (category: Category): Promise<void> => {
// 如果已经选中,则切换显示/隐藏二级分类
if (selectedParentCategory.value != null && selectedParentCategory.value.id === category.id) {
console.log('[onParentCategoryClick] 点击一级分类:', category.name, 'id:', category.id)
// 如果已经选中,则切换显示/隐藏二级分类
if (selectedParentCategory.value != null && selectedParentCategory.value.id === category.id) {
console.log('[onParentCategoryClick] 切换显示状态')
showSubCategories.value = !showSubCategories.value
return
}
}
// 选中新的分类
selectedParentCategory.value = category
showSubCategories.value = true
// 选中新的分类
selectedParentCategory.value = category
showSubCategories.value = true
console.log('[onParentCategoryClick] showSubCategories 设置为 true')
// 加载二级分类
await loadSubCategories(category.id)
// 加载二级分类
await loadSubCategories(category.id)
// 如果没有二级分类,直接跳转到分类页
if (subCategories.value.length == 0) {
console.log('[onParentCategoryClick] 没有二级分类,直接跳转到分类页')
uni.setStorageSync('selectedCategory', category.id)
uni.switchTab({
url: '/pages/mall/consumer/category'
})
}
}
// 点击二级分类
@@ -453,32 +471,28 @@ const doLoadHotProducts = async (targetLimit: number, resolve: (value: void) =>
switch (activeSort.value) {
case 'sales':
console.log('调用 getHotProducts')
products = await supabaseService.getHotProducts(limit)
console.log('调用 getProductsBySales')
products = await supabaseService.getProductsBySales(limit)
break
case 'price':
console.log('调用 getProductsByPrice')
// 按价格升序(从低到高)
products = await supabaseService.getProductsByPrice(limit, true)
console.log('调用 getProductsByPrice, 升序:', priceAscending.value)
products = await supabaseService.getProductsByPrice(limit, priceAscending.value)
break
case 'new':
console.log('调用 getProductsByNewest')
// 按创建时间,最新的在前
products = await supabaseService.getProductsByNewest(limit)
break
case 'recommend':
console.log('调用 getRecommendedProducts')
// 推荐商品带badge的商品
products = await supabaseService.getRecommendedProducts(limit)
console.log('调用 getSmartRecommendations')
products = await supabaseService.getSmartRecommendations(limit)
break
case 'discount':
console.log('调用 getDiscountProducts')
// 特价商品badge为'特价'
products = await supabaseService.getDiscountProducts(limit)
break
default:
console.log('调用默认 getHotProducts')
products = await supabaseService.getHotProducts(limit)
console.log('调用默认 getProductsBySales')
products = await supabaseService.getProductsBySales(limit)
}
console.log('加载到的商品数量:', products.length)
@@ -516,6 +530,25 @@ function loadRecommendedProducts(limit: number): Promise<void> {
})
}
// 加载热搜词
const loadHotKeywords = async (): Promise<void> => {
try {
const keywords = await supabaseService.getHotKeywords(10)
hotKeywords.value = keywords
console.log('加载热搜词:', keywords.length, '个')
} catch (error) {
console.error('加载热搜词失败:', error)
hotKeywords.value = []
}
}
// 点击热搜词进行搜索
const searchByKeyword = (keyword: string): void => {
uni.navigateTo({
url: `/pages/mall/consumer/search?keyword=${encodeURIComponent(keyword)}`
})
}
// 初始化数据
const initData = async () => {
// 首先确保用户资料已加载
@@ -527,6 +560,7 @@ const initData = async () => {
}
await loadCategories()
await loadBrands()
await loadHotKeywords()
await loadHotProducts(defaultLoadLimit)
await loadRecommendedProducts(defaultLoadLimit)
}
@@ -719,7 +753,17 @@ const switchBrand = (brand: Brand) => {
// 切换排序
const switchSort = (sortId: string) => {
activeSort.value = sortId
// 如果点击的是价格排序,切换升序/降序
if (sortId === 'price' && activeSort.value === 'price') {
priceAscending.value = !priceAscending.value
console.log('切换价格排序方向,升序:', priceAscending.value)
} else {
// 切换到其他排序时,重置价格排序为升序
if (sortId !== 'price') {
priceAscending.value = true
}
activeSort.value = sortId
}
hasMore.value = true // 重置加载更多状态
// 重新加载热销商品,排序由 Supabase 服务处理
loadHotProducts(defaultLoadLimit)
@@ -776,26 +820,45 @@ const loadMore = async () => {
try {
// 获取当前热销商品的数量
const currentCount = hotProducts.value.length
const nextLimit = currentCount + 6
const nextPage = Math.floor(currentCount / 6) + 1
const additionalLimit = 6
console.log('开始加载更多,当前数量:', currentCount, '目标数量:', nextLimit)
console.log('开始加载更多,当前数量:', currentCount, '页码:', nextPage)
// 加载更多热销商品
await loadHotProducts(nextLimit)
// 加载更多商品
let newProducts: Product[] = []
switch (activeSort.value) {
case 'sales':
newProducts = await supabaseService.getProductsBySales(currentCount + additionalLimit)
break
case 'price':
newProducts = await supabaseService.getProductsByPrice(currentCount + additionalLimit, priceAscending.value)
break
case 'new':
newProducts = await supabaseService.getProductsByNewest(currentCount + additionalLimit)
break
case 'recommend':
newProducts = await supabaseService.getSmartRecommendations(currentCount + additionalLimit)
break
case 'discount':
newProducts = await supabaseService.getDiscountProducts(currentCount + additionalLimit)
break
default:
newProducts = await supabaseService.getProductsBySales(currentCount + additionalLimit)
}
console.log('加载到的新商品数量:', newProducts.length)
// 检查是否还有更多数据
if (hotProducts.value.length === currentCount) {
if (newProducts.length <= currentCount) {
hasMore.value = false
uni.showToast({
title: '没有更多了',
icon: 'none'
})
} else {
// 还有数据,或者是刚加载了一批
/* uni.showToast({
title: '加载完成',
icon: 'success'
}) */
// 更新商品列表
hotProducts.value = newProducts
}
} catch (error) {
console.error('加载更多失败:', error)
@@ -963,14 +1026,10 @@ const navigateToReminders = () => uni.navigateTo({ url: '/pages/user/reminders'
top: 0;
left: 0;
right: 0;
background: linear-gradient(135deg, #4CAF50 0%, #2E7D32 100%);
background-color: #4CAF50;
z-index: 1000;
box-shadow: 0 2px 12px rgba(76, 175, 80, 0.15); /* 调整为与分类页一致 */
box-shadow: 0 2px 12px rgba(76, 175, 80, 0.15);
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
/* will-change: transform, opacity; removed for uniapp-x support */
/* pointer-events: auto; */
/* backface-visibility: hidden; */
/* -webkit-backface-visibility: hidden; */
}
/* 导航栏搜索框容器内边距调整 */
@@ -1320,14 +1379,12 @@ const navigateToReminders = () => uni.navigateTo({ url: '/pages/user/reminders'
.card-name {
font-size: 12px;
font-weight: 500;
font-weight: normal;
color: #333;
margin-bottom: 4px;
text-align: center;
lines: 1;
text-overflow: ellipsis;
overflow: hidden;
width: 100%;
overflow-wrap: break-word;
}
.card-desc {
@@ -1524,6 +1581,59 @@ const navigateToReminders = () => uni.navigateTo({ url: '/pages/user/reminders'
color: #666;
}
/* 热搜词区域 */
.hot-keywords-section {
background: white;
border-radius: 16px;
padding: 20px;
margin-bottom: 20px;
}
.keywords-list {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 15px;
}
.keyword-item {
display: flex;
align-items: center;
padding: 8px 16px;
background: #f5f5f5;
border-radius: 20px;
cursor: pointer;
transition: all 0.2s ease;
}
.keyword-item:hover {
background: #fff0f0;
}
.keyword-rank {
width: 20px;
height: 20px;
border-radius: 10px;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: bold;
color: #999;
background: #eee;
margin-right: 8px;
}
.keyword-rank.top-three {
background: #ff4757;
color: white;
}
.keyword-text {
font-size: 14px;
color: #333;
}
/* 热销药品 */
.hot-products {
background: white;
@@ -2076,45 +2186,43 @@ const navigateToReminders = () => uni.navigateTo({ url: '/pages/user/reminders'
}
.category-grid {
/* grid-template-columns: repeat(5, 1fr); removed for uniapp-x support */
/* gap: 8px; removed */
margin: 0 -1%;
padding: 0 4px;
}
.category-grid .category-card {
width: 18%; /* 5 cols : 20 - 2 */
margin: 0 1% 8px 1%;
padding: 8px 0;
background: transparent; /* 移除卡片背景 */
box-shadow: none; /* 移除阴影 */
border: none; /* 移除边框 */
width: 18%;
margin: 0 1% 6px 1%;
padding: 4px 0;
background: transparent;
box-shadow: none;
border: none;
}
.category-card:hover {
transform: none; /* 移动端移除悬停效果 */
transform: none;
box-shadow: none;
}
.card-icon {
width: 44px; /* 减小图标尺寸 */
height: 44px;
border-radius: 22px;
margin-bottom: 6px;
width: 36px;
height: 36px;
border-radius: 18px;
margin-bottom: 4px;
}
.card-icon-text {
font-size: 20px;
font-size: 18px;
}
.card-name {
font-size: 11px; /* 减小文字大小 */
font-size: 10px;
font-weight: normal;
color: #333;
}
.card-desc {
display: none; /* 手机端隐藏描述文字,保持界面整洁 */
display: none;
}
.services-grid .service-card {