unitTest.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="ezy-exam-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">单元测试</text>
  6. </view>
  7. <view class="exam-body">
  8. <view class="xx-jd-box" v-if="data.total">
  9. <view class="xx-row">
  10. <view>当前学习进度</view>
  11. <view class="text-row">
  12. <text class="dq-jd-text">{{data.current+1}}</text>
  13. <text class="dq-jd-line">/</text>{{data.total}}
  14. </view>
  15. </view>
  16. <progress :percent="(data.current+1)/data.total * 100" class="exam-progress-box" stroke-width="10"
  17. backgroundColor="#3c7dfd" activeColor="#ffd11c" />
  18. </view>
  19. <view class="shiti-frame-box">
  20. <template v-if="data.list.length" >
  21. <w-swiper :list="data.list" :current="data.current" class="ezy-exam-swiper" @change="onSwiperChange">
  22. <template v-slot:default="{item}">
  23. <view class="body" v-if="item.mta_show">
  24. <danxuan :question="item" v-if="item.type == '1'"></danxuan>
  25. <panduan :question="item" v-if="item.type == '2'"></panduan>
  26. <tiankong :question="item" v-if="item.type == '3'" :placeholders="item.placeholders">
  27. </tiankong>
  28. <yingyuDanxuan :question="item" v-if="item.type == '4'" :placeholders="item.placeholders"></yingyuDanxuan >
  29. <!-- 交卷按钮 -->
  30. <view class="shiti-jj-btn" v-if="item.stId == data.list[data.total-1].stId"
  31. @click="handleSubmit">交卷</view>
  32. </view>
  33. </template>
  34. </w-swiper>
  35. </template>
  36. <!-- 无数据 -->
  37. <view class="ezy-no-sj" v-else>
  38. <icon></icon>
  39. <text>暂无数据</text>
  40. </view>
  41. <!-- 左右滑动提示 -->
  42. <view class="swiper-tip-box">
  43. 左右滑动查看更多题目
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 填空 -->
  48. <FillItem :value="result" ref="popupRef" @blur="onBlur"></FillItem>
  49. <unitResultVue ref="uniResRef" @check-answer="onCheckAnswer" @do-replay="onDoReplay"></unitResultVue>
  50. <unitAnswerVue :list="data.list" ref="uniAnsRef" @back="handleBack"></unitAnswerVue>
  51. </view>
  52. </template>
  53. <script setup>
  54. import yingyuDanxuan from '@/components/question/yingyu/danxuan.vue'
  55. import FillItem from "@/components/question/FillItem.vue";
  56. import wSwiper from '@/components/wSwiper/wSwiper.vue';
  57. import danxuan from "@/components/question/danxuan.vue";
  58. import panduan from "@/components/question/panduan.vue";
  59. import tiankong from "@/components/question/tiankong.vue";
  60. import unitResultVue from './components/unitResult.vue';
  61. import unitAnswerVue from "./components/unitAnswer.vue";
  62. import * as httpApi from "@/api/chanpinZiRanPinDu.js"
  63. import {
  64. reactive,
  65. ref,
  66. onUnmounted
  67. } from "vue"
  68. import {
  69. onLoad
  70. } from "@dcloudio/uni-app"
  71. import {
  72. usePinduTest
  73. } from "./components/usePinduUnitTest.js"
  74. const {
  75. data,
  76. handleSubmit,
  77. updateRightWrong,
  78. resetStart
  79. } = usePinduTest(handleSeeResult, handleSeeResultClose)
  80. const curTiankong = ref(null);
  81. const result = ref('');
  82. const popupRef = ref(null);
  83. const uniResRef = ref(null);
  84. const uniAnsRef = ref(null);
  85. function handleSeeResultClose() {
  86. uniResRef.value.closePopup()
  87. }
  88. function handleSeeResult() {
  89. uniResRef.value.showPopup({
  90. right: data.rightAnswer,
  91. wrong: data.wrongAnswer
  92. })
  93. }
  94. function handleCheckAnswer() {
  95. uniResRef.value.showPopup({
  96. jieId: data.jieId
  97. })
  98. }
  99. function onDoReplay() {
  100. resetStart()
  101. }
  102. function onCheckAnswer() {
  103. uniAnsRef.value.showPopup();
  104. }
  105. onUnmounted(() => {
  106. uni.$emit('back-outpage')
  107. })
  108. onLoad(() => {
  109. uni.$on('tiankong-fillItem', (val) => {
  110. const {
  111. index,
  112. question
  113. } = val;
  114. curTiankong.value = val;
  115. result.value = question.reply[index];
  116. const dom = getPopupRef();
  117. dom && dom.showPopup();
  118. })
  119. uni.$on('unitPinduTest-submit', val => {
  120. updateRightWrong(val)
  121. })
  122. })
  123. function getPopupRef() {
  124. return popupRef.value;
  125. }
  126. function onBlur({
  127. result
  128. }) {
  129. if (curTiankong.value) {
  130. uni.$emit('tiankong-setResult', {
  131. index: curTiankong.value.index,
  132. stId: curTiankong.value.question.stId,
  133. result
  134. });
  135. }
  136. const dom = getPopupRef();
  137. dom && dom.handleClear();
  138. }
  139. function handleBack() {
  140. // uni.navigateBack()
  141. uni.switchTab({
  142. url: "/pages/chanpinneirong/index"
  143. })
  144. }
  145. function onSwiperChange(index) {
  146. data.current = index;
  147. uni.$emit('swiper-change', index)
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .swiper-box {
  152. height: 200px;
  153. }
  154. .swiper-item {
  155. display: flex;
  156. flex-direction: column;
  157. justify-content: center;
  158. align-items: center;
  159. height: 200px;
  160. }
  161. </style>