You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

410 lines
15 KiB

1 week ago
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. const common_assets = require("../../../common/assets.js");
  4. const utils_utils = require("../../../utils/utils.js");
  5. const config_api = require("../../../config/api.js");
  6. require("../../../uni_modules/uview-plus/index.js");
  7. const store_modules_car = require("../../../store/modules/car.js");
  8. const uni_modules_uviewPlus_libs_function_debounce = require("../../../uni_modules/uview-plus/libs/function/debounce.js");
  9. if (!Array) {
  10. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  11. const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  12. const _easycom_up_count_down2 = common_vendor.resolveComponent("up-count-down");
  13. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  14. (_easycom_u_icon2 + _easycom_up_icon2 + _easycom_up_count_down2 + _easycom_u_popup2)();
  15. }
  16. const _easycom_u_icon = () => "../../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  17. const _easycom_up_icon = () => "../../../uni_modules/uview-plus/components/u-icon/u-icon.js";
  18. const _easycom_up_count_down = () => "../../../uni_modules/uview-plus/components/u-count-down/u-count-down.js";
  19. const _easycom_u_popup = () => "../../../uni_modules/uview-plus/components/u-popup/u-popup.js";
  20. if (!Math) {
  21. (_easycom_u_icon + _easycom_up_icon + _easycom_up_count_down + _easycom_u_popup)();
  22. }
  23. const _sfc_main = {
  24. __name: "exam",
  25. setup(__props) {
  26. var _a;
  27. let usecarStore = store_modules_car.carStore();
  28. let randomNumber = "";
  29. common_vendor.onLoad((options) => {
  30. randomNumber = options.randomNumber;
  31. });
  32. const types = common_vendor.ref([
  33. "单选题",
  34. "多选题",
  35. "判断题"
  36. ]);
  37. let phone = (_a = common_vendor.index.getStorageSync("loginInfo")) == null ? void 0 : _a.phone;
  38. const showCommit = common_vendor.ref(false);
  39. const showNoPass = common_vendor.ref(false);
  40. const showWrong = common_vendor.ref(false);
  41. const show = common_vendor.ref(false);
  42. common_vendor.onMounted(() => {
  43. utils_utils.detectOrient("#brushQuestions");
  44. });
  45. function previewImg() {
  46. show.value = true;
  47. }
  48. function goBack() {
  49. common_vendor.index.navigateBack();
  50. }
  51. const questionBank = common_vendor.ref({});
  52. const questionBankList = common_vendor.ref([]);
  53. let ansCard = common_vendor.ref([]);
  54. let examInfo = common_vendor.ref({});
  55. let currentIndex = common_vendor.ref(0);
  56. async function startQuestionFn() {
  57. try {
  58. common_vendor.index.showLoading({
  59. title: "正在加载..."
  60. });
  61. let obj = {
  62. carType: usecarStore.carInfo.carType,
  63. stepType: usecarStore.carInfo.stepType,
  64. examType: 2
  65. };
  66. const { data: res } = await config_api.startExam(obj);
  67. common_vendor.index.hideLoading();
  68. questionBank.value = res.questionBank[0];
  69. questionBankList.value = res.questionBank;
  70. let size = usecarStore.carInfo.stepType == 1 ? 10 : 5;
  71. ansCard.value = chunk(questionBankList.value, size);
  72. initOptionArr();
  73. examInfo.value = res;
  74. } catch (e) {
  75. common_vendor.index.hideLoading();
  76. }
  77. }
  78. startQuestionFn();
  79. function chunk(arr, size) {
  80. if (arr.length == 0)
  81. return [];
  82. let result = [];
  83. let tmp = [];
  84. arr.forEach((item, index) => {
  85. if (tmp.length == 0) {
  86. result.push(tmp);
  87. }
  88. item.index = index;
  89. tmp.push(item);
  90. if (tmp.length == size) {
  91. tmp = [];
  92. }
  93. });
  94. return result;
  95. }
  96. function initOptionArr() {
  97. questionBank.value.optionArr = [];
  98. let abcd = [
  99. "a",
  100. "b",
  101. "c",
  102. "d",
  103. "e",
  104. "f"
  105. ];
  106. abcd.forEach((k, i) => {
  107. let option = "option" + k;
  108. if (questionBank.value[option]) {
  109. let obj = {
  110. key: k.toLocaleUpperCase(),
  111. text: questionBank.value[option],
  112. index: i + 1
  113. };
  114. questionBank.value.optionArr.push(obj);
  115. }
  116. });
  117. }
  118. const curOption = common_vendor.ref({});
  119. async function chooseOption(item) {
  120. if (questionBank.value.answerMy)
  121. return;
  122. console.log(item);
  123. if (questionBank.value.types != 2) {
  124. item.answer = item.key;
  125. curOption.value = item;
  126. } else if (questionBank.value.types == 2) {
  127. if (!curOption.value.answer)
  128. curOption.value.answer = "";
  129. if (curOption.value.answer.includes(item.key)) {
  130. curOption.value.answer = curOption.value.answer.replace(item.key, "");
  131. return;
  132. }
  133. curOption.value.answer = (curOption.value.answer + item.key).split("").sort().join("");
  134. }
  135. }
  136. async function nextQuestion(num) {
  137. if (curOption.value.answer) {
  138. questionBank.value.answerMy = curOption.value.answer;
  139. if (questionBank.value.types == 3)
  140. questionBank.value.answerMy = curOption.value.answer == "A" ? "true" : "false";
  141. }
  142. if (questionBank.value.answerMy && questionBank.value.answer != questionBank.value.answerMy && curOption.value.isNext != "next") {
  143. curOption.value.isNext = "next";
  144. showWrong.value = true;
  145. if (countDownRef.value) {
  146. countDownRef.value.pause();
  147. }
  148. return false;
  149. }
  150. curOption.value = {};
  151. currentIndex.value = currentIndex.value + num;
  152. getQuestionFn();
  153. }
  154. async function getQuestionFn() {
  155. console.log(currentIndex.value);
  156. questionBank.value = questionBankList.value[currentIndex.value];
  157. curOption.value = {};
  158. curOption.value.isNext = "";
  159. if (questionBank.value.answerMy)
  160. curOption.value.answer = questionBank.value.answerMy;
  161. initOptionArr();
  162. }
  163. function ansCardClick(item) {
  164. currentIndex.value = item.index;
  165. getQuestionFn();
  166. }
  167. let grade = common_vendor.ref(0);
  168. async function submitBtnFn() {
  169. if (curOption.value.answer)
  170. questionBank.value.answerMy = curOption.value.answer;
  171. let wrongArr = questionBankList.value.filter((item) => item.answer != item.answerMy);
  172. let worngId = wrongArr.map((item) => item.id).join(",");
  173. grade.value = info.value.funllScore / questionBankList.value.length * (questionBankList.value.length - wrongArr.length);
  174. let obj = {
  175. "answer": null,
  176. "carType": usecarStore.carInfo.carType,
  177. "examId": examInfo.value.id,
  178. "examType": 2,
  179. "grade": grade.value,
  180. "isEnd": 1,
  181. "pass": 1,
  182. "sort": examInfo.value.sort,
  183. "stepType": usecarStore.carInfo.stepType,
  184. "userId": examInfo.value.userId,
  185. "wrongQuestionIds": worngId
  186. };
  187. const res = await config_api.startExamDo(obj);
  188. console.log(res);
  189. if (showCommit.value)
  190. showCommit.value = false;
  191. if (grade.value < info.value.score) {
  192. showNoPass.value = true;
  193. } else {
  194. setTimeout(() => {
  195. common_vendor.index.navigateBack();
  196. }, 1500);
  197. }
  198. }
  199. function finishFn() {
  200. common_vendor.index.$u.toast("考试时间已到,准备自动为您交卷");
  201. setTimeout(() => {
  202. submitBtnFn();
  203. }, 1500);
  204. }
  205. const countDownRef = common_vendor.ref(null);
  206. const yesNum = common_vendor.ref(0);
  207. const noNum = common_vendor.ref(0);
  208. function handApaper() {
  209. if (curOption.value.answer)
  210. questionBank.value.answerMy = curOption.value.answer;
  211. yesNum.value = questionBankList.value.filter((item) => item.answer == item.answerMy).length;
  212. noNum.value = questionBankList.value.filter((item) => item.answerMy == void 0).length;
  213. console.log(questionBankList.value);
  214. if (noNum) {
  215. showCommit.value = true;
  216. if (countDownRef.value) {
  217. countDownRef.value.pause();
  218. }
  219. } else {
  220. submitBtnFn();
  221. }
  222. }
  223. function closeCommitPopup() {
  224. showCommit.value = false;
  225. if (countDownRef.value) {
  226. countDownRef.value.start();
  227. }
  228. }
  229. function showWrongClose() {
  230. showWrong.value = false;
  231. if (countDownRef.value) {
  232. countDownRef.value.start();
  233. }
  234. curOption.value = {};
  235. currentIndex.value = currentIndex.value + 1;
  236. getQuestionFn();
  237. }
  238. let info = common_vendor.ref({});
  239. async function questionExamFn() {
  240. const { data: res } = await config_api.questionExam({ stepType: usecarStore.carInfo.stepType, carType: usecarStore.carInfo.carType });
  241. info.value = res;
  242. }
  243. questionExamFn();
  244. return (_ctx, _cache) => {
  245. return common_vendor.e({
  246. a: common_vendor.t(common_vendor.unref(randomNumber)),
  247. b: common_vendor.p({
  248. name: "arrow-left",
  249. size: "16"
  250. }),
  251. c: common_vendor.o(goBack),
  252. d: common_assets._imports_0$4,
  253. e: common_vendor.t(common_vendor.unref(phone)),
  254. f: common_vendor.t(common_vendor.unref(usecarStore).carInfo.carTypeName),
  255. g: common_vendor.t(common_vendor.unref(usecarStore).carInfo.stepType == 1 ? "一" : "四"),
  256. h: common_vendor.t(common_vendor.unref(currentIndex) + 1),
  257. i: common_vendor.t(questionBank.value.title),
  258. j: common_vendor.f(questionBank.value.optionArr, (item, index, i0) => {
  259. return {
  260. a: common_vendor.t(item.key),
  261. b: common_vendor.t(item.text)
  262. };
  263. }),
  264. k: questionBank.value.types == 3
  265. }, questionBank.value.types == 3 ? {
  266. l: common_vendor.t(curOption.value.answer == "true" ? "A" : "B")
  267. } : {
  268. m: common_vendor.t(curOption.value.answer)
  269. }, {
  270. n: common_vendor.f(questionBank.value.optionArr, (item, index, i0) => {
  271. var _a2;
  272. return {
  273. a: common_vendor.t(item.key),
  274. b: ((_a2 = curOption.value.answer) == null ? void 0 : _a2.includes(item.key)) ? 1 : "",
  275. c: common_vendor.o(($event) => chooseOption(item))
  276. };
  277. }),
  278. o: common_vendor.unref(ansCard).length
  279. }, common_vendor.unref(ansCard).length ? {
  280. p: common_vendor.f(common_vendor.unref(usecarStore).carInfo.stepType == 1 ? 10 : 5, (item, index, i0) => {
  281. return {
  282. a: common_vendor.t(index + 1)
  283. };
  284. }),
  285. q: common_vendor.f(common_vendor.unref(ansCard), (item, index, i0) => {
  286. return {
  287. a: common_vendor.t(index + 1),
  288. b: common_vendor.f(item, (item2, index2, i1) => {
  289. return common_vendor.e({
  290. a: item2.types == 3 && item2.answerMy
  291. }, item2.types == 3 && item2.answerMy ? common_vendor.e({
  292. b: item2.answer == item2.answerMy
  293. }, item2.answer == item2.answerMy ? {
  294. c: "4d3e765a-1-" + i0 + "-" + i1,
  295. d: common_vendor.p({
  296. name: "checkmark",
  297. color: "#55ff7f",
  298. size: "18"
  299. })
  300. } : {
  301. e: "4d3e765a-2-" + i0 + "-" + i1,
  302. f: common_vendor.p({
  303. name: "close",
  304. color: "#ff0000",
  305. size: "18"
  306. })
  307. }) : {
  308. g: common_vendor.t(item2.answerMy)
  309. }, {
  310. h: item2.answer == item2.answerMy ? 1 : "",
  311. i: common_vendor.o(($event) => ansCardClick(item2))
  312. });
  313. })
  314. };
  315. })
  316. } : {}, {
  317. r: common_vendor.sr(countDownRef, "4d3e765a-3", {
  318. "k": "countDownRef"
  319. }),
  320. s: common_vendor.o(finishFn),
  321. t: common_vendor.p({
  322. time: common_vendor.unref(info).totalExamTime * 60 * 1e3,
  323. format: "mm:ss"
  324. }),
  325. v: common_vendor.t(types.value[questionBank.value.types - 1]),
  326. w: common_vendor.t(questionBank.value.types == 2 ? "多" : "一"),
  327. x: common_vendor.o(($event) => common_vendor.unref(uni_modules_uviewPlus_libs_function_debounce.debounce)(nextQuestion(-1), 500)),
  328. y: common_vendor.unref(currentIndex) == 0 ? 1 : "",
  329. z: common_vendor.unref(currentIndex) == 0,
  330. A: common_vendor.o(($event) => common_vendor.unref(uni_modules_uviewPlus_libs_function_debounce.debounce)(nextQuestion(1), 500)),
  331. B: common_vendor.unref(currentIndex) >= questionBankList.value.length - 1 ? 1 : "",
  332. C: common_vendor.unref(currentIndex) >= questionBankList.value.length - 1,
  333. D: common_vendor.o(handApaper),
  334. E: questionBank.value.img
  335. }, questionBank.value.img ? {
  336. F: questionBank.value.img,
  337. G: common_vendor.o(previewImg)
  338. } : {}, {
  339. H: questionBank.value.img,
  340. I: common_vendor.o(($event) => show.value = false),
  341. J: common_vendor.p({
  342. show: show.value,
  343. mode: "center",
  344. closeable: true,
  345. bgColor: "transparent"
  346. }),
  347. K: common_vendor.t(yesNum.value),
  348. L: common_vendor.t(questionBankList.value.length - yesNum.value - noNum.value),
  349. M: common_vendor.t(noNum.value),
  350. N: common_vendor.o(submitBtnFn),
  351. O: common_vendor.o(closeCommitPopup),
  352. P: common_vendor.o(closeCommitPopup),
  353. Q: common_vendor.p({
  354. show: showCommit.value,
  355. mode: "center",
  356. closeable: true,
  357. round: "10"
  358. }),
  359. R: common_vendor.t(common_vendor.unref(grade)),
  360. S: common_vendor.o(goBack),
  361. T: common_vendor.o(goBack),
  362. U: common_vendor.p({
  363. time: 4 * 1e3,
  364. format: "ss"
  365. }),
  366. V: common_vendor.o(($event) => showNoPass.value = false),
  367. W: common_vendor.p({
  368. show: showNoPass.value,
  369. mode: "center",
  370. closeable: true,
  371. round: "10"
  372. }),
  373. X: common_vendor.t(questionBank.value.title),
  374. Y: common_vendor.f(questionBank.value.optionArr, (item, index, i0) => {
  375. return {
  376. a: common_vendor.t(item.key),
  377. b: common_vendor.t(item.text)
  378. };
  379. }),
  380. Z: questionBank.value.types == 3
  381. }, questionBank.value.types == 3 ? {
  382. aa: common_vendor.t(questionBank.value.answer == "true" ? "A" : "B")
  383. } : {
  384. ab: common_vendor.t(questionBank.value.answer)
  385. }, {
  386. ac: questionBank.value.types == 3
  387. }, questionBank.value.types == 3 ? {
  388. ad: common_vendor.t(questionBank.value.answerMy == "true" ? "A" : "B")
  389. } : {
  390. ae: common_vendor.t(questionBank.value.answerMy)
  391. }, {
  392. af: common_vendor.o(showWrongClose),
  393. ag: common_vendor.o(showWrongClose),
  394. ah: common_vendor.p({
  395. time: 6 * 1e3,
  396. format: "ss"
  397. }),
  398. ai: common_vendor.o(showWrongClose),
  399. aj: common_vendor.p({
  400. show: showWrong.value,
  401. mode: "center",
  402. closeable: true,
  403. round: "10"
  404. })
  405. });
  406. };
  407. }
  408. };
  409. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-4d3e765a"]]);
  410. wx.createPage(MiniProgramPage);