猫妈狗爸伴宠师小程序前端代码
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.

121 lines
2.5 KiB

2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <view class="flex-rowl color-fff size-28 title">
  5. {{ `答题进度 ${answered}/${total}` }}
  6. </view>
  7. <up-line-progress class="progress" :percentage="progress" activeColor="#FFBF60" inactiveColor="#D9D9D9" height="16rpx" :showText="false"></up-line-progress>
  8. </view>
  9. <view class="box">
  10. <view class="content bg-fff">
  11. <view>
  12. <view class="label size-22">
  13. 选择题
  14. </view>
  15. </view>
  16. <view >
  17. <questionCard
  18. v-for="(item, qIdx) in list"
  19. :key="`question-${qIdx}`"
  20. v-model="item.value"
  21. :index="qIdx"
  22. :data="item"
  23. :type="TYPE"
  24. ></questionCard>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="footer-btn">
  29. <button plain class="btn" @click="toNext" :disabled="answered < total">
  30. 提交
  31. </button>
  32. </view>
  33. </view>
  34. </template>
  35. <script setup>
  36. import { ref, computed } from 'vue'
  37. import { onShow } from '@dcloudio/uni-app'
  38. import { getQuestionList, getQuestionOptions } from '@/api/examination'
  39. import questionCard from '../components/questionCard.vue';
  40. const TYPE = '基本'
  41. const list = ref([])
  42. const total = ref(0)
  43. const initQuestion = async () => {
  44. try {
  45. let questions = (await getQuestionList({ type: TYPE })).map(item => ({ id: item.id, title: item.title, value: null }))
  46. // todo: 替换成批量查询接口
  47. for (let i = 0; i < questions.length; i++) {
  48. const options = (await getQuestionOptions({ questionId: questions[i].id })).map(item => ({ id: item.id, title: item.title}))
  49. questions[i].options = options
  50. }
  51. list.value = questions
  52. total.value = questions.length
  53. } catch (err) {
  54. }
  55. }
  56. const answered = computed(() => {
  57. return list.value.filter(item => item.value !== null).length
  58. })
  59. const progress = computed(() => {
  60. return Math.floor(answered.value / total.value * 100)
  61. })
  62. const toNext = () => {
  63. uni.navigateTo({
  64. url: "/otherPages/authentication/examination/baseCompleted"
  65. })
  66. }
  67. onShow(() => {
  68. initQuestion()
  69. })
  70. </script>
  71. <style lang="scss" scoped>
  72. .page {
  73. padding-bottom: 144rpx;
  74. }
  75. .header {
  76. padding: 0 36rpx;
  77. position: sticky;
  78. top: 0;
  79. background-image: linear-gradient(180deg, #FFBF60 0, #ffbf60 2%, #ffbf60 8%, #f2f2f2 90%);
  80. .progress {
  81. margin-top: 19rpx;
  82. }
  83. }
  84. .box {
  85. margin-top: 31rpx;
  86. padding: 16rpx;
  87. .content {
  88. border-radius: 20rpx;
  89. padding: 15rpx 20rpx;
  90. .label {
  91. display: inline-block;
  92. padding: 5rpx 15rpx;
  93. color: #fff;
  94. background-color: #FFBF60;
  95. }
  96. }
  97. }
  98. </style>