SelectTone.vue 6.0 KB

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