danxuan.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view v-if="question" class="ezy-yingyu-danxuan-box">
  3. <!-- 标题区域 -->
  4. <view class="yingyu-danxuan-title"></view>
  5. <!-- 题干区域 -->
  6. <textReplaceIconVue :code="code" :question="question" :text="question.name" :placeholders="placeholders" class="ezy-shiti-question">
  7. </textReplaceIconVue>
  8. <!-- 选项区域 -->
  9. <view v-for="(item,index) in data.contents" class="yingyu-danxuan-option-box" :class="formatClass(index)" :key="index">
  10. <text class="option-change" @click="onSelect(index)">{{item.number}}</text>
  11. <textReplaceIconVue :code="code" :question="question" :text="item.label" :placeholders="placeholders" class="option-question">
  12. </textReplaceIconVue>
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. import {
  18. ref,
  19. reactive,
  20. watch
  21. } from 'vue';
  22. import {
  23. useQuestionTools
  24. } from "../useQuestionTools"
  25. import textReplaceIconVue from './textReplaceIcon.vue'
  26. const {
  27. getLetterByIndex
  28. } = useQuestionTools();
  29. const props = defineProps({
  30. question: {
  31. type: Object,
  32. },
  33. showError: {
  34. type: Boolean,
  35. default: false
  36. },
  37. placeholders: { // 占位符
  38. type: Array,
  39. required: true
  40. },
  41. code: {
  42. type: String,
  43. },
  44. })
  45. const data = reactive({
  46. name: '', //题干数据
  47. contents: [], // 选项数据
  48. })
  49. watch(() => props.question, (val) => formatData(val), {
  50. immediate: true
  51. })
  52. function formatClass(index) {
  53. if (props.showError) {
  54. return {
  55. active_right: props.question.result == index,
  56. showError: props.question.reply == index && props.question.result != index
  57. }
  58. } else {
  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.optList.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>