yuedu.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. <view class="yuedu-tip-box" v-if="data.content.length>1">本题有{{ data.content.length}}道小题,左右滑动切换小题</view>
  10. <!-- 选项区域 -->
  11. <swiper class="yuedu-swiper-box" @change="onSwitchChange" :current="swiperDotIndex">
  12. <swiper-item v-for="(item,index) in data.content" :key="index" class="yuedu-swiper-content">
  13. <template v-if="item.type == 'danxuan'">
  14. <!-- 单选 -->
  15. <danxuan :question="item" :key="item.stId"></danxuan>
  16. </template>
  17. <template v-if="item.type == 'duoxuan'">
  18. <!-- 多选 -->
  19. <duoxuan :question="item" :key="item.stId"></duoxuan>
  20. </template>
  21. <template v-if="item.type == 'panduan'">
  22. <!-- 判断 -->
  23. <panduan :question="item" :key="item.stId"></panduan>
  24. </template>
  25. <template v-if="item.type == 'tiankong'">
  26. <!-- 填空 -->
  27. <tiankong :question="item" :key="item.stId"></tiankong>
  28. </template>
  29. <template v-if="item.type == 'jianda'">
  30. <!-- 简答 -->
  31. <jianda :question="item" :key="item.stId"></jianda>
  32. </template>
  33. </swiper-item>
  34. </swiper>
  35. <!-- <view class="yuedu-left-jt" @click="handleRight" :class="{disable: swiperDotIndex == 0}"></view>
  36. <view class="yuedu-right-jt" @click="handleLeft" :class="{disable: swiperDotIndex == data.content.length-1}"></view>
  37. <view class="button-next-tip" v-if="showTishi">点击左右蓝色箭头,<br/>跳转阅读题上下小题</view>-->
  38. </view>
  39. </template>
  40. <script setup>
  41. import {
  42. reactive,
  43. watch,
  44. ref,
  45. computed
  46. } from 'vue';
  47. import danxuan from "@/components/questions/danxuan.vue";
  48. import duoxuan from "@/components/questions/duoxuan.vue";
  49. import tiankong from "@/components/questions/tiankong.vue";
  50. import panduan from "@/components/questions/panduan.vue";
  51. import jianda from "@/components/questions/jianda.vue";
  52. import cacheManager from '../../utils/cacheManager';
  53. const props = defineProps({
  54. question: {
  55. type: Object,
  56. },
  57. showError: {
  58. type: Boolean,
  59. default: false
  60. },
  61. showTishixinxi: {
  62. type:Boolean,
  63. default: false,
  64. }
  65. })
  66. const data = reactive({
  67. content: []
  68. })
  69. const Emits = defineEmits(['yudu-change'])
  70. const swiperDotIndex = ref(0);
  71. const showTishi = ref(false);
  72. watch(() => props.question, (question) => {
  73. const danxuanlist = question.danxuan.forEach(item => item.type = 'danxuan')
  74. const duoxuanlist = question.duoxuan.forEach(item => item.type = 'duoxuan')
  75. const panduanlist = question.panduan.forEach(item => item.type = 'panduan')
  76. const tiankonglist = question.tiankong.forEach(item => item.type = 'tiankong')
  77. const jiandalist = question.jianda.forEach(item => item.type = 'jianda')
  78. data.content = [...question.danxuan, ...question.duoxuan, ...question.panduan, ...question.tiankong, ...
  79. question.jianda
  80. ];
  81. data.content.map((item,index) => {
  82. item.onlyNum = index+1;
  83. return item
  84. })
  85. Emits('yudu-change', data.content[0])
  86. }, {
  87. immediate: true
  88. })
  89. watch(() => props.showTishixinxi,() => {
  90. if (props.showTishixinxi) {
  91. if (!cacheManager.get('exam-tishi')) {
  92. // 首次考试打开提示信息
  93. showTishi.value = true
  94. } else {
  95. showTishi.value = false
  96. }
  97. } else {
  98. showTishi.value = false
  99. }
  100. }, {
  101. immediate: true
  102. })
  103. function onSwitchChange(e) {
  104. console.log('eeee', e.detail,data.content[e.detail.current])
  105. Emits('yudu-change', data.content[e.detail.current])
  106. swiperDotIndex.value = e.detail.current
  107. }
  108. function handleRight() {
  109. if (swiperDotIndex.value > 0) {
  110. swiperDotIndex.value = swiperDotIndex.value-1;
  111. }
  112. }
  113. function handleLeft() {
  114. console.log(333)
  115. if (props.showTishixinxi) {
  116. // 阅读题提示
  117. cacheManager.set('exam-tishi', 1)
  118. showTishi.value = false
  119. }
  120. if (swiperDotIndex.value < data.content.length-1) {
  121. swiperDotIndex.value = swiperDotIndex.value+1;
  122. }
  123. console.log(' swiperDotIndex.value', swiperDotIndex.value,swiperDotIndex.value < data.content.length-1)
  124. }
  125. </script>