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

133 lines
2.6 KiB

3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 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 => {
  58. if(item.value == null){
  59. return false
  60. }
  61. // if(typeof item.value == 'string'){
  62. // return item.value.length >= 700
  63. // }
  64. return true
  65. }).length
  66. })
  67. const progress = computed(() => {
  68. return Math.floor(answered.value / total.value * 100)
  69. })
  70. const toNext = () => {
  71. uni.navigateTo({
  72. url: "/otherPages/authentication/examination/baseCompleted"
  73. })
  74. }
  75. onShow(() => {
  76. initQuestion()
  77. })
  78. </script>
  79. <style lang="scss" scoped>
  80. .page {
  81. padding-bottom: 144rpx;
  82. }
  83. .header {
  84. padding: 0 36rpx;
  85. position: sticky;
  86. top: 0;
  87. background-image: linear-gradient(180deg, #FFBF60 0, #ffbf60 2%, #ffbf60 8%, #f2f2f2 90%);
  88. z-index: 999;
  89. .progress {
  90. margin-top: 19rpx;
  91. }
  92. }
  93. .box {
  94. margin-top: 31rpx;
  95. padding: 16rpx;
  96. .content {
  97. border-radius: 20rpx;
  98. padding: 15rpx 20rpx;
  99. .label {
  100. display: inline-block;
  101. padding: 5rpx 15rpx;
  102. color: #fff;
  103. background-color: #FFBF60;
  104. }
  105. }
  106. }
  107. </style>