train.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view>
  3. <!-- 答题组件 -->
  4. <kz-question v-if="questions" mode="TRAINING" :title="cateName" :questions="questions" :questionCount="questionCount" :pageCount="pageCount" :currentPage="currentPage" :viewMode="mode" @loadQuestion="getQuestion"></kz-question>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. data() {
  10. return {
  11. cateId: 0,
  12. cateName: '',
  13. questions: [],
  14. questionCount: 0,
  15. pageCount: 100,
  16. currentPage: 0,
  17. lastPage: 0,
  18. mode: 'normal',
  19. }
  20. },
  21. onLoad(e) {
  22. this.cateId = e.cateId
  23. this.cateName = e?.cateName
  24. this.mode = e.mode
  25. this.getQuestion()
  26. },
  27. methods: {
  28. // 获取试题(包括延迟获取)
  29. getQuestion(page = 1, callback = null) {
  30. console.log('getQuestion', page, this.currentPage, this.lastPage)
  31. // 避免重复获取
  32. if (page <= this.currentPage || (this.lastPage && page > this.lastPage)) {
  33. return
  34. }
  35. // 请求参数
  36. let params = {
  37. page: page,
  38. page_count: this.pageCount,
  39. cate_id: this.cateId,
  40. mode: this.mode
  41. }
  42. this.http('question/train', params).then(res => {
  43. // 默认分页方式
  44. if (this.mode == 'normal') {
  45. this.questionCount = res.data.total
  46. this.currentPage = res.data.current_page
  47. this.lastPage = res.data.last_page
  48. this.questions = this.questions.concat(res.data.data)
  49. } else {
  50. // 记忆、随机模式暂时只能获取全部题目了
  51. this.questions = res.data.data
  52. }
  53. if (callback) {
  54. callback()
  55. }
  56. })
  57. }
  58. }
  59. }
  60. </script>
  61. <style>
  62. </style>