生日调整

This commit is contained in:
hebo 2025-12-08 20:02:11 +08:00
parent 33a4cac829
commit c79e037aab

View File

@ -62,20 +62,11 @@
<text class="deco-icon">🎁</text> <text class="deco-icon">🎁</text>
<text class="deco-icon">🎈</text> <text class="deco-icon">🎈</text>
</view> </view>
<!-- 右上角音乐图标 -->
<view
class="music-icon-wrapper"
:class="{ 'playing': isMusicPlaying, 'fade-out': isOpening }"
@click="toggleMusic"
>
<text class="music-icon-emoji">🎵</text>
</view>
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, computed, onUnmounted } from "vue"; import { ref, computed } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app"; import { onLoad, onShow } from "@dcloudio/uni-app";
import { useUserStore } from "@/store/modules/user"; import { useUserStore } from "@/store/modules/user";
@ -85,8 +76,6 @@ const openId = ref<string>("");
const receiverName = ref<string>(""); const receiverName = ref<string>("");
const isOpening = ref(false); const isOpening = ref(false);
const isOpened = ref(false); const isOpened = ref(false);
const audioContext = ref<any>(null);
const isMusicPlaying = ref(false);
// //
const pageStyle = computed(() => { const pageStyle = computed(() => {
@ -113,124 +102,6 @@ const openEnvelope = () => {
}, 1500); }, 1500);
}; };
//
const initAudio = () => {
try {
// #ifdef H5
audioContext.value = new Audio('/static/base/music/srkl.mp3');
audioContext.value.loop = true;
//
audioContext.value.addEventListener('play', () => {
isMusicPlaying.value = true;
});
audioContext.value.addEventListener('pause', () => {
isMusicPlaying.value = false;
});
audioContext.value.addEventListener('ended', () => {
isMusicPlaying.value = false;
});
//
let hasTriedPlay = false;
//
const attemptPlay = () => {
if (!audioContext.value || hasTriedPlay || isMusicPlaying.value) {
return;
}
hasTriedPlay = true;
audioContext.value.play().then(() => {
isMusicPlaying.value = true;
}).catch(() => {
// 便
hasTriedPlay = false;
});
};
//
let hasInteracted = false;
const playOnInteraction = () => {
if (!hasInteracted && !isMusicPlaying.value) {
hasInteracted = true;
attemptPlay();
}
};
//
const events = ['click', 'touchstart'];
events.forEach(eventType => {
document.addEventListener(eventType, playOnInteraction, { once: true, passive: true });
});
//
attemptPlay();
// #endif
// #ifdef MP-WEIXIN
audioContext.value = uni.createInnerAudioContext();
audioContext.value.src = '/static/base/music/srkl.mp3';
audioContext.value.loop = true;
//
audioContext.value.onPlay(() => {
isMusicPlaying.value = true;
});
audioContext.value.onPause(() => {
isMusicPlaying.value = false;
});
audioContext.value.onStop(() => {
isMusicPlaying.value = false;
});
//
audioContext.value.play();
isMusicPlaying.value = true;
// #endif
} catch (e) {
console.error("初始化音频失败:", e);
}
};
//
const playMusic = () => {
if (!audioContext.value) return;
try {
audioContext.value.play();
isMusicPlaying.value = true;
} catch (e) {
console.error("播放音乐失败:", e);
}
};
//
const toggleMusic = () => {
if (!audioContext.value) return;
try {
if (isMusicPlaying.value) {
audioContext.value.pause();
isMusicPlaying.value = false;
} else {
audioContext.value.play();
isMusicPlaying.value = true;
}
} catch (e) {
console.error("音乐播放控制失败:", e);
}
};
//
onUnmounted(() => {
if (audioContext.value) {
try {
audioContext.value.pause();
// #ifdef MP-WEIXIN
audioContext.value.destroy?.();
// #endif
} catch (e) {
console.error("清理音频失败:", e);
}
}
});
// //
const resetEnvelopeState = () => { const resetEnvelopeState = () => {
isOpening.value = false; isOpening.value = false;
@ -255,9 +126,6 @@ onLoad(async (options) => {
if (!xxtsId.value) { if (!xxtsId.value) {
uni.showToast({ title: "缺少贺卡ID", icon: "none" }); uni.showToast({ title: "缺少贺卡ID", icon: "none" });
} }
//
initAudio();
}); });
// //
@ -608,46 +476,4 @@ onShow(() => {
opacity: 0; opacity: 0;
transform: translateY(30px); transform: translateY(30px);
} }
/* 右上角音乐图标 */
.music-icon-wrapper {
position: fixed;
top: calc(20px + env(safe-area-inset-top));
right: 20px;
width: 50px;
height: 50px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.9);
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
z-index: 100;
cursor: pointer;
transition: all 0.3s ease;
}
.music-icon-wrapper:active {
transform: scale(0.95);
}
.music-icon-wrapper.playing .music-icon-emoji {
animation: music-rotate 2s linear infinite;
}
.music-icon-wrapper.fade-out {
opacity: 0;
transform: scale(0.8);
}
.music-icon-emoji {
font-size: 28px;
display: block;
transition: transform 0.3s ease;
}
@keyframes music-rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style> </style>