mixins.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import Vue from "vue";
  2. Vue.mixin({
  3. beforeCreate() {
  4. if (document.getElementById("app-placeholder"))
  5. document.getElementById("app-placeholder").remove();
  6. },
  7. mounted() {
  8. // console.log("mixin hook called");
  9. [...document.getElementsByTagName("a")].forEach(e => {
  10. e.addEventListener("click", function(event) {
  11. event.preventDefault();
  12. });
  13. });
  14. },
  15. methods: {
  16. async serverLog(level, logText) {
  17. try {
  18. await this.$http.post(
  19. "/api/ecs_core/log/studentClient/" + level,
  20. logText,
  21. {
  22. headers: {
  23. "Content-Type": "text/plain",
  24. },
  25. }
  26. );
  27. } catch (error) {
  28. console.log(error);
  29. }
  30. },
  31. async checkExamInProgress() {
  32. try {
  33. // 断点续考
  34. // const examingRes = (await this.$http.get(
  35. // "/api/ecs_oe_student/examControl/checkExamInProgress"
  36. // )).data;
  37. let examingRes;
  38. for (let i = 0; i < 4; i++) {
  39. examingRes = await this.$http.get(
  40. "/api/ecs_oe_student/examControl/checkExamInProgress"
  41. );
  42. console.log(examingRes);
  43. if (examingRes.data.code === "S-101000") {
  44. await new Promise(resolve => setTimeout(() => resolve(), 2000));
  45. continue;
  46. } else if (examingRes.data.code === "000000") {
  47. break;
  48. }
  49. }
  50. if (examingRes.data.code !== "000000") {
  51. window._hmt.push([
  52. "_trackEvent",
  53. "断点续考处理异常",
  54. "调用断点续考接口超过次数",
  55. ]);
  56. throw "调用断点续考接口超过次数";
  57. }
  58. examingRes = examingRes.data.data; // 保持和原接口一致
  59. if (examingRes && examingRes.isExceed) {
  60. // 超出断点续考次数的逻辑,仅此block
  61. this.$Message.info({
  62. content: `超出最大断点续考次数(${examingRes.maxInterruptNum}),正在自动交卷...`,
  63. duration: 15,
  64. closable: true,
  65. });
  66. this.$Spin.show({
  67. render: () => {
  68. return (
  69. <div style="font-size: 24px">
  70. 超出最大断点续考次数({examingRes.maxInterruptNum}
  71. ),正在自动交卷...
  72. </div>
  73. );
  74. },
  75. });
  76. const res = await this.$http.get(
  77. "/api/ecs_oe_student/examControl/endExam"
  78. );
  79. if (res.status === 200) {
  80. this.$router.replace({
  81. path: `/online-exam/exam/${examingRes.examId}/examRecordData/${examingRes.examRecordDataId}/end`,
  82. });
  83. this.$Spin.hide();
  84. } else {
  85. window._hmt.push(["_trackEvent", "断点续考处理异常", "交卷失败"]);
  86. this.$Message.error({
  87. content: "交卷失败",
  88. duration: 15,
  89. closable: true,
  90. });
  91. throw "交卷失败";
  92. }
  93. return true;
  94. }
  95. if (examingRes) {
  96. this.$Spin.show({
  97. render: () => {
  98. return <div style="font-size: 24px">正在进入断点续考...</div>;
  99. },
  100. });
  101. this.$router.push(
  102. `/online-exam/exam/${examingRes.examId}/examRecordData/${examingRes.examRecordDataId}/order/1` +
  103. (examingRes.faceVerifyMinute
  104. ? `?faceVerifyMinute=${examingRes.faceVerifyMinute}`
  105. : "")
  106. );
  107. setTimeout(() => this.$Spin.hide(), 1000);
  108. return true;
  109. }
  110. } catch (error) {
  111. window._hmt.push(["_trackEvent", "断点续考处理异常"]);
  112. this.$Message.error({
  113. content: "断点续考处理异常",
  114. duration: 15,
  115. closable: true,
  116. });
  117. throw error;
  118. }
  119. },
  120. logout(cause = "") {
  121. localStorage.removeItem("phoneVerified");
  122. window._hmt.push(["_trackEvent", "退出", cause]);
  123. const redirectUrl = sessionStorage.getItem("redirectUrl");
  124. if (redirectUrl) {
  125. this.$Modal.error({
  126. title: "确认退出",
  127. content: "",
  128. onOk: () => {
  129. window.location = redirectUrl;
  130. },
  131. });
  132. } else {
  133. this.$router.push("/login/" + localStorage.getItem("domain") + cause);
  134. }
  135. },
  136. },
  137. });