ques.vue 3.3 KB

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