1、结束页按钮间隔位置样式调整
2、首页滑动提示修改
3、bgm播放、鼓声播放、视频播放需要相互停止,保证同一时间内只有一种声音在播放
This commit is contained in:
Wenzhe 2026-02-04 21:27:25 +08:00
parent 3ed1978442
commit e7cc71d841
7 changed files with 217 additions and 42 deletions

View File

@ -23,7 +23,7 @@ const props = defineProps({
})
//
const emit = defineEmits(['collect-seal'])
const emit = defineEmits(['collect-seal', 'video-open', 'video-close'])
//
const sealCollected = ref(false)
@ -67,11 +67,13 @@ const openWebview = () => {
//
const openVideoPlayer = () => {
showVideoPlayer.value = true
emit('video-open')
}
//
const closeVideoPlayer = () => {
showVideoPlayer.value = false
emit('video-close')
}
//

View File

@ -23,7 +23,7 @@ const props = defineProps({
}
})
const emit = defineEmits(['collect-seal'])
const emit = defineEmits(['collect-seal', 'video-open', 'video-close'])
// sq3
const sq3ImageVisible = ref(false)
@ -478,11 +478,13 @@ const resetDuckPosition = () => {
//
const openVideoPlayer = () => {
showVideoPlayer.value = true
emit('video-open')
}
//
const closeVideoPlayer = () => {
showVideoPlayer.value = false
emit('video-close')
}
//

View File

@ -293,11 +293,14 @@ onMounted(() => {
.end-buttons {
display: flex;
gap: 20px;
justify-content: center;
margin-bottom: 60px;
}
.end-buttons .function-image:not(:last-child) {
margin-right: 20px;
}
.function-btn {
cursor: pointer;
width: 306rpx;

View File

@ -25,7 +25,7 @@ const props = defineProps({
})
//
const emit = defineEmits(['collect-seal'])
const emit = defineEmits(['collect-seal', 'video-open', 'video-close'])
// sq3
const sq3ImageVisible = ref(false)
@ -108,11 +108,13 @@ const closeGallery = () => {
//
const openVideoPlayer = () => {
showVideoPlayer.value = true
emit('video-open')
}
//
const closeVideoPlayer = () => {
showVideoPlayer.value = false
emit('video-close')
}
//

View File

@ -19,19 +19,28 @@ const props = defineProps({
videoUrl: {
type: String,
default: ''
},
// BGM
isMusicPlaying: {
type: Boolean,
default: false
}
})
//
const emit = defineEmits(['collect-seal', 'height-changed'])
const emit = defineEmits(['collect-seal', 'height-changed', 'video-open', 'video-close', 'pause-bgm', 'resume-bgm'])
//
const sealCollected = ref(false)
//
const isMusicPlaying = ref(false)
//
const musicPlayer = ref(null)
//
const isDrumPlaying = ref(false)
const drumPlayer = ref(null)
const wasBgPlayingBeforeDrum = ref(false)
//
const sq1ImageVisible = ref(false)
//
@ -79,7 +88,7 @@ const parallaxOffset = computed(() => {
return offset
})
// /
// /
const toggleMusic = () => {
//
if (!sealCollected.value) {
@ -88,38 +97,48 @@ const toggleMusic = () => {
emit('collect-seal')
}
if (!musicPlayer.value) {
//
musicPlayer.value = uni.createInnerAudioContext()
const bgmUrl = new URL('/static/music/bgm1.mp3', import.meta.url)
musicPlayer.value.src = bgmUrl.href
musicPlayer.value.loop = false
if (!drumPlayer.value) {
//
drumPlayer.value = uni.createInnerAudioContext()
const drumUrl = new URL('/static/music/bgm1.mp3', import.meta.url)
drumPlayer.value.src = drumUrl.href
drumPlayer.value.loop = false
//
musicPlayer.value.onEnded(() => {
isMusicPlaying.value = false
drumPlayer.value.onEnded(() => {
isDrumPlaying.value = false
// BGM
emit('resume-bgm')
})
//
musicPlayer.value.onError((err) => {
console.error('音乐播放失败:', err)
isMusicPlaying.value = false
showToast({
message: '音乐播放失败',
icon: 'error',
drumPlayer.value.onError((err) => {
console.error('鼓声播放失败:', err)
isDrumPlaying.value = false
// BGM
emit('resume-bgm')
uni.showToast({
title: '鼓声播放失败',
icon: 'none',
duration: 1500
})
})
}
if (isMusicPlaying.value) {
if (isDrumPlaying.value) {
//
musicPlayer.value.stop()
isMusicPlaying.value = false
drumPlayer.value.stop()
isDrumPlaying.value = false
// BGM
emit('resume-bgm')
} else {
//
musicPlayer.value.play()
isMusicPlaying.value = true
// BGM
wasBgPlayingBeforeDrum.value = props.isMusicPlaying
// BGM
emit('pause-bgm')
//
drumPlayer.value.play()
isDrumPlaying.value = true
}
}
@ -155,12 +174,23 @@ const calculateHeight = () => {
//
const openVideoPlayer = () => {
//
if (isDrumPlaying.value && drumPlayer.value) {
drumPlayer.value.stop()
isDrumPlaying.value = false
drumPlayer.value.destroy()
drumPlayer.value = null
// BGM
emit('resume-bgm')
}
showVideoPlayer.value = true
emit('video-open')
}
//
const closeVideoPlayer = () => {
showVideoPlayer.value = false
emit('video-close')
}
//
@ -170,6 +200,11 @@ onUnmounted(() => {
musicPlayer.value.destroy()
musicPlayer.value = null
}
if (drumPlayer.value) {
drumPlayer.value.stop()
drumPlayer.value.destroy()
drumPlayer.value = null
}
})
</script>
@ -181,22 +216,13 @@ onUnmounted(() => {
<img src="/static/bg/bg1.jpg" alt="前门商圈" class="background-image" />
</div>
<!-- 增强动效层 -->
<div class="enhancement-layer">
<!-- 灯笼增强动效 -->
<div class="lanterns">
<div class="lantern left-lantern">🏮</div>
<div class="lantern right-lantern">🏮</div>
</div>
</div>
<!-- 音乐控制按钮 -->
<div class="music-control" @click="toggleMusic">
<img
:src="isMusicPlaying ? '/static/images/icon_music2.png' : '/static/images/icon_music1.png'"
:src="isDrumPlaying ? '/static/images/icon_music2.png' : '/static/images/icon_music1.png' "
alt="音乐控制"
class="music-icon"
:class="{ 'playing': isMusicPlaying }"
:class="{ 'playing': isDrumPlaying }"
/>
</div>

View File

@ -117,6 +117,10 @@ const scenes = ref([
const sceneInteractiveStates = ref(scenes.value.map(() => false))
//
const sealCollectedStates = ref(scenes.value.map(() => false))
//
const isVideoPlaying = ref(false)
//
const isDrumPlaying = ref(false)
//
const collectedItems = computed(() => {
@ -140,6 +144,11 @@ const collectionProgress = computed(() => {
return Math.round((collected / total) * 100)
})
// BGM
const isBgmButtonDisabled = computed(() => {
return isVideoPlaying.value || isDrumPlaying.value
})
// EndPage
const collectedSeals = computed(() => {
return {
@ -325,6 +334,9 @@ const initMusicPlayer = () => {
// /
const toggleMusic = () => {
//
if (isBgmButtonDisabled.value) return
if (!audioPlayer.value) {
initMusicPlayer()
}
@ -599,6 +611,105 @@ const handleQianmenHeightChanged = (height) => {
console.log('当前CSS变量:', getComputedStyle(document.documentElement).getPropertyValue('--scene-height'))
}
// BGM
const wasMusicPlayingBeforeVideo = ref(false)
// BGM
const wasMusicPlayingBeforeDrum = ref(false)
//
const handleVideoOpen = () => {
//
isVideoPlaying.value = true
// BGM
wasMusicPlayingBeforeVideo.value = isMusicPlaying.value
// BGM
if (audioPlayer.value && isMusicPlaying.value) {
audioPlayer.value.pause()
isMusicPlaying.value = false
console.log('全局BGM已停止视频播放中')
}
}
//
const handleVideoClose = () => {
//
isVideoPlaying.value = false
// BGM
if (audioPlayer.value && wasMusicPlayingBeforeVideo.value && !isMusicPlaying.value) {
try {
const result = audioPlayer.value.play()
// play()PromiseWeb
if (result && typeof result.then === 'function') {
// Web使Promise
result.then(() => {
isMusicPlaying.value = true
console.log('全局BGM已恢复播放视频已关闭')
}).catch(error => {
console.error('BGM恢复播放失败需要用户交互:', error)
// isMusicPlayingfalse
})
} else {
//
isMusicPlaying.value = true
console.log('全局BGM已恢复播放视频已关闭')
}
} catch (error) {
console.error('BGM恢复播放失败需要用户交互:', error)
// isMusicPlayingfalse
}
}
}
// BGM
const pauseBgm = () => {
//
isDrumPlaying.value = true
// BGM
wasMusicPlayingBeforeDrum.value = isMusicPlaying.value
if (audioPlayer.value && isMusicPlaying.value) {
audioPlayer.value.pause()
isMusicPlaying.value = false
console.log('全局BGM已暂停鼓声播放中')
}
}
// BGM
const resumeBgm = () => {
//
isDrumPlaying.value = false
// BGM
if (audioPlayer.value && wasMusicPlayingBeforeDrum.value && !isMusicPlaying.value) {
try {
const result = audioPlayer.value.play()
// play()PromiseWeb
if (result && typeof result.then === 'function') {
// Web使Promise
result.then(() => {
isMusicPlaying.value = true
console.log('全局BGM已恢复播放鼓声已结束')
}).catch(error => {
console.error('BGM恢复播放失败需要用户交互:', error)
// isMusicPlayingfalse
})
} else {
//
isMusicPlaying.value = true
console.log('全局BGM已恢复播放鼓声已结束')
}
} catch (error) {
console.error('BGM恢复播放失败需要用户交互:', error)
// isMusicPlayingfalse
}
}
}
// 使scroll-view
// scroll-view
@ -613,7 +724,7 @@ onUnmounted(() => {
<!-- 音乐控制按钮 -->
<div
class="music-control"
:class="{ 'music-playing': isMusicPlaying }"
:class="{ 'music-playing': isMusicPlaying, 'disabled': isBgmButtonDisabled }"
@click="toggleMusic"
>
<img src="/static/images/music_on.png" alt="音乐" class="music-icon" />
@ -661,6 +772,8 @@ onUnmounted(() => {
:scroll-position="scrollContainer && scrollContainer.value ? scrollContainer.value.scrollTop : 0"
:video-url="scenes[1].videoUrl"
@collect-seal="collectSeal(1)"
@video-open="handleVideoOpen"
@video-close="handleVideoClose"
/>
<!-- 隆福寺商圈 -->
@ -669,6 +782,8 @@ onUnmounted(() => {
:scroll-position="scrollContainer && scrollContainer.value ? scrollContainer.value.scrollTop : 0"
:video-url="scenes[2].videoUrl"
@collect-seal="collectSeal(2)"
@video-open="handleVideoOpen"
@video-close="handleVideoClose"
/>
<!-- 王府井商圈 -->
@ -677,6 +792,8 @@ onUnmounted(() => {
:scroll-position="scrollContainer?.value?.scrollTop || 0"
:video-url="scenes[3].videoUrl"
@collect-seal="collectSeal(3)"
@video-open="handleVideoOpen"
@video-close="handleVideoClose"
/>
<!-- 崇文门商圈 -->
@ -685,6 +802,8 @@ onUnmounted(() => {
:scroll-position="scrollContainer?.value?.scrollTop || 0"
:video-url="scenes[4].videoUrl"
@collect-seal="collectSeal(4)"
@video-open="handleVideoOpen"
@video-close="handleVideoClose"
/>
<!-- 前门商圈 -->
@ -692,8 +811,13 @@ onUnmounted(() => {
:active="activeSceneIndex === 5"
:scroll-position="scrollContainer?.value?.scrollTop || 0"
:video-url="scenes[5].videoUrl"
:is-music-playing="isMusicPlaying"
@collect-seal="collectSeal(5)"
@height-changed="handleQianmenHeightChanged"
@video-open="handleVideoOpen"
@video-close="handleVideoClose"
@pause-bgm="pauseBgm"
@resume-bgm="resumeBgm"
/>
<!-- 新年文案模块 -->
@ -729,7 +853,7 @@ onUnmounted(() => {
<!-- 向上滑动提示 -->
<div class="scroll-tip-bottom" v-if="!hasScrolled">
<img src="/static/images/icon_hand1.png" class="tip-icon" alt="滑动提示" />
<p>滑动探索商圈</p>
<p>滑动探索商圈</p>
</div>
<!-- 抽奖留资弹窗 -->
@ -965,6 +1089,20 @@ onUnmounted(() => {
justify-content: center;
z-index: 1000;
cursor: pointer;
transition: all 0.3s ease;
}
.music-control:hover:not(.disabled) {
transform: scale(1.1);
}
.music-control:active:not(.disabled) {
transform: scale(0.95);
}
.music-control.disabled {
opacity: 0.5;
cursor: not-allowed;
}

View File

@ -25,7 +25,7 @@ const props = defineProps({
})
//
const emit = defineEmits(['collect-seal'])
const emit = defineEmits(['collect-seal', 'video-open', 'video-close'])
//
const sq3ImageVisible = ref(false)
@ -106,11 +106,13 @@ const closeGallery = () => {
//
const openVideoPlayer = () => {
showVideoPlayer.value = true
emit('video-open')
}
//
const closeVideoPlayer = () => {
showVideoPlayer.value = false
emit('video-close')
}
//