yuedu.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. computed
  41. } from 'vue';
  42. import danxuan from "@/components/questionsChengji/danxuan.vue";
  43. import duoxuan from "@/components/questionsChengji/duoxuan.vue";
  44. import tiankong from "@/components/questionsChengji/tiankong.vue";
  45. import panduan from "@/components/questionsChengji/panduan.vue";
  46. import jianda from "@/components/questionsChengji/jianda.vue";
  47. import cacheManager from '../../utils/cacheManager';
  48. const props = defineProps({
  49. question: {
  50. type: Object,
  51. },
  52. showError: {
  53. type: Boolean,
  54. default: false
  55. },
  56. showTishixinxi: {
  57. type:Boolean,
  58. default: false,
  59. }
  60. })
  61. const data = reactive({
  62. content: []
  63. })
  64. const Emits = defineEmits(['yudu-change'])
  65. const swiperDotIndex = ref(0);
  66. const showTishi = ref(false);
  67. watch(() => props.question, (question) => {
  68. const danxuanlist = question.danxuan.forEach(item => item.type = 'danxuan')
  69. const duoxuanlist = question.duoxuan.forEach(item => item.type = 'duoxuan')
  70. const panduanlist = question.panduan.forEach(item => item.type = 'panduan')
  71. const tiankonglist = question.tiankong.forEach(item => item.type = 'tiankong')
  72. const jiandalist = question.jianda.forEach(item => item.type = 'jianda')
  73. data.content = [...question.danxuan, ...question.duoxuan, ...question.panduan, ...question.tiankong, ...
  74. question.jianda
  75. ];
  76. data.content.map((item,index) => {
  77. item.onlyNum = index+1;
  78. return item
  79. })
  80. Emits('yudu-change', data.content[0])
  81. }, {
  82. immediate: true
  83. })
  84. watch(() => {
  85. if (props.showTishixinxi) {
  86. if (!cacheManager.get('exam-tishi')) {
  87. // 首次考试打开提示信息
  88. showTishi.value = true
  89. } else {
  90. showTishi.value = false
  91. }
  92. } else {
  93. showTishi.value = false
  94. }
  95. }, {
  96. immediate: true
  97. })
  98. function onSwitchChange(e) {
  99. console.log('eeee', e.detail,data.content[e.detail.current])
  100. Emits('yudu-change', data.content[e.detail.current])
  101. }
  102. function handleRight() {
  103. if (swiperDotIndex.value > 0) {
  104. swiperDotIndex.value = swiperDotIndex.value--;
  105. }
  106. }
  107. function handleLeft() {
  108. if (props.showTishixinxi) {
  109. // 阅读题提示
  110. cacheManager.set('exam-tishi', 1)
  111. showTishi.value = false
  112. }
  113. if (swiperDotIndex.value < data.content.length-1) {
  114. swiperDotIndex.value = swiperDotIndex.value++;
  115. }
  116. }
  117. </script>