补充数据库数据,修改分类栏内容

This commit is contained in:
2026-05-21 11:50:32 +08:00
parent b8b0b453e0
commit 7ba3d313be
32 changed files with 6657 additions and 1684 deletions

View File

@@ -201,6 +201,15 @@ const currentCategoryDesc = ref('')
// 页面参数
const pageParams = ref<any>({})
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
}
function getProductCover(product: Product): string {
if (product.main_image_url != null && product.main_image_url !== '') return product.main_image_url
if (product.images != null && product.images.length > 0 && product.images[0] !== '') return product.images[0]
@@ -272,7 +281,7 @@ async function loadProducts(): Promise<void> {
loading.value = true
try {
console.log('开始加载商品分类ID:', activePrimary.value, '页码:', currentPage.value)
const response = await supabaseService.getProductsByCategory(activePrimary.value, currentPage.value)
const response = await supabaseService.getMedicalMallProductsByCategory(activePrimary.value, currentPage.value, 20)
console.log('商品加载结果:', {
dataCount: response.data.length,
total: response.total,
@@ -324,7 +333,7 @@ async function loadProducts(): Promise<void> {
async function loadSubCategories(parentId: string): Promise<void> {
console.log('加载二级分类父级ID:', parentId)
try {
const subCats = await supabaseService.getSubCategories(parentId)
const subCats = await supabaseService.getMedicalMallSubCategories(parentId)
console.log('获取到二级分类数量:', subCats.length)
const categories: LocalCategory[] = []
@@ -379,9 +388,10 @@ async function selectSubCategory(subCategoryId: string): Promise<void> {
// originalCategoryId: 可能是一级分类ID也可能是二级分类ID
async function selectPrimaryCategory(originalCategoryId: string): Promise<void> {
console.log('=== selectPrimaryCategory函数开始执行 ===')
console.log('传入的categoryId:', originalCategoryId)
const normalizedCategoryId = normalizeSelectedMedicalCategoryId(originalCategoryId)
console.log('传入的categoryId:', originalCategoryId, '归一化后:', normalizedCategoryId)
if (originalCategoryId == '') {
if (normalizedCategoryId == '') {
console.error('categoryId为空尝试使用第一个分类')
if (primaryCategories.value.length > 0) {
originalCategoryId = primaryCategories.value[0].id
@@ -397,8 +407,9 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise<void>
console.log('当前一级分类列表长度:', primaryCategories.value.length)
let foundInPrimary: LocalCategory | null = null
for (let i = 0; i < primaryCategories.value.length; i++) {
if (primaryCategories.value[i].id == originalCategoryId) {
if (primaryCategories.value[i].id == normalizedCategoryId) {
foundInPrimary = primaryCategories.value[i]
targetParentId = normalizedCategoryId
break
}
}
@@ -410,7 +421,7 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise<void>
// 从服务器获取分类信息以确定父级
try {
const categoryInfo = await supabaseService.getCategoryById(originalCategoryId)
const categoryInfo = await supabaseService.getMedicalMallCategoryById(normalizedCategoryId)
if (categoryInfo != null && categoryInfo.parent_id != null && categoryInfo.parent_id != '') {
console.log('找到父级分类ID:', categoryInfo.parent_id)
@@ -427,7 +438,7 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise<void>
if (parentInPrimary != null) {
console.log('父级分类在列表中找到:', parentInPrimary.name)
targetParentId = categoryInfo.parent_id!
targetSubId = originalCategoryId // 记住要选中的二级分类
targetSubId = normalizedCategoryId // 记住要选中的二级分类
} else {
console.log('父级分类不在列表中,使用第一个分类')
// 打印当前列表中的所有分类ID
@@ -530,21 +541,13 @@ async function selectPrimaryCategory(originalCategoryId: string): Promise<void>
async function loadCategories(): Promise<void> {
try {
// 只获取一级分类parent_id 为 null 的分类)
const categoriesData = await supabaseService.getParentCategories()
const categoriesData = await supabaseService.getMedicalMallParentCategories()
console.log('加载一级分类数据成功,数量:', categoriesData.length)
// 映射数据并添加默认颜色,防止选中时背景透明导致文字看不清
// 过滤掉医药健康相关分类
const categories: LocalCategory[] = []
for (let i = 0; i < categoriesData.length; i++) {
const cat = categoriesData[i]
const name = cat.name
console.log('一级分类:', cat.id, name)
if (name.includes('医药') || name.includes('健康')) {
console.log('过滤掉分类:', name)
continue
}
console.log('一级分类:', cat.id, cat.name)
categories.push({
id: cat.id,
name: cat.name,
@@ -572,16 +575,16 @@ async function loadCategories(): Promise<void> {
// 检查是否有预设的分类ID
if (activePrimary.value != '') {
console.log('有预设的分类ID:', activePrimary.value)
const target = categories.find((c: LocalCategory): boolean => c.id == activePrimary.value)
const normalizedCategoryId = normalizeSelectedMedicalCategoryId(activePrimary.value)
const target = categories.find((c: LocalCategory): boolean => c.id == normalizedCategoryId)
if (target != null) {
console.log('找到目标分类,执行选中:', target.name)
selectPrimaryCategory(activePrimary.value)
selectPrimaryCategory(normalizedCategoryId)
return
}
}
// 默认选中第一个分类或"厨具"分类
const defaultCategory = categories.find((c: LocalCategory): boolean => c.name.includes('厨具')) ?? categories[0]
const defaultCategory = categories.find((c: LocalCategory): boolean => c.id == 'all_medical') ?? categories[0]
if (defaultCategory != null) {
console.log('设置默认分类:', defaultCategory.name)
selectPrimaryCategory(defaultCategory.id)
@@ -622,7 +625,7 @@ onShow(() => {
console.log('onShow检查Storage:', savedCategoryId)
if (savedCategoryId != null && savedCategoryId != '') {
const targetId = savedCategoryId as string
const targetId = normalizeSelectedMedicalCategoryId(savedCategoryId as string)
console.log('onShow发现存储的分类ID:', targetId)
// 清除存储,避免下次进入默认选中
@@ -679,7 +682,7 @@ onLoad((options: any) => {
const optObj = (options instanceof UTSJSONObject) ? (options as UTSJSONObject) : (JSON.parse(JSON.stringify(options ?? {})) as UTSJSONObject)
const optCategoryId = optObj.getString('categoryId') ?? ''
if (optCategoryId !== '') {
categoryId = optCategoryId
categoryId = normalizeSelectedMedicalCategoryId(optCategoryId)
categoryName = optObj.getString('name') ?? ''
console.log('✅ onLoad中找到分类参数:', categoryId, categoryName)
}
@@ -694,7 +697,7 @@ onLoad((options: any) => {
const pageOptObj = (rawPageOptions instanceof UTSJSONObject) ? (rawPageOptions as UTSJSONObject) : (JSON.parse(JSON.stringify(rawPageOptions)) as UTSJSONObject)
const pageCategoryId = pageOptObj.getString('categoryId') ?? ''
if (pageCategoryId !== '') {
categoryId = pageCategoryId
categoryId = normalizeSelectedMedicalCategoryId(pageCategoryId)
categoryName = pageOptObj.getString('name') ?? ''
console.log('✅ 从getCurrentPages()找到分类参数:', categoryId, categoryName)
}