商品标签筛选功能完善
This commit is contained in:
@@ -147,8 +147,8 @@ const allTags = ref<TagVO[]>([])
|
||||
// 当前选中的分类
|
||||
const selectedCategory = ref('全部')
|
||||
|
||||
// 分类列表
|
||||
const categories = ['全部', '美甲', '美睫', '手足护理', '纹绣']
|
||||
// 分类列表(动态从标签获取)
|
||||
const categories = ref<string[]>(['全部'])
|
||||
|
||||
// 商品数据
|
||||
const products = ref<ProductVO[]>([])
|
||||
@@ -164,6 +164,8 @@ const fetchTags = async () => {
|
||||
try {
|
||||
const tags = await tagApi.getAllTags()
|
||||
allTags.value = tags as unknown as TagVO[]
|
||||
// 动态生成分类列表
|
||||
categories.value = ['全部', ...allTags.value.map(tag => tag.tagName)]
|
||||
} catch (error) {
|
||||
console.error('获取标签失败:', error)
|
||||
}
|
||||
@@ -240,9 +242,9 @@ const handleLoadMore = () => {
|
||||
hasMore.value = false
|
||||
}
|
||||
|
||||
// 页面挂载时获取商品数据
|
||||
onMounted(() => {
|
||||
fetchTags()
|
||||
// 页面挂载时获取标签和商品数据
|
||||
onMounted(async () => {
|
||||
await fetchTags()
|
||||
fetchProducts()
|
||||
})
|
||||
</script>
|
||||
|
||||
+17
-1
@@ -105,9 +105,25 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductDO> im
|
||||
|
||||
@Override
|
||||
public List<ProductVO> listProductsByTag(String tag) {
|
||||
// 先根据标签名称查找标签ID
|
||||
TagVO tagVO = tagService.getTagByTagName(tag);
|
||||
if (tagVO == null) {
|
||||
return new java.util.ArrayList<>();
|
||||
}
|
||||
|
||||
// 用标签ID查询商品,只完整匹配标签ID
|
||||
String tagIdStr = String.valueOf(tagVO.getId());
|
||||
List<ProductDO> productDOs = productMapper.selectList(
|
||||
Wrappers.lambdaQuery(ProductDO.class)
|
||||
.like(ProductDO::getTags, tag)
|
||||
.and(wrapper -> wrapper
|
||||
.eq(ProductDO::getTags, tagIdStr)
|
||||
.or()
|
||||
.likeRight(ProductDO::getTags, tagIdStr + ";")
|
||||
.or()
|
||||
.likeLeft(ProductDO::getTags, ";" + tagIdStr)
|
||||
.or()
|
||||
.like(ProductDO::getTags, ";" + tagIdStr + ";")
|
||||
)
|
||||
);
|
||||
return productDOs.stream()
|
||||
.map(this::convertToVO)
|
||||
|
||||
Reference in New Issue
Block a user