2021-07-26 17:47:15 +08:00
|
|
|
<template>
|
2024-05-16 18:54:30 +08:00
|
|
|
<div class="search-page">
|
|
|
|
|
<n-layout class="hot-search" :class="setAnimationClass('animate__fadeInDown')" :native-scrollbar="false">
|
|
|
|
|
<div class="title">热搜列表</div>
|
|
|
|
|
<div class="hot-search-list">
|
|
|
|
|
<template v-for="(item, index) in hotSearchData?.data" :key="index">
|
|
|
|
|
<div
|
|
|
|
|
:class="setAnimationClass('animate__bounceInLeft')"
|
|
|
|
|
:style="setAnimationDelay(index, 10)"
|
|
|
|
|
class="hot-search-item"
|
|
|
|
|
@click.stop="clickHotKeyword(item.searchWord)"
|
|
|
|
|
>
|
|
|
|
|
<span class="hot-search-item-count" :class="{ 'hot-search-item-count-3': index < 3 }">{{ index + 1 }}</span>
|
|
|
|
|
{{ item.searchWord }}
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</n-layout>
|
|
|
|
|
<!-- 搜索到的歌曲列表 -->
|
|
|
|
|
<n-layout class="search-list" :class="setAnimationClass('animate__fadeInUp')" :native-scrollbar="false">
|
|
|
|
|
<div class="title">{{ hotKeyword }}</div>
|
|
|
|
|
<div class="search-list-box">
|
|
|
|
|
<template v-if="searchDetail">
|
|
|
|
|
<div
|
|
|
|
|
v-for="(item, index) in searchDetail?.songs"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:class="setAnimationClass('animate__bounceInRight')"
|
|
|
|
|
:style="setAnimationDelay(index, 50)"
|
|
|
|
|
>
|
|
|
|
|
<song-item :item="item" @play="handlePlay" />
|
|
|
|
|
</div>
|
|
|
|
|
<template v-for="(list, key) in searchDetail">
|
|
|
|
|
<template v-if="key.toString() !== 'songs'">
|
|
|
|
|
<div
|
|
|
|
|
v-for="(item, index) in list"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:class="setAnimationClass('animate__bounceInRight')"
|
|
|
|
|
:style="setAnimationDelay(index, 50)"
|
|
|
|
|
>
|
|
|
|
|
<SearchItem :item="item" />
|
|
|
|
|
</div>
|
2021-09-28 17:31:08 +08:00
|
|
|
</template>
|
2024-05-16 18:54:30 +08:00
|
|
|
</template>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</n-layout>
|
|
|
|
|
</div>
|
2021-07-26 17:47:15 +08:00
|
|
|
</template>
|
|
|
|
|
|
2021-07-27 16:01:33 +08:00
|
|
|
<script lang="ts" setup>
|
2024-05-16 18:54:30 +08:00
|
|
|
import { useDateFormat } from '@vueuse/core';
|
|
|
|
|
import { onMounted, ref, watch } from 'vue';
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
|
|
|
|
import { useStore } from 'vuex';
|
|
|
|
|
|
|
|
|
|
import { getHotSearch } from '@/api/home';
|
|
|
|
|
import { getSearch } from '@/api/search';
|
|
|
|
|
import SongItem from '@/components/common/SongItem.vue';
|
|
|
|
|
import type { IHotSearch } from '@/type/search';
|
|
|
|
|
import { setAnimationClass, setAnimationDelay } from '@/utils';
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2021-07-26 17:47:15 +08:00
|
|
|
const route = useRoute();
|
2021-09-28 17:31:08 +08:00
|
|
|
const router = useRouter();
|
2021-11-09 11:34:09 +08:00
|
|
|
const searchDetail = ref<any>();
|
2023-12-27 23:25:26 +08:00
|
|
|
const searchType = ref(Number(route.query.type) || 1);
|
2021-07-27 16:01:33 +08:00
|
|
|
|
|
|
|
|
// 热搜列表
|
2021-09-28 17:31:08 +08:00
|
|
|
const hotSearchData = ref<IHotSearch>();
|
2021-07-27 16:01:33 +08:00
|
|
|
const loadHotSearch = async () => {
|
2024-05-16 18:54:30 +08:00
|
|
|
const { data } = await getHotSearch();
|
|
|
|
|
hotSearchData.value = data;
|
2021-09-28 17:31:08 +08:00
|
|
|
};
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2021-09-28 17:31:08 +08:00
|
|
|
onMounted(() => {
|
2024-05-16 18:54:30 +08:00
|
|
|
loadHotSearch();
|
2021-09-28 17:31:08 +08:00
|
|
|
});
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
const hotKeyword = ref(route.query.keyword || '搜索列表');
|
2021-07-27 16:01:33 +08:00
|
|
|
const clickHotKeyword = (keyword: string) => {
|
2024-05-16 18:54:30 +08:00
|
|
|
hotKeyword.value = keyword;
|
|
|
|
|
router.push({
|
|
|
|
|
path: '/search',
|
|
|
|
|
query: {
|
|
|
|
|
keyword,
|
|
|
|
|
type: 1,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
// isHotSearchList.value = false;
|
2021-09-28 17:31:08 +08:00
|
|
|
};
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
const dateFormat = (time: any) => useDateFormat(time, 'YYYY.MM.DD').value;
|
2023-12-27 23:25:26 +08:00
|
|
|
const loadSearch = async (keywords: any) => {
|
2024-05-16 18:54:30 +08:00
|
|
|
hotKeyword.value = keywords;
|
|
|
|
|
searchDetail.value = undefined;
|
|
|
|
|
if (!keywords) return;
|
|
|
|
|
const { data } = await getSearch({ keywords, type: searchType.value });
|
|
|
|
|
|
|
|
|
|
const songs = data.result.songs || [];
|
|
|
|
|
const albums = data.result.albums || [];
|
|
|
|
|
|
|
|
|
|
// songs map 替换属性
|
|
|
|
|
songs.forEach((item: any) => {
|
|
|
|
|
item.picUrl = item.al.picUrl;
|
|
|
|
|
item.song = item;
|
|
|
|
|
item.artists = item.ar;
|
|
|
|
|
});
|
|
|
|
|
albums.forEach((item: any) => {
|
|
|
|
|
item.desc = `${item.artist.name} ${item.company} ${dateFormat(item.publishTime)}`;
|
|
|
|
|
});
|
|
|
|
|
searchDetail.value = {
|
|
|
|
|
songs,
|
|
|
|
|
albums,
|
|
|
|
|
};
|
2021-09-28 17:31:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loadSearch(route.query.keyword);
|
|
|
|
|
|
|
|
|
|
watch(
|
2024-05-16 18:54:30 +08:00
|
|
|
() => route.query,
|
|
|
|
|
async (newParams) => {
|
|
|
|
|
searchType.value = Number(newParams.type || 1);
|
|
|
|
|
loadSearch(newParams.keyword);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
|
|
const handlePlay = () => {
|
|
|
|
|
const tracks = searchDetail.value?.songs || [];
|
|
|
|
|
store.commit('setPlayList', tracks);
|
|
|
|
|
};
|
2021-07-26 17:47:15 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-07-27 16:01:33 +08:00
|
|
|
.search-page {
|
2024-05-16 18:54:30 +08:00
|
|
|
@apply flex h-full;
|
2021-07-27 16:01:33 +08:00
|
|
|
}
|
|
|
|
|
.hot-search {
|
2024-05-16 18:54:30 +08:00
|
|
|
@apply mr-4 rounded-xl flex-1 overflow-hidden;
|
|
|
|
|
background-color: #0d0d0d;
|
|
|
|
|
animation-duration: 0.2s;
|
|
|
|
|
min-width: 400px;
|
|
|
|
|
height: 100%;
|
|
|
|
|
&-list {
|
|
|
|
|
@apply pb-28;
|
|
|
|
|
}
|
|
|
|
|
&-item {
|
|
|
|
|
@apply px-4 py-3 text-lg hover:bg-gray-700 rounded-xl cursor-pointer;
|
|
|
|
|
&-count {
|
|
|
|
|
@apply text-green-500 inline-block ml-3 w-8;
|
|
|
|
|
&-3 {
|
|
|
|
|
@apply text-red-600 font-bold inline-block ml-3 w-8;
|
|
|
|
|
}
|
2021-07-27 16:01:33 +08:00
|
|
|
}
|
2024-05-16 18:54:30 +08:00
|
|
|
}
|
2021-07-27 16:01:33 +08:00
|
|
|
}
|
2021-09-28 17:31:08 +08:00
|
|
|
|
|
|
|
|
.search-list {
|
2024-05-16 18:54:30 +08:00
|
|
|
@apply flex-1 rounded-xl;
|
|
|
|
|
background-color: #0d0d0d;
|
|
|
|
|
height: 100%;
|
|
|
|
|
&-box {
|
|
|
|
|
@apply pb-28;
|
|
|
|
|
}
|
2021-09-30 13:44:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.title {
|
2024-05-16 18:54:30 +08:00
|
|
|
@apply text-gray-200 text-xl font-bold my-2 mx-4;
|
2021-09-28 17:31:08 +08:00
|
|
|
}
|
2021-07-26 17:47:15 +08:00
|
|
|
</style>
|