examinee.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. var examineeBehaviour = function () {
  2. var sender = this;
  3. // 题目导航ID前缀
  4. var prefix = '#navigation_';
  5. // 已完成题目的样式
  6. var complateClass = "navigation_question_complate";
  7. // 考试答案
  8. var examinee_answers = new Hashtable();
  9. // 已标识题目
  10. var signcount = 0;
  11. // 命令列表
  12. var commander = new Hashtable();
  13. // 单独警告次数
  14. var warningCount = 0;
  15. // 全体警告次数
  16. var allWarningCount = 0;
  17. // 考生状态
  18. var examState = 1;
  19. // 操作类型
  20. var ExamOperaType = {
  21. 交卷: 0,
  22. 取消交卷: 1,
  23. 提醒: 2,
  24. 警告: 3,
  25. 取消绑定: 4,
  26. 延时: 5,
  27. 强制交卷: 6,
  28. 取消强制交卷: 7,
  29. 举手: 8,
  30. 取消举手: 9,
  31. 更新状态: 10,
  32. 取消控制: 11
  33. }
  34. // 保存答案
  35. var Save = function (question_id, answer) {
  36. examinee_answers.add(question_id, answer);
  37. $("#exam_over").text(examInfo.questionCount - examinee_answers.count());
  38. }
  39. // 单选题
  40. this.Check_rad = function (obj, answerid, questionid) {
  41. cl(questionid);
  42. Save(questionid, answerid);
  43. }
  44. // 多选题
  45. this.Check_chk = function (obj, ctrlName, answerid, questionid) {
  46. var answers = $("input[name=" + ctrlName + "]:checked");
  47. var answer = "";
  48. if (answers.length > 0) {
  49. cl(questionid);
  50. answers.each(function (i, j) {
  51. if (answer.length > 0)
  52. answer += "|";
  53. answer += $(j).val();
  54. });
  55. }
  56. Save(questionid, answer);
  57. }
  58. // 填空题和计算题
  59. this.Check_text = function (obj, answerid, questionid) {
  60. if ($(obj).val().length > 0) {
  61. cl(questionid);
  62. Save(questionid, $(obj).val());
  63. }
  64. }
  65. // 简答题和论述题
  66. this.Check_area = function (obj, answerid, questionid) {
  67. if ($(obj).text().length > 0) {
  68. cl(questionid);
  69. Save(questionid, $(obj).text());
  70. }
  71. }
  72. // 多项填空题
  73. this.Check_text2 = function (obj, ctrlName, answerid, questionid) {
  74. var inputs = $("input[name=" + ctrlName + "]");
  75. if (inputs.filter(function (index) { return $(this).val().length > 0 }).length == inputs.length) {
  76. cl(questionid);
  77. }
  78. var answer = "";
  79. inputs.each(function (i, j) {
  80. if (answer.length > 0)
  81. answer += "|";
  82. answer += clearKeyChar($(j).val());
  83. });
  84. Save(questionid, answer);
  85. }
  86. // 交卷按钮点击事件
  87. $("#btn_takePaper").click(function () {
  88. takePaper();
  89. //sender.setSaftLeaveFlat(true);
  90. });
  91. this.bindSignEvent = function () {
  92. $(".btn_sign").click(function () {
  93. setSign(this);
  94. });
  95. }
  96. // 将答案半角字符修改成全角
  97. var clearKeyChar = function (val) {
  98. return val.replace(/\|/gi, "│")
  99. }
  100. // 屏蔽考试页面
  101. this.togglePapert = function (enabled) {
  102. if (enabled) {
  103. examState = 1;
  104. sender.setSaftLeaveFlat(false);
  105. $("#paper_body").show();
  106. $("#ExamMessage").hide();
  107. //$("#btn_takePaper").val("交 卷");
  108. $("#btn_takePaper").removeAttr("disabled");
  109. } else {
  110. examState = 2;
  111. sender.setSaftLeaveFlat(true);
  112. $("#paper_body").hide();
  113. $("#ExamMessage").show();
  114. //$("#btn_takePaper").val("已交卷");
  115. $("#btn_takePaper").attr("disabled", "disabled");
  116. }
  117. }
  118. this.registTimer = function (len) {
  119. len = len || examinee.lastLength;
  120. sender.setSaftLeaveFlat(false);
  121. $(".timer").calcTimer({
  122. limit: len,
  123. inputType: "s",
  124. format: "<span style='color:white;padding-right:40pt;'><font size='20pt' style='color:blue'>#H</font>时<font size='20pt' style='color:blue'>#M</font>分<font size='20pt' style='color:blue'>#S</font>秒</span>",
  125. ontimeout: function () {
  126. takePaper();
  127. },
  128. onCountdownError: function (container) {
  129. var examLength = Invoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/GetLastLengthOfExam", { test_id: examInfo.test_id, userid: examinee.userid });
  130. sender.registTimer(examLength);
  131. }
  132. });
  133. }
  134. this.setSaftLeaveFlat = function (saftleave) {
  135. if (saftleave) {
  136. window.onbeforeunload = null;
  137. }
  138. else {
  139. window.onbeforeunload = function () {
  140. return ('离开考试页面将清除您的答案,且增加考试登录次数!\n请确认是否离开当前考试页面?');
  141. }
  142. }
  143. }
  144. // 处理服务端返回命令
  145. this.handleCommand = function (cmdType, args) {
  146. commander.items(cmdType)(args);
  147. }
  148. // 标识已做题目
  149. var cl = function (id) {
  150. $(prefix + id).addClass(complateClass);
  151. }
  152. // 交卷
  153. var takePaper = function () {
  154. var result = JSON.stringify(examinee_answers.allitems());
  155. debugger
  156. var re = Invoke(CMS_SystemConfig.VirtualDirectoryPath + "/OnlineTest/TakePaper",
  157. { test_id: examInfo.test_id, userid: examinee.userid, answer: result });
  158. if (re.length > 6)
  159. alert(re);
  160. else {
  161. $('[id$=lbScore]').text("本次考试分数:" + re + "分");
  162. $(".timer").clear();
  163. sender.togglePapert(false);
  164. }
  165. }
  166. // 设置标识
  167. var setSign = function (btn) {
  168. var me = $(btn);
  169. var questionid = $(btn).attr("author");
  170. if (me.hasClass("btn_sign")) {
  171. $(prefix + questionid).addClass("navigation_question_sign");
  172. me.val(' 取消 ');
  173. me.removeClass("btn_sign");
  174. me.addClass("btn_signed");
  175. signcount += 1;
  176. }
  177. else {
  178. $(prefix + questionid).removeClass("navigation_question_sign");
  179. me.val(' 标识 ');
  180. me.removeClass("btn_signed");
  181. me.addClass("btn_sign");
  182. signcount -= 1;
  183. }
  184. $("#exam_sign").text(signcount);
  185. }
  186. // 警告处理
  187. commander.add(ExamOperaType.警告, function (args) {
  188. if (examState == 1) {
  189. if (args.type == 'person') {
  190. warningAlert(personWarring, args.intData);
  191. }
  192. else {
  193. warningAlert(allWarring, args.intData);
  194. }
  195. }
  196. });
  197. commander.add(ExamOperaType.交卷, function (args) {
  198. if (examState == 1) {
  199. takePaper();
  200. }
  201. });
  202. commander.add(ExamOperaType.取消交卷, function (args) {
  203. if (examState == 2) {
  204. examState = 1;
  205. sender.togglePapert(true);
  206. var examLength = Invoke("WaitExam.aspx/CancelTakePaper", { test_id: examInfo.test_id, userid: examinee.userid });
  207. sender.registTimer(examLength);
  208. }
  209. });
  210. commander.add(ExamOperaType.延时, function (args) {
  211. examState = 1;
  212. sender.togglePapert(true);
  213. var examLength = Invoke("WaitExam.aspx/CancelTakePaper", { test_id: examInfo.test_id, userid: examinee.userid });
  214. sender.registTimer(examLength);
  215. });
  216. commander.add(ExamOperaType.取消控制, function (args) {
  217. args.sender.removeExamineeExchangeEvent();
  218. });
  219. var warningAlert = function (warningInfo, count) {
  220. var message = '提示:监考员向您发出警告!请您遵守考场规则。';
  221. var msg = $(warningInfo).filter(function () { return this.key == count; });
  222. if (msg.length > 0) {
  223. message = msg.val();
  224. }
  225. examAlert(message);
  226. }
  227. var examAlert = function (msg) {
  228. radalert("<font size='6px'>" + msg + "</font>", 400, 210);
  229. }
  230. }