index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view>
  3. <view class="card-view">
  4. <image src="../../static/img/train-banner1.png" mode="aspectFill" style="width: 100%;"></image>
  5. </view>
  6. <view class="card-view">
  7. <!-- <tui-divider width="80%" gradual>选择要练习的题目类型</tui-divider> -->
  8. <view class="margin">
  9. <tn-radio-group activeColor="#5677fc" v-model="mode">
  10. <tn-radio name="normal">正常模式</tn-radio>
  11. <tn-radio name="memory">记忆模式</tn-radio>
  12. <tn-radio name="random">随机模式</tn-radio>
  13. </tn-radio-group>
  14. </view>
  15. <tui-cascade-selection height="200px" :itemList="cateList" @complete="complete" text="请选择题库" :defaultItemList="defaultCateList"></tui-cascade-selection>
  16. </view>
  17. <view style="width:90%; margin: 10rpx auto;" class="padding-bottom-xl">
  18. <tui-button shape="circle" shadow bold preventClick :disabled="questionCount == 0" @click="goTrain">{{btnText}}</tui-button>
  19. </view>
  20. <login ref="login" v-on:succ="getCate"></login>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. page: '',
  28. cateList: [],
  29. cateId: 0,
  30. cateName: '',
  31. questionCount: 0,
  32. btnText: '开始练习',
  33. mode: 'normal',
  34. defaultCateList: []
  35. }
  36. },
  37. onLoad(e) {
  38. this.page = e?.page
  39. this.getCate()
  40. },
  41. methods: {
  42. // 获取分类
  43. getCate() {
  44. this.http('cate/getThree', {
  45. kind: 'QUESTION'
  46. }).then(res => {
  47. this.cateList = res.data
  48. // 模拟分类点击事件
  49. if (this.cateId) {
  50. this.complete({
  51. value: this.cateId,
  52. result: [
  53. {
  54. text: this.cateName
  55. }
  56. ]
  57. })
  58. } else {
  59. let defaultCate = this.utils.getData('default_cate-QUESTION')
  60. console.log('defaultCate', defaultCate)
  61. if (defaultCate) {
  62. let lastCate = [...defaultCate.result].pop()
  63. console.log('lastCate', lastCate)
  64. let defaultCateList = []
  65. for (var i = 0; i < defaultCate.result.length; i++) {
  66. defaultCateList.push(defaultCate.result[i].text)
  67. }
  68. this.defaultCateList = defaultCateList
  69. this.cateId = lastCate.value
  70. this.cateName = lastCate.text
  71. this.complete({
  72. value: this.cateId,
  73. result: [
  74. {
  75. text: this.cateName
  76. }
  77. ]
  78. })
  79. }
  80. // let user = this.utils.getData('user')
  81. // if (user?.info && user.info?.default_cate_ids) {
  82. // this.defaultCateList = [...user.info.default_cate_names]
  83. // this.cateId = [...user.info.default_cate_ids].pop()
  84. // this.cateName = [...user.info.default_cate_names].pop()
  85. // this.complete({
  86. // value: this.cateId,
  87. // result: [
  88. // {
  89. // text: this.cateName
  90. // }
  91. // ]
  92. // })
  93. // }
  94. }
  95. // this.defaultCateList = ["消防","灭火救援常识",]
  96. })
  97. },
  98. // 选择分类
  99. complete(e) {
  100. console.log(e);
  101. console.log('您选择的数据为:', e);
  102. this.cateId = e.value
  103. this.cateName = e.result[e.result.length - 1].text
  104. let params = {
  105. cate_id: this.cateId,
  106. just_get_count: 1,
  107. }
  108. this.$refs.login.afterMethod = () => {
  109. this.complete(e)
  110. }
  111. console.log('afterMethod', this.$refs.login.afterMethod)
  112. this.http('question/train', params).then(res => {
  113. if (res.code == 1) {
  114. this.questionCount = res.data.total
  115. if (this.questionCount) {
  116. this.btnText = '开始练习(' + this.questionCount + '题)'
  117. } else {
  118. this.btnText = '当前分类无试题'
  119. }
  120. } else {
  121. this.utils.toast(res.msg)
  122. }
  123. })
  124. },
  125. // 开始练习
  126. goTrain() {
  127. if (!this.cateId) {
  128. this.utils.toast('请先选择练习题分类')
  129. return
  130. }
  131. this.page = this.page == 'train' ? 'train' : 'look'
  132. this.utils.goto(this.page + '?cateId=' + this.cateId + '&cateName=' + this.cateName + '&mode=' + this.mode)
  133. }
  134. }
  135. }
  136. </script>
  137. <style>
  138. .tn-radio__label {
  139. color: #333 !important;
  140. font-size: 15px !important;
  141. }
  142. </style>