question.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>exam</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" href="../css/iconfont.css">
  10. <link rel="stylesheet" href="../css/mui.min.css">
  11. <script src="../js/mui.min.js"></script>
  12. <script src="../js/routes.js"></script>
  13. <script src="../js/app.js"></script>
  14. <script src="../js/des.js"></script>
  15. <script src="../js/service.js"></script>
  16. <style>
  17. html,
  18. body {
  19. background-color: #efeff4;
  20. }
  21. .youbar {
  22. margin-right: 40px !important;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <header class="mui-bar mui-bar-nav">
  28. <a id="back" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  29. <a id="dati" data-section-id='' data-name="答题卡" data-href="card.html" class="youbar mui-pull-right">
  30. <i class="mui-icon icon iconfont icon-24"></i>
  31. </a>
  32. <a id="shoucang" data-section-id='' data-name="收藏本" data-href='' class="youbar mui-pull-right">
  33. <i class="mui-icon icon iconfont icon-shoucang2"></i>
  34. </a>
  35. <h1 id="title" class="mui-title"></h1>
  36. </header>
  37. <footer class="mui-bar mui-bar-footer">
  38. <ul class="mui-pager" style="margin-top: 5px;">
  39. <li id="pre-id" class="mui-disabled">
  40. <a> &nbsp;&nbsp;上&nbsp;&nbsp;一&nbsp;&nbsp;题&nbsp;&nbsp; </a>
  41. </li>
  42. <li id="next-id" style="margin-left: 50px;">
  43. <a> &nbsp;&nbsp;下&nbsp;&nbsp;一&nbsp;&nbsp;题&nbsp;&nbsp; </a>
  44. </li>
  45. </ul>
  46. </footer>
  47. <div class="mui-content" id="my-content-id">
  48. <div class="my-pagination" style="margin-top: 20px;" id="list">
  49. <ul class="mui-table-view">
  50. <li class="mui-table-view-cell mui-media">
  51. <div class="mui-media-body" style="text-align: center;">
  52. <p class='mui-ellipsis' style="">正在加载数据</p>
  53. </div>
  54. </li>
  55. </ul>
  56. </div>
  57. </div>
  58. <script type="text/html" id="template-question-id">
  59. <li class="mui-table-view-cell">
  60. <b style="color: blue;">{indexed}/{pageSize}({type})</b>: {name}
  61. </li>
  62. </script>
  63. <script type="text/html" id="template-option-id">
  64. <li class="mui-table-view-cell mui-{inputType} mui-left my-auto-next">
  65. <input class="question" name="{inputName}" type="{inputType}" data-checked="false" {checked} data-label="{label}">{label}:{name}
  66. </li>
  67. </script>
  68. <script type="text/html" id="template-option-disable-id">
  69. <li class="mui-table-view-cell mui-{inputType} mui-left my-auto-next">
  70. <input class="question" name="{inputName}" type="{inputType}" disabled data-checked="false" {checked} data-label="{label}">{label}:{name}
  71. </li>
  72. </script>
  73. <script type="text/html" id="template-resolution-id">
  74. <li class="mui-table-view-cell my-table-cell-jiexi">解析:</li>
  75. <li class="mui-table-view-cell">{name}</li>
  76. </script>
  77. <script type="text/html" id="template-correct-id">
  78. <li class="mui-table-view-cell" style="color: {isOkStyle};">你的答案:{userAnswer},正确答案:{questionAnswer}</li>
  79. </script>
  80. <script type="text/html" id="template-material-id">
  81. <li class="mui-table-view-cell">{name}</li>
  82. </script>
  83. <script type="text/html" id="template-fanyi-id">
  84. <li class="mui-table-view-cell">{fanyi}</li>
  85. </script>
  86. <script>
  87. function autoNextEvent() {
  88. mui('#list').on('tap', '.my-auto-next', function() {
  89. var self = this;
  90. var timeout = setTimeout(function() {
  91. var inputType = self.children[0].getAttribute('type');
  92. if (inputType == 'radio') {
  93. next();
  94. }
  95. clearTimeout(timeout);
  96. }, 500);
  97. });
  98. }
  99. function preAndNextEvent() {
  100. var preDom = document.getElementById("pre-id");
  101. preDom.addEventListener('tap', function() {
  102. prev();
  103. });
  104. var nextDom = document.getElementById("next-id");
  105. nextDom.addEventListener('tap', function() {
  106. next();
  107. });
  108. }
  109. var childPagination = null;
  110. function hideAll() {
  111. for (var i = 0; i < childPagination.length; i++) {
  112. var child = childPagination[i];
  113. child.style.display = 'none';
  114. }
  115. }
  116. function showFirst() {
  117. childPagination[0].style.display = 'block';
  118. }
  119. window.currentNo = 0;
  120. function show(idx) {
  121. hideAll();
  122. window.currentNo = idx;
  123. for (var i = 0; i < childPagination.length; i++) {
  124. if (i == idx) {
  125. var child = childPagination[i];
  126. child.style.display = 'block';
  127. }
  128. }
  129. if (window.currentNo == 0) {
  130. document.getElementById("pre-id").classList.add('mui-disabled');
  131. } else {
  132. document.getElementById("pre-id").classList.remove('mui-disabled');
  133. }
  134. if (window.currentNo == (childPagination.length - 1)) {
  135. if (window._disableSubmit) {
  136. document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;答&nbsp;&nbsp;题&nbsp;&nbsp;卡&nbsp;&nbsp; ';
  137. } else {
  138. document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;';
  139. }
  140. } else {
  141. document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;下&nbsp;&nbsp;一&nbsp;&nbsp;题&nbsp;&nbsp; ';
  142. }
  143. }
  144. function preBtnEffect() {
  145. if (window.currentNo <= 1) {
  146. document.getElementById("pre-id").classList.add('mui-disabled');
  147. }
  148. if (window.currentNo < childPagination.length) {
  149. document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;下&nbsp;&nbsp;一&nbsp;&nbsp;题&nbsp;&nbsp; ';
  150. }
  151. }
  152. function nextBtnEffect() {
  153. if (window.currentNo >= 0 && (window.serviceObj.questionList.length > 1)) {
  154. document.getElementById("pre-id").classList.remove('mui-disabled');
  155. }
  156. if (window.currentNo >= (childPagination.length - 2)) {
  157. document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;';
  158. }
  159. }
  160. function prev(event) {
  161. preBtnEffect();
  162. // if (Math.abs(event.detail.angle) > 170) {
  163. if (window.currentNo) {
  164. window.currentNo = window.currentNo - 1;
  165. show(window.currentNo);
  166. var _self = childPagination[currentNo]
  167. var _questionId = _self.getAttribute("data-id");
  168. var questionAll = window.serviceObj.getQuestion(_questionId);
  169. updateBookmarkIco(questionAll);
  170. }
  171. // event.detail.gesture.preventDefault();
  172. // }
  173. }
  174. function next(event) {
  175. nextBtnEffect();
  176. // if (Math.abs(event.detail.angle) > 170) {
  177. if (window.currentNo < (childPagination.length - 1)) {
  178. window.currentNo = window.currentNo + 1;
  179. show(window.currentNo);
  180. // grade(window.currentNo); // 下一屏的时候进行判分
  181. var _self2 = childPagination[currentNo]
  182. var _questionId2 = _self2.getAttribute("data-id");
  183. var questionAll = window.serviceObj.getQuestion(_questionId2);
  184. updateBookmarkIco(questionAll);
  185. // event.detail.gesture.preventDefault();
  186. return false;
  187. } else {
  188. // if (window.serviceObj.isAllReply()) {
  189. daTiTapHandler.apply(window.datiDom);
  190. // } else {
  191. // var msg = '您还没有完成答题,是否继续答题';
  192. // var btn = ["是", "否"];
  193. // mui.confirm(msg, '', btn, function(e) {
  194. // if (e.index != 0) {
  195. // daTiTapHandler.apply(window.datiDom);
  196. // }
  197. // });
  198. // }
  199. // event.detail.gesture.preventDefault();
  200. return true;
  201. }
  202. // }
  203. }
  204. // var myContentDom = document.getElementById("my-content-id");
  205. window.addEventListener("swiperight", prev);
  206. window.addEventListener("swipeleft", next);
  207. /**
  208. * 判分、错题
  209. * @param {Object} currentNo
  210. */
  211. function grade() {
  212. var userResult = [];
  213. for (var i = 0; i < childPagination.length; i++) {
  214. var _questionDiv = childPagination[i];
  215. var _questionId = _questionDiv.getAttribute("data-id");
  216. var inputs = _questionDiv.children[0].getElementsByClassName('question');
  217. var userAnswerList = [];
  218. for (var k = 0; k < inputs.length; k++) {
  219. var option = inputs[k];
  220. if (option.checked) {
  221. userAnswerList.push(option.getAttribute("data-label"));
  222. }
  223. }
  224. userResult.push({
  225. questionId: _questionId,
  226. userAnswerList: userAnswerList
  227. });
  228. }
  229. window.serviceObj.grade(userResult);
  230. }
  231. function daTiTapHandler() {
  232. grade();
  233. var href = this.getAttribute("data-href");
  234. var name = this.getAttribute("data-name");
  235. var sectionId = this.getAttribute("data-section-id");
  236. var questionList = window.serviceObj.questionList;
  237. for (var i = 0; i < questionList.length; i++) {
  238. var questionAll = questionList[i];
  239. }
  240. mui.openWindow({
  241. id: 'card-win-' + sectionId,
  242. url: href,
  243. extras: {
  244. name: name,
  245. sectionId: sectionId,
  246. chapterId: window.chapterId,
  247. serviceObj: window.serviceObj,
  248. disableSubmit: window._disableSubmit
  249. }
  250. })
  251. }
  252. //点击答题卡,打开答题卡页面
  253. function openSheetEvent() {
  254. document.getElementById('dati').addEventListener('tap', daTiTapHandler);
  255. }
  256. //更新收藏图标,显示当前题是否被收藏
  257. function updateBookmarkIco(questionAll) {
  258. var questionId = questionAll.question.id;
  259. var hasCollect = questionAll.hasCollect;
  260. var shoucangDom = document.getElementById("shoucang");
  261. shoucangDom.setAttribute("data-question-id", questionId);
  262. if (hasCollect) {
  263. shoucangDom.style.color = "red";
  264. } else {
  265. shoucangDom.style.color = "white";
  266. }
  267. }
  268. //点击收藏,收藏此试题
  269. function collectEvent() {
  270. document.getElementById('shoucang').addEventListener('tap', function() {
  271. var _questionId = this.getAttribute('data-question-id');
  272. var questionAll = window.serviceObj.getQuestion(_questionId);
  273. if (questionAll.hasCollect) {
  274. mui.toast('已取消收藏');
  275. } else {
  276. mui.toast('已添加收藏');
  277. }
  278. window.serviceObj.updateBookMark(questionAll);
  279. updateBookmarkIco(questionAll);
  280. });
  281. }
  282. /**
  283. * 元数据配置
  284. */
  285. var questionMetadata = {
  286. '单选题': ["materialName", "question", "option"],
  287. '填空题': ["materialName", "question", "option"],
  288. '英译汉': ["question", "resolution"],
  289. '作文': ["question", "materialName"]
  290. };
  291. function myOnReady(sectionId) {
  292. //获取节下的所有试题
  293. queryQuestionAll(sectionId, function(all) {}, function(serviceObj) {
  294. window.serviceObj = serviceObj;
  295. initDom();
  296. childPagination = document.getElementsByClassName("my-pagination")[0].children;
  297. hideAll();
  298. showFirst();
  299. updateBookmarkIco(window.serviceObj.questionList[0]);
  300. openSheetEvent();
  301. collectEvent();
  302. autoNextEvent();
  303. preAndNextEvent();
  304. // document.getElementById("pre-id").classList.add('mui-disabled');
  305. if (window.serviceObj.questionList.length <= 1) {
  306. // document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;';
  307. if (window._disableSubmit) {
  308. document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;答&nbsp;&nbsp;题&nbsp;&nbsp;卡&nbsp;&nbsp; ';
  309. } else {
  310. document.getElementById("next-id").children[0].innerHTML = '&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;';
  311. }
  312. }
  313. });
  314. }
  315. mui.plusReady(function() {
  316. var self = plus.webview.currentWebview();
  317. var sectionId = self.sectionId;
  318. window.chapterId = self.chapterId
  319. // 设置答题卡按钮的参数,答题卡页面用
  320. window.datiDom = document.getElementById('dati');
  321. datiDom.setAttribute("data-section-id", sectionId);
  322. myOnReady(sectionId);
  323. });
  324. var old_back = mui.back;
  325. mui.back = function() {
  326. var btn = ["退出", "取消"];
  327. mui.confirm('您还未提交答案,是否要坚持退出?退出后答题记录将不予保留。', '', btn, function(e) {
  328. if (e.index == 0) {
  329. var self = plus.webview.currentWebview();
  330. self.opener().evalJS('initDom();');
  331. //执行mui封装好的窗口关闭逻辑;
  332. old_back();
  333. }
  334. });
  335. }
  336. mui.myBack = function() {
  337. var self = plus.webview.currentWebview();
  338. self.opener().evalJS('initDom();');
  339. //执行mui封装好的窗口关闭逻辑;
  340. old_back();
  341. }
  342. </script>
  343. </body>
  344. </html>