2021-07-26 17:47:15 +08:00
|
|
|
<template>
|
2021-07-27 16:01:33 +08:00
|
|
|
<div class="search-page">
|
2021-09-30 13:44:23 +08:00
|
|
|
<n-layout
|
|
|
|
|
class="hot-search"
|
|
|
|
|
:class="setAnimationClass('animate__fadeInDown')"
|
|
|
|
|
:native-scrollbar="false"
|
|
|
|
|
>
|
|
|
|
|
<div class="title">热搜列表</div>
|
2021-09-28 17:31:08 +08:00
|
|
|
<template v-for="(item, index) in hotSearchData?.data">
|
|
|
|
|
<div
|
|
|
|
|
:class="setAnimationClass('animate__bounceInLeft')"
|
2021-09-30 13:44:23 +08:00
|
|
|
:style="setAnimationDelay(index, 10)"
|
2021-09-28 17:31:08 +08:00
|
|
|
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>
|
2021-09-30 13:44:23 +08:00
|
|
|
</n-layout>
|
2021-09-28 17:31:08 +08:00
|
|
|
<!-- 搜索到的歌曲列表 -->
|
2021-09-30 13:44:23 +08:00
|
|
|
<n-layout
|
|
|
|
|
class="search-list"
|
|
|
|
|
:class="setAnimationClass('animate__fadeInUp')"
|
|
|
|
|
:native-scrollbar="false"
|
2021-11-09 11:34:09 +08:00
|
|
|
@scroll="searchScrolling"
|
2021-09-30 13:44:23 +08:00
|
|
|
>
|
|
|
|
|
<div class="title">{{ hotKeyword }}</div>
|
2021-09-28 17:31:08 +08:00
|
|
|
<template v-if="searchDetail">
|
|
|
|
|
<div
|
2021-11-09 11:34:09 +08:00
|
|
|
v-for="(item, index) in searchDetail?.result.songs"
|
2021-09-28 17:31:08 +08:00
|
|
|
:key="item.id"
|
|
|
|
|
:class="setAnimationClass('animate__bounceInRight')"
|
|
|
|
|
:style="setAnimationDelay(index, 100)"
|
|
|
|
|
>
|
|
|
|
|
<SongItem :item="item" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2021-09-30 13:44:23 +08:00
|
|
|
</n-layout>
|
2021-07-27 16:01:33 +08:00
|
|
|
</div>
|
2021-07-26 17:47:15 +08:00
|
|
|
</template>
|
|
|
|
|
|
2021-07-27 16:01:33 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
|
import { getSearch } from "@/api/search";
|
|
|
|
|
import type { IHotSearch } from "@/type/search";
|
2021-09-28 17:31:08 +08:00
|
|
|
import { getHotSearch } from "@/api/home";
|
|
|
|
|
import { useRoute, useRouter } from "vue-router";
|
|
|
|
|
import { setAnimationClass, setAnimationDelay } from "@/utils";
|
|
|
|
|
import type { ISearchDetail } from "@/type/search";
|
|
|
|
|
import { onMounted, ref, watch } from "vue";
|
|
|
|
|
import SongItem from "@/components/common/SongItem.vue";
|
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>();
|
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 () => {
|
|
|
|
|
const { data } = await getHotSearch();
|
|
|
|
|
hotSearchData.value = data;
|
2021-09-28 17:31:08 +08:00
|
|
|
};
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2021-11-09 11:34:09 +08:00
|
|
|
function searchScrolling(e: any) {
|
|
|
|
|
console.log(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2021-09-28 17:31:08 +08:00
|
|
|
onMounted(() => {
|
|
|
|
|
loadHotSearch();
|
|
|
|
|
});
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2021-09-30 13:44:23 +08:00
|
|
|
const hotKeyword = ref(route.query.keyword || "搜索列表");
|
2021-07-27 16:01:33 +08:00
|
|
|
const clickHotKeyword = (keyword: string) => {
|
2021-09-30 13:44:23 +08:00
|
|
|
hotKeyword.value = keyword;
|
2021-07-27 16:01:33 +08:00
|
|
|
router.push({
|
|
|
|
|
path: "/search",
|
|
|
|
|
query: {
|
2021-09-28 17:31:08 +08:00
|
|
|
keyword: keyword,
|
|
|
|
|
},
|
|
|
|
|
});
|
2021-07-27 16:01:33 +08:00
|
|
|
// isHotSearchList.value = false;
|
2021-09-28 17:31:08 +08:00
|
|
|
};
|
2021-07-27 16:01:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-09-28 17:31:08 +08:00
|
|
|
const loadSearch = async (keyword: any) => {
|
|
|
|
|
searchDetail.value = undefined;
|
|
|
|
|
if (!keyword) return;
|
|
|
|
|
const { data } = await getSearch(keyword);
|
2021-11-09 11:34:09 +08:00
|
|
|
|
|
|
|
|
const songs = data.result.songs;
|
|
|
|
|
|
2021-09-28 17:31:08 +08:00
|
|
|
// songs map 替换属性
|
|
|
|
|
songs.map((item: any) => {
|
|
|
|
|
item.picUrl = item.al.picUrl;
|
|
|
|
|
item.song = item;
|
|
|
|
|
item.artists = item.ar;
|
|
|
|
|
});
|
|
|
|
|
searchDetail.value = data;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loadSearch(route.query.keyword);
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => route.query,
|
|
|
|
|
async newParams => {
|
|
|
|
|
loadSearch(newParams.keyword);
|
|
|
|
|
}
|
|
|
|
|
)
|
2021-07-26 17:47:15 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-09-28 17:31:08 +08:00
|
|
|
.search {
|
|
|
|
|
height: 750px;
|
|
|
|
|
background-color: #333;
|
|
|
|
|
}
|
2021-07-27 16:01:33 +08:00
|
|
|
.search-page {
|
|
|
|
|
@apply flex;
|
|
|
|
|
}
|
|
|
|
|
.hot-search {
|
2021-09-28 17:31:08 +08:00
|
|
|
@apply mt-3 mr-4 rounded-xl flex-1 overflow-hidden;
|
2021-09-30 13:44:23 +08:00
|
|
|
height: 740px;
|
|
|
|
|
background-color: #0d0d0d;
|
2021-07-27 16:01:33 +08:00
|
|
|
animation-duration: 0.2s;
|
|
|
|
|
min-width: 400px;
|
|
|
|
|
&-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-09-28 17:31:08 +08:00
|
|
|
|
|
|
|
|
.search-list {
|
2021-09-30 13:44:23 +08:00
|
|
|
@apply mt-3 flex-1 rounded-xl;
|
|
|
|
|
height: 740px;
|
|
|
|
|
background-color: #0d0d0d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.title {
|
|
|
|
|
@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>
|