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

139 lines
2.5 KiB

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