danxuan.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view v-if="question" class="phone-danxuan-box">
  3. <view class="phone-shiti-question">
  4. <view class="question-num">{{ question.onlyNum }}、</view>
  5. <!-- 题干区域 -->
  6. <rich-text :nodes="data.name"></rich-text>
  7. </view>
  8. <!-- 选项区域 -->
  9. <view
  10. v-for="(item, index) in data.contents"
  11. class="danxuan-option-box"
  12. :class="formatClass(index)"
  13. :key="index"
  14. >
  15. <text class="option-change" @click="onSelect(index)">{{
  16. item.number
  17. }}</text>
  18. <rich-text :nodes="item.label" class="option-question"></rich-text>
  19. </view>
  20. </view>
  21. </template>
  22. <script setup>
  23. import { ref, reactive, watch } from "vue";
  24. import { useQuestionTools } from "@/utils/useQuestionTools.js";
  25. const { getLetterByIndex } = useQuestionTools();
  26. const props = defineProps({
  27. question: {
  28. type: Object,
  29. },
  30. showError: {
  31. type: Boolean,
  32. default: false,
  33. },
  34. });
  35. const data = reactive({
  36. name: "", //题干数据
  37. contents: [], // 选项数据
  38. });
  39. watch(
  40. () => props.question,
  41. (val) => formatData(val),
  42. {
  43. immediate: true,
  44. }
  45. );
  46. function formatClass(index) {
  47. if (props.showError) {
  48. return {
  49. active_right: props.question.result == index,
  50. showError:
  51. props.question.reply == index && props.question.result != index,
  52. };
  53. } else {
  54. if (props.question.reply === "" || props.question.reply === null) {
  55. return {
  56. active: false,
  57. };
  58. }
  59. return {
  60. active: props.question.reply == index,
  61. };
  62. }
  63. }
  64. function formatData(val) {
  65. if (val) {
  66. data.name = val.name;
  67. data.contents = val.content.map((item, index) => {
  68. return {
  69. label: item,
  70. number: getLetterByIndex(index),
  71. };
  72. });
  73. }
  74. }
  75. function onSelect(index) {
  76. if (props.showError) {
  77. return;
  78. }
  79. props.question.reply = index;
  80. }
  81. </script>