feat(web): show album + playlist sections in search

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
saopig1andClaude Sonnet 4.6 committed 2026-05-07 20:26:03 +08:00
1 parent 51d7ce61bd
commit f6b82b8e21
1 file changed
+70 -13
+70 -13
View File
@@ -20,9 +20,42 @@
<div v-if="loading" class="loading">搜索中...</div> <div v-if="loading" class="loading">搜索中...</div>
<div v-else-if="results.length > 0" class="results"> <template v-else-if="songs.length || albums.length || playlists.length">
<section v-if="albums.length" class="result-section">
<h2 class="section-title">专辑</h2>
<div class="card-grid">
<router-link
v-for="al in albums"
:key="`${al.platform}-${al.id}`"
:to="`/album/${al.id}?platform=${al.platform}`"
class="card hover-scale"
>
<CoverArt :url="al.coverUrl" :size="160" :radius="10" :show-shadow="true" />
<div class="card-name">{{ al.name }}</div>
<div class="card-sub">{{ al.artist }}</div>
</router-link>
</div>
</section>
<section v-if="playlists.length" class="result-section">
<h2 class="section-title">歌单</h2>
<div class="card-grid">
<router-link
v-for="pl in playlists"
:key="`${pl.platform}-${pl.id}`"
:to="`/playlist/${pl.id}?platform=${pl.platform}`"
class="card hover-scale"
>
<CoverArt :url="pl.coverUrl" :size="160" :radius="10" :show-shadow="true" />
<div class="card-name">{{ pl.name }}</div>
</router-link>
</div>
</section>
<section v-if="songs.length" class="result-section">
<h2 class="section-title">单曲</h2>
<SongCard <SongCard
v-for="(song, i) in results" v-for="(song, i) in songs"
:key="`${song.platform}-${song.id}`" :key="`${song.platform}-${song.id}`"
:song="song" :song="song"
:index="i + 1" :index="i + 1"
@@ -31,11 +64,10 @@
@playNext="store.playNextSong(song)" @playNext="store.playNextSong(song)"
@add="store.addSong(song)" @add="store.addSong(song)"
/> />
</div> </section>
</template>
<div v-else-if="searched" class="empty"> <div v-else-if="searched" class="empty">未找到相关结果</div>
未找到相关结果
</div>
</div> </div>
</template> </template>
@@ -45,15 +77,21 @@ import { useRoute } from 'vue-router';
import { Icon } from '@iconify/vue'; import { Icon } from '@iconify/vue';
import axios from 'axios'; import axios from 'axios';
import { usePlayerStore } from '../stores/player.js'; import { usePlayerStore } from '../stores/player.js';
import type { Song } from '../stores/player.js';
import SongCard from '../components/SongCard.vue'; import SongCard from '../components/SongCard.vue';
import CoverArt from '../components/CoverArt.vue';
const store = usePlayerStore(); const store = usePlayerStore();
const route = useRoute(); const route = useRoute();
const query = ref((route.query.q as string) || ''); const query = ref((route.query.q as string) || '');
import { Song } from '../stores/player.js';
const results = ref<Song[]>([]); interface Album { id: string; name: string; artist: string; coverUrl: string; songCount?: number; platform: string; }
interface Playlist { id: string; name: string; coverUrl: string; songCount?: number; platform: string; }
const songs = ref<Song[]>([]);
const albums = ref<Album[]>([]);
const playlists = ref<Playlist[]>([]);
const loading = ref(false); const loading = ref(false);
const searched = ref(false); const searched = ref(false);
@@ -62,12 +100,12 @@ async function doSearch() {
loading.value = true; loading.value = true;
searched.value = true; searched.value = true;
try { try {
const res = await axios.get('/api/music/search/all', { const res = await axios.get('/api/music/search/all', { params: { q: query.value } });
params: { q: query.value }, songs.value = res.data.songs ?? [];
}); albums.value = res.data.albums ?? [];
results.value = res.data.songs; playlists.value = res.data.playlists ?? [];
} catch { } catch {
results.value = []; songs.value = []; albums.value = []; playlists.value = [];
} finally { } finally {
loading.value = false; loading.value = false;
} }
@@ -141,4 +179,23 @@ onMounted(() => {
flex-direction: column; flex-direction: column;
gap: 2px; gap: 2px;
} }
.result-section {
margin-bottom: 32px;
.section-title { font-size: 18px; margin: 0 0 12px; opacity: 0.85; }
}
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 16px;
}
.card {
display: flex;
flex-direction: column;
gap: 6px;
text-decoration: none;
color: inherit;
.card-name { font-size: 14px; line-height: 1.3; max-height: 2.6em; overflow: hidden; }
.card-sub { font-size: 12px; opacity: 0.6; }
}
</style> </style>