登录注册/数据分析
This commit is contained in:
@@ -169,34 +169,44 @@ const loadBanners = async () => {
|
||||
|
||||
if (error !== null) {
|
||||
console.error('加载轮播图失败:', error)
|
||||
bannerList.value = []
|
||||
return
|
||||
}
|
||||
|
||||
bannerList.value = data ?? []
|
||||
} catch (err) {
|
||||
console.error('加载轮播图异常:', err)
|
||||
bannerList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 加载分类
|
||||
const loadCategories = async () => {
|
||||
try {
|
||||
// 查询所有活跃分类,然后在前端过滤出顶级分类(parent_id 为 null)
|
||||
// 这样可以避免 UTS 中 .is(null) 的类型问题
|
||||
const { data, error } = await supa
|
||||
.from('categories')
|
||||
.select('*')
|
||||
.eq('is_active', true)
|
||||
.is('parent_id', null)
|
||||
.order('sort_order', { ascending: true })
|
||||
.limit(8)
|
||||
|
||||
if (error !== null) {
|
||||
console.error('加载分类失败:', error)
|
||||
categoryList.value = []
|
||||
return
|
||||
}
|
||||
|
||||
categoryList.value = data ?? []
|
||||
// 过滤出顶级分类(parent_id 为 null 或 undefined)
|
||||
const topCategories = (data ?? []).filter((item: any) => {
|
||||
return item.parent_id === null || item.parent_id === undefined || item.parent_id === ''
|
||||
}).slice(0, 8) // 限制为前8个
|
||||
|
||||
categoryList.value = topCategories
|
||||
} catch (err) {
|
||||
console.error('加载分类异常:', err)
|
||||
// 如果查询失败,使用空数组避免页面崩溃
|
||||
categoryList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,22 +214,25 @@ const loadCategories = async () => {
|
||||
const loadCoupons = async () => {
|
||||
try {
|
||||
const now = new Date().toISOString()
|
||||
// 查询当前时间在有效期内的优惠券:start_time <= now <= end_time
|
||||
const { data, error } = await supa
|
||||
.from('coupon_templates')
|
||||
.select('*')
|
||||
.eq('status', 1)
|
||||
.gte('end_time', now)
|
||||
.lte('start_time', now)
|
||||
.lte('start_time', now) // 开始时间 <= 当前时间
|
||||
.gte('end_time', now) // 结束时间 >= 当前时间
|
||||
.limit(5)
|
||||
|
||||
if (error !== null) {
|
||||
console.error('加载优惠券失败:', error)
|
||||
couponList.value = []
|
||||
return
|
||||
}
|
||||
|
||||
couponList.value = data ?? []
|
||||
} catch (err) {
|
||||
console.error('加载优惠券异常:', err)
|
||||
couponList.value = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +255,9 @@ const loadProducts = async (loadMore: boolean = false) => {
|
||||
|
||||
if (error !== null) {
|
||||
console.error('加载商品失败:', error)
|
||||
if (!loadMore) {
|
||||
productList.value = []
|
||||
}
|
||||
isLoading.value = false
|
||||
return
|
||||
}
|
||||
@@ -261,6 +277,9 @@ const loadProducts = async (loadMore: boolean = false) => {
|
||||
hasMore.value = newProducts.length === pageSize.value
|
||||
} catch (err) {
|
||||
console.error('加载商品异常:', err)
|
||||
if (!loadMore) {
|
||||
productList.value = []
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user