From 02de63210d867b840869f520721d2f98dec5c8ee Mon Sep 17 00:00:00 2001 From: jxxghp Date: Wed, 9 Apr 2025 08:07:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20HeaderTab=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/components/HeaderTab.vue | 198 +++++++++++++++++++ src/main.ts | 2 + src/pages/recommend.vue | 280 +++++++-------------------- 3 files changed, 272 insertions(+), 208 deletions(-) create mode 100644 src/layouts/components/HeaderTab.vue diff --git a/src/layouts/components/HeaderTab.vue b/src/layouts/components/HeaderTab.vue new file mode 100644 index 00000000..ed81aaea --- /dev/null +++ b/src/layouts/components/HeaderTab.vue @@ -0,0 +1,198 @@ + + + diff --git a/src/main.ts b/src/main.ts index 0298893b..5b51ebc6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -37,6 +37,7 @@ import TorrentCard from './components/cards/TorrentCard.vue' import MediaIdSelector from './components/misc/MediaIdSelector.vue' import CronField from './components/field/CronField.vue' import PathField from './components/field/PathField.vue' +import HeaderTab from './layouts/components/HeaderTab.vue' // 7. 样式文件 import '@core/scss/template/libs/vuetify/index.scss' @@ -93,6 +94,7 @@ initializeApp().then(() => { .component('VMediaIdSelector', MediaIdSelector) .component('VCronField', CronField) .component('VPathField', PathField) + .component('VHeaderTab', HeaderTab) // 5. 注册其他插件 app diff --git a/src/pages/recommend.vue b/src/pages/recommend.vue index 2736fbf2..a8edcbbb 100644 --- a/src/pages/recommend.vue +++ b/src/pages/recommend.vue @@ -2,7 +2,6 @@ import api from '@/api' import { RecommendSource } from '@/api/types' import MediaCardSlideView from '@/views/discover/MediaCardSlideView.vue' -import { ref, onMounted, onUnmounted, computed, reactive, watch, nextTick } from 'vue' // 当前选择的分类 const currentCategory = ref('全部') @@ -157,39 +156,33 @@ async function saveConfig() { } // 标签图标映射 -const categoryIcons: Record = { - 全部: 'mdi-filmstrip-box-multiple', - 电影: 'mdi-movie', - 电视剧: 'mdi-television-classic', - 动漫: 'mdi-animation', - 榜单: 'mdi-trophy', -} - -// Ref for the tabs container -const tabsContainerRef = ref(null) -// State for showing the scroll indicator -const showTabsScrollIndicator = ref(false) - -// Function to check and update the indicator state -const updateTabsIndicator = () => { - const el = tabsContainerRef.value - if (!el) return - - const tolerance = 1 // Allow 1px tolerance - const hasOverflow = el.scrollWidth > el.clientWidth + tolerance - const isScrolledToEnd = el.scrollLeft + el.clientWidth >= el.scrollWidth - tolerance - - showTabsScrollIndicator.value = hasOverflow && !isScrolledToEnd -} - -// Debounce resize handler -let resizeTimeout: ReturnType | null = null -const handleResize = () => { - if (resizeTimeout) clearTimeout(resizeTimeout) - resizeTimeout = setTimeout(() => { - updateTabsIndicator() - }, 150) -} +const categoryItems: Record[] = [ + { + title: '全部', + icon: 'mdi-filmstrip-box-multiple', + key: 'all', + }, + { + title: '电影', + icon: 'mdi-movie', + key: 'movie', + }, + { + title: '电视剧', + icon: 'mdi-television-classic', + key: 'tv', + }, + { + title: '动漫', + icon: 'mdi-animation', + key: 'anime', + }, + { + title: '榜单', + icon: 'mdi-trophy', + key: 'rank', + }, +] onBeforeMount(async () => { await loadConfig() @@ -197,22 +190,6 @@ onBeforeMount(async () => { onMounted(async () => { await loadExtraRecommendSources() - - // Add resize listener for tabs indicator - window.addEventListener('resize', handleResize) - // Initial check for tabs indicator after DOM update - await nextTick() // Ensure element is rendered - updateTabsIndicator() - - // Listen for scroll events specifically on the tabs container - tabsContainerRef.value?.addEventListener('scroll', updateTabsIndicator, { passive: true }) -}) - -onUnmounted(() => { - // Remove resize listener - window.removeEventListener('resize', handleResize) - // Remove tabs scroll listener - tabsContainerRef.value?.removeEventListener('scroll', updateTabsIndicator) }) onActivated(async () => { @@ -232,28 +209,18 @@ watch(currentCategory, () => {