danxuan.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view v-if="question" class="ezy-yingyu-danxuan-box">
  3. <!-- 标题区域 -->
  4. <view class="yingyu-danxuan-title"></view>
  5. <!-- 题干区域 -->
  6. <textReplaceIconVue :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" @click="onSelect(index)">
  10. <text class="option-change">{{item.number}}</text>
  11. <textReplaceIconVue :question="question" :text="item.label" :placeholders="placeholders" @itemclick="onSelect(index)" 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. })
  42. const data = reactive({
  43. name: '', //题干数据
  44. contents: [], // 选项数据
  45. })
  46. watch(() => props.question, (val) => formatData(val), {
  47. immediate: true
  48. })
  49. function formatClass(index) {
  50. if (props.showError) {
  51. return {
  52. active_right: props.question.result == index,
  53. showError: props.question.reply == index && props.question.result != index
  54. }
  55. } else {
  56. return {
  57. active: props.question.reply == index
  58. }
  59. }
  60. }
  61. function formatData(val) {
  62. if (val) {
  63. data.name = val.name;
  64. data.contents = val.optList.map((item, index) => {
  65. return {
  66. label: item,
  67. number: getLetterByIndex(index)
  68. }
  69. })
  70. }
  71. }
  72. function onSelect(index) {
  73. if (props.showError) {
  74. return;
  75. }
  76. props.question.reply = index;
  77. }
  78. </script>