补充数据库数据,修改分类栏内容
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
<scroll-view
|
||||
class="category-scroll"
|
||||
direction="horizontal"
|
||||
:scroll-x="true"
|
||||
:show-scrollbar="false"
|
||||
:scroll-with-animation="true"
|
||||
:scroll-into-view="categoryScrollIntoView"
|
||||
@@ -66,6 +67,8 @@
|
||||
:loading="loading"
|
||||
:has-more="hasMore"
|
||||
:show-load-more="showLoadMore"
|
||||
:empty-state-title="homeEmptyStateTitle"
|
||||
:empty-state-description="homeEmptyStateDescription"
|
||||
@secondary-category-click="handleSecondaryCategoryClick"
|
||||
@select-channel="navigateToChannel"
|
||||
@select-simple-channel="navigateToSimpleChannel"
|
||||
@@ -285,7 +288,7 @@ const headerSearchPlaceholder = computed((): string => {
|
||||
if (activeTopModule.value == 'service') {
|
||||
return '居家护理 / 康复照护 / 血压计 / 助餐服务'
|
||||
}
|
||||
return currentPlaceholderKeyword.value != '' ? currentPlaceholderKeyword.value : '感冒药 / 康复护理 / 居家护理 / 血压计'
|
||||
return currentPlaceholderKeyword.value != '' ? currentPlaceholderKeyword.value : '血压计 / 血糖仪 / 制氧机 / 维生素'
|
||||
})
|
||||
|
||||
type HomeCareCategoryType = {
|
||||
@@ -641,11 +644,16 @@ const showSubCategories = ref(false)
|
||||
|
||||
// 首页占位词轮播相关
|
||||
const placeholderKeywords = ref([
|
||||
'neo2无人机',
|
||||
'华为mate50',
|
||||
'血压计',
|
||||
'血糖仪',
|
||||
'体温计',
|
||||
'制氧机',
|
||||
'口罩',
|
||||
'创可贴',
|
||||
'维生素',
|
||||
'钙片',
|
||||
'感冒药',
|
||||
'维生素C',
|
||||
'康复护具',
|
||||
'护理床',
|
||||
|
||||
])
|
||||
const currentPlaceholderIndex = ref(0)
|
||||
@@ -655,6 +663,20 @@ const placeholderAnimating = ref(false)
|
||||
let placeholderTimer: number = 0
|
||||
let placeholderAnimationTimer: number = 0
|
||||
|
||||
const homeEmptyStateTitle = computed((): string => {
|
||||
if (currentFeedCategoryId.value == 'recommend') {
|
||||
return '康养医疗商品正在完善中'
|
||||
}
|
||||
return '当前分类暂无商品'
|
||||
})
|
||||
|
||||
const homeEmptyStateDescription = computed((): string => {
|
||||
if (currentFeedCategoryId.value == 'recommend') {
|
||||
return '可先查看居家服务或稍后再试'
|
||||
}
|
||||
return ''
|
||||
})
|
||||
|
||||
const syncNextPlaceholderKeyword = () => {
|
||||
const total = placeholderKeywords.value.length
|
||||
if (total <= 1) {
|
||||
@@ -1114,7 +1136,7 @@ const handleSecondaryCategoryClick = async (category: Category): Promise<void> =
|
||||
hasMore.value = true
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await supabaseService.getProductsByCategory(category.id, 1, defaultLoadLimit)
|
||||
const result = await supabaseService.getMedicalMallProductsByCategory(category.id, 1, defaultLoadLimit)
|
||||
failedProductImageIds.value = []
|
||||
setHotProducts(result.data)
|
||||
hasMore.value = result.hasmore
|
||||
@@ -1165,9 +1187,9 @@ const healthNews = [
|
||||
]
|
||||
|
||||
// 获取一级分类数据
|
||||
const loadCategories = async (): Promise<void> => {
|
||||
const loadMedicalMallCategories = async (): Promise<void> => {
|
||||
try {
|
||||
const categoriesData = await supabaseService.getParentCategories()
|
||||
const categoriesData = await supabaseService.getMedicalMallParentCategories()
|
||||
parentCategories.value = categoriesData
|
||||
// 兼容其他使用 categories 的地方
|
||||
categories.value = categoriesData
|
||||
@@ -1190,7 +1212,7 @@ const loadCategories = async (): Promise<void> => {
|
||||
async function loadSubCategories(parentId: string): Promise<void> {
|
||||
try {
|
||||
console.log('[loadSubCategories] 开始加载二级分类, parentId:', parentId)
|
||||
const subData = await supabaseService.getSubCategories(parentId)
|
||||
const subData = await supabaseService.getMedicalMallSubCategories(parentId)
|
||||
console.log('[loadSubCategories] 获取到二级分类数量:', subData.length)
|
||||
console.log('[loadSubCategories] 二级分类数据:', JSON.stringify(subData))
|
||||
subCategories.value = subData
|
||||
@@ -1315,6 +1337,15 @@ function getCategoryLabelById(categoryId: string): string {
|
||||
return '精选'
|
||||
}
|
||||
|
||||
function normalizeSelectedMedicalCategoryId(categoryId: string): string {
|
||||
if (categoryId == 'device') return 'med_device'
|
||||
if (categoryId == 'external') return 'home_care_daily'
|
||||
if (categoryId == 'cold') return 'otc_medicine'
|
||||
if (categoryId == 'medicine') return 'otc_medicine'
|
||||
if (categoryId == 'care') return 'home_care_daily'
|
||||
return categoryId
|
||||
}
|
||||
|
||||
async function consumeSelectedCategoryFromStorage(): Promise<boolean> {
|
||||
if (activeTopModule.value != 'home' || categoryList.value.length == 0) {
|
||||
return false
|
||||
@@ -1328,14 +1359,15 @@ async function consumeSelectedCategoryFromStorage(): Promise<boolean> {
|
||||
return false
|
||||
}
|
||||
uni.removeStorageSync('selectedCategory')
|
||||
const matchedItem = categoryList.value.find((item: CategoryItem): boolean => item.id == nextCategoryId)
|
||||
const normalizedCategoryId = normalizeSelectedMedicalCategoryId(nextCategoryId)
|
||||
const matchedItem = categoryList.value.find((item: CategoryItem): boolean => item.id == normalizedCategoryId)
|
||||
if (matchedItem != null) {
|
||||
await refreshHomeCategory(matchedItem)
|
||||
return true
|
||||
}
|
||||
await refreshHomeCategory({
|
||||
id: nextCategoryId,
|
||||
name: getCategoryLabelById(nextCategoryId)
|
||||
id: normalizedCategoryId,
|
||||
name: getCategoryLabelById(normalizedCategoryId)
|
||||
})
|
||||
return true
|
||||
}
|
||||
@@ -1364,17 +1396,17 @@ const fetchSortedProductsPage = async (page: number, limit: number): Promise<Pag
|
||||
console.log('加载热销商品,当前排序方式:', activeSort.value, 'page:', page, 'limit:', limit)
|
||||
switch (activeSort.value) {
|
||||
case 'sales':
|
||||
console.log('调用 getProductsBySales')
|
||||
return await supabaseService.getProductsBySales(page, limit)
|
||||
console.log('调用 getMedicalMallSmartRecommendations(sales-fallback)')
|
||||
return await supabaseService.getMedicalMallSmartRecommendations(page, limit)
|
||||
case 'price':
|
||||
console.log('调用 getProductsByPrice, 升序:', priceAscending.value)
|
||||
return await supabaseService.getProductsByPrice(page, limit, priceAscending.value)
|
||||
console.log('调用 getMedicalMallSmartRecommendations(price-fallback), 升序:', priceAscending.value)
|
||||
return await supabaseService.getMedicalMallSmartRecommendations(page, limit)
|
||||
case 'new':
|
||||
console.log('调用 getProductsByNewest')
|
||||
return await supabaseService.getProductsByNewest(page, limit)
|
||||
console.log('调用 getMedicalMallSmartRecommendations(new-fallback)')
|
||||
return await supabaseService.getMedicalMallSmartRecommendations(page, limit)
|
||||
case 'recommend':
|
||||
console.log('调用 getSmartRecommendations')
|
||||
return await supabaseService.getSmartRecommendations(page, limit)
|
||||
console.log('调用 getMedicalMallSmartRecommendations')
|
||||
return await supabaseService.getMedicalMallSmartRecommendations(page, limit)
|
||||
case 'discount': {
|
||||
console.log('调用 getDiscountProducts')
|
||||
const products = await supabaseService.getDiscountProducts(limit)
|
||||
@@ -1387,8 +1419,8 @@ const fetchSortedProductsPage = async (page: number, limit: number): Promise<Pag
|
||||
}
|
||||
}
|
||||
default:
|
||||
console.log('调用默认 getProductsBySales')
|
||||
return await supabaseService.getProductsBySales(page, limit)
|
||||
console.log('调用默认 getMedicalMallSmartRecommendations')
|
||||
return await supabaseService.getMedicalMallSmartRecommendations(page, limit)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1427,7 +1459,7 @@ async function syncCategoryLayout(categoryId: string): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
const subData = await supabaseService.getSubCategories(categoryId)
|
||||
const subData = await supabaseService.getMedicalMallSubCategories(categoryId)
|
||||
subCategories.value = subData
|
||||
} catch (error) {
|
||||
console.error('加载子分类数据失败:', error)
|
||||
@@ -1444,33 +1476,7 @@ async function loadCategoryGoods(categoryId: string): Promise<void> {
|
||||
await syncCategoryLayout(categoryId)
|
||||
if (categoryId === 'recommend') {
|
||||
try {
|
||||
let result: PaginatedResponse<Product>
|
||||
switch (activeSort.value) {
|
||||
case 'sales':
|
||||
result = await supabaseService.getProductsBySales(1, defaultLoadLimit)
|
||||
break
|
||||
case 'price':
|
||||
result = await supabaseService.getProductsByPrice(1, defaultLoadLimit, priceAscending.value)
|
||||
break
|
||||
case 'new':
|
||||
result = await supabaseService.getProductsByNewest(1, defaultLoadLimit)
|
||||
break
|
||||
case 'discount': {
|
||||
const products = await supabaseService.getDiscountProducts(defaultLoadLimit)
|
||||
result = {
|
||||
data: products,
|
||||
total: products.length,
|
||||
page: 1,
|
||||
limit: defaultLoadLimit,
|
||||
hasmore: false
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'recommend':
|
||||
default:
|
||||
result = await supabaseService.getSmartRecommendations(1, defaultLoadLimit)
|
||||
break
|
||||
}
|
||||
const result = await supabaseService.getMedicalMallSmartRecommendations(1, defaultLoadLimit)
|
||||
failedProductImageIds.value = []
|
||||
setHotProducts(result.data)
|
||||
hasMore.value = result.hasmore
|
||||
@@ -1483,7 +1489,7 @@ async function loadCategoryGoods(categoryId: string): Promise<void> {
|
||||
} else {
|
||||
try {
|
||||
loading.value = true
|
||||
const result = await supabaseService.getProductsByCategory(categoryId, 1, defaultLoadLimit)
|
||||
const result = await supabaseService.getMedicalMallProductsByCategory(categoryId, 1, defaultLoadLimit)
|
||||
failedProductImageIds.value = []
|
||||
setHotProducts(result.data)
|
||||
hasMore.value = result.hasmore
|
||||
@@ -1514,7 +1520,7 @@ async function refreshHomeCategory(item: CategoryItem): Promise<void> {
|
||||
secondaryCategoryDisplay.value = buildSecondaryCategoryDisplay(item.id)
|
||||
applyChannelDisplay(item.id)
|
||||
try {
|
||||
const result = await supabaseService.getSmartRecommendations(1, defaultLoadLimit)
|
||||
const result = await supabaseService.getMedicalMallSmartRecommendations(1, defaultLoadLimit)
|
||||
setHotProducts(result.data)
|
||||
hasMore.value = result.hasmore
|
||||
} catch (error) {
|
||||
@@ -1528,7 +1534,7 @@ async function refreshHomeCategory(item: CategoryItem): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
const subData = await supabaseService.getSubCategories(item.id)
|
||||
const subData = await supabaseService.getMedicalMallSubCategories(item.id)
|
||||
subCategories.value = subData
|
||||
} catch (error) {
|
||||
console.error('加载子分类数据失败:', error)
|
||||
@@ -1537,7 +1543,7 @@ async function refreshHomeCategory(item: CategoryItem): Promise<void> {
|
||||
secondaryCategoryDisplay.value = buildSecondaryCategoryDisplay(item.id)
|
||||
applyChannelDisplay(item.id)
|
||||
try {
|
||||
const result = await supabaseService.getProductsByCategory(item.id, 1, defaultLoadLimit)
|
||||
const result = await supabaseService.getMedicalMallProductsByCategory(item.id, 1, defaultLoadLimit)
|
||||
setHotProducts(result.data)
|
||||
hasMore.value = result.hasmore
|
||||
} catch (error) {
|
||||
@@ -1559,7 +1565,8 @@ function selectCategoryFromPanel(item: CategoryItem): void {
|
||||
}
|
||||
|
||||
const loadRecommendedProducts = async (limit: number): Promise<void> => {
|
||||
recommendedProducts.value = await supabaseService.getRecommendedProducts(limit)
|
||||
const result = await supabaseService.getMedicalMallSmartRecommendations(1, limit)
|
||||
recommendedProducts.value = result.data
|
||||
}
|
||||
|
||||
// 加载热搜词
|
||||
@@ -1592,7 +1599,7 @@ const initData = async () => {
|
||||
} catch (error) {
|
||||
console.error('加载用户资料失败:', error)
|
||||
}
|
||||
await loadCategories()
|
||||
await loadMedicalMallCategories()
|
||||
await loadBrands()
|
||||
await loadHotKeywords()
|
||||
await loadServiceHomeData()
|
||||
@@ -1613,7 +1620,7 @@ const familyItems = [
|
||||
desc: '伤口护理',
|
||||
icon: '🩹',
|
||||
color: '#FF5722',
|
||||
categoryId: 'external'
|
||||
categoryId: 'wound_care'
|
||||
},
|
||||
{
|
||||
id: 'family2',
|
||||
@@ -1621,7 +1628,7 @@ const familyItems = [
|
||||
desc: '健康监测',
|
||||
icon: '🌡️',
|
||||
color: '#2196F3',
|
||||
categoryId: 'device'
|
||||
categoryId: 'thermometer'
|
||||
},
|
||||
{
|
||||
id: 'family3',
|
||||
@@ -1629,7 +1636,7 @@ const familyItems = [
|
||||
desc: '环境消毒',
|
||||
icon: '🧪',
|
||||
color: '#ff5000',
|
||||
categoryId: 'external'
|
||||
categoryId: 'disinfectant'
|
||||
},
|
||||
{
|
||||
id: 'family4',
|
||||
@@ -1637,7 +1644,7 @@ const familyItems = [
|
||||
desc: '日常防护',
|
||||
icon: '😷',
|
||||
color: '#607D8B',
|
||||
categoryId: 'device'
|
||||
categoryId: 'mask'
|
||||
},
|
||||
{
|
||||
id: 'family5',
|
||||
@@ -1645,7 +1652,7 @@ const familyItems = [
|
||||
desc: '物理降温',
|
||||
icon: '🧊',
|
||||
color: '#00BCD4',
|
||||
categoryId: 'cold'
|
||||
categoryId: 'cold_fever'
|
||||
},
|
||||
{
|
||||
id: 'family6',
|
||||
@@ -1653,7 +1660,7 @@ const familyItems = [
|
||||
desc: '伤口处理',
|
||||
icon: '🩹',
|
||||
color: '#FF9800',
|
||||
categoryId: 'external'
|
||||
categoryId: 'dressing_tools'
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1931,7 +1938,7 @@ const loadMore = async () => {
|
||||
currentPage.value = nextPage
|
||||
}
|
||||
} else {
|
||||
const result = await supabaseService.getProductsByCategory(currentFeedCategoryId.value, nextPage, defaultLoadLimit)
|
||||
const result = await supabaseService.getMedicalMallProductsByCategory(currentFeedCategoryId.value, nextPage, defaultLoadLimit)
|
||||
if (result.data.length == 0) {
|
||||
hasMore.value = false
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user