danxuan.vue 1.7 KB

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