SelectTone.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Textdes SelectTone" v-if="curQue">
  4. <div
  5. class="aduioLine-box"
  6. v-if="
  7. curQue.mp3_list && curQue.mp3_list.length > 0 && curQue.mp3_list[0].id
  8. "
  9. >
  10. <AudioLine
  11. audioId="sentenceListenAudio"
  12. :mp3="curQue.mp3_list[0].id"
  13. :getCurTime="getCurTime"
  14. :themeColor="themeColor"
  15. :ed="ed"
  16. type="audioLine"
  17. ref="audioLine"
  18. @handleListenRead="handleListenRead"
  19. />
  20. </div>
  21. <ul>
  22. <li v-for="(item, index) in curQue.option" :key="index">
  23. <a
  24. :class="[
  25. 'play-btn',
  26. curTime >= curQue.wordTime[index].bg &&
  27. curTime < curQue.wordTime[index].ed &&
  28. stopAudio
  29. ? 'active'
  30. : '',
  31. ]"
  32. @click="handleChangeTime(curQue.wordTime[index].bg,curQue.wordTime[index].ed)"
  33. ></a>
  34. <!-- <Audio
  35. :mp3="item.mp3_list.length > 0 ? item.mp3_list[0].url : ''"
  36. :themeColor="themeColor"
  37. class="audio-play"
  38. /> -->
  39. <div v-html="item.con" class="con"></div>
  40. <a
  41. v-for="(itmes, indexs) in toneList"
  42. :key="indexs"
  43. :class="['tone-item', curQue.Bookanswer[index] === indexs ? 'active' : '']"
  44. @click="handleClick(index, indexs)"
  45. >
  46. <img :src="itmes" />
  47. </a>
  48. </li>
  49. </ul>
  50. </div>
  51. </template>
  52. <script>
  53. import Audio from "../preview/components/AudioRed.vue"; // 音频播放
  54. import AudioLine from "../preview/AudioLine.vue";
  55. export default {
  56. components: { Audio, AudioLine },
  57. props: ["curQue", "themeColor","TaskModel"],
  58. data() {
  59. return {
  60. toneList: [
  61. require("../../../assets/NPC/tone1.png"),
  62. require("../../../assets/NPC/tone2.png"),
  63. require("../../../assets/NPC/tone3.png"),
  64. require("../../../assets/NPC/tone4.png"),
  65. require("../../../assets/NPC/tone0.png"),
  66. ],
  67. userSelect: [],
  68. curTime: "",
  69. stopAudio: false,
  70. timer: null,
  71. ed: null,
  72. };
  73. },
  74. computed: {},
  75. watch: {},
  76. //方法集合
  77. methods: {
  78. // 处理数据
  79. handleData() {
  80. let _this = this;
  81. let userSelect = [];
  82. _this.curQue.option.forEach((item) => {
  83. userSelect.push("");
  84. });
  85. if (!this.curQue.Bookanswer) {
  86. this.$set(this.curQue, "Bookanswer", userSelect);
  87. }
  88. },
  89. handleClick(index, indexs) {
  90. if(!this.TaskModel||this.TaskModel!='ANSWER'){
  91. this.$set(this.curQue.Bookanswer, index, indexs);
  92. }
  93. },
  94. handleChangeTime(time,edTime) {
  95. let _this = this;
  96. // if(!_this.stopAudio){
  97. // _this.timer = setInterval(() => {
  98. // if(_this.curTime >= edTime){
  99. // _this.stopAudio = false
  100. // _this.$refs.audioLine.onTimeupdateTime(_this.curTime / 1000, false);
  101. // clearInterval(_this.timer);
  102. // }
  103. // }, 200);
  104. // }
  105. _this.curTime = time;
  106. _this.stopAudio = true
  107. _this.$refs.audioLine.onTimeupdateTime(time / 1000, true);
  108. _this.ed = edTime
  109. },
  110. getCurTime(curTime) {
  111. this.curTime = curTime * 1000;
  112. },
  113. handleListenRead(playFlag) {
  114. this.stopAudio = playFlag;
  115. if(this.timer){
  116. clearInterval(this.timer);
  117. }
  118. },
  119. emptyEd(){
  120. this.ed = null;
  121. }
  122. },
  123. //生命周期 - 创建完成(可以访问当前this实例)
  124. created() {
  125. if(this.timer){
  126. clearInterval(this.timer);
  127. }
  128. this.handleData()
  129. },
  130. //生命周期 - 挂载完成(可以访问DOM元素)
  131. mounted() {},
  132. beforeCreate() {}, //生命周期 - 创建之前
  133. beforeMount() {}, //生命周期 - 挂载之前
  134. beforeUpdate() {}, //生命周期 - 更新之前
  135. updated() {}, //生命周期 - 更新之后
  136. beforeDestroy() {
  137. if(this.timer){
  138. clearInterval(this.timer);
  139. }
  140. }, //生命周期 - 销毁之前
  141. destroyed() {
  142. if(this.timer){
  143. clearInterval(this.timer);
  144. }
  145. }, //生命周期 - 销毁完成
  146. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  147. };
  148. </script>
  149. <style lang='scss' scoped>
  150. //@import url(); 引入公共css类
  151. .Big-Book-prev-Textdes {
  152. width: 100%;
  153. background: #f7f7f7;
  154. border: 1px solid rgba(0, 0, 0, 0.1);
  155. box-sizing: border-box;
  156. border-radius: 8px;
  157. overflow: hidden;
  158. ul {
  159. display: flex;
  160. flex-flow: wrap;
  161. justify-content: space-between;
  162. align-items: flex-start;
  163. padding: 24px 12px;
  164. li {
  165. width: 363px;
  166. background: #ffffff;
  167. border: 1px solid rgba(0, 0, 0, 0.1);
  168. box-sizing: border-box;
  169. border-radius: 8px;
  170. display: flex;
  171. align-items: center;
  172. padding: 8px 12px 8px 16px;
  173. margin: 8px 0;
  174. .play-btn {
  175. width: 16px;
  176. height: 16px;
  177. background: url("../../../assets/NPC/play-red.png") center no-repeat;
  178. background-size: cover;
  179. margin-right: 8px;
  180. &.active {
  181. background-image: url("../../../assets/NPC/icon-voice-play-red.png");
  182. background-size: cover;
  183. }
  184. }
  185. .audio-play {
  186. width: 16px;
  187. margin-right: 12px;
  188. }
  189. > div.con {
  190. font-size: 16px;
  191. line-height: 1.5;
  192. flex: 1;
  193. margin: 0;
  194. }
  195. a {
  196. margin-left: 8px;
  197. font-size: 0;
  198. &.active {
  199. background: #98d1eb;
  200. border-radius: 4px;
  201. }
  202. img {
  203. width: 24px;
  204. }
  205. }
  206. }
  207. }
  208. }
  209. .NPC-Big-Book-preview-green {
  210. .Big-Book-prev-Textdes {
  211. li {
  212. b {
  213. background: #24b99e;
  214. }
  215. .play-btn {
  216. background: url("../../../assets/NPC/play-green.png") center no-repeat;
  217. background-size: cover;
  218. &.active {
  219. background-image: url("../../../assets/NPC/icon-voice-play-green.png");
  220. background-size: cover;
  221. }
  222. }
  223. }
  224. }
  225. }
  226. .NPC-Big-Book-preview-brown {
  227. .Big-Book-prev-Textdes {
  228. li {
  229. b {
  230. background: #bd8865;
  231. }
  232. .play-btn {
  233. background: url("../../../assets/NPC/play-brown.png") center no-repeat;
  234. background-size: cover;
  235. &.active {
  236. background-image: url("../../../assets/NPC/icon-voice-play-brown.png");
  237. background-size: cover;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. </style>
  244. <style lang="scss">
  245. .SelectTone.Big-Book-prev-Textdes {
  246. ul {
  247. li {
  248. div.con {
  249. margin: 0;
  250. > p {
  251. margin: 0;
  252. }
  253. }
  254. }
  255. }
  256. }
  257. </style>