danxuan.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <view v-if="question" class="phone-danxuan-box">
  3. <view class="phone-shiti-question">
  4. <view>{{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. return {
  51. active: props.question.reply == index
  52. }
  53. }
  54. }
  55. function formatData(val) {
  56. if (val) {
  57. data.name = val.name;
  58. data.contents = val.content.map((item, index) => {
  59. return {
  60. label: item,
  61. number: getLetterByIndex(index)
  62. }
  63. })
  64. }
  65. }
  66. function onSelect(index) {
  67. if (props.showError) {
  68. return;
  69. }
  70. props.question.reply = index;
  71. }
  72. </script>