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

163 lines
3.5 KiB

  1. <template>
  2. <view class="mt32 question__view" :class="[props.mode]">
  3. <view class="size-28 mb20 question">
  4. {{ `${props.index + 1}${props.data.question}` }}
  5. </view>
  6. <template v-if="props.mode === 'edit'">
  7. <template v-if="props.data.options?.length">
  8. <view class="size-28 option"
  9. v-for="(option, oIdx) in props.data.options"
  10. :key="`${props.index}-option-${oIdx}`"
  11. :class="[value === option.value ? 'is-selected' : '']"
  12. @click="onClick(option.value)"
  13. >
  14. {{ `${String.fromCharCode(65 + oIdx)}${option.label}` }}
  15. </view>
  16. </template>
  17. <template v-else>
  18. <view class="textarea">
  19. <textarea
  20. v-model="value"
  21. placeholder="请输入您的答案,不得低于700个字"
  22. :rows="10"
  23. ></textarea>
  24. </view>
  25. </template>
  26. </template>
  27. <template v-else>
  28. <template v-if="props.data.options?.length">
  29. <view class="size-28 option"
  30. v-for="(option, oIdx) in props.data.options"
  31. :key="`${props.index}-option-${oIdx}`"
  32. :class="[
  33. props.data.answer === option.value ? 'is-correct' : '',
  34. props.data.value === option.value ? 'is-error' : '',
  35. ]"
  36. @click="onClick(option.value)"
  37. >
  38. {{ `${String.fromCharCode(65 + oIdx)}${option.label}` }}
  39. <view class="icon icon-correct">
  40. <up-icon name="checkmark" color="#05C160" size="35rpx"></up-icon>
  41. </view>
  42. <view class="icon icon-error">
  43. <up-icon name="close" color="#FF2A2A" size="35rpx"></up-icon>
  44. </view>
  45. </view>
  46. </template>
  47. <template v-else>
  48. <view class="textarea">
  49. <view>{{ props.data.value }}</view>
  50. <view class="highlight">{{ props.data.reason }}</view>
  51. </view>
  52. </template>
  53. </template>
  54. </view>
  55. </template>
  56. <script setup>
  57. import { computed } from 'vue'
  58. const props = defineProps({
  59. index: {
  60. type: Number,
  61. default: null,
  62. },
  63. data: {
  64. type: Object,
  65. default() {
  66. return {}
  67. }
  68. },
  69. modelValue: {
  70. type: String | Number,
  71. default: null,
  72. },
  73. mode: {
  74. type: String,
  75. default: 'edit', // edit | display
  76. }
  77. })
  78. const emit = defineEmits(['update:modelValue'])
  79. const value = computed({
  80. set(val) {
  81. emit('update:modelValue', val)
  82. },
  83. get() {
  84. return props.modelValue
  85. }
  86. })
  87. const onClick = (val) => {
  88. value.value = val
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. .question {
  93. color: #000000;
  94. }
  95. .option {
  96. background-color: #F3F3F3;
  97. color: #707070;
  98. line-height: 37rpx;
  99. padding: 23rpx;
  100. border-radius: 28rpx;
  101. position: relative;
  102. & + & {
  103. margin-top: 20rpx;
  104. }
  105. .icon {
  106. position: absolute;
  107. right: 45rpx;
  108. bottom: 23rpx;
  109. display: none;
  110. }
  111. }
  112. .textarea {
  113. background-color: #F3F3F3;
  114. padding: 23rpx;
  115. border-radius: 16rpx;
  116. .highlight {
  117. color: #FF2A2A;
  118. font-size: 28rpx;
  119. }
  120. }
  121. .question__view.edit {
  122. .option.is-selected {
  123. background-color: rgba($color: #FFBF60, $alpha: 0.22);
  124. color: #FFBF60;
  125. }
  126. }
  127. .question__view.display {
  128. .option {
  129. &.is-correct {
  130. background-color: rgba($color: #05C160, $alpha: 0.08);
  131. color: #05C160;
  132. .icon-correct {
  133. display: block;
  134. }
  135. }
  136. &.is-error {
  137. background-color: rgba($color: #FFEBCE, $alpha: 0.36);
  138. color: #FF2A2A;
  139. .icon-error {
  140. display: block;
  141. }
  142. }
  143. }
  144. }
  145. </style>