answers.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. {extend name="public/container"}
  2. {block name="head"}
  3. <style>
  4. .first {
  5. margin: 30px;
  6. font-weight: bold;
  7. font-size: 22px;
  8. text-align: center;
  9. }
  10. .second {
  11. margin: 30px 0;
  12. font-weight: bold;
  13. font-size: 14px;
  14. }
  15. .third {
  16. margin: 30px 0;
  17. font-weight: bold;
  18. font-size: 14px;
  19. }
  20. .third table {
  21. width: 100%;
  22. }
  23. .third td {
  24. padding: 5px;
  25. font-weight: normal;
  26. }
  27. .third table,
  28. .third td {
  29. border: 1px solid #333;
  30. }
  31. .fourth {
  32. margin: 30px 0;
  33. }
  34. .fourth>div:first-child {
  35. margin: 0 0 15px;
  36. font-weight: bold;
  37. font-size: 14px;
  38. }
  39. .fourth .userinfo .title {
  40. margin: 0 0 10px;
  41. }
  42. .fourth .userinfo .content>div {
  43. padding: 5px;
  44. margin: 0 0 15px;
  45. background: #efefef;
  46. }
  47. .question {
  48. margin: 0 0 15px;
  49. }
  50. .question .content {
  51. margin: 5px 0;
  52. }
  53. .question li {
  54. margin: 5px 0;
  55. }
  56. .question li>div:nth-child(2) {
  57. margin: 5px 0;
  58. }
  59. .result {
  60. display: inline-block;
  61. color: #0092db;
  62. }
  63. .question li label {
  64. display: block;
  65. }
  66. .question li input {
  67. margin: 0 5px 0 0;
  68. }
  69. .question li input:checked {
  70. color: #999;
  71. }
  72. .btn {
  73. display: inline-block;
  74. padding: 5px 10px;
  75. border: 1px solid #0092DC;
  76. border-radius: 5px;
  77. color: #0092DC;
  78. }
  79. .layui-icon-radio {
  80. color: #0092db;
  81. }
  82. </style>
  83. {/block}
  84. {block name="content"}
  85. <div v-cloak class="layui-fluid" id="app">
  86. <div class="layui-card">
  87. <div class="layui-card-body">
  88. <div class="btn" @click="print">打印</div>
  89. <div class="first">{{ title }}</div>
  90. <div class="second">
  91. <div>答题人</div>
  92. <div>UID:{{ information.uid }} | 昵称:{{ information.nickname }}</div>
  93. </div>
  94. <div class="third" v-if="type==2">
  95. <div>成绩单</div>
  96. <div>
  97. <table>
  98. <tr>
  99. <td>得分:{{ score }} | 总分:{{ total_score }}</td>
  100. <td>答对题数: {{ yes_questions }} | 总题数:{{ item_number }}</td>
  101. </tr>
  102. </table>
  103. </div>
  104. </div>
  105. <div class="fourth">
  106. <div>答题解析</div>
  107. <div v-for="(test, num) in testPaperAnswers" :key="test.type" class="question">
  108. <div class="title">
  109. {{ num ? (num === 1 ? '二' : '三') : '一' }}、{{ test.name }}(每题{{ test.questions.length && test.questions[0].single_score }}分,共{{ test.questions.length }}题)
  110. </div>
  111. <div class="content">
  112. <ul v-if="test.questions.length">
  113. <li v-for="(question, index) in test.questions" :key="index">
  114. <div>{{ index + 1 }}.{{ question.stem }}</div>
  115. <img v-if="question.image" :src="question.image" width="380" height="266">
  116. <div v-if="question.is_img">
  117. <label v-for="(option, key) in question.option" :key="key">
  118. <i :class="!question.user_answer || question.user_answer.indexOf(key) == -1 ? 'layui-icon-circle' : 'layui-icon-radio'" class="layui-icon"></i>
  119. {{ key }}.<img :src="option" width="205" height="144">
  120. </label>
  121. </div>
  122. <div v-else>
  123. <label v-for="(option, key) in question.option" :key="key">
  124. <i :class="!question.user_answer || question.user_answer.indexOf(key) == -1 ? 'layui-icon-circle' : 'layui-icon-radio'" class="layui-icon"></i>
  125. {{ key }}.{{ option }}
  126. </label>
  127. </div>
  128. <div class="result">回答{{ question.is_correct === 2 ? '正确' : '错误' }}</div>
  129. </li>
  130. </ul>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  138. {/block}
  139. {block name="script"}
  140. <script>
  141. require(['vue'], function (Vue) {
  142. var uid =<?= $uid ?>;
  143. var record_id =<?= $record_id ?>;
  144. var test_id =<?= $test_id ?>;
  145. var type =<?= $type ?>;
  146. var single_sort =<?= $single_sort ?>;
  147. var many_sort =<?= $many_sort ?>;
  148. var judge_sort =<?= $judge_sort ?>;
  149. var testPaperAnswers = [
  150. {
  151. name: '单选题',
  152. type: 1,
  153. sort: single_sort,
  154. questions: []
  155. },
  156. {
  157. name: '多选题',
  158. type: 2,
  159. sort: many_sort,
  160. questions: []
  161. },
  162. {
  163. name: '判断题',
  164. type: 3,
  165. sort: judge_sort,
  166. questions: []
  167. }
  168. ].sort(function (a, b) {
  169. return b.sort - a.sort;
  170. });
  171. new Vue({
  172. el: '#app',
  173. data: {
  174. testPaperAnswers: [],
  175. title: '',
  176. type: type,
  177. total_score: 0,
  178. item_number: 0,
  179. score: 0,
  180. yes_questions: 0,
  181. information: {}
  182. },
  183. created: function () {
  184. this.getUserInformation();
  185. if (type == 2) {
  186. this.getUserAchievement();
  187. }
  188. for (var i = 1; i <= 3; i++) {
  189. this.getTestPaperAnswers(i);
  190. }
  191. },
  192. methods: {
  193. // 信息
  194. getUserInformation: function () {
  195. var vm = this;
  196. layList.baseGet(layList.U({
  197. a: 'getUserInformation',
  198. p: {
  199. uid: uid
  200. }
  201. }), function (res) {
  202. vm.information = res.data;
  203. });
  204. },
  205. // 成绩
  206. getUserAchievement: function () {
  207. var vm = this;
  208. layList.baseGet(layList.U({
  209. a: 'getUserAchievement',
  210. p: {
  211. uid: uid,
  212. test_id: test_id,
  213. record_id: record_id
  214. }
  215. }), function (res) {
  216. vm.title = res.data.title;
  217. vm.total_score = res.data.total_score;
  218. vm.item_number = res.data.item_number;
  219. vm.score = res.data.score;
  220. vm.yes_questions = res.data.yes_questions;
  221. });
  222. },
  223. // 试卷中的试题答题情况
  224. getTestPaperAnswers: function (question_type) {
  225. var vm = this;
  226. layList.baseGet(layList.U({
  227. a: 'getTestPaperAnswers',
  228. q: {
  229. test_id: test_id,
  230. record_id: record_id,
  231. question_type: question_type
  232. }
  233. }), function (res) {
  234. var questions = res.data;
  235. questions.forEach(function (question) {
  236. question.option = JSON.parse(question.option);
  237. if (Array.isArray(question.option)) {
  238. var options = {};
  239. question.option.forEach(function (option, index) {
  240. options[String.fromCharCode(65 + index)] = option;
  241. });
  242. question.option = options;
  243. }
  244. });
  245. for (var i = 0; i < testPaperAnswers.length; i++) {
  246. if (testPaperAnswers[i].type === question_type) {
  247. if (questions.length) {
  248. testPaperAnswers[i].questions = questions;
  249. } else {
  250. testPaperAnswers.splice(i, 1);
  251. }
  252. break;
  253. }
  254. }
  255. vm.testPaperAnswers = testPaperAnswers;
  256. });
  257. },
  258. print: function () {
  259. window.print()
  260. }
  261. }
  262. });
  263. });
  264. </script>
  265. {/block}