From 476d2f7e81f954a1cc477c0b76d5dd34fea741a0 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 18 Apr 2025 13:47:39 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E9=80=8F=E6=98=8E?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E6=94=AF=E6=8C=81=E5=8F=8A=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=BD=AE=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 App.vue 中引入 API 获取背景图片,并实现背景图片的轮换功能。 - 更新主题切换逻辑,支持透明主题,并在主题变化时更新 HTML 属性。 - 在样式中添加透明主题的特定样式,确保各个组件在透明主题下的显示效果。 --- src/@core/components/ThemeSwitcher.vue | 6 +- src/App.vue | 144 +++++++++++++++++- src/components/dialog/AddDownloadDialog.vue | 2 +- src/layouts/components/HeaderTab.vue | 10 +- .../components/NavbarThemeSwitcher.vue | 7 +- src/pages/resource.vue | 6 +- src/plugins/vuetify/theme.ts | 67 +++++++- src/styles/styles.scss | 97 +++++++++++- src/views/discover/MediaDetailView.vue | 12 +- src/views/torrent/TorrentCardListView.vue | 5 +- src/views/torrent/TorrentRowListView.vue | 4 +- 11 files changed, 317 insertions(+), 43 deletions(-) diff --git a/src/@core/components/ThemeSwitcher.vue b/src/@core/components/ThemeSwitcher.vue index c21a2511..06df70b5 100644 --- a/src/@core/components/ThemeSwitcher.vue +++ b/src/@core/components/ThemeSwitcher.vue @@ -195,11 +195,10 @@ onMounted(() => { - + 主题选择 -
{ } .theme-switcher-options { - max-block-size: 300px; - overflow-y: auto; + overflow-y: hidden; } .theme-option { diff --git a/src/App.vue b/src/App.vue index 011e1f64..58f02c65 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,6 +2,7 @@ import { useTheme } from 'vuetify' import { checkPrefersColorSchemeIsDark } from '@/@core/utils' import { ensureRenderComplete, removeEl } from './@core/utils/dom' +import api from '@/api' // 生效主题 const { global: globalTheme } = useTheme() @@ -9,9 +10,61 @@ let themeValue = localStorage.getItem('theme') || 'light' const autoTheme = checkPrefersColorSchemeIsDark() ? 'dark' : 'light' globalTheme.name.value = themeValue === 'auto' ? autoTheme : themeValue +// 更新data-theme属性以便CSS选择器能正确匹配 +function updateHtmlThemeAttribute(themeName) { + document.documentElement.setAttribute('data-theme', themeName) + // 确保body元素也有相同的主题属性,以便更好地选择弹出窗口 + document.body.setAttribute('data-theme', themeName) +} + // 显示状态 const show = ref(false) +// 背景图片 +const backgroundImages = ref([]) +const activeImageIndex = ref(0) +const isTransparentTheme = computed(() => globalTheme.name.value === 'transparent') +let backgroundRotationTimer: NodeJS.Timeout | null = null + +// 获取背景图片 +async function fetchBackgroundImages() { + try { + backgroundImages.value = await api.get('/login/wallpapers') + console.log('获取背景图片成功:', backgroundImages.value) + } catch (e) { + console.error('获取背景图片失败:', e) + } +} + +// 开始背景图片轮换 +function startBackgroundRotation() { + if (backgroundRotationTimer) clearInterval(backgroundRotationTimer) + + if (backgroundImages.value.length > 1) { + backgroundRotationTimer = setInterval(() => { + activeImageIndex.value = (activeImageIndex.value + 1) % backgroundImages.value.length + }, 10000) // 每10秒切换一次 + } +} + +// 监听主题变化 +watch( + () => globalTheme.name.value, + async newTheme => { + // 更新HTML属性 + updateHtmlThemeAttribute(newTheme) + + if (newTheme === 'transparent' && backgroundImages.value.length === 0) { + await fetchBackgroundImages() + startBackgroundRotation() + } else if (newTheme !== 'transparent' && backgroundRotationTimer) { + clearInterval(backgroundRotationTimer) + backgroundRotationTimer = null + } + }, + { immediate: true }, +) + // ApexCharts 全局配置 declare global { interface Window { @@ -43,6 +96,9 @@ if (window.Apex) { } onMounted(() => { + // 初始化data-theme属性 + updateHtmlThemeAttribute(globalTheme.name.value) + ensureRenderComplete(() => { nextTick(() => { setTimeout(() => { @@ -56,10 +112,92 @@ onMounted(() => { }) }) }) + +onUnmounted(() => { + if (backgroundRotationTimer) { + clearInterval(backgroundRotationTimer) + backgroundRotationTimer = null + } +}) + + diff --git a/src/components/dialog/AddDownloadDialog.vue b/src/components/dialog/AddDownloadDialog.vue index 11a63f99..c6f9ea65 100644 --- a/src/components/dialog/AddDownloadDialog.vue +++ b/src/components/dialog/AddDownloadDialog.vue @@ -120,7 +120,7 @@ onMounted(() => {