|
@@ -3,8 +3,12 @@
|
|
|
<div v-html="questionDetail.text"></div>
|
|
|
<!-- <div v-html="questionDetail.audio"></div> -->
|
|
|
<div v-for="({src, name}, index) in questionDetail.audio" :key="name" class="audio-div">
|
|
|
- <audio controls preload="auto" controlsList='nodownload' :key="src" :name="name" :src="src" @click="audioClicked" @play="($event) => played(index, $event)"></audio>
|
|
|
- <span>(剩余播放次数:{{getAudioPlayedTimes(name)}})</span><br />
|
|
|
+ <div style="position: relative;" class="audio-div">
|
|
|
+ <audio controls preload="auto" controlsList='nodownload' :key="src" :name="name" :src="src" @play="($event) => played(index, $event)" @ended="() => audioEnded(name)" @click="($event) => audioClicked(index, $event)"></audio>
|
|
|
+ <span v-if="examQuestion.limitedPlayTimes">(剩余播放次数:{{getAudioPlayedTimes(name)}})</span><br />
|
|
|
+ <div v-if="audioInPlay.has(name)" style="position: absolute;top: 0;right: 0;bottom: 0;left: 0;">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
@@ -20,7 +24,11 @@ const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
|
|
|
export default {
|
|
|
name: "QuestionBody",
|
|
|
data() {
|
|
|
- return { questionDetail: null, audioPlayTimes: null };
|
|
|
+ return {
|
|
|
+ questionDetail: null,
|
|
|
+ audioPlayTimes: null,
|
|
|
+ audioInPlay: new Set()
|
|
|
+ };
|
|
|
},
|
|
|
props: {
|
|
|
questionBody: String,
|
|
@@ -126,13 +134,20 @@ export default {
|
|
|
// });
|
|
|
// });
|
|
|
// },
|
|
|
- audioClicked($event) {
|
|
|
+ audioClicked(index, $event) {
|
|
|
if ($event.target.paused === false) {
|
|
|
// 正在播放中,不能暂停
|
|
|
$event.preventDefault();
|
|
|
}
|
|
|
},
|
|
|
+ audioEnded(name) {
|
|
|
+ this.audioInPlay.delete(name);
|
|
|
+ },
|
|
|
played(index, $event) {
|
|
|
+ if (!this.examQuestion.limitedPlayTimes) {
|
|
|
+ // 如果没有设置音频播放次数
|
|
|
+ return false;
|
|
|
+ }
|
|
|
const limitedPlayTimes = this.examQuestion.limitedPlayTimes;
|
|
|
console.log("开始播放");
|
|
|
const name = $event.target.attributes.name.value;
|
|
@@ -144,6 +159,7 @@ export default {
|
|
|
$event.target.pause();
|
|
|
return;
|
|
|
}
|
|
|
+ this.audioInPlay.add(name);
|
|
|
|
|
|
// var audio = new Audio($event.target.src);
|
|
|
// audio.play();
|
|
@@ -153,7 +169,10 @@ export default {
|
|
|
// } else {
|
|
|
// this.audioPlayTimes.push({ name: name, times: 1 });
|
|
|
// }
|
|
|
- this.updateQuestionAudioPlayTimes(name);
|
|
|
+ if ($event.target.paused === false) {
|
|
|
+ // 正在播放中
|
|
|
+ this.updateQuestionAudioPlayTimes(name);
|
|
|
+ }
|
|
|
},
|
|
|
getAudioPlayedTimes(name) {
|
|
|
return Math.max(
|