Browse Source

add disabled feature: 限制客户端登录

Michael Wang 5 years ago
parent
commit
b41079f622
1 changed files with 53 additions and 1 deletions
  1. 53 1
      src/features/Login/Login.vue

+ 53 - 1
src/features/Login/Login.vue

@@ -191,6 +191,7 @@ export default {
       disableLoginBtnBecauseVCam: true,
       disableLoginBtnBecauseAppVersionChecker: false,
       disableLoginBtnBecauseRefreshServiceWorker: false,
+      disableLoginBtnBecauseNotAllowedNative: true,
       newVersionAvailable: false,
       VUE_APP_GIT_REPO_VERSION: process.env.VUE_APP_GIT_REPO_VERSION,
     };
@@ -249,7 +250,10 @@ export default {
           (this.disableLoginBtnBecauseRemoteApp ||
             this.disableLoginBtnBecauseVCam)) ||
         this.disableLoginBtnBecauseAppVersionChecker ||
-        this.disableLoginBtnBecauseRefreshServiceWorker
+        this.disableLoginBtnBecauseRefreshServiceWorker ||
+        (this.FE_FEATURE_ALLOW_CHECK
+          ? false
+          : this.disableLoginBtnBecauseNotAllowedNative)
       );
     },
   },
@@ -414,6 +418,7 @@ export default {
 
     await this.checkElectronConfig();
     await this.checkVCam();
+    await this.checkAllowedClient();
 
     if (
       this.allowLoginType.length === 1 &&
@@ -800,6 +805,53 @@ export default {
         this.disableLoginBtnBecauseVCam = false;
       }
     },
+    async checkAllowedClient() {
+      if (!this.FE_FEATURE_ALLOW_CHECK) {
+        this.disableLoginBtnBecauseNotAllowedNative = false;
+        return;
+      }
+      if (this.QECSConfig.LOGIN_SUPPORT.includes("NATIVE")) {
+        // 检测是否是学生端。 检测是否有node。检测是否能node调用。
+        const hasShell = UA.getBrowser().name === "electron-exam-shell";
+        const hasNode = typeof nodeRequire !== "undefined";
+        let hasFs = false;
+        let hasReadFileSync = false;
+        if (hasShell && hasNode) {
+          const fs = window.nodeRequire("fs");
+          if (fs && typeof fs.readFileSync === "function") {
+            hasFs = true;
+            hasReadFileSync = true;
+            this.disableLoginBtnBecauseNotAllowedNative = false;
+          }
+        }
+        if (this.disableLoginBtnBecauseNotAllowedNative) {
+          window._hmt.push([
+            "_trackEvent",
+            "登录页面",
+            "不允许访问-" +
+              JSON.stringify({
+                hasShell,
+                hasNode,
+                hasFs,
+                hasReadFileSync,
+              }),
+          ]);
+          this.$Message.error({
+            content: "请与学校申请最新的客户端,进行考试!",
+            duration: 2 * 24 * 60 * 60,
+          });
+        }
+      } else if (this.QECSConfig.LOGIN_SUPPORT.includes("BROWSER")) {
+        // TODO: redirect to wap site
+        // if(chromeUA.major < "66") { } // 到移动端去判断
+        return;
+      } else {
+        this.$Message.error({
+          content: "设置错误!",
+          duration: 2 * 24 * 60 * 60,
+        });
+      }
+    },
     closeApp() {
       console.log("关闭应用");
       window.close();