QuestionsItemSelect.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="question-item" @tap="handleClick">
  3. <view
  4. class="option-label"
  5. :class="{
  6. 'option-label-selected': question.checked && !props.showResult,
  7. 'option-label-correct':
  8. question.checked && props.showResult && question.isRight,
  9. 'option-label-wrong':
  10. question.checked && props.showResult && !question.isRight,
  11. }"
  12. >
  13. {{ question.value }}
  14. </view>
  15. <uvParse
  16. :content="replaceImageDimensions(question.label)"
  17. class="option-text"
  18. ></uvParse>
  19. <view
  20. class="option-icon"
  21. v-if="
  22. question.checked &&
  23. props.showResult &&
  24. !question.isRight &&
  25. styleCount !== 6
  26. "
  27. >
  28. <uni-icons type="closeempty" color="#f00"></uni-icons>
  29. </view>
  30. <view
  31. class="option-icon"
  32. v-if="
  33. question.checked &&
  34. props.showResult &&
  35. question.isRight &&
  36. styleCount !== 6
  37. "
  38. >
  39. <uni-icons type="checkmarkempty" color="#00be00"></uni-icons>
  40. </view>
  41. </view>
  42. </template>
  43. <script setup>
  44. import uvParse from "../../uni_modules/uv-parse/components/uv-parse/uv-parse.vue";
  45. // Props 定义
  46. const props = defineProps({
  47. answerList: {
  48. type: Array,
  49. default: () => [],
  50. },
  51. selectCount: {
  52. type: Array,
  53. default: () => [],
  54. },
  55. question: {
  56. type: Object,
  57. required: true,
  58. default: () => ({
  59. label: "",
  60. value: 0,
  61. checked: false,
  62. }),
  63. },
  64. parindex: {
  65. type: Number,
  66. required: true,
  67. },
  68. showResult: {
  69. type: Boolean,
  70. default: false,
  71. },
  72. styleCount: Number,
  73. });
  74. // Emits 定义
  75. const emit = defineEmits(["select"]);
  76. const replaceImageDimensions = (str) =>
  77. str
  78. .replace(
  79. /<img([^>]*?)style="([^"]*?)width:\s*[^;]+;\s*height:\s*[^;]+;([^"]*?)"([^>]*?)\/?>/g,
  80. '<img$1style="$2width:100%;height:100%;$3"$4/>'
  81. )
  82. .replace(
  83. /<img([^>]*?)width="[^"]*"([^>]*?)height="[^"]*"([^>]*?)\/?>/g,
  84. '<img$1width="100%"$2height="100%"$3/>'
  85. );
  86. // 方法
  87. const handleClick = () => {
  88. if (props.showResult) return;
  89. emit("select", {
  90. ...props.question,
  91. pid: props.parindex,
  92. style: props.styleCount,
  93. });
  94. };
  95. </script>
  96. <style lang="scss" scoped>
  97. @import "@/uni.scss";
  98. .question-item {
  99. display: flex;
  100. gap: 12px;
  101. align-items: center;
  102. color: #333;
  103. }
  104. .option-label {
  105. border: 1px solid #ccc;
  106. border-radius: 50%;
  107. padding: 0 5px;
  108. }
  109. .option-label-correct {
  110. border-color: $success;
  111. background-color: $success;
  112. color: #fff;
  113. }
  114. .option-label-wrong {
  115. border-color: $error;
  116. background-color: $error;
  117. color: #fff;
  118. }
  119. .option-label-selected {
  120. border-color: $uni-primary;
  121. background-color: $uni-primary;
  122. color: #fff;
  123. }
  124. .option-text {
  125. flex: 1;
  126. white-space: normal;
  127. }
  128. </style>