question_sheet.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!-- +---------------------------------------------------------------------- -->
  2. <!-- | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -->
  3. <!-- +---------------------------------------------------------------------- -->
  4. <!-- | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -->
  5. <!-- +---------------------------------------------------------------------- -->
  6. <!-- | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -->
  7. <!-- +---------------------------------------------------------------------- -->
  8. <!-- | Author: CRMEB Team <admin@crmeb.com> -->
  9. <!-- +---------------------------------------------------------------------- -->
  10. {extend name="public/container"}
  11. {block name="title"}答题卡{/block}
  12. {block name="head"}
  13. <style>
  14. body {
  15. background-color: #f5f5f5;
  16. }
  17. </style>
  18. {/block}
  19. {block name="content"}
  20. <div v-cloak id="app">
  21. <div class="answer-sheet-page">
  22. <div class="header">
  23. <a :href="'{:url('topic/question_detail')}?test_id=' + test_id + '&e_id=' + record_id + '&is_analysis=' + is_analysis + '&index=' + index + '&txamination_time=' + txamination_time + '&exam_time=' + duration">{{ is_analysis ? '返回试题' : '返回答题' }}</a>
  24. <a v-if="!is_analysis" class="time" href="javascript:">{{ duration | formatTime }}</a>
  25. </div>
  26. <div class="main">
  27. <div class="main-hd">
  28. <div>答题情况</div>
  29. <ul>
  30. <li>已答</li>
  31. <li>未答</li>
  32. </ul>
  33. </div>
  34. <div v-if="questions.length" class="main-bd">
  35. <a
  36. v-for="(item, index) in questions"
  37. :class="{ blue: item.is_correct }"
  38. :href="'{:url('topic/question_detail')}?test_id=' + test_id + '&index=' + index + '&is_analysis=' + is_analysis + '&e_id=' + record_id + '&txamination_time=' + txamination_time"
  39. >{{ index + 1 }}</a>
  40. </div>
  41. </div>
  42. <div v-if="!is_analysis && !isSubmits" class="footer">
  43. <a href="javascript:" @click="submit">提交考试</a>
  44. </div>
  45. </div>
  46. <quick-menu v-if="is_analysis"></quick-menu>
  47. </div>
  48. <script>
  49. require([
  50. 'vue',
  51. 'helper',
  52. 'store',
  53. 'quick'
  54. ], function (Vue, $h, $http) {
  55. var vm = new Vue({
  56. el: '#app',
  57. filters: {
  58. formatTime: function (time) {
  59. var hour = Math.floor(time / 3600000);
  60. var minute = Math.floor((time - hour * 3600000) / 60000);
  61. var second = Math.floor((time - hour * 3600000 - minute * 60000) / 1000);
  62. if (hour < 10) {
  63. hour = '0' + hour;
  64. }
  65. if (minute < 10) {
  66. minute = '0' + minute;
  67. }
  68. if (second < 10) {
  69. second = '0' + second;
  70. }
  71. return hour + ':' + minute + ':' + second;
  72. }
  73. },
  74. data: {
  75. startTime: new Date(),
  76. duration: 0,
  77. test_id: '',
  78. record_id: '',
  79. index: 0,
  80. questions: [],
  81. loading: false,
  82. is_analysis: 0,
  83. txamination_time: 0,
  84. isSubmits: 1
  85. },
  86. watch: {
  87. loading: function (val) {
  88. val ? $h.loadFFF() : $h.loadClear();
  89. }
  90. },
  91. created: function () {
  92. if ($h.getCookie('exam_time')) {
  93. this.exam_time = parseInt($h.getCookie('exam_time'));
  94. }
  95. this.test_id = $h.getParmas('test_id');
  96. this.record_id = $h.getParmas('record_id');
  97. this.is_analysis = parseInt($h.getParmas('is_analysis'));
  98. if ($h.getParmas('index')) {
  99. this.index = parseInt($h.getParmas('index'));
  100. }
  101. if ($h.getParmas('is_analysis') && parseInt($h.getParmas('is_analysis'))) {
  102. } else {
  103. this.setTimer();
  104. this.txamination_time = parseInt($h.getParmas('txamination_time'));
  105. }
  106. this.getSheet();
  107. this.isSubmit();
  108. },
  109. mounted: function () {
  110. this.$nextTick(function () {
  111. window.addEventListener('pagehide', function () {
  112. $h.setCookie('exam_time', vm.duration);
  113. });
  114. });
  115. },
  116. methods: {
  117. getSheet: function () {
  118. this.loading = true;
  119. $http.baseGet($h.U({
  120. c: 'topic',
  121. a: 'answerSheet',
  122. q: {
  123. test_id: this.test_id,
  124. type: 2,
  125. record_id: this.record_id
  126. }
  127. }), function (res) {
  128. vm.loading = false;
  129. var questions = res.data.data;
  130. for (var i = questions.length; i--;) {
  131. if (!Array.isArray(questions[i].userAnswer)) {
  132. Object.assign(questions[i], questions[i].userAnswer);
  133. }
  134. }
  135. vm.questions = questions;
  136. }, function () {
  137. window.location.replace($h.U({
  138. c: 'topic',
  139. a: 'question_user'
  140. }));
  141. });
  142. },
  143. setTimer: function () {
  144. var timer = setInterval(function () {
  145. vm.duration = new Date() - vm.startTime + vm.exam_time;
  146. if (vm.duration >= vm.txamination_time * 60000) {
  147. clearInterval(timer);
  148. $h.pushMsg('考试时间已到', function () {
  149. vm.submit();
  150. });
  151. }
  152. }, 1000);
  153. },
  154. submit: function () {
  155. var that=this;
  156. this.loading = true;
  157. $http.basePost($h.U({
  158. c: 'topic',
  159. a: 'submitTestPaper'
  160. }), {
  161. examination_id: that.record_id,
  162. type: 2,
  163. duration: that.duration
  164. }, function (res) {
  165. vm.loading = false;
  166. if (200 === res.data.code) {
  167. $h.delCookie('e_id');
  168. $h.delCookie('exam_time');
  169. vm.is_analysis = 1;
  170. $h.pushMsg('提交成功', function () {
  171. location.href = "{:url('topic/question_result')}?test_id=" + that.test_id;
  172. });
  173. } else {
  174. $h.pushMsg(res.data.msg);
  175. }
  176. });
  177. },
  178. isSubmit: function (n) {
  179. var that=this;
  180. $h.loadFFF();
  181. $http.basePost($h.U({
  182. c: 'topic',
  183. a: 'is_submit'
  184. }), {
  185. examination_id: that.record_id,
  186. type: 2
  187. }, function (res) {
  188. $h.loadClear();
  189. $h.delCookie('e_id');
  190. that.isSubmits = res.data.data;
  191. }, undefined, true);
  192. },
  193. }
  194. });
  195. });
  196. </script>
  197. {/block}