|
@@ -2,10 +2,10 @@
|
|
<div v-if="questionDetail" class="question-body" :key="examQuestion.order">
|
|
<div v-if="questionDetail" class="question-body" :key="examQuestion.order">
|
|
<div v-html="questionDetail.text"></div>
|
|
<div v-html="questionDetail.text"></div>
|
|
<!-- <div v-html="questionDetail.audio"></div> -->
|
|
<!-- <div v-html="questionDetail.audio"></div> -->
|
|
- <div v-for="(ad, index) in questionDetail.audio" :key="ad" class="audio-div">
|
|
|
|
- <audio controls preload="auto" controlsList='nodownload' :src="ad" @play="($event) => played(index, $event)"></audio>
|
|
|
|
|
|
+ <div v-for="({src, name}, index) in questionDetail.audio" :key="name" class="audio-div">
|
|
|
|
+ <audio controls preload="auto" controlsList='nodownload' :name="name" :src="src" @play="($event) => played(index, $event)"></audio>
|
|
<span>(剩余播放次数:{{examQuestion.limitedPlayTimes -
|
|
<span>(剩余播放次数:{{examQuestion.limitedPlayTimes -
|
|
- audioPlayTimes[index]}})</span><br />
|
|
|
|
|
|
+ (audioPlayTimes.find(a => a.name === name) || { times: 0 }).times}})</span><br />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@@ -79,12 +79,13 @@ export default {
|
|
// /question-audio.*?url="[^"]*"/.exec(this.questionBody)
|
|
// /question-audio.*?url="[^"]*"/.exec(this.questionBody)
|
|
|
|
|
|
question.audio = [];
|
|
question.audio = [];
|
|
- let re = /question-audio.*?url="([^"]*)"/g;
|
|
|
|
|
|
+ let re = /name="([^"]*)".*question-audio.*?url="([^"]*)"/g;
|
|
let array1;
|
|
let array1;
|
|
while ((array1 = re.exec(this.questionBody)) !== null) {
|
|
while ((array1 = re.exec(this.questionBody)) !== null) {
|
|
// console.log(`Found ${array1[0]}. Next starts at ${re.lastIndex}.`);
|
|
// console.log(`Found ${array1[0]}. Next starts at ${re.lastIndex}.`);
|
|
// console.log(array1[1]);
|
|
// console.log(array1[1]);
|
|
- question.audio.push(array1[1]);
|
|
|
|
|
|
+ question.audio.push({ name: array1[1], src: array1[2] });
|
|
|
|
+ console.log(question.audio);
|
|
// expected output: "Found foo. Next starts at 9."
|
|
// expected output: "Found foo. Next starts at 9."
|
|
// expected output: "Found foo. Next starts at 19."
|
|
// expected output: "Found foo. Next starts at 19."
|
|
}
|
|
}
|
|
@@ -130,15 +131,24 @@ export default {
|
|
const limitedPlayTimes = this.examQuestion.limitedPlayTimes;
|
|
const limitedPlayTimes = this.examQuestion.limitedPlayTimes;
|
|
let audioPlayTimes = this.audioPlayTimes;
|
|
let audioPlayTimes = this.audioPlayTimes;
|
|
console.log("开始播放");
|
|
console.log("开始播放");
|
|
- if (limitedPlayTimes - audioPlayTimes[index] <= 0) {
|
|
|
|
|
|
+ // console.log($event.target.attributes.name.value);
|
|
|
|
+ const name = $event.target.attributes.name.value;
|
|
|
|
+ // console.log(name);
|
|
|
|
+ const theAudio = audioPlayTimes.find(a => a.name === name);
|
|
|
|
+ const playedTimes = (theAudio || { times: 0 }).times;
|
|
|
|
+ if (limitedPlayTimes - playedTimes <= 0) {
|
|
console.log("无剩余播放次数");
|
|
console.log("无剩余播放次数");
|
|
$event.target.pause();
|
|
$event.target.pause();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- audioPlayTimes[index] = audioPlayTimes[index] + 1;
|
|
|
|
|
|
+ if (theAudio) {
|
|
|
|
+ theAudio.times = playedTimes + 1;
|
|
|
|
+ } else {
|
|
|
|
+ this.audioPlayTimes.push({ name: name, times: 1 });
|
|
|
|
+ }
|
|
this.updateExamQuestion({
|
|
this.updateExamQuestion({
|
|
order: this.examQuestion.order,
|
|
order: this.examQuestion.order,
|
|
- audioPlayTimes: audioPlayTimes
|
|
|
|
|
|
+ audioPlayTimes: this.audioPlayTimes
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|