2021-07-26 17:47:15 +08:00
|
|
|
<template>
|
2021-07-27 16:01:33 +08:00
|
|
|
<div class="search-page">
|
|
|
|
|
<div
|
|
|
|
|
class="hot-search"
|
|
|
|
|
style="height:750px"
|
|
|
|
|
:class="setAnimationClass('animate__fadeInDown')"
|
|
|
|
|
>
|
|
|
|
|
<n-layout style="height:750px" :native-scrollbar="false">
|
|
|
|
|
<template v-for="(item,index) in hotSearchData?.data">
|
|
|
|
|
<div 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>
|
|
|
|
|
</n-layout>
|
|
|
|
|
</div>
|
|
|
|
|
<div>{{ searchDetail }}</div>
|
|
|
|
|
</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";
|
|
|
|
|
|
|
|
|
|
import { getHotSearch } from '@/api/home';
|
|
|
|
|
import { onBeforeRouteUpdate, useRoute, useRouter } from "vue-router";
|
|
|
|
|
import { setAnimationClass } from "@/utils";
|
2021-07-26 17:47:15 +08:00
|
|
|
import type { ISearchDetail } from "@/type/search"
|
2021-07-27 16:01:33 +08:00
|
|
|
import { onBeforeMount, onMounted, ref } from "vue";
|
|
|
|
|
|
2021-07-26 17:47:15 +08:00
|
|
|
const route = useRoute();
|
2021-07-27 16:01:33 +08:00
|
|
|
const router = useRouter()
|
2021-07-26 17:47:15 +08:00
|
|
|
const searchDetail = ref<ISearchDetail>()
|
2021-07-27 16:01:33 +08:00
|
|
|
const loadSearch = async (keyword: any) => {
|
|
|
|
|
if (!keyword) return;
|
2021-07-26 17:47:15 +08:00
|
|
|
const { data } = await getSearch(keyword);
|
|
|
|
|
searchDetail.value = data;
|
|
|
|
|
}
|
2021-07-27 16:01:33 +08:00
|
|
|
|
|
|
|
|
// 热搜列表
|
|
|
|
|
const hotSearchData = ref<IHotSearch>()
|
|
|
|
|
const loadHotSearch = async () => {
|
|
|
|
|
const { data } = await getHotSearch();
|
|
|
|
|
hotSearchData.value = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
|
loadSearch(route.params.keyword)
|
|
|
|
|
loadHotSearch();
|
2021-07-26 17:47:15 +08:00
|
|
|
})
|
2021-07-27 16:01:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
const clickHotKeyword = (keyword: string) => {
|
|
|
|
|
router.push({
|
|
|
|
|
path: "/search",
|
|
|
|
|
query: {
|
|
|
|
|
keyword: keyword
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// isHotSearchList.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 监听路由参数变化
|
|
|
|
|
onBeforeRouteUpdate(to => {
|
|
|
|
|
let value = to.query.keyword?.toString()
|
|
|
|
|
loadSearch(value);
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
2021-07-26 17:47:15 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-07-27 16:01:33 +08:00
|
|
|
.search-page {
|
|
|
|
|
@apply flex;
|
|
|
|
|
}
|
|
|
|
|
.hot-search {
|
|
|
|
|
@apply mt-3 mr-4 border rounded-xl border-2 flex-1 overflow-hidden;
|
|
|
|
|
background: #1a1a1a;
|
|
|
|
|
border-color: #63e2b7;
|
|
|
|
|
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-07-26 17:47:15 +08:00
|
|
|
</style>
|