train.vue 1.7 KB

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