SelectTone.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. :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', userSelect[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"],
  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. _this.userSelect = [];
  82. _this.curQue.option.forEach((item) => {
  83. _this.userSelect.push("");
  84. });
  85. },
  86. handleClick(index, indexs) {
  87. this.$set(this.userSelect, index, indexs);
  88. },
  89. handleChangeTime(time,edTime) {
  90. let _this = this;
  91. // if(!_this.stopAudio){
  92. // _this.timer = setInterval(() => {
  93. // if(_this.curTime >= edTime){
  94. // _this.stopAudio = false
  95. // _this.$refs.audioLine.onTimeupdateTime(_this.curTime / 1000, false);
  96. // clearInterval(_this.timer);
  97. // }
  98. // }, 200);
  99. // }
  100. _this.curTime = time;
  101. _this.stopAudio = true
  102. _this.$refs.audioLine.onTimeupdateTime(time / 1000, true);
  103. _this.ed = edTime
  104. },
  105. getCurTime(curTime) {
  106. this.curTime = curTime * 1000;
  107. },
  108. handleListenRead(playFlag) {
  109. this.stopAudio = playFlag;
  110. if(this.timer){
  111. clearInterval(this.timer);
  112. }
  113. },
  114. emptyEd(){
  115. this.ed = null;
  116. }
  117. },
  118. //生命周期 - 创建完成(可以访问当前this实例)
  119. created() {
  120. if(this.timer){
  121. clearInterval(this.timer);
  122. }
  123. },
  124. //生命周期 - 挂载完成(可以访问DOM元素)
  125. mounted() {},
  126. beforeCreate() {}, //生命周期 - 创建之前
  127. beforeMount() {}, //生命周期 - 挂载之前
  128. beforeUpdate() {}, //生命周期 - 更新之前
  129. updated() {}, //生命周期 - 更新之后
  130. beforeDestroy() {
  131. if(this.timer){
  132. clearInterval(this.timer);
  133. }
  134. }, //生命周期 - 销毁之前
  135. destroyed() {
  136. if(this.timer){
  137. clearInterval(this.timer);
  138. }
  139. }, //生命周期 - 销毁完成
  140. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  141. };
  142. </script>
  143. <style lang='scss' scoped>
  144. //@import url(); 引入公共css类
  145. .Big-Book-prev-Textdes {
  146. width: 100%;
  147. background: #f7f7f7;
  148. border: 1px solid rgba(0, 0, 0, 0.1);
  149. box-sizing: border-box;
  150. border-radius: 8px;
  151. overflow: hidden;
  152. ul {
  153. display: flex;
  154. flex-flow: wrap;
  155. justify-content: space-between;
  156. align-items: flex-start;
  157. padding: 24px 12px;
  158. li {
  159. width: 363px;
  160. background: #ffffff;
  161. border: 1px solid rgba(0, 0, 0, 0.1);
  162. box-sizing: border-box;
  163. border-radius: 8px;
  164. display: flex;
  165. align-items: center;
  166. padding: 8px 12px 8px 16px;
  167. margin: 8px 0;
  168. .play-btn {
  169. width: 16px;
  170. height: 16px;
  171. background: url("../../../assets/NPC/play-red.png") center no-repeat;
  172. background-size: cover;
  173. margin-right: 8px;
  174. &.active {
  175. background-image: url("../../../assets/NPC/icon-voice-play-red.png");
  176. background-size: cover;
  177. }
  178. }
  179. .audio-play {
  180. width: 16px;
  181. margin-right: 12px;
  182. }
  183. > div.con {
  184. font-size: 16px;
  185. line-height: 1.5;
  186. flex: 1;
  187. margin: 0;
  188. }
  189. a {
  190. margin-left: 8px;
  191. font-size: 0;
  192. &.active {
  193. background: #98d1eb;
  194. border-radius: 4px;
  195. }
  196. img {
  197. width: 24px;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. .NPC-Big-Book-preview-green {
  204. .Big-Book-prev-Textdes {
  205. li {
  206. b {
  207. background: #24b99e;
  208. }
  209. .play-btn {
  210. background: url("../../../assets/NPC/play-green.png") center no-repeat;
  211. background-size: cover;
  212. &.active {
  213. background-image: url("../../../assets/NPC/icon-voice-play-green.png");
  214. background-size: cover;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. .NPC-Big-Book-preview-brown {
  221. .Big-Book-prev-Textdes {
  222. li {
  223. b {
  224. background: #bd8865;
  225. }
  226. .play-btn {
  227. background: url("../../../assets/NPC/play-brown.png") center no-repeat;
  228. background-size: cover;
  229. &.active {
  230. background-image: url("../../../assets/NPC/icon-voice-play-brown.png");
  231. background-size: cover;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. </style>
  238. <style lang="scss">
  239. .SelectTone.Big-Book-prev-Textdes {
  240. ul {
  241. li {
  242. div.con {
  243. margin: 0;
  244. > p {
  245. margin: 0;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. </style>