SelectTone.vue 12 KB

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