yuedu.vue 4.0 KB

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