猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

188 lines
3.6 KiB

  1. <template>
  2. <!-- <view>伴宠师认证</view> -->
  3. <view class="page">
  4. <view class="box">
  5. <view class="content bg-fff">
  6. <view class="group" v-for="(group, gIdx) in list" :key="`group-${gIdx}`">
  7. <view class="label size-22 level" :style="{borderRadius:'10rpx'}">
  8. {{ group.title }}
  9. </view>
  10. <view class="">
  11. <questionCard
  12. v-for="(item, qIdx) in group.children"
  13. :key="`${gIdx}-question-${qIdx}`"
  14. :index="qIdx"
  15. :data="item"
  16. :type="item.type"
  17. mode="display"
  18. ></questionCard>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="footer-btn flex-colc">
  24. <view class="size-22 color-777 tips-rest">
  25. <!-- todo -->
  26. 剩余考试机会<text class="highlight">{{ restTimes }}</text>
  27. </view>
  28. <view class="btn" @click="onClick">
  29. 重新考试
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup>
  35. import { ref } from 'vue'
  36. import { onShow } from '@dcloudio/uni-app'
  37. import { getQuestionList, getQuestionOptions, answeBaseByQuestionId, answeTrainByQuestionId } from '@/api/examination'
  38. import questionCard from '../components/questionCard.vue';
  39. const list = ref([
  40. {
  41. title: '选择题',
  42. children: [],
  43. },
  44. {
  45. title: '主观题',
  46. children: [],
  47. },
  48. ])
  49. const initList = async () => {
  50. try {
  51. let groups = [
  52. { title: '选择题', children: [], },
  53. { title: '主观题', children: [], },
  54. ]
  55. let questions = await getQuestionList()
  56. for (let i = 0; i < questions.length; i++) {
  57. const { id, title, type } = questions[i]
  58. let data = { id, title, type }
  59. if (type === '基本') {
  60. const options = (await getQuestionOptions({ questionId: id })).map(item => ({ id: item.id, title: item.title}))
  61. data.options = options
  62. // todo: 替换成批量查询接口
  63. const { answer, answerId, isTrue } = await answeBaseByQuestionId({ questionId: id })
  64. if (isTrue) {
  65. continue
  66. }
  67. data.answer = answer.id
  68. data.value = answerId
  69. data.isTrue = isTrue
  70. groups[0].children.push(data)
  71. } else {
  72. // todo: 替换成批量查询接口
  73. const { answer, remark } = await answeTrainByQuestionId({ questionId: id })
  74. if (!remark) {
  75. continue
  76. }
  77. data.answer = remark
  78. data.value = answer
  79. groups[1].children.push(data)
  80. }
  81. }
  82. list.value = groups
  83. console.log('--list', list.value)
  84. } catch (err) {
  85. console.log('--initList--err', err)
  86. }
  87. }
  88. const restTimes = ref()
  89. onShow(() => {
  90. // todo: fetch
  91. restTimes.value = 3
  92. initList()
  93. })
  94. const onClick = () => {
  95. uni.reLaunch({
  96. url: "/otherPages/authentication/examination/start"
  97. // todo: check
  98. // url: "/otherPages/authentication/list/index"
  99. })
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. $bar-height: 163rpx;
  104. .page {
  105. padding-bottom: $bar-height;
  106. }
  107. .box {
  108. // background-image: linear-gradient(to bottom, #ffbf60, #f2f2f2);
  109. padding: 16rpx;
  110. .step {
  111. width: 720rpx;
  112. height: 32rpx;
  113. border-radius: 32rpx;
  114. background-color: #D9D9D9;
  115. .in {
  116. width: 50%;
  117. height: 32rpx;
  118. background-color: #ffbf60;
  119. border-radius: 32rpx;
  120. }
  121. }
  122. }
  123. .content {
  124. border-radius: 20rpx;
  125. padding: 15rpx 20rpx;
  126. .label {
  127. width: 86rpx;
  128. padding: 5rpx 15rpx;
  129. color: #fff;
  130. background-color: #FFBF60;
  131. justify-content: center;
  132. }
  133. }
  134. .group + .group {
  135. margin-top: 68rpx;
  136. }
  137. .level {
  138. display: flex;
  139. }
  140. .footer-btn {
  141. height: $bar-height;
  142. }
  143. .tips {
  144. &-rest {
  145. color: #707070;
  146. font-size: 22rpx;
  147. margin: 9rpx 0 13rpx 0;
  148. .highlight {
  149. color: #FF8DC6;
  150. }
  151. }
  152. }
  153. </style>