QuestionsItemSelect.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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([^>]*?)src="([^"]*?)"([^>]*?)\/?>/g,
  80. '<img$1src="$2"$3 style="width:100%;height:100%;"/>'
  81. )
  82. .replace(
  83. /<img([^>]*?)style="([^"]*?)width:\s*[^;]+;\s*height:\s*[^;]+;([^"]*?)"([^>]*?)\/?>/g,
  84. '<img$1style="$2width:100%;height:100%;$3"$4/>'
  85. )
  86. .replace(
  87. /<img([^>]*?)width="[^"]*"([^>]*?)height="[^"]*"([^>]*?)\/?>/g,
  88. '<img$1width="100%"$2height="100%"$3/>'
  89. );
  90. // 方法
  91. const handleClick = () => {
  92. if (props.showResult) return;
  93. emit("select", {
  94. ...props.question,
  95. pid: props.parindex,
  96. style: props.styleCount,
  97. });
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. @import "@/uni.scss";
  102. .question-item {
  103. display: flex;
  104. gap: 12px;
  105. align-items: center;
  106. color: #333;
  107. }
  108. .option-label {
  109. border: 1px solid #ccc;
  110. border-radius: 50%;
  111. padding: 0 5px;
  112. }
  113. .option-label-correct {
  114. border-color: $success;
  115. background-color: $success;
  116. color: #fff;
  117. }
  118. .option-label-wrong {
  119. border-color: $error;
  120. background-color: $error;
  121. color: #fff;
  122. }
  123. .option-label-selected {
  124. border-color: $uni-primary;
  125. background-color: $uni-primary;
  126. color: #fff;
  127. }
  128. .option-text {
  129. flex: 1;
  130. white-space: normal;
  131. }
  132. </style>