123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import Vue from "vue";
- import { createLog } from "@/utils/logger";
- import moment from "moment";
- Vue.mixin({
- beforeCreate() {
- if (document.getElementById("app-placeholder"))
- document.getElementById("app-placeholder").remove();
- },
- mounted() {
- // console.log("mixin hook called");
- [...document.getElementsByTagName("a")].forEach(e => {
- e.addEventListener("click", function(event) {
- event.preventDefault();
- });
- });
- },
- methods: {
- logger(logs) {
- createLog(logs);
- },
- async checkExamInProgress() {
- try {
- // 断点续考
- // const examingRes = (await this.$http.get(
- // "/api/ecs_oe_student/examControl/checkExamInProgress"
- // )).data;
- let examingRes;
- for (let i = 0; i < 4; i++) {
- examingRes = await this.$http.get(
- "/api/ecs_oe_student/examControl/checkExamInProgress"
- );
- if (
- examingRes.status === 503 ||
- examingRes.data.code === "S-101000"
- ) {
- await new Promise(resolve => setTimeout(() => resolve(), 2000));
- continue;
- } else if (examingRes.data.code === "000000") {
- break;
- }
- }
- if (examingRes.status !== 200 || examingRes.data.code !== "000000") {
- window._hmt.push([
- "_trackEvent",
- "断点续考处理异常",
- "调用断点续考接口超过次数",
- ]);
- throw new Error("调用断点续考接口超过次数");
- }
- this.$store.commit(
- "updateTimeDifference",
- moment(examingRes.headers.date).diff(moment())
- );
- examingRes = examingRes.data.data; // 保持和原接口一致
- if (examingRes && examingRes.isExceed) {
- // 超出断点续考次数的逻辑,仅此block
- this.$Message.info({
- content: `超出最大断点续考次数(${examingRes.maxInterruptNum}),正在自动交卷...`,
- duration: 15,
- closable: true,
- });
- this.$Spin.show({
- render: () => {
- return (
- <div style="font-size: 24px">
- 超出最大断点续考次数({examingRes.maxInterruptNum}
- ),正在自动交卷...
- </div>
- );
- },
- });
- // 断点续考消息一闪而过,此处可以加延迟
- // await new Promise(resolve => setTimeout(() => resolve(), 3000));
- const res = await this.$http.get(
- "/api/ecs_oe_student/examControl/endExam"
- );
- this.$Spin.hide();
- if (res.status === 200) {
- this.$router.replace({
- path: `/online-exam/exam/${examingRes.examId}/examRecordData/${examingRes.examRecordDataId}/end`,
- });
- } else {
- window._hmt.push(["_trackEvent", "断点续考处理异常", "交卷失败"]);
- this.$Message.error({
- content: "交卷失败",
- duration: 15,
- closable: true,
- });
- throw new Error("交卷失败");
- }
- return true;
- }
- if (examingRes) {
- this.$Spin.show({
- render: () => {
- return <div style="font-size: 24px">正在进入断点续考...</div>;
- },
- });
- this.$router.push(
- `/online-exam/exam/${examingRes.examId}/examRecordData/${examingRes.examRecordDataId}/order/1`
- );
- setTimeout(() => this.$Spin.hide(), 1000);
- return true;
- }
- } catch (error) {
- this.$Spin.hide();
- window._hmt.push(["_trackEvent", "断点续考处理异常"]);
- this.$Message.error({
- content: "断点续考处理异常",
- duration: 15,
- closable: true,
- });
- throw error;
- }
- },
- logout(cause = "") {
- console.log("退出登录:", cause);
- this.logger({ action: "退出登录", cause });
- localStorage.removeItem("phoneVerified");
- window._hmt.push(["_trackEvent", "退出", cause]);
- const redirectUrl = sessionStorage.getItem("redirectUrl");
- if (redirectUrl) {
- this.$Modal.error({
- title: "确认返回",
- content: "",
- onOk: () => {
- window.location = redirectUrl;
- },
- });
- } else {
- this.$router.push("/login/" + localStorage.getItem("domain") + cause);
- }
- },
- },
- });
|