SentenceInput.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Textdes" v-if="curQue">
  4. <h2 v-if="curQue.title">{{curQue.title}}</h2>
  5. <ul>
  6. <li v-for="(items, indexs) in curQue.option" :key="indexs">
  7. <p :class="[oldsrc==items.mp3_list[0].url?palyClass:'']" @click="handlePlayVoice(items.mp3_list[0].url)" v-if="items.mp3_list&&items.mp3_list.length>0">
  8. </p>
  9. <b v-if="items.number">{{ items.number }}.</b>
  10. <span class="item-con">{{items.con}}</span>
  11. <!-- <template v-if="curQue.ChildType=='sentence_answer'"> -->
  12. <input
  13. @input="handleInput"
  14. :class="['item-input']"
  15. v-model="curQue.Bookanswer[indexs]"
  16. placeholder="输入"
  17. >
  18. <!-- </template> -->
  19. <template v-if="curQue.ChildType=='sentence_judge'">
  20. <div class="judge-box">
  21. <a :class="['right-btn',curQue.Bookanswer[indexs]=='right'?'active':'']" @click="handleSelectJudge('right',indexs)"></a>
  22. <a :class="['error-btn',curQue.Bookanswer[indexs]=='error'?'active':'']" @click="handleSelectJudge('error',indexs)"></a>
  23. </div>
  24. </template>
  25. <template v-if="curQue.ChildType=='sentence_Record'">
  26. <Soundrecord @handleWav="handleWav" type="mini" class="luyin-box"/>
  27. </template>
  28. </li>
  29. </ul>
  30. </div>
  31. </template>
  32. <script>
  33. import Soundrecord from "../preview/Soundrecord.vue"; // 录音模板
  34. export default {
  35. components: {Soundrecord},
  36. props: ["curQue"],
  37. data() {
  38. return {
  39. audio: new Audio(),
  40. oldsrc: '', // 存储播放音频的src 用来比对是否点击的是同一个音频
  41. palyClass: '',
  42. judge: '',
  43. };
  44. },
  45. computed: {},
  46. watch: {},
  47. //方法集合
  48. methods: {
  49. // input 输入时
  50. handleInput (e) {
  51. e.target.value = e.target.value ? e.target.value.trim() : '';
  52. },
  53. handlePlayVoice(url) {
  54. let _this = this;
  55. if (!url) {
  56. return;
  57. }
  58. if (!this.audio.paused && this.oldsrc == url) {
  59. this.audio.pause();
  60. }else if(this.audio.paused && this.oldsrc == url){
  61. this.audio.play();
  62. } else {
  63. _this.audio.pause();
  64. _this.audio.load();
  65. _this.audio.src = url;
  66. _this.oldsrc = url
  67. _this.audio.loop = false;
  68. _this.audio.play();
  69. }
  70. },
  71. // 处理数据
  72. handleData(){
  73. if(!this.curQue.Bookanswer){
  74. let curCorrect = [];
  75. this.curQue.option.forEach(item => {
  76. curCorrect.push('')
  77. });
  78. this.$set(this.curQue, "Bookanswer", curCorrect);
  79. }
  80. },
  81. // 判断题选择
  82. handleSelectJudge(obj,index){
  83. this.$set(this.curQue.Bookanswer, index, obj);
  84. },
  85. },
  86. //生命周期 - 创建完成(可以访问当前this实例)
  87. created() {
  88. this.handleData()
  89. },
  90. //生命周期 - 挂载完成(可以访问DOM元素)
  91. mounted() {
  92. let _this = this;
  93. _this.audio.addEventListener("play", function () {
  94. _this.palyClass = 'active'
  95. });
  96. _this.audio.addEventListener("pause", function () {
  97. _this.palyClass = ''
  98. });
  99. _this.audio.addEventListener("ended", function () {
  100. _this.palyClass = ''
  101. });
  102. },
  103. beforeCreate() {}, //生命周期 - 创建之前
  104. beforeMount() {}, //生命周期 - 挂载之前
  105. beforeUpdate() {}, //生命周期 - 更新之前
  106. updated() {}, //生命周期 - 更新之后
  107. beforeDestroy() {}, //生命周期 - 销毁之前
  108. destroyed() {}, //生命周期 - 销毁完成
  109. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  110. };
  111. </script>
  112. <style lang='scss' scoped>
  113. //@import url(); 引入公共css类
  114. .Big-Book-prev-Textdes{
  115. width: 100%;
  116. h2{
  117. font-weight: normal;
  118. font-size: 16px;
  119. line-height: 150%;
  120. color: #000000;
  121. margin: 0 2px 8px 2px;
  122. }
  123. ul{
  124. display: flex;
  125. flex-flow: wrap;
  126. justify-content: start;
  127. list-style: none;
  128. li{
  129. width: 100%;
  130. background: #FFFFFF;
  131. border: 1px solid rgba(0, 0, 0, 0.1);
  132. box-sizing: border-box;
  133. border-radius: 8px;
  134. display: flex;
  135. align-items: center;
  136. padding: 8px 12px;
  137. margin-bottom: 8px;
  138. >b{
  139. width: 24px;
  140. line-height: 24px;
  141. font-size: 16px;
  142. text-align: right;
  143. margin-right: 8px;
  144. font-weight: 400;
  145. color: #000000;
  146. // margin-top: 4px;
  147. font-family: 'FZJCGFKTK';
  148. }
  149. >p{
  150. width: 24px;
  151. height: 24px;
  152. cursor: pointer;
  153. background: url('../../../assets/newImage/common/icon-voice.png') left center no-repeat;
  154. background-size: 24px;
  155. margin: 0px 8px 0 0;
  156. &.active{
  157. background: url('../../../assets/newImage/common/icon-voice-play-zise.png') left center no-repeat;
  158. background-size: 24px;
  159. }
  160. }
  161. .item-con{
  162. flex: 1;
  163. font-size: 16px;
  164. line-height: 150%;
  165. color: #000000;
  166. margin-right: 8px;
  167. word-break: break-word;
  168. // margin-top: 4px;
  169. font-family: 'FZJCGFKTK';
  170. }
  171. input{
  172. width: 68px;
  173. border: 1px solid rgba(0, 0, 0, 0.15);
  174. box-sizing: border-box;
  175. border-radius: 4px;
  176. outline: none;
  177. height: 32px;
  178. padding: 4px 8px;
  179. color: #000000;
  180. text-align: center;
  181. font-size: 16px;
  182. line-height: 150%;
  183. }
  184. .judge-box{
  185. display: flex;
  186. justify-content: center;
  187. a{
  188. width: 32px;
  189. height: 32px;
  190. background: #fff url('../../../assets/newImage/common/right-btn.png') center no-repeat;
  191. background-size: 24px;
  192. border-radius: 8px;
  193. border: 1px solid rgba(0, 0, 0, 0.1);
  194. &:hover,&.active{
  195. background-color: #E5FFF0;
  196. border-color: #00C850;
  197. }
  198. }
  199. a.error-btn{
  200. background: #fff url('../../../assets/newImage/common/error-btn.png') center no-repeat;
  201. background-size: 24px;
  202. margin-left: 4px;
  203. &:hover,&.active{
  204. background-color: #FFE5E5;
  205. border-color: #DE4444;
  206. }
  207. }
  208. }
  209. .luyin-box{
  210. border: 1px solid rgba(0, 0, 0, 0.1);
  211. border-radius: 8px;
  212. width: 68px;
  213. }
  214. }
  215. }
  216. }
  217. </style>