ques.vue 3.3 KB

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