From db0d5133e8eb3b313c1844dc8046fd28b39c0eb2 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 26 Apr 2024 20:35:40 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BA=BA=E7=89=A9=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/cards/TmdbPersonCard.vue | 19 +++--- src/layouts/components/SearchBar.vue | 45 +++++++------- src/pages/browse.vue | 24 +++++--- src/views/discover/MediaCardListView.vue | 43 +++---------- src/views/discover/PersonCardListView.vue | 75 ++++++++--------------- 5 files changed, 82 insertions(+), 124 deletions(-) diff --git a/src/components/cards/TmdbPersonCard.vue b/src/components/cards/TmdbPersonCard.vue index d58b5191..c4d18d44 100644 --- a/src/components/cards/TmdbPersonCard.vue +++ b/src/components/cards/TmdbPersonCard.vue @@ -17,15 +17,13 @@ const isImageLoaded = ref(false) // 人物图片地址 function getPersonImage() { - if (!personInfo.value?.profile_path) - return personIcon + if (!personInfo.value?.profile_path) return personIcon return `https://image.tmdb.org/t/p/w600_and_h900_bestv2${personInfo.value?.profile_path}` } // 人物详情 function goPersonDetail() { - if (!personInfo.value?.id) - return + if (!personInfo.value?.id) return router.push({ path: '/person', query: { @@ -51,7 +49,7 @@ function goPersonDetail() {
-
+
- +
{{ personInfo?.name }}
-
+
{{ personInfo?.character }}
diff --git a/src/layouts/components/SearchBar.vue b/src/layouts/components/SearchBar.vue index 8e6dd33a..f7f6aa71 100644 --- a/src/layouts/components/SearchBar.vue +++ b/src/layouts/components/SearchBar.vue @@ -11,20 +11,28 @@ const searchDialog = ref(false) // ref const searchWordInput = ref(null) +// 当前的搜索类型 media/person +const searchType = ref('media') + // Search function search() { - if (!searchWord.value) - return + if (!searchWord.value) return searchDialog.value = false router.push({ path: '/browse/media/search', query: { title: searchWord.value, + type: searchType.value, }, }) } +// 切换搜索类型 +function switchSearchType() { + searchType.value = searchType.value === 'media' ? 'person' : 'media' +} + // 打开搜索弹窗 function openSearchDialog() { searchDialog.value = true @@ -36,15 +44,8 @@ function openSearchDialog() { diff --git a/src/pages/browse.vue b/src/pages/browse.vue index 31c7cf89..b9b5e576 100644 --- a/src/pages/browse.vue +++ b/src/pages/browse.vue @@ -1,5 +1,6 @@ @@ -26,14 +30,20 @@ function getApiPath(paths: string[] | string) {
-

+

{{ title }}

- +
diff --git a/src/views/discover/MediaCardListView.vue b/src/views/discover/MediaCardListView.vue index 1992c54a..158f5658 100644 --- a/src/views/discover/MediaCardListView.vue +++ b/src/views/discover/MediaCardListView.vue @@ -12,11 +12,7 @@ const props = defineProps({ // 判断是否有滚动条 function hasScroll() { - return ( - document.body.scrollHeight - - (window.innerHeight || document.documentElement.clientHeight) - > 2 - ) + return document.body.scrollHeight - (window.innerHeight || document.documentElement.clientHeight) > 2 } // 当前页码 @@ -37,8 +33,7 @@ function getParams() { let params = { page: page.value, } - if (props.params) - params = { ...params, ...props.params } + if (props.params) params = { ...params, ...props.params } return params } @@ -46,8 +41,7 @@ function getParams() { // 获取列表数据 async function fetchData({ done }: { done: any }) { try { - if (!props.apipath) - return + if (!props.apipath) return // 如果正在加载中,直接返回 if (loading.value) { @@ -81,8 +75,7 @@ async function fetchData({ done }: { done: any }) { // 返回加载成功 done('ok') } - } - else { + } else { // 加载一次 // 设置加载中 loading.value = true @@ -106,8 +99,7 @@ async function fetchData({ done }: { done: any }) { } // 取消加载中 loading.value = false - } - catch (error) { + } catch (error) { console.error(error) // 返回加载失败 done('error') @@ -116,29 +108,12 @@ async function fetchData({ done }: { done: any }) {