feat(singer): 优化歌手搜索功能

- 修改了前端 Singer.vue 文件,增加了对 keyword 的判断,以显示不同的标题
- 更新了后端 SingerServiceImpl 文件,改进了搜索逻辑,支持多字段查询
This commit is contained in:
ikmkj
2025-07-29 19:56:08 +08:00
parent 8aa076ded1
commit f67c6f2262
2 changed files with 8 additions and 3 deletions

View File

@@ -93,10 +93,14 @@ public class SingerServiceImpl implements SingerService {
// 构建查询条件 // 构建查询条件
Specification<Singer> spec = (root, query, cb) -> { Specification<Singer> spec = (root, query, cb) -> {
List<Predicate> predicates = new ArrayList<>(); List<Predicate> predicates = new ArrayList<>();
query.distinct(true); // 添加 distinct 查询
// 关键字查询 // 关键字查询
if (StringUtils.hasText(keyword)) { if (StringUtils.hasText(keyword)) {
predicates.add(cb.like(root.get("name"), "%" + keyword + "%")); Predicate p1 = cb.like(root.get("name"), "%" + keyword + "%");
Predicate p2 = cb.like(root.get("introduction"), "%" + keyword + "%");
Predicate p3 = cb.like(root.join("musics", jakarta.persistence.criteria.JoinType.LEFT).get("name"), "%" + keyword + "%");
predicates.add(cb.or(p1, p2, p3));
} }
// 类型查询 // 类型查询

View File

@@ -243,7 +243,7 @@ onMounted(() => {
</div> </div>
<!-- 热门歌手 --> <!-- 热门歌手 -->
<div class="hot-singers" v-if="activeType === null && currentPage === 1"> <div class="hot-singers" v-if="!keyword && activeType === null && currentPage === 1">
<h2>热门歌手</h2> <h2>热门歌手</h2>
<div class="singer-list" v-loading="loadingHot"> <div class="singer-list" v-loading="loadingHot">
<div <div
@@ -277,7 +277,8 @@ onMounted(() => {
<!-- 歌手列表 --> <!-- 歌手列表 -->
<div class="all-singers"> <div class="all-singers">
<h2 v-if="activeType === null && currentPage === 1">全部歌手</h2> <h2 v-if="keyword">搜索结果</h2>
<h2 v-else-if="activeType === null && currentPage === 1">全部歌手</h2>
<div class="singer-list" v-loading="loading"> <div class="singer-list" v-loading="loading">
<div <div
v-for="singer in singers" v-for="singer in singers"