danxuan.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <view v-if="question" class="ezy-danxuan-box">
  3. <!-- 标题区域 -->
  4. <view class="danxuan-title"></view>
  5. <!-- 题干区域 -->
  6. <rich-text :nodes="data.name" class="ezy-shiti-question"></rich-text>
  7. <!-- 选项区域 -->
  8. <view v-for="(item,index) in data.contents" class="danxuan-option-box" :class="formatClass(index)" :key="index">
  9. <text class="option-change" @click="onSelect(index)">{{item.number}}</text>
  10. <rich-text :nodes="item.label" class="option-question"></rich-text>
  11. </view>
  12. </view>
  13. </template>
  14. <script setup>
  15. import {
  16. ref,
  17. reactive,
  18. watch
  19. } from 'vue';
  20. import {
  21. useQuestionTools
  22. } from "./useQuestionTools"
  23. const {
  24. getLetterByIndex
  25. } = 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(() => props.question, (val) => formatData(val), {
  40. immediate: true
  41. })
  42. function formatClass(index) {
  43. if (props.showError) {
  44. return {
  45. active_right: props.question.result == index,
  46. showError: props.question.reply == index && props.question.result != index
  47. }
  48. } else {
  49. return {
  50. active: props.question.reply == index
  51. }
  52. }
  53. }
  54. function formatData(val) {
  55. if (val) {
  56. data.name = val.name;
  57. data.contents = val.optList.map((item, index) => {
  58. return {
  59. label: item,
  60. number: getLetterByIndex(index)
  61. }
  62. })
  63. }
  64. }
  65. function onSelect(index) {
  66. if (props.showError) {
  67. return;
  68. }
  69. props.question.reply = index;
  70. }
  71. </script>