paper.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航 -->
  4. <!-- <topbar :title="paper_name" :scrollTop="scrollTop"></topbar> -->
  5. <!-- <tui-navigation-bar splitLine @init="initNavigation" @change="opacityChange" :scrollTop="scrollTop" title="NavBar自定义导航栏" backgroundColor="#fff" color="#333">
  6. <view class="tui-header-icon" :style="{ marginTop: top + 'px' }"><tui-icon name="arrowleft" :color="opacity > 0.85 ? '#333' : '#fff'" @click="back"></tui-icon></view>
  7. </tui-navigation-bar> -->
  8. <!-- <view class="tui-header-bg"><image src="/static/componentBg.png" class="tui-header-img"></image></view> -->
  9. <!-- <tui-navigation-bar @init="initNavigation" :title="paper_name" @change="opacityChange" :scrollTop="scrollTop" :isOpacity="false" backgroundColor="#fff" color="#333">
  10. <view class="tui-header-icon" :style="{ marginTop: top + 'px' }"><tui-icon name="arrowleft" color="#333" @click="back"></tui-icon></view>
  11. </tui-navigation-bar> -->
  12. <!-- 倒计时 -->
  13. <!-- <tui-countdown :time="limit_time" borderColor="transparent" :isColon="false" @end="endOfTime"></tui-countdown> -->
  14. <!-- 答题组件 -->
  15. <kz-question v-show="result == null" mode="EXAM" :title="paper_name" :questions="questions" :configs="configs" :limit_time="limit_time" @submitQuestion="submitQuestion"></kz-question>
  16. <!-- 成绩组件 -->
  17. <kz-grade-result v-show="result != null" :score="score" :gradeResult="result" ref="gradeResult" :examMode="exam_mode"></kz-grade-result>
  18. <login ref="login" v-on:succ="getQuestion()"></login>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. // 顶部栏
  26. scrollTop: 0,
  27. // 试卷
  28. user: this.utils.getData('user'),
  29. paper_id: 0,
  30. paper: null,
  31. paper_name: '试卷考试中',
  32. questions: [],
  33. configs: {},
  34. start_time: 0,
  35. limit_time: 3600,
  36. total: 0,
  37. // 考试成绩
  38. result: null,
  39. score: 0,
  40. // 考场
  41. room_id: 0,
  42. room_grade_id: 0,
  43. exam_mode: 'PAPER',
  44. paper_mode: 'RANDOM',
  45. isSubmit: false,
  46. }
  47. },
  48. onLoad(options) {
  49. this.paper_id = options.id
  50. this.room_id = options.room_id ? options.room_id : 0
  51. this.getQuestion()
  52. },
  53. onBackPress(e) {
  54. console.log('onBackPress e', e)
  55. if (!this.isSubmit) {
  56. if (e.from == "backbutton") {
  57. let message = '您尚未交卷,离开本页面将没有成绩哦'
  58. if (this.room_id) {
  59. message = '您尚未交卷,离开本页面将没有成绩且失去本次考试资格哦'
  60. }
  61. uni.showModal({
  62. title: '提示',
  63. content: message,
  64. success: (res) => {
  65. if (res.confirm) {
  66. uni.navigateBack({
  67. delta: 1
  68. });
  69. }
  70. }
  71. });
  72. return true; //阻止默认返回行为
  73. }
  74. }
  75. },
  76. onPageScroll(e) {
  77. this.scrollTop = e.scrollTop;
  78. },
  79. methods: {
  80. // 获取试卷试题
  81. getQuestion() {
  82. this.http('paper/getExamQuestion', {
  83. paper_id: this.paper_id,
  84. room_id: this.room_id
  85. }, 'get').then(res => {
  86. if (res.code == 0) {
  87. uni.showToast({
  88. title: res.msg,
  89. icon: 'none'
  90. })
  91. setTimeout(() => {
  92. const pages = getCurrentPages();
  93. if (pages && pages.length > 0) {
  94. const firstPage = pages[0];
  95. if (pages.length == 1 && (!firstPage.route || firstPage.route != "pages/index/index")) {
  96. uni.reLaunch({
  97. url: "/pages/index/index",
  98. });
  99. } else {
  100. uni.navigateBack({
  101. delta: 1,
  102. });
  103. }
  104. } else {
  105. uni.reLaunch({
  106. url: "/pages/index/index",
  107. });
  108. }
  109. }, 2000)
  110. return
  111. }
  112. this.paper = res.data.paper
  113. this.paper_name = this.paper.title
  114. this.limit_time = this.paper.limit_time
  115. this.start_time = res.data.start_time
  116. this.room_grade_id = res.data.room_grade_id
  117. this.paper_mode = this.paper.mode
  118. let questions = res.data.questions
  119. for (let i in questions) {
  120. questions[i]['code2'] = false
  121. questions[i]['score'] = this.getSingleScore(questions[i].kind, questions[i].difficulty, questions[i])
  122. }
  123. this.questions = questions
  124. this.total = questions.length
  125. this.configs = this.paper.configs
  126. console.log('total', this.total)
  127. })
  128. },
  129. // 交卷
  130. submitQuestion(paperData) {
  131. console.log('paperData', paperData)
  132. if (this.isSubmit) {
  133. return
  134. }
  135. uni.showLoading({
  136. title:'交卷中'
  137. })
  138. let data = {
  139. paper_id: this.paper.id,
  140. start_time: this.start_time,
  141. questions: paperData.questions,
  142. room_id: this.room_id,
  143. room_grade_id: this.room_grade_id,
  144. }
  145. this.http('paper/submit', data, 'post').then(res => {
  146. this.result = res
  147. this.score = res.score
  148. this.isSubmit = true
  149. })
  150. },
  151. // 计算试题分数
  152. getSingleScore(kind, difficulty, question) {
  153. if (this.paper_mode == 'FIX') {
  154. return question.score
  155. }
  156. const configs = this.paper.configs[kind.toLowerCase()]
  157. if (configs && configs['use_difficulty']) {
  158. return configs['difficulty'][difficulty.toLowerCase()]['score']
  159. }
  160. return configs['score']
  161. },
  162. }
  163. }
  164. </script>
  165. <style>
  166. page {
  167. height: 100%;
  168. }
  169. .container {
  170. padding-bottom: 120rpx;
  171. box-sizing: border-box;
  172. }
  173. .tui-header-icon {
  174. width: 100%;
  175. position: fixed;
  176. top: 0;
  177. padding: 0 12rpx;
  178. display: flex;
  179. align-items: center;
  180. height: 32px;
  181. transform: translateZ(0);
  182. z-index: 99999;
  183. box-sizing: border-box;
  184. }
  185. </style>