SelectYinjie.vue 12 KB

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