ques.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="ques-content">
  3. <view class="ques-content-tit" v-show="openCommentStatus!=1">问答题</view>
  4. <view v-for="(item,index) in quesList" :key="index">
  5. <view class="ques-title">
  6. <text>{{index + 1}}.</text>
  7. <view class="ques-type" v-show="item.type == 1 || item.type == 2">
  8. {{item.type == 1 ? '单选' : item.type == 2 ? '多选' : ''}}
  9. </view>
  10. <text>{{item.title}}</text>
  11. </view>
  12. <view :class="isAnswer(item,option.name) ?'ques-option ques-option-active':'ques-option'"
  13. v-for="(option,idx) in item.questionOption" :key="idx" @click="handleAnswer(item,option)">
  14. <view>
  15. {{numberToLetter(idx)}}.
  16. </view>
  17. <view>{{option.name}}</view>
  18. </view>
  19. </view>
  20. <view class="empty" v-if="quesList&&quesList.length==0">暂未设置题目~</view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. props: ['quesList','openCommentStatus'],
  26. data() {
  27. return {
  28. }
  29. },
  30. computed: {
  31. isAnswer() {
  32. return (item, name) => {
  33. if (item.type == 1) {
  34. return item.answer == name
  35. } else if (item.type == 2) {
  36. const array = item.answer.split(',')
  37. return array.some(i => i == name)
  38. } else {
  39. return false
  40. }
  41. }
  42. }
  43. },
  44. methods: {
  45. numberToLetter(num) {
  46. // 将数字转换为字母的 ASCII 码
  47. let letterCode = num + 65;
  48. // 将 ASCII 码转换为大写字母
  49. let letter = String.fromCharCode(letterCode);
  50. return letter;
  51. },
  52. handleAnswer(item, option) {
  53. const param = {
  54. item,
  55. option
  56. }
  57. this.$emit("handleAnswer", param)
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. @mixin u-flex($flexD, $alignI, $justifyC) {
  64. display: flex;
  65. flex-direction: $flexD;
  66. align-items: $alignI;
  67. justify-content: $justifyC;
  68. }
  69. .empty {
  70. @include u-flex(row, center, center);
  71. padding: 24rpx 50rpx;
  72. color: #999999;
  73. }
  74. .ques-content {
  75. background-color: #fff;
  76. padding: 24rpx 32rpx 24rpx 32rpx;
  77. box-sizing: border-box;
  78. font-family: PingFang SC, PingFang SC;
  79. font-weight: 400;
  80. font-size: 28rpx;
  81. color: #222222;
  82. }
  83. .ques-content-tit {
  84. font-family: PingFang SC, PingFang SC;
  85. font-weight: 600;
  86. font-size: 36rpx;
  87. color: #222222;
  88. }
  89. .ques-title {
  90. margin: 48rpx 0 34rpx 0;
  91. font-weight: 500;
  92. font-size: 32rpx;
  93. white-space: normal;
  94. }
  95. .ques-type {
  96. flex-shrink: 0;
  97. min-width: 72rpx;
  98. min-height: 40rpx;
  99. padding: 0 12rpx;
  100. margin: 0 12rpx;
  101. box-sizing: border-box;
  102. background: #FF5C03;
  103. border-radius: 8rpx 8rpx 8rpx 8rpx;
  104. line-height: 40rpx;
  105. text-align: center;
  106. font-family: PingFang SC, PingFang SC;
  107. font-weight: 400;
  108. font-size: 24rpx;
  109. color: #FFFFFF;
  110. display: inline-block;
  111. }
  112. .ques-option {
  113. min-height: 88rpx;
  114. padding: 24rpx 32rpx;
  115. box-sizing: border-box;
  116. margin-bottom: 24rpx;
  117. background: #F5F7FA;
  118. border-radius: 16rpx 16rpx 16rpx 16rpx;
  119. display: flex;
  120. align-items: center;
  121. &-active {
  122. color: #FF5C03 !important;
  123. background: #FCF0E7 !important;
  124. }
  125. }
  126. </style>