SelectTone.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. _this.$forceUpdate();
  197. },
  198. handleChangeTime(time, edTime) {
  199. let _this = this;
  200. // if(!_this.stopAudio){
  201. // _this.timer = setInterval(() => {
  202. // if(_this.curTime >= edTime){
  203. // _this.stopAudio = false
  204. // _this.$refs.audioLine.onTimeupdateTime(_this.curTime / 1000, false);
  205. // clearInterval(_this.timer);
  206. // }
  207. // }, 200);
  208. // }
  209. _this.curTime = time;
  210. _this.stopAudio = true;
  211. _this.$refs.audioLine.onTimeupdateTime(time / 1000, true);
  212. _this.ed = edTime;
  213. },
  214. getCurTime(curTime) {
  215. this.curTime = curTime * 1000;
  216. },
  217. handleListenRead(playFlag) {
  218. this.stopAudio = playFlag;
  219. if (this.timer) {
  220. clearInterval(this.timer);
  221. }
  222. },
  223. emptyEd() {
  224. this.ed = null;
  225. },
  226. },
  227. //生命周期 - 创建完成(可以访问当前this实例)
  228. created() {
  229. if (this.timer) {
  230. clearInterval(this.timer);
  231. }
  232. this.handleData();
  233. },
  234. //生命周期 - 挂载完成(可以访问DOM元素)
  235. mounted() {},
  236. beforeCreate() {}, //生命周期 - 创建之前
  237. beforeMount() {}, //生命周期 - 挂载之前
  238. beforeUpdate() {}, //生命周期 - 更新之前
  239. updated() {}, //生命周期 - 更新之后
  240. beforeDestroy() {
  241. if (this.timer) {
  242. clearInterval(this.timer);
  243. }
  244. }, //生命周期 - 销毁之前
  245. destroyed() {
  246. if (this.timer) {
  247. clearInterval(this.timer);
  248. }
  249. }, //生命周期 - 销毁完成
  250. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  251. };
  252. </script>
  253. <style lang='scss' scoped>
  254. //@import url(); 引入公共css类
  255. .Big-Book-prev-Textdes {
  256. width: 100%;
  257. background: #f7f7f7;
  258. border: 1px solid rgba(0, 0, 0, 0.1);
  259. box-sizing: border-box;
  260. border-radius: 8px;
  261. overflow: hidden;
  262. ul {
  263. display: flex;
  264. flex-flow: wrap;
  265. justify-content: space-between;
  266. align-items: flex-start;
  267. padding: 24px 12px;
  268. div.op-li {
  269. width: 363px;
  270. background: #ffffff;
  271. border: 1px solid rgba(0, 0, 0, 0.1);
  272. box-sizing: border-box;
  273. border-radius: 8px;
  274. display: flex;
  275. align-items: center;
  276. padding: 8px 12px 8px 16px;
  277. margin: 8px 0;
  278. .play-btn {
  279. width: 16px;
  280. height: 16px;
  281. background: url("../../../assets/NPC/play-red.png") center no-repeat;
  282. background-size: cover;
  283. margin-right: 8px;
  284. &.active {
  285. background-image: url("../../../assets/NPC/icon-voice-play-red.png");
  286. background-size: cover;
  287. }
  288. }
  289. .audio-play {
  290. width: 16px;
  291. margin-right: 12px;
  292. }
  293. > div.con {
  294. font-size: 16px;
  295. line-height: 1.5;
  296. flex: 1;
  297. margin: 0;
  298. }
  299. a {
  300. margin-left: 8px;
  301. font-size: 0;
  302. border: 1px #fff solid;
  303. border-radius: 4px;
  304. &.active {
  305. background: #98d1eb;
  306. border-color: #98d1eb;
  307. }
  308. &.userRight {
  309. background: rgba(44, 167, 103, 0.1);
  310. border-color: #2ca767;
  311. }
  312. &.userError {
  313. background: rgba(237, 52, 45, 0.1);
  314. border-color: #ed342d;
  315. }
  316. img {
  317. width: 24px;
  318. }
  319. }
  320. }
  321. }
  322. }
  323. .NPC-Big-Book-preview-green {
  324. .Big-Book-prev-Textdes {
  325. li {
  326. b {
  327. background: #24b99e;
  328. }
  329. .play-btn {
  330. background: url("../../../assets/NPC/play-green.png") center no-repeat;
  331. background-size: cover;
  332. &.active {
  333. background-image: url("../../../assets/NPC/icon-voice-play-green.png");
  334. background-size: cover;
  335. }
  336. }
  337. }
  338. }
  339. }
  340. .NPC-Big-Book-preview-brown {
  341. .Big-Book-prev-Textdes {
  342. li {
  343. b {
  344. background: #bd8865;
  345. }
  346. .play-btn {
  347. background: url("../../../assets/NPC/play-brown.png") center no-repeat;
  348. background-size: cover;
  349. &.active {
  350. background-image: url("../../../assets/NPC/icon-voice-play-brown.png");
  351. background-size: cover;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. </style>
  358. <style lang="scss">
  359. .SelectTone.Big-Book-prev-Textdes {
  360. ul {
  361. li {
  362. div.con {
  363. margin: 0;
  364. > p {
  365. margin: 0;
  366. }
  367. }
  368. }
  369. }
  370. }
  371. </style>