-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
105 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ import { isVideoUrl } from '../utils' | |
import { getLocalStorageItem, setLocalStorageItem } from '../utils/storage' | ||
import { useSakuraAppStore } from '../stores' | ||
import { useThemeConfig } from '../composables' | ||
import playIconUrl from '../assets/icon/[email protected]' | ||
import pauseIconUrl from '../assets/icon/[email protected]' | ||
const props = withDefaults(defineProps<{ | ||
urls?: string[] | string | ||
|
@@ -21,6 +23,8 @@ const themeConfig = useThemeConfig() | |
const urls = computed(() => props.urls || themeConfig.value.banner.urls || '') | ||
const currentWallpaperUrl = computed(() => typeof urls.value === 'string' ? urls.value : urls.value[currentIndex.value]) | ||
const isCurrentMediaVideo = computed(() => isVideoUrl(currentWallpaperUrl.value)) | ||
const currentIconUrl = computed(() => sakura.isPlaying ? pauseIconUrl : playIconUrl) | ||
const banner = computed(() => themeConfig.value.banner) | ||
watch(() => sakura.wallpaperIndex[storageKey], (newIndex) => { | ||
setLocalStorageItem(storageKey, newIndex!) | ||
|
@@ -31,6 +35,10 @@ watch(() => urls.value.length, async (length) => { | |
sakura.wallpaperLength[storageKey] = length | ||
}) | ||
function togglePlayPause() { | ||
sakura.isPlaying = !sakura.isPlaying | ||
} | ||
onMounted(() => { | ||
currentIndex.value = getLocalStorageItem(storageKey) || 0 | ||
sakura.wallpaperIndex[storageKey] = currentIndex.value | ||
|
@@ -39,16 +47,69 @@ onMounted(() => { | |
</script> | ||
|
||
<template> | ||
<div class="sakura-background-display h-100vh w-full"> | ||
<template v-if="isCurrentMediaVideo"> | ||
<video :key="currentWallpaperUrl" class="block h-full w-full bg-cover object-cover" preload="auto" autoplay loop muted> | ||
<source :src="currentWallpaperUrl" type="video/mp4"> | ||
Your browser does not support video tags | ||
</video> | ||
</template> | ||
<template v-else> | ||
<img v-if="currentWallpaperUrl" alt="Image Wallpaper" class="block h-full w-full bg-cover bg-center object-cover" :src="currentWallpaperUrl"> | ||
<div v-else class="default-wallpaper h-full w-full" /> | ||
</template> | ||
<div class="sakura-background-display h-100vh w-full overflow-hidden"> | ||
<Transition | ||
:name="sakura.wallpaperOperation === 'nextMedia' ? 'slide-right' | ||
: sakura.wallpaperOperation === 'prevMedia' ? 'slide-left' | ||
: 'fade'" | ||
mode="out-in" | ||
> | ||
<template v-if="sakura.isPlaying || isCurrentMediaVideo"> | ||
<video | ||
:key="sakura.isPlaying ? banner.playerUrl : currentWallpaperUrl" | ||
class="min-h-full min-w-full object-cover" | ||
preload="auto" autoplay :loop="!sakura.isPlaying" :muted="!sakura.isPlaying" | ||
:disablePictureInPicture="banner.disablePictureInPicture" | ||
@ended="sakura.isPlaying = false" | ||
> | ||
<source :src="sakura.isPlaying ? banner.playerUrl : currentWallpaperUrl" type="video/mp4"> | ||
Your browser does not support video tags | ||
</video> | ||
</template> | ||
<template v-else> | ||
<img v-if="currentWallpaperUrl" :key="currentWallpaperUrl" alt="Image Wallpaper" class="block h-full w-full bg-cover bg-center object-cover" :src="currentWallpaperUrl"> | ||
<div v-else class="default-wallpaper h-full w-full" /> | ||
</template> | ||
</Transition> | ||
</div> | ||
<img :src="currentIconUrl" z-5 class="animation-fly absolute bottom-2 right-2 h-8 w-8 cursor-pointer" style="animation-duration: 2s; --translate-distance: 0.2em" @click="togglePlayPause"> | ||
</template> | ||
|
||
<style lang="scss" scoped> | ||
.fade-enter-active, | ||
.fade-leave-active { | ||
transition: opacity 0.5s; | ||
} | ||
.fade-enter, | ||
.fade-leave-to { | ||
opacity: 0; | ||
} | ||
.slide-right { | ||
&-enter-active, | ||
&-leave-active { | ||
transition: transform 1s ease; | ||
} | ||
&-enter-from, | ||
&-leave-to { | ||
transform: translateX(-100%); | ||
} | ||
&-enter-to, | ||
&-leave-from { | ||
transform: translateX(0); | ||
} | ||
} | ||
.slide-left-enter-active, | ||
.slide-left-leave-active { | ||
transition: transform 1s ease; | ||
} | ||
.slide-left-enter, | ||
.slide-left-leave-to { | ||
transform: translateX(100%); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters