SelectTone.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <!-- -->
  2. <template>
  3. <div class="Big-Book-prev-Textdes SelectTone" v-if="isShowTemp">
  4. <AnswerTitle :judgeAnswer="judgeAnswer" />
  5. <div
  6. class="aduioLine-box"
  7. v-if="
  8. curQue.mp3_list && curQue.mp3_list.length > 0 && curQue.mp3_list[0].id
  9. "
  10. :style="{ height: judgeAnswer == 'standardAnswer' ? '0px' : 'auto' }"
  11. >
  12. <AudioLine
  13. audioId="sentenceListenAudio"
  14. :mp3="curQue.mp3_list[0].id"
  15. :getCurTime="getCurTime"
  16. :themeColor="themeColor"
  17. :ed="ed"
  18. type="audioLine"
  19. ref="audioLine"
  20. @handleListenRead="handleListenRead"
  21. />
  22. </div>
  23. <ul>
  24. <li v-for="(item, index) in curQue.option" :key="index">
  25. <div class="op-li" v-if="isShowOption(item, index)">
  26. <a
  27. v-if="curQue.wordTime && curQue.wordTime.length > 0"
  28. :class="[
  29. 'play-btn',
  30. curTime >= curQue.wordTime[index].bg &&
  31. curTime < curQue.wordTime[index].ed &&
  32. stopAudio
  33. ? 'active'
  34. : '',
  35. ]"
  36. @click="
  37. handleChangeTime(
  38. curQue.wordTime[index].bg,
  39. curQue.wordTime[index].ed
  40. )
  41. "
  42. ></a>
  43. <div v-html="item.con" class="con"></div>
  44. <a
  45. v-for="(itmes, indexs) in toneList"
  46. :key="indexs"
  47. :class="['tone-item', lookanswerClass(index, indexs)]"
  48. @click="handleClick(index, indexs)"
  49. >
  50. <img :src="itmes" />
  51. </a>
  52. </div>
  53. </li>
  54. </ul>
  55. </div>
  56. </template>
  57. <script>
  58. import Audio from "../preview/components/AudioRed.vue"; // 音频播放
  59. import AudioLine from "../preview/AudioLine.vue";
  60. import AnswerTitle from "../preview/components/AnswerTitle.vue";
  61. export default {
  62. components: { Audio, AudioLine, AnswerTitle },
  63. props: ["curQue", "themeColor", "TaskModel", "judgeAnswer"],
  64. data() {
  65. return {
  66. toneList: [
  67. require("../../../assets/NPC/tone1.png"),
  68. require("../../../assets/NPC/tone2.png"),
  69. require("../../../assets/NPC/tone3.png"),
  70. require("../../../assets/NPC/tone4.png"),
  71. require("../../../assets/NPC/tone0.png"),
  72. ],
  73. userSelect: [],
  74. curTime: "",
  75. stopAudio: false,
  76. timer: null,
  77. ed: null,
  78. userErrorNumberTotal: 0,
  79. };
  80. },
  81. computed: {
  82. lookanswerClass() {
  83. return function (index, indexs) {
  84. let _this = this;
  85. let className = "";
  86. let userAnswer = this.curQue.Bookanswer[index].value.toString();
  87. if (this.curQue.option[index].answer) {
  88. let answer = (this.curQue.option[index].answer - 1).toString();
  89. if (_this.judgeAnswer == "standardAnswer") {
  90. if (indexs.toString() === answer) {
  91. className = "userRight";
  92. } else {
  93. className = "";
  94. }
  95. } else if (
  96. _this.judgeAnswer == "userAnswer" ||
  97. _this.judgeAnswer == "studentAnswer"
  98. ) {
  99. if (indexs.toString() === userAnswer) {
  100. if (answer === userAnswer) {
  101. className = "userRight";
  102. } else {
  103. className = "userError";
  104. }
  105. } else {
  106. className = "";
  107. }
  108. }
  109. }
  110. if (!_this.judgeAnswer && userAnswer == indexs.toString()) {
  111. className = "active";
  112. }
  113. return className;
  114. };
  115. },
  116. isShowTemp() {
  117. let _this = this;
  118. let bool = false;
  119. if (_this.curQue && _this.curQue.Bookanswer) {
  120. if (_this.judgeAnswer == "standardAnswer") {
  121. if (_this.userErrorNumberTotal > 0) {
  122. bool = true;
  123. } else {
  124. bool = false;
  125. }
  126. } else {
  127. bool = true;
  128. }
  129. }
  130. return bool;
  131. },
  132. isShowOption() {
  133. return function (item, index) {
  134. let _this = this;
  135. let bool = true;
  136. if (_this.judgeAnswer == "standardAnswer") {
  137. if (!item.answer) {
  138. bool = false;
  139. } else if (
  140. _this.curQue.Bookanswer[index].userAnswerJudge ==
  141. "[JUDGE##T##JUDGE]"
  142. ) {
  143. bool = false;
  144. }
  145. }
  146. return bool;
  147. };
  148. },
  149. },
  150. watch: {},
  151. //方法集合
  152. methods: {
  153. // 处理数据
  154. handleData() {
  155. let _this = this;
  156. if (!_this.curQue.Bookanswer) {
  157. let userSelect = [];
  158. _this.curQue.option.forEach((item) => {
  159. let obj = {
  160. value: "",
  161. userAnswerJudge: item.answer ? "[JUDGE##F##JUDGE]" : "",
  162. };
  163. userSelect.push(JSON.parse(JSON.stringify(obj)));
  164. });
  165. _this.$set(this.curQue, "Bookanswer", userSelect);
  166. } else {
  167. let BookanswerStr = JSON.stringify(_this.curQue.Bookanswer);
  168. let errReg = /\[JUDGE##F##JUDGE\]/g;
  169. if (errReg.test(BookanswerStr)) {
  170. let errorArr = BookanswerStr.match(/\[JUDGE##F##JUDGE\]/g);
  171. _this.userErrorNumberTotal = errorArr.length;
  172. }
  173. }
  174. },
  175. handleClick(index, indexs) {
  176. let _this = this;
  177. if (!_this.TaskModel || _this.TaskModel != "ANSWER") {
  178. _this.$set(_this.curQue.Bookanswer[index], "value", indexs);
  179. if (_this.curQue.option[index].answer) {
  180. let answer = _this.curQue.option[index].answer - 1;
  181. if (indexs.toString() === answer.toString()) {
  182. _this.$set(
  183. _this.curQue.Bookanswer[index],
  184. "userAnswerJudge",
  185. "[JUDGE##T##JUDGE]"
  186. );
  187. } else {
  188. _this.$set(
  189. _this.curQue.Bookanswer[index],
  190. "userAnswerJudge",
  191. "[JUDGE##F##JUDGE]"
  192. );
  193. }
  194. }
  195. }
  196. },
  197. handleChangeTime(time, edTime) {
  198. let _this = this;
  199. // if(!_this.stopAudio){
  200. // _this.timer = setInterval(() => {
  201. // if(_this.curTime >= edTime){
  202. // _this.stopAudio = false
  203. // _this.$refs.audioLine.onTimeupdateTime(_this.curTime / 1000, false);
  204. // clearInterval(_this.timer);
  205. // }
  206. // }, 200);
  207. // }
  208. _this.curTime = time;
  209. _this.stopAudio = true;
  210. _this.$refs.audioLine.onTimeupdateTime(time / 1000, true);
  211. _this.ed = edTime;
  212. },
  213. getCurTime(curTime) {
  214. this.curTime = curTime * 1000;
  215. },
  216. handleListenRead(playFlag) {
  217. this.stopAudio = playFlag;
  218. if (this.timer) {
  219. clearInterval(this.timer);
  220. }
  221. },
  222. emptyEd() {
  223. this.ed = null;
  224. },
  225. },
  226. //生命周期 - 创建完成(可以访问当前this实例)
  227. created() {
  228. if (this.timer) {
  229. clearInterval(this.timer);
  230. }
  231. this.handleData();
  232. },
  233. //生命周期 - 挂载完成(可以访问DOM元素)
  234. mounted() {},
  235. beforeCreate() {}, //生命周期 - 创建之前
  236. beforeMount() {}, //生命周期 - 挂载之前
  237. beforeUpdate() {}, //生命周期 - 更新之前
  238. updated() {}, //生命周期 - 更新之后
  239. beforeDestroy() {
  240. if (this.timer) {
  241. clearInterval(this.timer);
  242. }
  243. }, //生命周期 - 销毁之前
  244. destroyed() {
  245. if (this.timer) {
  246. clearInterval(this.timer);
  247. }
  248. }, //生命周期 - 销毁完成
  249. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  250. };
  251. </script>
  252. <style lang='scss' scoped>
  253. //@import url(); 引入公共css类
  254. .Big-Book-prev-Textdes {
  255. width: 100%;
  256. background: #f7f7f7;
  257. border: 1px solid rgba(0, 0, 0, 0.1);
  258. box-sizing: border-box;
  259. border-radius: 8px;
  260. overflow: hidden;
  261. ul {
  262. display: flex;
  263. flex-flow: wrap;
  264. justify-content: space-between;
  265. align-items: flex-start;
  266. padding: 24px 12px;
  267. div.op-li {
  268. width: 363px;
  269. background: #ffffff;
  270. border: 1px solid rgba(0, 0, 0, 0.1);
  271. box-sizing: border-box;
  272. border-radius: 8px;
  273. display: flex;
  274. align-items: center;
  275. padding: 8px 12px 8px 16px;
  276. margin: 8px 0;
  277. .play-btn {
  278. width: 16px;
  279. height: 16px;
  280. background: url("../../../assets/NPC/play-red.png") center no-repeat;
  281. background-size: cover;
  282. margin-right: 8px;
  283. &.active {
  284. background-image: url("../../../assets/NPC/icon-voice-play-red.png");
  285. background-size: cover;
  286. }
  287. }
  288. .audio-play {
  289. width: 16px;
  290. margin-right: 12px;
  291. }
  292. > div.con {
  293. font-size: 16px;
  294. line-height: 1.5;
  295. flex: 1;
  296. margin: 0;
  297. }
  298. a {
  299. margin-left: 8px;
  300. font-size: 0;
  301. border: 1px #fff solid;
  302. border-radius: 4px;
  303. &.active {
  304. background: #98d1eb;
  305. border-color: #98d1eb;
  306. }
  307. &.userRight {
  308. background: rgba(44, 167, 103, 0.1);
  309. border-color: #2ca767;
  310. }
  311. &.userError {
  312. background: rgba(237, 52, 45, 0.1);
  313. border-color: #ed342d;
  314. }
  315. img {
  316. width: 24px;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. .NPC-Big-Book-preview-green {
  323. .Big-Book-prev-Textdes {
  324. li {
  325. b {
  326. background: #24b99e;
  327. }
  328. .play-btn {
  329. background: url("../../../assets/NPC/play-green.png") center no-repeat;
  330. background-size: cover;
  331. &.active {
  332. background-image: url("../../../assets/NPC/icon-voice-play-green.png");
  333. background-size: cover;
  334. }
  335. }
  336. }
  337. }
  338. }
  339. .NPC-Big-Book-preview-brown {
  340. .Big-Book-prev-Textdes {
  341. li {
  342. b {
  343. background: #bd8865;
  344. }
  345. .play-btn {
  346. background: url("../../../assets/NPC/play-brown.png") center no-repeat;
  347. background-size: cover;
  348. &.active {
  349. background-image: url("../../../assets/NPC/icon-voice-play-brown.png");
  350. background-size: cover;
  351. }
  352. }
  353. }
  354. }
  355. }
  356. </style>
  357. <style lang="scss">
  358. .SelectTone.Big-Book-prev-Textdes {
  359. ul {
  360. li {
  361. div.con {
  362. margin: 0;
  363. > p {
  364. margin: 0;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. </style>