2021-07-26 17:47:15 +08:00
|
|
|
<template>
|
2024-05-16 18:54:30 +08:00
|
|
|
<div class="search-page">
|
2024-05-23 17:12:35 +08:00
|
|
|
<n-layout
|
|
|
|
|
v-if="isMobile ? !searchDetail : true"
|
|
|
|
|
class="hot-search"
|
|
|
|
|
:class="setAnimationClass('animate__fadeInDown')"
|
|
|
|
|
:native-scrollbar="false"
|
|
|
|
|
>
|
2025-02-19 01:01:43 +08:00
|
|
|
<div class="title">{{ t('search.title.hotSearch') }}</div>
|
2024-05-16 18:54:30 +08:00
|
|
|
<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"
|
2024-09-12 17:28:51 +08:00
|
|
|
@click.stop="loadSearch(item.searchWord, 1)"
|
2024-05-16 18:54:30 +08:00
|
|
|
>
|
2025-01-01 02:25:18 +08:00
|
|
|
<span class="hot-search-item-count" :class="{ 'hot-search-item-count-3': index < 3 }">{{
|
|
|
|
|
index + 1
|
|
|
|
|
}}</span>
|
2024-05-16 18:54:30 +08:00
|
|
|
{{ item.searchWord }}
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</n-layout>
|
|
|
|
|
<!-- 搜索到的歌曲列表 -->
|
2024-05-23 17:12:35 +08:00
|
|
|
<n-layout
|
|
|
|
|
v-if="isMobile ? searchDetail : true"
|
|
|
|
|
class="search-list"
|
2025-01-13 22:13:46 +08:00
|
|
|
:class="setAnimationClass('animate__fadeInDown')"
|
2024-05-23 17:12:35 +08:00
|
|
|
:native-scrollbar="false"
|
2025-01-13 22:13:21 +08:00
|
|
|
@scroll="handleScroll"
|
2024-05-23 17:12:35 +08:00
|
|
|
>
|
2025-01-13 22:13:21 +08:00
|
|
|
<div v-if="searchDetail" class="title">
|
|
|
|
|
<i
|
|
|
|
|
class="ri-arrow-left-s-line mr-1 cursor-pointer hover:text-gray-500 hover:scale-110"
|
|
|
|
|
@click="searchDetail = null"
|
|
|
|
|
></i>
|
|
|
|
|
{{ hotKeyword }}
|
2025-05-11 15:37:37 +08:00
|
|
|
<div v-if="searchDetail?.songs?.length" class="title-play-all">
|
|
|
|
|
<div class="play-all-btn" @click="handlePlayAll">
|
|
|
|
|
<i class="ri-play-circle-fill"></i>
|
|
|
|
|
<span>{{ t('search.button.playAll') }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-01-13 22:13:21 +08:00
|
|
|
</div>
|
2024-09-04 15:20:43 +08:00
|
|
|
<div v-loading="searchDetailLoading" class="search-list-box">
|
|
|
|
|
<template v-if="searchDetail">
|
2025-03-29 23:19:51 +08:00
|
|
|
<!-- B站视频搜索结果 -->
|
|
|
|
|
<template v-if="searchType === SEARCH_TYPE.BILIBILI">
|
|
|
|
|
<div
|
|
|
|
|
v-for="(item, index) in searchDetail?.bilibili"
|
|
|
|
|
:key="item.bvid"
|
|
|
|
|
:class="setAnimationClass('animate__bounceInRight')"
|
2025-05-11 15:37:37 +08:00
|
|
|
:style="getSearchListAnimation(index)"
|
2025-03-29 23:19:51 +08:00
|
|
|
>
|
|
|
|
|
<bilibili-item :item="item" @play="handlePlayBilibili" />
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="isLoadingMore" class="loading-more">
|
|
|
|
|
<n-spin size="small" />
|
|
|
|
|
<span class="ml-2">{{ t('search.loading.more') }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="!hasMore && searchDetail" class="no-more">{{ t('search.noMore') }}</div>
|
|
|
|
|
</template>
|
|
|
|
|
<!-- 原有音乐搜索结果 -->
|
|
|
|
|
<template v-else>
|
|
|
|
|
<div
|
|
|
|
|
v-for="(item, index) in searchDetail?.songs"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:class="setAnimationClass('animate__bounceInRight')"
|
2025-05-11 15:37:37 +08:00
|
|
|
:style="getSearchListAnimation(index)"
|
2025-03-29 23:19:51 +08:00
|
|
|
>
|
2025-05-11 15:37:37 +08:00
|
|
|
<song-item :item="item" @play="handlePlay" :is-next="true" />
|
2025-03-29 23:19:51 +08:00
|
|
|
</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="mb-3"
|
|
|
|
|
:class="setAnimationClass('animate__bounceInRight')"
|
2025-05-11 15:37:37 +08:00
|
|
|
:style="getSearchListAnimation(index)"
|
2025-03-29 23:19:51 +08:00
|
|
|
>
|
|
|
|
|
<search-item :item="item" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2021-09-28 17:31:08 +08:00
|
|
|
</template>
|
2025-03-29 23:19:51 +08:00
|
|
|
<!-- 加载状态 -->
|
|
|
|
|
<div v-if="isLoadingMore" class="loading-more">
|
|
|
|
|
<n-spin size="small" />
|
|
|
|
|
<span class="ml-2">{{ t('search.loading.more') }}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-if="!hasMore && searchDetail" class="no-more">{{ t('search.noMore') }}</div>
|
2024-05-16 18:54:30 +08:00
|
|
|
</template>
|
2025-01-13 22:13:21 +08:00
|
|
|
</template>
|
|
|
|
|
<!-- 搜索历史 -->
|
|
|
|
|
<template v-else>
|
|
|
|
|
<div class="search-history">
|
|
|
|
|
<div class="search-history-header title">
|
2025-02-19 01:01:43 +08:00
|
|
|
<span>{{ t('search.title.searchHistory') }}</span>
|
2025-01-13 22:13:21 +08:00
|
|
|
<n-button text type="error" @click="clearSearchHistory">
|
|
|
|
|
<template #icon>
|
|
|
|
|
<i class="ri-delete-bin-line"></i>
|
|
|
|
|
</template>
|
2025-02-19 01:01:43 +08:00
|
|
|
{{ t('search.button.clear') }}
|
2025-01-13 22:13:21 +08:00
|
|
|
</n-button>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="search-history-list">
|
|
|
|
|
<n-tag
|
|
|
|
|
v-for="(item, index) in searchHistory"
|
|
|
|
|
:key="index"
|
2025-01-13 22:13:46 +08:00
|
|
|
:class="setAnimationClass('animate__bounceIn')"
|
2025-05-11 15:37:37 +08:00
|
|
|
:style="getSearchListAnimation(index)"
|
2025-01-13 22:13:21 +08:00
|
|
|
class="search-history-item"
|
|
|
|
|
round
|
|
|
|
|
closable
|
|
|
|
|
@click="handleSearchHistory(item)"
|
|
|
|
|
@close="handleCloseSearchHistory(item)"
|
|
|
|
|
>
|
2025-03-30 00:18:44 +08:00
|
|
|
{{ item.keyword }}
|
2025-01-13 22:13:21 +08:00
|
|
|
</n-tag>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2024-09-04 15:20:43 +08:00
|
|
|
</template>
|
|
|
|
|
</div>
|
2024-05-16 18:54:30 +08:00
|
|
|
</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';
|
2025-03-29 23:19:51 +08:00
|
|
|
import { computed, onMounted, ref, watch } from 'vue';
|
2025-02-19 01:01:43 +08:00
|
|
|
import { useI18n } from 'vue-i18n';
|
2025-03-30 01:20:28 +08:00
|
|
|
import { useRoute, useRouter } from 'vue-router';
|
2024-05-16 18:54:30 +08:00
|
|
|
|
2025-03-29 23:19:51 +08:00
|
|
|
import { getBilibiliProxyUrl, searchBilibili } from '@/api/bilibili';
|
2024-05-16 18:54:30 +08:00
|
|
|
import { getHotSearch } from '@/api/home';
|
|
|
|
|
import { getSearch } from '@/api/search';
|
2025-03-29 23:19:51 +08:00
|
|
|
import BilibiliItem from '@/components/common/BilibiliItem.vue';
|
2025-01-10 22:49:55 +08:00
|
|
|
import SearchItem from '@/components/common/SearchItem.vue';
|
2024-05-16 18:54:30 +08:00
|
|
|
import SongItem from '@/components/common/SongItem.vue';
|
2025-03-29 23:19:51 +08:00
|
|
|
import { SEARCH_TYPE } from '@/const/bar-const';
|
2025-03-19 22:48:28 +08:00
|
|
|
import { usePlayerStore } from '@/store/modules/player';
|
|
|
|
|
import { useSearchStore } from '@/store/modules/search';
|
2025-03-29 23:19:51 +08:00
|
|
|
import type { IBilibiliSearchResult } from '@/types/bilibili';
|
2025-08-07 22:57:17 +08:00
|
|
|
import type { IHotSearch } from '@/types/search';
|
2024-05-23 17:12:35 +08:00
|
|
|
import { isMobile, setAnimationClass, setAnimationDelay } from '@/utils';
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2024-05-22 12:07:48 +08:00
|
|
|
defineOptions({
|
2025-01-01 02:25:18 +08:00
|
|
|
name: 'Search'
|
2024-05-22 12:07:48 +08:00
|
|
|
});
|
|
|
|
|
|
2025-02-19 01:01:43 +08:00
|
|
|
const { t } = useI18n();
|
2021-07-26 17:47:15 +08:00
|
|
|
const route = useRoute();
|
2025-03-30 01:20:28 +08:00
|
|
|
const router = useRouter();
|
2025-03-19 22:48:28 +08:00
|
|
|
const playerStore = usePlayerStore();
|
|
|
|
|
const searchStore = useSearchStore();
|
2024-09-12 17:28:51 +08:00
|
|
|
|
2021-11-09 11:34:09 +08:00
|
|
|
const searchDetail = ref<any>();
|
2025-03-19 22:48:28 +08:00
|
|
|
const searchType = computed(() => searchStore.searchType as number);
|
2024-05-22 12:07:48 +08:00
|
|
|
const searchDetailLoading = ref(false);
|
2025-03-30 00:18:44 +08:00
|
|
|
const searchHistory = ref<Array<{ keyword: string; type: number }>>([]);
|
2025-01-13 22:13:21 +08:00
|
|
|
|
|
|
|
|
// 添加分页相关的状态
|
|
|
|
|
const ITEMS_PER_PAGE = 30; // 每页数量
|
|
|
|
|
const page = ref(0);
|
|
|
|
|
const hasMore = ref(true);
|
|
|
|
|
const isLoadingMore = ref(false);
|
|
|
|
|
const currentKeyword = ref('');
|
|
|
|
|
|
2025-05-11 15:37:37 +08:00
|
|
|
const getSearchListAnimation = (index: number) => {
|
|
|
|
|
return setAnimationDelay(index % ITEMS_PER_PAGE, 50);
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-13 22:13:21 +08:00
|
|
|
// 从 localStorage 加载搜索历史
|
|
|
|
|
const loadSearchHistory = () => {
|
|
|
|
|
const history = localStorage.getItem('searchHistory');
|
|
|
|
|
searchHistory.value = history ? JSON.parse(history) : [];
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-30 00:18:44 +08:00
|
|
|
// 保存搜索历史,改为保存关键词和类型
|
|
|
|
|
const saveSearchHistory = (keyword: string, type: number) => {
|
2025-01-13 22:13:21 +08:00
|
|
|
if (!keyword) return;
|
|
|
|
|
const history = searchHistory.value;
|
|
|
|
|
// 移除重复的关键词
|
2025-03-30 00:18:44 +08:00
|
|
|
const index = history.findIndex((item) => item.keyword === keyword);
|
2025-01-13 22:13:21 +08:00
|
|
|
if (index > -1) {
|
|
|
|
|
history.splice(index, 1);
|
|
|
|
|
}
|
|
|
|
|
// 添加到开头
|
2025-03-30 00:18:44 +08:00
|
|
|
history.unshift({ keyword, type });
|
2025-01-13 22:13:21 +08:00
|
|
|
// 只保留最近的20条记录
|
|
|
|
|
if (history.length > 20) {
|
|
|
|
|
history.pop();
|
|
|
|
|
}
|
|
|
|
|
searchHistory.value = history;
|
|
|
|
|
localStorage.setItem('searchHistory', JSON.stringify(history));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 清空搜索历史
|
|
|
|
|
const clearSearchHistory = () => {
|
|
|
|
|
searchHistory.value = [];
|
|
|
|
|
localStorage.removeItem('searchHistory');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 删除搜索历史
|
2025-03-30 00:18:44 +08:00
|
|
|
const handleCloseSearchHistory = (item: { keyword: string; type: number }) => {
|
|
|
|
|
searchHistory.value = searchHistory.value.filter((h) => h.keyword !== item.keyword);
|
2025-01-13 22:13:21 +08:00
|
|
|
localStorage.setItem('searchHistory', JSON.stringify(searchHistory.value));
|
|
|
|
|
};
|
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();
|
2025-01-13 22:13:21 +08:00
|
|
|
loadSearchHistory();
|
2025-03-30 00:18:44 +08:00
|
|
|
// 注意:路由参数的处理已经在 watch route.query 中处理了
|
2021-09-28 17:31:08 +08:00
|
|
|
});
|
2021-07-27 16:01:33 +08:00
|
|
|
|
2025-02-19 01:01:43 +08:00
|
|
|
const hotKeyword = ref(route.query.keyword || t('search.title.searchList'));
|
2024-09-12 17:28:51 +08:00
|
|
|
|
2025-01-13 22:13:21 +08:00
|
|
|
const loadSearch = async (keywords: any, type: any = null, isLoadMore = false) => {
|
2024-05-16 18:54:30 +08:00
|
|
|
if (!keywords) return;
|
2024-05-22 12:07:48 +08:00
|
|
|
|
2025-03-30 00:18:44 +08:00
|
|
|
// 使用传入的类型或当前类型
|
|
|
|
|
const searchTypeToUse = type !== null ? type : searchType.value;
|
|
|
|
|
|
2025-01-13 22:13:21 +08:00
|
|
|
if (!isLoadMore) {
|
|
|
|
|
hotKeyword.value = keywords;
|
|
|
|
|
searchDetail.value = undefined;
|
|
|
|
|
page.value = 0;
|
|
|
|
|
hasMore.value = true;
|
|
|
|
|
currentKeyword.value = keywords;
|
2025-03-30 00:18:44 +08:00
|
|
|
|
|
|
|
|
// 保存搜索历史
|
|
|
|
|
saveSearchHistory(keywords, searchTypeToUse);
|
|
|
|
|
|
|
|
|
|
// 始终更新搜索框内容和类型
|
|
|
|
|
searchStore.searchType = searchTypeToUse;
|
|
|
|
|
searchStore.searchValue = keywords;
|
2025-01-13 22:13:21 +08:00
|
|
|
} else if (isLoadingMore.value || !hasMore.value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isLoadMore) {
|
|
|
|
|
isLoadingMore.value = true;
|
|
|
|
|
} else {
|
|
|
|
|
searchDetailLoading.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2025-03-29 23:19:51 +08:00
|
|
|
// B站搜索
|
2025-03-30 00:18:44 +08:00
|
|
|
if (searchTypeToUse === SEARCH_TYPE.BILIBILI) {
|
2025-03-29 23:19:51 +08:00
|
|
|
const response = await searchBilibili({
|
|
|
|
|
keyword: currentKeyword.value,
|
|
|
|
|
page: page.value + 1,
|
|
|
|
|
pagesize: ITEMS_PER_PAGE
|
|
|
|
|
});
|
|
|
|
|
console.log('response', response);
|
|
|
|
|
|
|
|
|
|
const bilibiliVideos = response.data.data.result.map((item: any) => ({
|
|
|
|
|
id: item.aid,
|
|
|
|
|
bvid: item.bvid,
|
|
|
|
|
title: item.title,
|
|
|
|
|
author: item.author,
|
|
|
|
|
pic: getBilibiliProxyUrl(item.pic),
|
|
|
|
|
duration: item.duration,
|
|
|
|
|
pubdate: item.pubdate,
|
|
|
|
|
description: item.description,
|
|
|
|
|
view: item.play,
|
|
|
|
|
danmaku: item.video_review
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
if (isLoadMore && searchDetail.value) {
|
|
|
|
|
// 合并数据
|
|
|
|
|
searchDetail.value.bilibili = [...searchDetail.value.bilibili, ...bilibiliVideos];
|
|
|
|
|
} else {
|
|
|
|
|
searchDetail.value = {
|
|
|
|
|
bilibili: bilibiliVideos
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断是否还有更多数据
|
|
|
|
|
hasMore.value = bilibiliVideos.length === ITEMS_PER_PAGE;
|
|
|
|
|
}
|
|
|
|
|
// 音乐搜索
|
|
|
|
|
else {
|
|
|
|
|
const { data } = await getSearch({
|
|
|
|
|
keywords: currentKeyword.value,
|
2025-03-30 00:18:44 +08:00
|
|
|
type: searchTypeToUse,
|
2025-03-29 23:19:51 +08:00
|
|
|
limit: ITEMS_PER_PAGE,
|
|
|
|
|
offset: page.value * ITEMS_PER_PAGE
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const songs = data.result.songs || [];
|
|
|
|
|
const albums = data.result.albums || [];
|
|
|
|
|
const mvs = (data.result.mvs || []).map((item: any) => ({
|
|
|
|
|
...item,
|
|
|
|
|
picUrl: item.cover,
|
|
|
|
|
playCount: item.playCount,
|
|
|
|
|
desc: item.artists.map((artist: any) => artist.name).join('/'),
|
|
|
|
|
type: 'mv'
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const playlists = (data.result.playlists || []).map((item: any) => ({
|
|
|
|
|
...item,
|
|
|
|
|
picUrl: item.coverImgUrl,
|
|
|
|
|
playCount: item.playCount,
|
|
|
|
|
desc: item.creator.nickname,
|
|
|
|
|
type: 'playlist'
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
// songs map 替换属性
|
|
|
|
|
songs.forEach((item: any) => {
|
|
|
|
|
item.picUrl = item.al.picUrl;
|
|
|
|
|
item.artists = item.ar;
|
|
|
|
|
});
|
|
|
|
|
albums.forEach((item: any) => {
|
|
|
|
|
item.desc = `${item.artist.name} ${item.company} ${dateFormat(item.publishTime)}`;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (isLoadMore && searchDetail.value) {
|
|
|
|
|
// 合并数据
|
|
|
|
|
searchDetail.value.songs = [...searchDetail.value.songs, ...songs];
|
|
|
|
|
searchDetail.value.albums = [...searchDetail.value.albums, ...albums];
|
|
|
|
|
searchDetail.value.mvs = [...searchDetail.value.mvs, ...mvs];
|
|
|
|
|
searchDetail.value.playlists = [...searchDetail.value.playlists, ...playlists];
|
|
|
|
|
} else {
|
|
|
|
|
searchDetail.value = {
|
|
|
|
|
songs,
|
|
|
|
|
albums,
|
|
|
|
|
mvs,
|
|
|
|
|
playlists
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 判断是否还有更多数据
|
|
|
|
|
hasMore.value =
|
|
|
|
|
songs.length === ITEMS_PER_PAGE ||
|
|
|
|
|
albums.length === ITEMS_PER_PAGE ||
|
|
|
|
|
mvs.length === ITEMS_PER_PAGE ||
|
|
|
|
|
playlists.length === ITEMS_PER_PAGE;
|
2025-01-13 22:13:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page.value++;
|
|
|
|
|
} catch (error) {
|
2025-02-19 01:01:43 +08:00
|
|
|
console.error(t('search.error.searchFailed'), error);
|
2025-01-13 22:13:21 +08:00
|
|
|
} finally {
|
|
|
|
|
searchDetailLoading.value = false;
|
|
|
|
|
isLoadingMore.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-19 22:48:28 +08:00
|
|
|
watch(
|
|
|
|
|
() => searchStore.searchValue,
|
|
|
|
|
(value) => {
|
|
|
|
|
loadSearch(value);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => searchType.value,
|
|
|
|
|
() => {
|
|
|
|
|
if (searchStore.searchValue) {
|
|
|
|
|
loadSearch(searchStore.searchValue);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
// 修改 store.state 的访问
|
|
|
|
|
if (searchStore.searchValue) {
|
|
|
|
|
loadSearch(searchStore.searchValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 修改 store.state 的设置
|
|
|
|
|
searchStore.searchValue = route.query.keyword as string;
|
|
|
|
|
|
|
|
|
|
const dateFormat = (time: any) => useDateFormat(time, 'YYYY.MM.DD').value;
|
|
|
|
|
|
2025-01-13 22:13:21 +08:00
|
|
|
// 添加滚动处理函数
|
|
|
|
|
const handleScroll = (e: any) => {
|
|
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.target;
|
|
|
|
|
// 距离底部100px时加载更多
|
|
|
|
|
if (scrollTop + clientHeight >= scrollHeight - 100 && !isLoadingMore.value && hasMore.value) {
|
|
|
|
|
loadSearch(currentKeyword.value, null, true);
|
|
|
|
|
}
|
2021-09-28 17:31:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
watch(
|
2025-03-30 00:18:44 +08:00
|
|
|
() => route.query,
|
|
|
|
|
(query) => {
|
|
|
|
|
if (route.path === '/search' && query.keyword) {
|
|
|
|
|
const routeKeyword = query.keyword as string;
|
|
|
|
|
const routeType = query.type ? Number(query.type) : searchType.value;
|
|
|
|
|
|
|
|
|
|
// 更新搜索类型和值
|
|
|
|
|
searchStore.searchType = routeType;
|
|
|
|
|
searchStore.searchValue = routeKeyword;
|
|
|
|
|
|
|
|
|
|
// 加载搜索结果
|
|
|
|
|
loadSearch(routeKeyword, routeType);
|
2024-09-12 17:28:51 +08:00
|
|
|
}
|
2025-03-30 00:18:44 +08:00
|
|
|
},
|
|
|
|
|
{ immediate: true }
|
2024-05-16 18:54:30 +08:00
|
|
|
);
|
|
|
|
|
|
2025-05-11 15:37:37 +08:00
|
|
|
const handlePlay = (item: any) => {
|
|
|
|
|
// 添加到下一首
|
|
|
|
|
playerStore.addToNextPlay(item);
|
2024-05-16 18:54:30 +08:00
|
|
|
};
|
2025-01-13 22:13:21 +08:00
|
|
|
|
|
|
|
|
// 点击搜索历史
|
2025-03-30 00:18:44 +08:00
|
|
|
const handleSearchHistory = (item: { keyword: string; type: number }) => {
|
|
|
|
|
// 更新搜索类型
|
|
|
|
|
searchStore.searchType = item.type;
|
|
|
|
|
// 先更新搜索值到 store
|
|
|
|
|
searchStore.searchValue = item.keyword;
|
|
|
|
|
// 使用关键词和类型加载搜索
|
|
|
|
|
loadSearch(item.keyword, item.type);
|
2025-01-13 22:13:21 +08:00
|
|
|
};
|
2025-03-29 23:19:51 +08:00
|
|
|
|
|
|
|
|
// 处理B站视频播放
|
|
|
|
|
const handlePlayBilibili = (item: IBilibiliSearchResult) => {
|
2025-03-30 01:20:28 +08:00
|
|
|
// 使用路由导航到B站播放页面
|
|
|
|
|
router.push(`/bilibili/${item.bvid}`);
|
2025-03-29 23:19:51 +08:00
|
|
|
};
|
2025-05-11 15:37:37 +08:00
|
|
|
|
|
|
|
|
const handlePlayAll = () => {
|
|
|
|
|
if (!searchDetail.value?.songs?.length) return;
|
2025-07-23 23:54:35 +08:00
|
|
|
|
2025-05-11 15:37:37 +08:00
|
|
|
// 设置播放列表为搜索结果中的所有歌曲
|
|
|
|
|
playerStore.setPlayList(searchDetail.value.songs);
|
2025-07-23 23:54:35 +08:00
|
|
|
|
2025-05-11 15:37:37 +08:00
|
|
|
// 开始播放第一首歌
|
|
|
|
|
if (searchDetail.value.songs[0]) {
|
|
|
|
|
playerStore.setPlay(searchDetail.value.songs[0]);
|
|
|
|
|
}
|
|
|
|
|
};
|
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
|
|
|
}
|
2024-12-28 16:43:52 +08:00
|
|
|
|
2021-07-27 16:01:33 +08:00
|
|
|
.hot-search {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply mr-4 rounded-xl flex-1 overflow-hidden;
|
|
|
|
|
@apply bg-light-100 dark:bg-dark-100;
|
2024-05-16 18:54:30 +08:00
|
|
|
animation-duration: 0.2s;
|
|
|
|
|
min-width: 400px;
|
|
|
|
|
height: 100%;
|
2024-12-28 16:43:52 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
&-list {
|
|
|
|
|
@apply pb-28;
|
|
|
|
|
}
|
2024-12-28 16:43:52 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
&-item {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply px-4 py-3 text-lg rounded-xl cursor-pointer;
|
|
|
|
|
@apply text-gray-900 dark:text-white;
|
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
@apply bg-light-100 dark:bg-dark-200;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
&-count {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply inline-block ml-3 w-8;
|
|
|
|
|
@apply text-green-500;
|
|
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
&-3 {
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply font-bold inline-block ml-3 w-8;
|
|
|
|
|
@apply text-red-500;
|
2024-05-16 18:54:30 +08:00
|
|
|
}
|
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;
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply bg-light-100 dark:bg-dark-100;
|
2024-05-16 18:54:30 +08:00
|
|
|
height: 100%;
|
2025-01-13 22:13:46 +08:00
|
|
|
animation-duration: 0.2s;
|
2024-12-28 16:43:52 +08:00
|
|
|
|
2024-05-16 18:54:30 +08:00
|
|
|
&-box {
|
|
|
|
|
@apply pb-28;
|
|
|
|
|
}
|
2021-09-30 13:44:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.title {
|
2025-05-11 15:37:37 +08:00
|
|
|
@apply text-xl font-bold my-2 mx-4 flex items-center;
|
2024-12-28 16:43:52 +08:00
|
|
|
@apply text-gray-900 dark:text-white;
|
2025-07-23 23:54:35 +08:00
|
|
|
|
2025-05-11 15:37:37 +08:00
|
|
|
&-play-all {
|
|
|
|
|
@apply ml-auto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.play-all-btn {
|
|
|
|
|
@apply flex items-center gap-1 px-3 py-1 rounded-full cursor-pointer transition-all;
|
|
|
|
|
@apply text-sm font-normal text-gray-900 dark:text-white hover:bg-light-300 dark:hover:bg-dark-300 hover:text-green-500;
|
2025-07-23 23:54:35 +08:00
|
|
|
|
2025-05-11 15:37:37 +08:00
|
|
|
i {
|
|
|
|
|
@apply text-xl;
|
|
|
|
|
}
|
2021-09-28 17:31:08 +08:00
|
|
|
}
|
2024-05-23 17:12:35 +08:00
|
|
|
|
2025-01-13 22:13:21 +08:00
|
|
|
.search-history {
|
|
|
|
|
&-header {
|
|
|
|
|
@apply flex justify-between items-center mb-4;
|
|
|
|
|
@apply text-gray-900 dark:text-white;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&-list {
|
|
|
|
|
@apply flex flex-wrap gap-2 px-4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&-item {
|
|
|
|
|
@apply cursor-pointer;
|
|
|
|
|
animation-duration: 0.2s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-23 17:12:35 +08:00
|
|
|
.mobile {
|
|
|
|
|
.hot-search {
|
|
|
|
|
@apply mr-0 w-full;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-13 22:13:21 +08:00
|
|
|
|
|
|
|
|
.loading-more {
|
|
|
|
|
@apply flex justify-center items-center py-4;
|
|
|
|
|
@apply text-gray-500 dark:text-gray-400;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.no-more {
|
|
|
|
|
@apply text-center py-4;
|
|
|
|
|
@apply text-gray-500 dark:text-gray-400;
|
|
|
|
|
}
|
2021-07-26 17:47:15 +08:00
|
|
|
</style>
|