index.vue 4.8 KB

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