index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <Container
  3. title="学习本"
  4. bgColor="#f8f8f8"
  5. :scrollStyle="{
  6. padding: 0,
  7. }"
  8. :showBack="false"
  9. headerColor="#fff"
  10. @scrolltolower="scrolltolower"
  11. >
  12. <div class="top">
  13. <div
  14. class="item col left"
  15. :class="currentIndex === 0 && 'select'"
  16. @click="currentIndex = 0"
  17. >
  18. <span>
  19. <span class="primary">{{ info.answer_total }}</span
  20. >/{{ info.topic_total }}
  21. </span>
  22. <span
  23. >正确率<span class="primary">{{ info.accuracy }}</span></span
  24. >
  25. </div>
  26. <div
  27. class="item"
  28. :class="currentIndex === 1 && 'select'"
  29. @click="currentIndex = 1"
  30. >
  31. 考试记录(<span class="primary">{{ info.real_paper_total }}</span
  32. >)
  33. </div>
  34. <div
  35. class="item right"
  36. :class="currentIndex === 2 && 'select'"
  37. @click="currentIndex = 2"
  38. >
  39. 题目收藏(<span class="primary">{{ info.favorite_total }}</span
  40. >)
  41. </div>
  42. </div>
  43. <div class="tab">
  44. <scroll-view class="scroll" scroll-x>
  45. <div class="box">
  46. <div
  47. v-for="(item, index) in info.chapter_infos"
  48. class="item"
  49. :class="{
  50. select: item.id === currentTab,
  51. }"
  52. :key="item.id"
  53. @click="
  54. () => {
  55. currentTab = item.id;
  56. }
  57. "
  58. >
  59. {{ item.name }}
  60. </div>
  61. </div>
  62. </scroll-view>
  63. <div class="select-line" v-if="currentIndex === 0">
  64. <div class="item" :class="{ select: isRight }" @click="isRight = 1">
  65. 答案正确({{ rightTotal }})
  66. </div>
  67. <div class="item" :class="{ select: !isRight }" @click="isRight = 0">
  68. 答案错误({{ errorTotal }})
  69. </div>
  70. </div>
  71. </div>
  72. <div class="context">
  73. <template v-if="currentIndex === 0 && dataList.length">
  74. <QuestionsItem
  75. :data="dataList"
  76. :isRight="isRight"
  77. :catalogue_id="currentTab"
  78. />
  79. </template>
  80. <template v-else-if="currentIndex === 1 && examList.length">
  81. <div class="card" v-for="item in examList" :key="item.catalogue_id">
  82. <div class="card-header">
  83. <span class="title">{{ item.year }}年真题</span>
  84. <span class="exam-count">已考试{{ item.exam_count }}次</span>
  85. </div>
  86. <div class="card-body">
  87. <span>最低分:{{ item.min_score }}分</span>
  88. <span>最高分:{{ item.max_score }}分</span>
  89. </div>
  90. <div class="footer">
  91. <div class="c-primary" @click="toHistory(item)">再考一次</div>
  92. </div>
  93. </div>
  94. </template>
  95. <template v-else-if="currentIndex === 2 && favoriteList.length">
  96. <QuestionsItem :data="favoriteList" isRight :onClick="toFavorite" />
  97. </template>
  98. <Empty v-else text="暂无数据"></Empty>
  99. </div>
  100. </Container>
  101. </template>
  102. <script setup>
  103. import Container from "@/components/Container/Container.vue";
  104. import Empty from "@/components/Empty/Empty.vue";
  105. import { ref, watch } from "vue";
  106. import { onShow, onHide } from "@dcloudio/uni-app";
  107. import { request } from "../../utils/request";
  108. import QuestionsItem from "../../components/Topic/QuestionsItem.vue";
  109. import { router } from "../../utils/router";
  110. const show = ref(true);
  111. const currentIndex = ref(0);
  112. const currentTab = ref(0);
  113. const isRight = ref(1);
  114. const info = ref({});
  115. const rightTotal = ref(0);
  116. const errorTotal = ref(0);
  117. const dataList = ref([]);
  118. const examList = ref([]);
  119. const favoriteList = ref([]);
  120. const pageParams = ref({
  121. limit: 10,
  122. page_num: 1,
  123. });
  124. const initPage = () => {
  125. pageParams.value = {
  126. limit: 10,
  127. page_num: 1,
  128. };
  129. };
  130. const toHistory = (item) => {
  131. router.push({
  132. url: "/pages/real/history",
  133. params: {
  134. id: item.catalogue_id,
  135. },
  136. });
  137. };
  138. const scrolltolower = (e) => {
  139. pageParams.value.page_num += 1;
  140. requestTopic(isRight.value);
  141. };
  142. const requestTopic = (is_correct) => {
  143. const t = isRight.value ? rightTotal.value : errorTotal.value;
  144. if (t < pageParams.value.limit * (pageParams.value.page_num - 1)) {
  145. return;
  146. }
  147. request(
  148. "api/question_bank/question_reception/study_book/get_answer_topic_record",
  149. {
  150. chapter_id: currentTab.value,
  151. is_correct,
  152. showToast: false,
  153. ...pageParams.value,
  154. }
  155. ).then((res) => {
  156. let da = [];
  157. if (pageParams.value.page_num !== 1) {
  158. console.log(pageParams.value);
  159. da = dataList.value;
  160. }
  161. da.push(...res.data.data);
  162. if (is_correct) {
  163. rightTotal.value = res.data.total;
  164. } else {
  165. errorTotal.value = res.data.total;
  166. }
  167. if (isRight.value === is_correct) {
  168. dataList.value = da;
  169. }
  170. });
  171. };
  172. const requestExamList = () => {
  173. request("api/question_bank/question_reception/real_topic/get_exam_record", {
  174. chapter_id: currentTab.value,
  175. }).then((res) => {
  176. examList.value = res.data;
  177. });
  178. };
  179. const requestFavo = () => {
  180. if (
  181. info.value.favorite_total <
  182. pageParams.value.limit * (pageParams.value.page_num - 1)
  183. )
  184. return;
  185. request(
  186. "api/question_bank/question_reception/favorite/get_user_favorite_list",
  187. {
  188. chapter_id: currentTab.value,
  189. ...pageParams.value,
  190. }
  191. ).then((res) => {
  192. let da = [];
  193. if (pageParams.value.page_num !== 1) {
  194. da = favoriteList.value;
  195. }
  196. da.push(...res.data.data);
  197. favoriteList.value = da;
  198. });
  199. };
  200. const toFavorite = () => {
  201. router.redirectTo({
  202. url: "/pages/learn/favorite",
  203. params: {
  204. chapter_id: currentTab.value,
  205. title: "收藏",
  206. },
  207. });
  208. };
  209. watch([currentIndex, show], () => {
  210. initPage();
  211. switch (currentIndex.value) {
  212. case 1:
  213. requestExamList();
  214. break;
  215. case 2:
  216. requestFavo();
  217. break;
  218. default:
  219. break;
  220. }
  221. });
  222. watch([currentTab, show], () => {
  223. initPage();
  224. switch (currentIndex.value) {
  225. case 0:
  226. isRight.value = 1;
  227. requestTopic(isRight.value);
  228. requestTopic(Number(!isRight.value));
  229. break;
  230. case 1:
  231. requestExamList();
  232. break;
  233. case 2:
  234. requestFavo();
  235. break;
  236. default:
  237. break;
  238. }
  239. });
  240. watch([isRight, show], () => {
  241. initPage();
  242. requestTopic(isRight.value);
  243. });
  244. onShow(() => {
  245. show.value = true;
  246. request(
  247. "api/question_bank/question_reception/study_book/get_study_record_title"
  248. ).then((res) => {
  249. info.value = res.data;
  250. currentTab.value = res.data.chapter_infos[0].id;
  251. });
  252. });
  253. onHide(() => {
  254. show.value = false;
  255. info.value = {};
  256. dataList.value = [];
  257. examList.value = [];
  258. favoriteList.value = [];
  259. initPage();
  260. });
  261. // 示例数据
  262. </script>
  263. <style scoped lang="scss">
  264. @import "@/uni.scss";
  265. .primary {
  266. color: $primary;
  267. }
  268. .top {
  269. margin: 24rpx 32rpx 0;
  270. display: grid;
  271. grid-template-columns: repeat(3, 1fr);
  272. .item {
  273. border: 1px solid $primary;
  274. display: flex;
  275. align-items: center;
  276. justify-content: center;
  277. height: 113rpx;
  278. background-color: #fff;
  279. font-weight: 500;
  280. font-size: 24rpx;
  281. color: #333333;
  282. }
  283. .item.col {
  284. flex-direction: column;
  285. gap: 12rpx;
  286. }
  287. .item.left {
  288. border-top-left-radius: 24rpx;
  289. }
  290. .item.right {
  291. border-top-right-radius: 24rpx;
  292. }
  293. .select {
  294. border-color: #fff;
  295. }
  296. }
  297. .tab {
  298. background-color: #fff;
  299. .select-line {
  300. display: grid;
  301. grid-template-columns: repeat(2, 1fr);
  302. .item {
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. padding: 28rpx;
  307. border-bottom: 1px solid #fff;
  308. font-weight: 500;
  309. font-size: 32rpx;
  310. }
  311. .item.select {
  312. color: $primary;
  313. border-color: $primary;
  314. }
  315. }
  316. }
  317. .scroll {
  318. white-space: nowrap;
  319. font-weight: 500;
  320. font-size: 32rpx;
  321. color: #333333;
  322. .box {
  323. padding: 30rpx;
  324. }
  325. .item {
  326. display: inline-flex;
  327. padding: 8rpx 36rpx;
  328. }
  329. .item.select {
  330. border-radius: 200rpx;
  331. background-color: $primary;
  332. color: #fff;
  333. }
  334. }
  335. .context {
  336. padding: 20rpx 32rpx;
  337. display: flex;
  338. flex-direction: column;
  339. gap: 16rpx;
  340. .card {
  341. border-radius: 16rpx;
  342. padding: 16rpx;
  343. background-color: #fff;
  344. display: flex;
  345. flex-direction: column;
  346. .question-header {
  347. display: flex;
  348. justify-content: space-between;
  349. margin-bottom: 12rpx;
  350. color: #999;
  351. .question-type {
  352. font-weight: 500;
  353. font-size: 32rpx;
  354. color: #999999;
  355. border-radius: 8rpx 8rpx 8rpx 8rpx;
  356. border: 1rpx solid #dddddd;
  357. padding: 0 10rpx;
  358. }
  359. .question-date {
  360. color: #999;
  361. font-size: 24rpx;
  362. }
  363. }
  364. .question-text {
  365. font-size: 28rpx;
  366. color: #333;
  367. margin-bottom: 16rpx;
  368. }
  369. .options {
  370. margin-top: 8rpx;
  371. .option {
  372. display: flex;
  373. align-items: center;
  374. margin-bottom: 12rpx;
  375. gap: 14rpx;
  376. .option-select {
  377. width: 51rpx;
  378. height: 51rpx;
  379. display: flex;
  380. align-items: center;
  381. justify-content: center;
  382. border: 1rpx solid #dddddd;
  383. border-radius: 50%;
  384. }
  385. }
  386. }
  387. .footer {
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. }
  392. .card-header {
  393. display: flex;
  394. justify-content: space-between;
  395. margin-bottom: 12rpx;
  396. .title {
  397. font-weight: bold;
  398. font-size: 28rpx;
  399. color: #333;
  400. }
  401. .exam-count {
  402. color: #999;
  403. font-size: 24rpx;
  404. }
  405. }
  406. .card-body {
  407. display: flex;
  408. justify-content: space-between;
  409. align-items: center;
  410. font-weight: 500;
  411. font-size: 28rpx;
  412. color: #000000;
  413. }
  414. }
  415. }
  416. .c-primary {
  417. padding: 2rpx 10rpx;
  418. border-radius: 4rpx;
  419. border: 1rpx solid $primary;
  420. color: $primary;
  421. font-size: 24rpx;
  422. }
  423. .c-error {
  424. padding: 2rpx 10rpx;
  425. border-radius: 4rpx;
  426. border: 1rpx solid $error;
  427. color: $error;
  428. font-size: 24rpx;
  429. }
  430. </style>