yuedu.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view v-if="question" class="phone-yuedu-box">
  3. <view class="phone-shiti-question">
  4. <view class="question-num">{{question.onlyNum}}、</view>
  5. <!-- 题干区域 -->
  6. <rich-text :nodes="question.name"></rich-text>
  7. </view>
  8. <!-- 选项区域 -->
  9. <swiper class="yuedu-swiper-box" @change="onSwitchChange" :current="swiperDotIndex">
  10. <swiper-item v-for="(item,index) in data.content" :key="index" class="yuedu-swiper-content">
  11. <template v-if="item.type == 'danxuan'">
  12. <!-- 单选 -->
  13. <danxuan :question="item" :key="item.stId"></danxuan>
  14. </template>
  15. <template v-if="item.type == 'duoxuan'">
  16. <!-- 多选 -->
  17. <duoxuan :question="item" :key="item.stId"></duoxuan>
  18. </template>
  19. <template v-if="item.type == 'panduan'">
  20. <!-- 判断 -->
  21. <panduan :question="item" :key="item.stId"></panduan>
  22. </template>
  23. <template v-if="item.type == 'tiankong'">
  24. <!-- 填空 -->
  25. <tiankong :question="item" :key="item.stId"></tiankong>
  26. </template>
  27. <template v-if="item.type == 'jianda'">
  28. <!-- 简答 -->
  29. <jianda :question="item" :key="item.stId"></jianda>
  30. </template>
  31. </swiper-item>
  32. </swiper>
  33. </view>
  34. </template>
  35. <script setup>
  36. import {
  37. reactive,
  38. watch,
  39. ref
  40. } from 'vue';
  41. import danxuan from "@/components/questions/danxuan.vue";
  42. import duoxuan from "@/components/questions/duoxuan.vue";
  43. import tiankong from "@/components/questions/tiankong.vue";
  44. import panduan from "@/components/questions/panduan.vue";
  45. import jianda from "@/components/questions/jianda.vue";
  46. const props = defineProps({
  47. question: {
  48. type: Object,
  49. },
  50. showError: {
  51. type: Boolean,
  52. default: false
  53. }
  54. })
  55. const data = reactive({
  56. content: []
  57. })
  58. const Emits = defineEmits(['yudu-change'])
  59. const swiperDotIndex = ref(0);
  60. watch(() => props.question, (question) => {
  61. const danxuanlist = question.danxuan.forEach(item => item.type = 'danxuan')
  62. const duoxuanlist = question.duoxuan.forEach(item => item.type = 'duoxuan')
  63. const panduanlist = question.panduan.forEach(item => item.type = 'panduan')
  64. const tiankonglist = question.tiankong.forEach(item => item.type = 'tiankong')
  65. const jiandalist = question.jianda.forEach(item => item.type = 'jianda')
  66. data.content = [...question.danxuan, ...question.duoxuan, ...question.panduan, ...question.tiankong, ...
  67. question.jianda
  68. ];
  69. data.content.map((item,index) => {
  70. item.onlyNum = index+1;
  71. return item
  72. })
  73. Emits('yudu-change', data.content[0])
  74. }, {
  75. immediate: true
  76. })
  77. function onSwitchChange(e) {
  78. console.log('eeee', e.detail,data.content[e.detail.current])
  79. Emits('yudu-change', data.content[e.detail.current])
  80. }
  81. </script>