<template>
  <div
    id="app"
    onpaste="return false"
    oncopy="return false"
    oncut="return false"
  >
    <router-view></router-view>
  </div>
</template>

<script>
import { mapState } from "vuex";

export default {
  name: "APP",
  computed: {
    ...mapState(["QECSConfig"]),
  },
  watch: {
    QECSConfig() {
      // console.log(this.$store.state.QECSConfig.PREVENT_CHEATING_CONFIG);
      if (this.QECSConfig.PREVENT_CHEATING_CONFIG.includes("FULL_SCREEN_TOP")) {
        if (typeof nodeRequire == "undefined") {
          console.log("非考生端，不检测置顶状态");
          this.logger({
            action: "非考生端，不检测置顶状态",
          });
          return;
        }
        console.log("考生端，设置检测置顶状态");
        this.logger({
          action: "考生端，设置检测置顶状态",
        });
        let remote = window.nodeRequire("electron").remote;
        // const { electron, dialog } = remote;
        // console.log(remote);
        // Module to control application life.
        // const app = remote.app;
        // const dialog = remote.dialog;
        const mainWindow = remote.getCurrentWindow();
        const blurHandler = () => {
          // console.log("blur...");
          // dialog.showErrorBox("学生端不是置顶状态", "退出学生端!");
          // app.exit(0);

          this.logger({
            page: window.location.pathname,
            action: "学生端不是置顶状态",
          });
          window._hmt.push([
            "_trackEvent",
            window.location.pathname.replace(/\d+/g, ""),
            "学生端不是置顶状态",
          ]);
          if (this.$route.name === "OnlineExamingHome") {
            this.$http.post(
              "/api/ecs_oe_student/examControl/switchScreen?examRecordDataId=" +
                this.$route.params.examRecordDataId
            );
          }
          return;

          // const redirectUrl = sessionStorage.getItem("redirectUrl");
          // this.logger({
          //   action: "学生端不是置顶状态--退出",
          // });
          // console.log(`学生端不是置顶状态--退出`);
          // this.$Modal.error({
          //   title: "学生端不是置顶状态",
          //   content: "退出考试",
          //   onOk: () => {
          //     if (redirectUrl) {
          //       window.location = redirectUrl;
          //     } else {
          //       this.$router.push(
          //         "/login/" +
          //           localStorage.getItem("domain") +
          //           "?LogoutReason=学生端不是置顶状态--退出"
          //       );
          //     }
          //   },
          // });
        };
        mainWindow.removeListener("blur", blurHandler);
        mainWindow.on("blur", blurHandler);
      }
    },
  },
};
</script>

<style>
#app {
  font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  font-size: 14px;
  font-weight: normal;
  font-stretch: normal;
  /* line-height: 20px; */
  color: #777777;
}
</style>
