ques.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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,index)">
  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,index) {
  53. const param = {
  54. item,
  55. option,
  56. index
  57. }
  58. this.$emit("handleAnswer", param)
  59. }
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. @mixin u-flex($flexD, $alignI, $justifyC) {
  65. display: flex;
  66. flex-direction: $flexD;
  67. align-items: $alignI;
  68. justify-content: $justifyC;
  69. }
  70. .empty {
  71. @include u-flex(row, center, center);
  72. padding: 24rpx 50rpx;
  73. color: #999999;
  74. }
  75. .ques-content {
  76. background-color: #fff;
  77. padding: 24rpx 32rpx 24rpx 32rpx;
  78. box-sizing: border-box;
  79. font-family: PingFang SC, PingFang SC;
  80. font-weight: 400;
  81. font-size: 28rpx;
  82. color: #222222;
  83. }
  84. .ques-content-tit {
  85. font-family: PingFang SC, PingFang SC;
  86. font-weight: 600;
  87. font-size: 36rpx;
  88. color: #222222;
  89. }
  90. .ques-title {
  91. margin: 48rpx 0 34rpx 0;
  92. font-weight: 500;
  93. font-size: 32rpx;
  94. white-space: normal;
  95. }
  96. .ques-type {
  97. flex-shrink: 0;
  98. min-width: 72rpx;
  99. min-height: 40rpx;
  100. padding: 0 12rpx;
  101. margin: 0 12rpx;
  102. box-sizing: border-box;
  103. background: #FF5C03;
  104. border-radius: 8rpx 8rpx 8rpx 8rpx;
  105. line-height: 40rpx;
  106. text-align: center;
  107. font-family: PingFang SC, PingFang SC;
  108. font-weight: 400;
  109. font-size: 24rpx;
  110. color: #FFFFFF;
  111. display: inline-block;
  112. }
  113. .ques-option {
  114. min-height: 88rpx;
  115. padding: 24rpx 32rpx;
  116. box-sizing: border-box;
  117. margin-bottom: 24rpx;
  118. background: #F5F7FA;
  119. border-radius: 16rpx 16rpx 16rpx 16rpx;
  120. display: flex;
  121. align-items: center;
  122. &-active {
  123. color: #FF5C03 !important;
  124. background: #FCF0E7 !important;
  125. }
  126. }
  127. </style>