App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div
  3. id="app"
  4. onpaste="return false"
  5. oncopy="return false"
  6. oncut="return false"
  7. >
  8. <router-view></router-view>
  9. <video id="ssVideo" style="display: none"></video>
  10. </div>
  11. </template>
  12. <script>
  13. import { mapState, createNamespacedHelpers } from "vuex";
  14. import { nodeCheckProcess } from "./utils/nativeExe";
  15. import { isElectron } from "./utils/util";
  16. const { mapMutations } = createNamespacedHelpers("examingHomeModule");
  17. export default {
  18. name: "APP",
  19. computed: {
  20. ...mapState(["user", "QECSConfig"]),
  21. },
  22. watch: {
  23. QECSConfig() {
  24. // console.log(this.$store.state.QECSConfig.PREVENT_CHEATING_CONFIG);
  25. if (this.QECSConfig.PREVENT_CHEATING_CONFIG.includes("FULL_SCREEN_TOP")) {
  26. if (typeof nodeRequire == "undefined") {
  27. console.log("非考生端,不检测置顶状态");
  28. this.logger({
  29. action: "非考生端,不检测置顶状态",
  30. });
  31. return;
  32. }
  33. console.log("考生端,设置检测置顶状态");
  34. this.logger({
  35. action: "考生端,设置检测置顶状态",
  36. });
  37. let remote = window.nodeRequire("electron").remote;
  38. // const { electron, dialog } = remote;
  39. // console.log(remote);
  40. // Module to control application life.
  41. // const app = remote.app;
  42. // const dialog = remote.dialog;
  43. const mainWindow = remote.getCurrentWindow();
  44. let lastBlurTimeStamp = 0;
  45. const blurHandler = () => {
  46. if (Date.now() - lastBlurTimeStamp < 1000) {
  47. // 小于1秒的切屏不计算在内,快捷键alt+tab容易连续触发两次
  48. return;
  49. }
  50. lastBlurTimeStamp = Date.now();
  51. // console.log("blur...");
  52. // dialog.showErrorBox("学生端不是置顶状态", "退出学生端!");
  53. // app.exit(0);
  54. this.logger({
  55. page: window.location.pathname,
  56. action: "学生端不是置顶状态",
  57. });
  58. window._hmt.push([
  59. "_trackEvent",
  60. window.location.pathname
  61. .replace(/=\w*/g, "=")
  62. .replace(/\d+/g, "{id}"),
  63. "学生端不是置顶状态",
  64. ]);
  65. if (this.$route.name === "OnlineExamingHome") {
  66. this.$Message.warning({
  67. content: "考试过程请勿尝试切屏,可能影响考试成绩",
  68. duration: 10,
  69. closable: true,
  70. });
  71. this.$http
  72. .post(
  73. "/api/ecs_oe_student/examControl/switchScreen?examRecordDataId=" +
  74. this.$route.params.examRecordDataId
  75. )
  76. .then((res) => {
  77. if (
  78. this.QECSConfig.PREVENT_CHEATING_CONFIG.includes(
  79. "RECORD_SWITCH_SCREEN"
  80. )
  81. ) {
  82. if (res.data) {
  83. // console.log(res.data);
  84. const { switchScreenCount, maxSwitchScreenCount } =
  85. res.data;
  86. if (
  87. typeof switchScreenCount === "number" &&
  88. typeof maxSwitchScreenCount === "number"
  89. ) {
  90. if (switchScreenCount > maxSwitchScreenCount) {
  91. this.updateExceedSwitchCount(true);
  92. }
  93. }
  94. }
  95. }
  96. });
  97. }
  98. return;
  99. // const redirectUrl = sessionStorage.getItem("redirectUrl");
  100. // this.logger({
  101. // action: "学生端不是置顶状态--退出",
  102. // });
  103. // console.log(`学生端不是置顶状态--退出`);
  104. // this.$Modal.error({
  105. // title: "学生端不是置顶状态",
  106. // content: "退出考试",
  107. // onOk: () => {
  108. // if (redirectUrl) {
  109. // window.location = redirectUrl;
  110. // } else {
  111. // this.$router.push(
  112. // "/login/" +
  113. // localStorage.getItem("domain") +
  114. // "?LogoutReason=学生端不是置顶状态--退出"
  115. // );
  116. // }
  117. // },
  118. // });
  119. };
  120. mainWindow.removeListener("blur", blurHandler);
  121. mainWindow.on("blur", blurHandler);
  122. }
  123. },
  124. },
  125. async created() {
  126. this.interval = setInterval(() => {
  127. this.sendOnlineSignal();
  128. }, 3 * 60 * 1000);
  129. if (isElectron()) {
  130. nodeCheckProcess();
  131. this.processInterval = setInterval(
  132. () => nodeCheckProcess(),
  133. 2 * 60 * 1000
  134. );
  135. }
  136. },
  137. beforeDestroy() {
  138. clearInterval(this.interval);
  139. clearInterval(this.processInterval);
  140. },
  141. methods: {
  142. ...mapMutations(["updateExceedSwitchCount"]),
  143. async sendOnlineSignal() {
  144. if (!window.sessionStorage.getItem("token")) {
  145. return;
  146. }
  147. try {
  148. await this.$http.get(
  149. "/api/ecs_core/student/online_signal/" + this.user.id
  150. );
  151. } catch (error) {
  152. this.logger({
  153. page: window.location.pathname,
  154. action: "发送在线信号",
  155. userId: this.user.id,
  156. });
  157. }
  158. },
  159. },
  160. };
  161. </script>
  162. <style>
  163. #app {
  164. font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
  165. "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
  166. -webkit-font-smoothing: antialiased;
  167. -moz-osx-font-smoothing: grayscale;
  168. text-align: center;
  169. font-size: 14px;
  170. font-weight: normal;
  171. font-stretch: normal;
  172. /* line-height: 20px; */
  173. color: #777777;
  174. }
  175. </style>