换皮test1.3

音频动效的添加
This commit is contained in:
minimaxagent1 2025-08-06 14:47:08 +08:00
parent 69c05c4911
commit a38c896ac4

View File

@ -18,11 +18,22 @@
</view> </view>
</view> </view>
</view> </view>
<!-- 右侧图标 --> <!-- 音频与VR图标 -->
<view class="tubiao"> <view class="tubiao">
<view class=""> <view class="">
<image v-if="pageConfig.topIcons.leftIcon.hidden" :src="pageConfig.topIcons.leftIcon.img" mode=""></image> <image
<image :src="pageConfig.topIcons.rightIcon.img" mode=""></image> v-if="pageConfig.topIcons.leftIcon.hidden"
:src="pageConfig.topIcons.leftIcon.img"
mode=""
@click="playAudio"
:class="{ 'playing': isAudioPlaying }"
></image>
<image
:src="pageConfig.topIcons.rightIcon.img"
mode=""
@click="stopAudio"
:class="{ 'stopped': !isAudioPlaying }"
></image>
</view> </view>
<view class="tubiao-item"> <view class="tubiao-item">
<image :src="pageConfig.topIcons.bottomIcon.img" mode=""></image> <image :src="pageConfig.topIcons.bottomIcon.img" mode=""></image>
@ -377,6 +388,82 @@ import { getArticleById } from "../../api/article/article.js";
icon: 'none' icon: 'none'
}); });
} }
},
/**
* 播放音频
*/
playAudio() {
if (!this.templeData.audioUrl) {
uni.showToast({
title: '暂无音频资源',
icon: 'none'
});
return;
}
try {
//
if (this.audioContext) {
this.stopAudio();
}
//
this.audioContext = uni.createInnerAudioContext();
this.audioContext.src = this.templeData.audioUrl;
this.audioContext.loop = true; //
//
this.audioContext.onPlay(() => {
console.log('音频开始播放');
this.isAudioPlaying = true;
uni.showToast({
title: '音频已开启',
icon: 'none'
});
});
this.audioContext.onError((err) => {
console.error('音频播放错误:', err);
this.isAudioPlaying = false;
uni.showToast({
title: '音频播放失败',
icon: 'none'
});
});
this.audioContext.onEnded(() => {
console.log('音频播放结束');
this.isAudioPlaying = false;
});
//
this.audioContext.play();
} catch (error) {
console.error('音频播放失败:', error);
this.isAudioPlaying = false;
uni.showToast({
title: '音频播放失败',
icon: 'none'
});
}
},
/**
* 停止音频
*/
stopAudio() {
if (this.audioContext) {
this.audioContext.stop();
this.audioContext.destroy();
this.audioContext = null;
}
this.isAudioPlaying = false;
uni.showToast({
title: '音频已关闭',
icon: 'none'
});
} }
} }
} }
@ -537,11 +624,39 @@ import { getArticleById } from "../../api/article/article.js";
padding: 0 30rpx; padding: 0 30rpx;
box-sizing: border-box; box-sizing: border-box;
justify-content: space-between; justify-content: space-between;
image{ view {
width: 82rpx; image{
height: 82rpx; width: 82rpx;
display: block; height: 82rpx;
margin-top: 50rpx; display: block;
margin-top: 50rpx;
transition: all 0.3s ease;
&:active {
transform: scale(0.9);
opacity: 0.8;
}
&.playing {
animation: pulse 2s infinite;
}
&.stopped {
opacity: 0.6;
}
}
}
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(1.1);
}
100% {
transform: scale(1);
} }
} }
.announcement { .announcement {