|
@@ -4,12 +4,16 @@
|
|
|
:key="examQuestion.questionId"
|
|
|
class="question-body"
|
|
|
>
|
|
|
- <div v-html="questionDetail.text"></div>
|
|
|
+ <QuestionContainer
|
|
|
+ :node="questionDetail.container"
|
|
|
+ :exam-question="examQuestion"
|
|
|
+ />
|
|
|
+ <!-- <div v-html="questionDetail.text"></div> -->
|
|
|
<!-- <div v-html="questionDetail.audio"></div> -->
|
|
|
- <div
|
|
|
+ <!-- <div
|
|
|
v-for="{ src, name } in questionDetail.audio"
|
|
|
:key="name"
|
|
|
- class="audio-div"
|
|
|
+ class="audio-container"
|
|
|
>
|
|
|
<div style="position: relative; margin-bottom: 2px;" class="audio-div">
|
|
|
<QuestionAudio
|
|
@@ -29,21 +33,23 @@
|
|
|
style="position: absolute;top: 0;right: 0;bottom: 0;left: 0;"
|
|
|
></div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </div> -->
|
|
|
</div>
|
|
|
|
|
|
<div v-else>获取试题中...</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import QuestionAudio from "./QuestionAudio";
|
|
|
+// import QuestionAudio from "./QuestionAudio";
|
|
|
+import QuestionContainer from "./QuestionContainer";
|
|
|
import { createNamespacedHelpers } from "vuex";
|
|
|
const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
|
|
|
|
|
|
export default {
|
|
|
name: "QuestionBody",
|
|
|
components: {
|
|
|
- QuestionAudio,
|
|
|
+ // QuestionAudio,
|
|
|
+ QuestionContainer,
|
|
|
},
|
|
|
props: {
|
|
|
questionBody: { type: String, default: "" },
|
|
@@ -74,18 +80,24 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
this.parseQuestion();
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // const ap = document.querySelectorAll(".audio-placeholder");
|
|
|
+ // const as = document.querySelectorAll(".audio-container");
|
|
|
+ // [...ap].forEach((v, i) => (v.innerHTML = [...as][i].innerHTML));
|
|
|
+ // });
|
|
|
},
|
|
|
methods: {
|
|
|
...mapMutations(["updateExamQuestion", "updateQuestionAudioPlayTimes"]),
|
|
|
async parseQuestion() {
|
|
|
let question = {};
|
|
|
+ const container = document.createElement("div");
|
|
|
if (this.questionBody.includes("question-audio")) {
|
|
|
question.text = this.questionBody.replace(
|
|
|
- /<a.*?question-audio.*?\/a>/g,
|
|
|
- ""
|
|
|
+ /<a.*?name="([^"]*)".*?question-audio.*?url="([^"]*)".*?\/a>/g,
|
|
|
+ "<span class='audio-placeholder' data-name='$1' data-src='$2'></span>"
|
|
|
);
|
|
|
+ // console.log(question.text);
|
|
|
// 测试 v-html中含有directive是否生效。结论:不生效
|
|
|
-
|
|
|
question.audio = [];
|
|
|
let re;
|
|
|
if (/<a.*?question-audio.*?\/a>/.test(this.questionBody)) {
|
|
@@ -99,33 +111,35 @@ export default {
|
|
|
question.text = this.questionBody;
|
|
|
question.audio = [];
|
|
|
}
|
|
|
+ container.innerHTML = question.text;
|
|
|
+ question.container = container;
|
|
|
this.questionDetail = question;
|
|
|
},
|
|
|
- played(name) {
|
|
|
- if (!this.examQuestion.limitedPlayTimes) {
|
|
|
- // 如果没有设置音频播放次数,可无限播放
|
|
|
- return false;
|
|
|
- }
|
|
|
- console.log("开始播放");
|
|
|
+ // played(name) {
|
|
|
+ // if (!this.examQuestion.limitedPlayTimes) {
|
|
|
+ // // 如果没有设置音频播放次数,可无限播放
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
+ // console.log("开始播放");
|
|
|
|
|
|
- // 正在播放中
|
|
|
- this.updateQuestionAudioPlayTimes(name);
|
|
|
- },
|
|
|
- getAudioPlayedTimes(name) {
|
|
|
- return Math.max(
|
|
|
- this.examQuestion.limitedPlayTimes -
|
|
|
- (this.allAudioPlayTimes.find(a => a.name === name) || { times: 0 })
|
|
|
- .times,
|
|
|
- 0
|
|
|
- );
|
|
|
- },
|
|
|
+ // // 正在播放中
|
|
|
+ // this.updateQuestionAudioPlayTimes(name);
|
|
|
+ // },
|
|
|
+ // getAudioPlayedTimes(name) {
|
|
|
+ // return Math.max(
|
|
|
+ // this.examQuestion.limitedPlayTimes -
|
|
|
+ // (this.allAudioPlayTimes.find(a => a.name === name) || { times: 0 })
|
|
|
+ // .times,
|
|
|
+ // 0
|
|
|
+ // );
|
|
|
+ // },
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style>
|
|
|
.audio-div {
|
|
|
- display: flex;
|
|
|
+ display: inline-flex;
|
|
|
align-items: center;
|
|
|
}
|
|
|
/* .question-body audio::-webkit-media-controls-timeline,
|