index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <view class="box" @touchstart="touchStart" @touchend="touchEnd">
  3. <nav-bar :title="navTitle"> </nav-bar>
  4. <view style="text-align: center">
  5. <van-count-down :time="time"></van-count-down>
  6. </view>
  7. <view class="divider"></view>
  8. <m-do-topic
  9. :hiddenFunction="true"
  10. :trueNum.sync="trueNum"
  11. :falseNum.sync="falseNum"
  12. :query="query"
  13. :problemListIndex="problemListIndex"
  14. ></m-do-topic>
  15. <!-- #ifdef MP-WEIXIN -->
  16. <van-tabbar>
  17. <van-tabbar-item @click="goBeforeTopics"
  18. ><van-icon
  19. slot="icon"
  20. custom-style="transform: rotate(90deg);"
  21. custom-class="last-subject"
  22. name="down"
  23. size="18px"
  24. />上一题
  25. </van-tabbar-item>
  26. <van-tabbar-item
  27. ><van-icon slot="icon" size="18px" name="description" />{{
  28. problemListIndex + 1
  29. }}/{{ problemListTotal }}
  30. </van-tabbar-item>
  31. <van-tabbar-item @click="submitExam"
  32. ><van-icon slot="icon" size="18px" name="records" />交卷
  33. </van-tabbar-item>
  34. <van-tabbar-item @click="goNextTopics"
  35. ><van-icon
  36. slot="icon"
  37. custom-style="transform: rotate(-90deg);"
  38. custom-class="last-subject"
  39. name="down"
  40. size="18px"
  41. />下一题
  42. </van-tabbar-item>
  43. </van-tabbar>
  44. <!-- #endif -->
  45. <!-- #ifdef MP-TOUTIAO -->
  46. <tabbar height="35px">
  47. <view @click="goBeforeTopics" class="flex-all-center h-full">
  48. <van-icon
  49. slot="icon"
  50. custom-style="transform: rotate(90deg);"
  51. custom-class="last-subject"
  52. name="down"
  53. size="18px"
  54. /><text> 上一题 </text>
  55. </view>
  56. <view class="flex-all-center h-full">
  57. <van-icon size="18px" name="description" />{{ problemListIndex + 1 }}/{{
  58. problemListTotal
  59. }}
  60. </view>
  61. <view @click="submitExam" class="flex-all-center h-full">
  62. <van-icon slot="icon" size="18px" name="records" />交卷
  63. </view>
  64. <view @click="goNextTopics" class="flex-all-center h-full">
  65. 下一题
  66. <van-icon
  67. custom-style="transform: rotate(-90deg);"
  68. custom-class="last-subject"
  69. name="down"
  70. size="18px"
  71. />
  72. </view>
  73. </tabbar>
  74. <!-- #endif -->
  75. </view>
  76. </template>
  77. <script>
  78. import navBar from "./components/navBar.vue";
  79. import api from "@/api/index";
  80. import utils from "@/utils/index";
  81. import tabbar from "./components/tabbar.vue";
  82. import mRadio from "@/components/m-radio/m-radio.vue";
  83. import mRadioGroup from "@/components/m-radio-group/m-radio-group.vue";
  84. import mCheckbox from "@/components/m-checkbox/m-checkbox.vue";
  85. import mCheckboxGroup from "@/components/m-checkbox-group/m-checkbox-group.vue";
  86. export default {
  87. data() {
  88. return {
  89. query: {
  90. cert: "",
  91. vehicle: "",
  92. subject: "",
  93. title: "",
  94. },
  95. gsMap: {
  96. xc: "小车",
  97. hc: "货车",
  98. mtc: "摩托车",
  99. kc: "客车",
  100. },
  101. examTimer: 0,
  102. examTimeUse: 0,
  103. time: 45 * 60 * 1000,
  104. problemListTotal: 1,
  105. problemList: [
  106. {
  107. answer: "×",
  108. answerkeyword: "",
  109. answermp3:
  110. "https://t1-1305573081.file.myqcloud.com/kt/answer_mp3/answer1389.mp3",
  111. classIssue: "54",
  112. classIssueName: "车内开关/装置",
  113. classSort: 16,
  114. createTime: "2022-04-21 13:33:46",
  115. excellIssue: "23",
  116. excellIssueName: "必学题三",
  117. excellSort: 4,
  118. explainGif:
  119. "https://t1-1305573081.file.myqcloud.com/kt/explain_gif/explain1389.gif",
  120. explainJq:
  121. "看图答题:红色圆圈套在杆子中间.答对;不在中间或没有圆圈的.答错。",
  122. explainJs:
  123. "图中所示为左右转向灯开关转向灯操作:上提是右转向灯亮起,下压是左转向灯。",
  124. explainMp3:
  125. "https://t1-1305573081.file.myqcloud.com/kt/explain_mp3/explain1389.mp3",
  126. explainjsmp3:
  127. "https://t1-1305573081.file.myqcloud.com/kt/explain_js_mp3/explainJS1389.mp3",
  128. id: 831,
  129. idKt: 1389,
  130. idYdt: 950,
  131. image:
  132. "https://t1-1305573081.file.myqcloud.com/kt/image/image1389.png",
  133. imageYdt:
  134. "https://t1-1305573081.file.myqcloud.com/kt/image_ydt/5eb4d75agw1e291vmniovj.jpg",
  135. issue: "将转向灯开关向上提,左转向灯亮。",
  136. issuemp3:
  137. "https://t1-1305573081.file.myqcloud.com/kt/issue_mp3/issue1389.mp3",
  138. liceBus: "1",
  139. liceCar: "1",
  140. liceMoto: null,
  141. liceTruck: "1",
  142. number: 831,
  143. opts: "√-×",
  144. optsArr: ["√", "×"],
  145. placeIssue: null,
  146. placeIssueName: null,
  147. placeSort: null,
  148. questionType: 1,
  149. sequeIssue: "7",
  150. sequeIssueName: "机械仪表",
  151. sequeSort: 25,
  152. skillkeyword: "没有圆圈-答错",
  153. subject: 1,
  154. titlekeyword: "",
  155. updateTime: "2022-04-22 13:43:07",
  156. userAnswer: [],
  157. },
  158. ],
  159. touchx: 0,
  160. touchy: 0,
  161. problemListIndex: 0,
  162. };
  163. },
  164. filters: {
  165. questionType: function (value) {
  166. let question = "";
  167. switch (value) {
  168. case 1:
  169. case "1":
  170. question = "判断题";
  171. break;
  172. case 2:
  173. case "2":
  174. question = "单选题";
  175. break;
  176. case 3:
  177. case "3":
  178. question = "多选题";
  179. break;
  180. }
  181. return question;
  182. },
  183. },
  184. methods: {
  185. confirmMult() {
  186. this.$set(this.problemList[this.problemListIndex], "isCompleted", true);
  187. if (
  188. JSON.stringify(
  189. this.problemList[this.problemListIndex].answer.split("-").sort()
  190. ) ===
  191. JSON.stringify(
  192. this.problemList[this.problemListIndex].userAnswer.sort()
  193. )
  194. ) {
  195. this.trueNum++;
  196. } else {
  197. this.falseNum++;
  198. api.exam.studentQuestionWrong({
  199. questionId: this.problemList[this.problemListIndex].id,
  200. carType: this.gsMap[this.query.gs],
  201. km: this.query.subject === "4" ? "科目四" : "科目一",
  202. });
  203. }
  204. },
  205. touchStart(e) {
  206. var that = this;
  207. (this.touchx = e.changedTouches[0].clientX),
  208. (this.touchy = e.changedTouches[0].clientY);
  209. },
  210. touchEnd(e) {
  211. console.log(e);
  212. var that = this;
  213. let x = e.changedTouches[0].clientX;
  214. let y = e.changedTouches[0].clientY;
  215. let turn = "";
  216. if (x - that.touchx > 50 && Math.abs(y - that.touchy) < 50) {
  217. //右滑
  218. turn = "right";
  219. this.problemListIndex <= 0
  220. ? uni.showToast({
  221. title: "到底了",
  222. icon: "none",
  223. })
  224. : this.problemListIndex--;
  225. } else if (x - that.touchx < -50 && Math.abs(y - that.touchy) < 50) {
  226. //左滑
  227. turn = "left";
  228. this.problemListIndex >= this.problemList.length - 1
  229. ? uni.showToast({
  230. title: "到底了",
  231. icon: "none",
  232. })
  233. : this.problemListIndex++;
  234. }
  235. if (y - that.touchy > 50 && Math.abs(x - that.touchx) < 50) {
  236. //下滑
  237. turn = "down";
  238. } else if (y - that.touchy < -50 && Math.abs(x - that.touchx) < 50) {
  239. //上滑
  240. turn = "up";
  241. }
  242. //根据方向进行操作
  243. if (turn == "down") {
  244. //下滑触发操作
  245. }
  246. console.log(turn);
  247. },
  248. submitExam(e) {
  249. let score = 0;
  250. let query = this.query;
  251. let that = this;
  252. let scorePerQuestion = 0;
  253. query.subject === "4" ? (scorePerQuestion = 2) : (scorePerQuestion = 1);
  254. score = this.trueNum*scorePerQuestion
  255. uni.showModal({
  256. title: "是否交卷",
  257. content: "交卷后不可再修改了",
  258. success(res) {
  259. if (res.confirm) {
  260. let useTime = "";
  261. let useTimer = new Date(that.examTimeUse);
  262. clearInterval(that.examTimer);
  263. useTime = `${useTimer.getMinutes()}:${useTimer.getSeconds()}`;
  264. uni.navigateTo({
  265. url:
  266. "/otherPages/mockExamEnd/index?" +
  267. utils.mapToUrlQuery({
  268. score,
  269. useTime,
  270. ...that.query,
  271. }),
  272. });
  273. }
  274. },
  275. fail() {},
  276. });
  277. },
  278. goBeforeTopics() {
  279. if (this.problemListIndex <= 0) {
  280. uni.showToast({
  281. title: "到底了",
  282. icon: "none",
  283. });
  284. return;
  285. }
  286. this.problemListIndex = this.problemListIndex - 1;
  287. },
  288. goNextTopics() {
  289. if (this.problemListIndex >= this.problemList.length - 1) {
  290. uni.showToast({
  291. title: "到底了",
  292. icon: "none",
  293. });
  294. return;
  295. }
  296. this.problemListIndex = this.problemListIndex + 1;
  297. },
  298. readQuestion(e) {
  299. let globalAudio = utils.wxUtils.getGlobAudio();
  300. if (globalAudio) {
  301. globalAudio.src = e;
  302. globalAudio.stop();
  303. globalAudio.play();
  304. }
  305. },
  306. changeRadioGroup(e) {
  307. this.$set(
  308. this.problemList[this.problemListIndex],
  309. "userAnswer",
  310. e.detail
  311. );
  312. //错题
  313. if (e.detail !== this.problemList[this.problemListIndex].answer) {
  314. api.exam.studentQuestionWrong({
  315. questionId: this.problemList[this.problemListIndex].id,
  316. carType: this.gsMap[this.query.gs],
  317. km: this.query.subject === "4" ? "科目四" : "科目一",
  318. });
  319. }
  320. this.problemList[this.problemListIndex].optsArr.forEach((item, index) => {
  321. if (e.detail === item.value) {
  322. item.selected = true;
  323. this.$set(
  324. this.problemList[this.problemListIndex].optsArr[index],
  325. "selected",
  326. true
  327. );
  328. } else {
  329. item.selected = false;
  330. this.$set(
  331. this.problemList[this.problemListIndex].optsArr[index],
  332. "selected",
  333. false
  334. );
  335. }
  336. });
  337. this.$set(this.problemList[this.problemListIndex], "isCompleted", true);
  338. // this.problemList[this.problemListIndex].optsArr.forEach((item) => {
  339. // if (e.detail.value === item.value) {
  340. // item.selected = true;
  341. // } else {
  342. // item.selected = false;
  343. // }
  344. // });
  345. },
  346. changeCheckboxGroup(e) {
  347. this.$set(
  348. this.problemList[this.problemListIndex],
  349. "userAnswer",
  350. e.detail
  351. );
  352. this.problemList[this.problemListIndex].optsArr.forEach((item, index) => {
  353. if (e.detail.includes(item.value)) {
  354. item.selected = true;
  355. this.$set(
  356. this.problemList[this.problemListIndex].optsArr[index],
  357. "selected",
  358. true
  359. );
  360. } else {
  361. item.selected = false;
  362. this.$set(
  363. this.problemList[this.problemListIndex].optsArr[index],
  364. "selected",
  365. false
  366. );
  367. }
  368. });
  369. },
  370. changeGroup(e) {
  371. console.log(e);
  372. this.$set(
  373. this.problemList[this.problemListIndex],
  374. "userAnswer",
  375. e.detail
  376. );
  377. },
  378. changeCheckbox(e) {
  379. console.log(e);
  380. },
  381. numberToLetter(index) {
  382. index = Number(index);
  383. return String.fromCharCode(index + 65);
  384. },
  385. },
  386. onLoad(query) {
  387. let that = this;
  388. this.query = query;
  389. api.open
  390. .questionInfoSelectTestK14QuestionInfoList({
  391. ...this.query,
  392. })
  393. .then((res) => {
  394. res.rows.forEach((element) => {
  395. element.optsArr = [];
  396. element.opts.split("-").forEach((item, index) => {
  397. if (element.questionType == 3) {
  398. element.optsArr.push({
  399. selected: false,
  400. value: item,
  401. index: index,
  402. isAnswer: element.answer.split("-").includes(item),
  403. });
  404. } else {
  405. element.optsArr.push({
  406. selected: false,
  407. value: item,
  408. index: index,
  409. isAnswer: item === element.answer,
  410. });
  411. }
  412. });
  413. element.isCompleted = false;
  414. element.userAnswer = [];
  415. });
  416. that.problemListTotal = res.total;
  417. that.problemList = res.rows;
  418. });
  419. this.examTimer = setInterval(() => {
  420. this.examTimeUse = this.examTimeUse + 1000;
  421. if (this.examTimeUse > this.time) {
  422. this.submitExam();
  423. clearInterval(this.examTimer);
  424. }
  425. }, 1000);
  426. },
  427. computed: {
  428. //liceCar=1&liceTruck=&liceBus=&liceMoto=&name=科目一&cert=C1/C2/C3&vehicle=轿车&subject=1&title=顺序练习&sort=3
  429. navTitle() {
  430. let subjectName = this.query.subject == 1 ? "科目一" : "科目四";
  431. return `(${this.query.cert})/${subjectName}/${this.query.title}`;
  432. },
  433. },
  434. onUnload() {
  435. clearInterval(this.examTimer);
  436. },
  437. components: {
  438. navBar,
  439. tabbar,
  440. mRadio,
  441. mRadioGroup,
  442. mCheckbox,
  443. mCheckboxGroup,
  444. },
  445. };
  446. </script>
  447. <style lang="scss" scoped>
  448. .flex-all-center {
  449. display: flex;
  450. align-content: center;
  451. align-items: center;
  452. }
  453. .divider {
  454. width: 100%;
  455. height: 24rpx;
  456. background-color: #f2f3f5;
  457. }
  458. .box {
  459. width: 100%;
  460. height: 100vh;
  461. background: #fff;
  462. .last-subject {
  463. transform: rotate(90deg);
  464. }
  465. .function-list {
  466. width: 100%;
  467. font-size: 13px;
  468. display: flex;
  469. justify-content: space-around;
  470. flex-wrap: wrap;
  471. padding: 15px;
  472. box-sizing: border-box;
  473. .function-item {
  474. margin-bottom: 20px;
  475. width: 30%;
  476. display: flex;
  477. flex-direction: column;
  478. align-items: center;
  479. font-size: 13px;
  480. font-weight: 400;
  481. color: #8a9099;
  482. span {
  483. margin-top: 5px;
  484. }
  485. }
  486. }
  487. .problem-box {
  488. padding: 15rpx;
  489. background: #fff;
  490. /deep/ .van-checkbox {
  491. padding-bottom: 15rpx;
  492. }
  493. /deep/ .van-radio {
  494. padding-bottom: 15rpx;
  495. }
  496. .problem-issue {
  497. font-size: 42rpx;
  498. }
  499. .problem-select {
  500. display: flex;
  501. align-content: center;
  502. align-items: center;
  503. margin-top: 15rpx;
  504. padding-left: 30rpx;
  505. }
  506. .problem-type {
  507. padding-left: 10rpx;
  508. padding-right: 10rpx;
  509. padding-top: 4rpx;
  510. padding-bottom: 4rpx;
  511. font-size: 24rpx;
  512. border-radius: 16rpx 16rpx 0 16rpx;
  513. background: #498ef5;
  514. margin-right: 10rpx;
  515. color: #fff;
  516. font-size: 32rpx;
  517. }
  518. .problem-ops {
  519. margin-top: 30rpx;
  520. padding-left: 30rpx;
  521. .problem-checkbox {
  522. height: 100rpx;
  523. }
  524. }
  525. .problem-op {
  526. width: 75rpx;
  527. height: 75rpx;
  528. line-height: 75rpx;
  529. border-radius: 50%;
  530. text-align: center;
  531. overflow: hidden;
  532. background: #fff;
  533. box-shadow: 0px 4rpx 12rpx rgba(0, 0, 0, 0.16);
  534. }
  535. .problem-op_green {
  536. width: 75rpx;
  537. height: 75rpx;
  538. line-height: 75rpx;
  539. border-radius: 50%;
  540. text-align: center;
  541. overflow: hidden;
  542. background: #01c18d;
  543. box-shadow: 0px 4rpx 12rpx rgba(0, 0, 0, 0.16);
  544. }
  545. .problem-op_selected {
  546. background: #498ef5;
  547. }
  548. .problem-img {
  549. width: 100%;
  550. margin-top: 20rpx;
  551. display: flex;
  552. justify-content: center;
  553. image {
  554. margin: 0 auto;
  555. }
  556. }
  557. }
  558. }
  559. </style>