unitTest.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. <!-- 交卷按钮 -->
  29. <view class="shiti-jj-btn" v-if="item.stId == data.list[data.total-1].stId"
  30. @click="handleSubmit"></view>
  31. </view>
  32. </template>
  33. </w-swiper>
  34. </template>
  35. <!-- 无数据 -->
  36. <view class="ezy-no-sj" v-else>
  37. <icon></icon>
  38. <text>暂无数据</text>
  39. </view>
  40. <!-- 左右滑动提示 -->
  41. <view class="swiper-tip-box">
  42. 左右滑动查看更多题目
  43. </view>
  44. </view>
  45. </view>
  46. <!-- 填空 -->
  47. <FillItem :value="result" ref="popupRef" @blur="onBlur"></FillItem>
  48. <unitResultVue ref="uniResRef" @check-answer="onCheckAnswer" @do-replay="onDoReplay"></unitResultVue>
  49. <unitAnswerVue :list="data.list" ref="uniAnsRef" @back="handleBack"></unitAnswerVue>
  50. </view>
  51. </template>
  52. <script setup>
  53. import mtaRadio from '@/components/question/yingyu/mtaRadio.vue'
  54. import FillItem from "@/components/question/FillItem.vue";
  55. import wSwiper from '@/components/wSwiper/wSwiper.vue';
  56. import danxuan from "@/components/question/danxuan.vue";
  57. import panduan from "@/components/question/panduan.vue";
  58. import tiankong from "@/components/question/tiankong.vue";
  59. import unitResultVue from './components/unitResult.vue';
  60. import unitAnswerVue from "./components/unitAnswer.vue";
  61. import * as httpApi from "@/api/chanpinShuxue.js"
  62. import {
  63. reactive,
  64. ref
  65. } from "vue"
  66. import {
  67. onLoad
  68. } from "@dcloudio/uni-app"
  69. import {
  70. useShuxueTest
  71. } from "./components/useShuxueUnitTest.js"
  72. const {
  73. data,
  74. handleSubmit,
  75. updateRightWrong,
  76. resetStart
  77. } = useShuxueTest(handleSeeResult, handleSeeResultClose)
  78. const curTiankong = ref(null);
  79. const result = ref('');
  80. const popupRef = ref(null);
  81. const uniResRef = ref(null);
  82. const uniAnsRef = ref(null);
  83. function handleSeeResultClose() {
  84. uniResRef.value.closePopup()
  85. }
  86. function handleSeeResult() {
  87. uniResRef.value.showPopup({
  88. right: data.rightAnswer,
  89. wrong: data.wrongAnswer
  90. })
  91. }
  92. function handleCheckAnswer() {
  93. uniResRef.value.showPopup({
  94. jieId: data.jieId
  95. })
  96. }
  97. function onDoReplay() {
  98. resetStart()
  99. }
  100. function onCheckAnswer() {
  101. uniAnsRef.value.showPopup();
  102. }
  103. onLoad(() => {
  104. uni.$on('tiankong-fillItem', (val) => {
  105. const {
  106. index,
  107. question
  108. } = val;
  109. curTiankong.value = val;
  110. result.value = question.reply[index];
  111. const dom = getPopupRef();
  112. dom && dom.showPopup();
  113. })
  114. uni.$on('unitShuxueTest-submit', val => {
  115. updateRightWrong(val)
  116. })
  117. })
  118. function getPopupRef() {
  119. return popupRef.value;
  120. }
  121. function onBlur({
  122. result
  123. }) {
  124. if (curTiankong.value) {
  125. uni.$emit('tiankong-setResult', {
  126. index: curTiankong.value.index,
  127. stId: curTiankong.value.question.stId,
  128. result
  129. });
  130. }
  131. const dom = getPopupRef();
  132. dom && dom.handleClear();
  133. }
  134. function handleBack() {
  135. // uni.navigateBack()
  136. uni.redirectTo({
  137. url: "/pages/chanpinneirong/index"
  138. })
  139. }
  140. function onSwiperChange(index) {
  141. data.current = index;
  142. uni.$emit('swiper-change', index)
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .swiper-box {
  147. height: 200px;
  148. }
  149. .swiper-item {
  150. display: flex;
  151. flex-direction: column;
  152. justify-content: center;
  153. align-items: center;
  154. height: 200px;
  155. }
  156. </style>