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