Jelajahi Sumber

极验分机构启用

Michael Wang 4 tahun lalu
induk
melakukan
94b4c25a50
2 mengubah file dengan 65 tambahan dan 13 penghapusan
  1. 3 1
      src/features/Login/GeeTest.vue
  2. 62 12
      src/features/Login/Login.vue

+ 3 - 1
src/features/Login/GeeTest.vue

@@ -3,6 +3,7 @@
     <!-- <label>完成验证:</label> -->
     <div id="captcha">
       <p v-if="loading" class="show">正在加载验证码......</p>
+      <!-- 重新获取验证码 -->
     </div>
   </div>
 </template>
@@ -45,7 +46,8 @@ export default {
           });
           that.$Message.error({
             content: "资源加载失败,请关闭程序,检查网络状况后重试。",
-            duration: 3 * 60,
+            duration: 1 * 60,
+            closable: true,
           });
         });
       }

+ 62 - 12
src/features/Login/Login.vue

@@ -82,6 +82,7 @@
             </i-form-item>
 
             <i-form-item
+              v-if="isGeeTestEnabled"
               class="form-item-style"
               style="height: 40px; margin-top: 0px;"
             >
@@ -211,6 +212,7 @@ export default {
       disableLoginBtnBecauseNotAllowedNative: true,
       newVersionAvailable: false,
       VUE_APP_GIT_REPO_VERSION: process.env.VUE_APP_GIT_REPO_VERSION,
+      GeeTestConfig: {},
     };
   },
   computed: {
@@ -265,6 +267,12 @@ export default {
         this.disableLoginBtnBecauseNotAllowedNative
       );
     },
+    isGeeTestEnabled() {
+      const thisOrg = this.GeeTestConfig[this.QECSConfig.ROOT_ORG_ID];
+      const isThisOrgUndefined = thisOrg === undefined;
+      const allOrg = this.GeeTestConfig["-1"];
+      return isThisOrgUndefined ? allOrg : thisOrg;
+    },
   },
   async mounted() {
     // this.testServiceWorker();
@@ -439,6 +447,7 @@ export default {
     // }
 
     await this.checkElectronConfig();
+    await this.checkGeeTestConfig();
     await this.checkVCam();
     await this.checkAllowedClient();
 
@@ -483,10 +492,12 @@ export default {
       const before = Date.now();
 
       // console.log(this.captchaObj.getValidate());
-      if (!this.captchaObj || !this.captchaObj.getValidate()) {
-        this.$Message.error("请完成验证");
-        this.loginBtnLoading = false;
-        return;
+      if (this.isGeeTestEnabled) {
+        if (!this.captchaObj || !this.captchaObj.getValidate()) {
+          this.$Message.error("请完成验证");
+          this.loginBtnLoading = false;
+          return;
+        }
       }
       try {
         await this.login();
@@ -528,8 +539,20 @@ export default {
         }
 
         let repPara = this.loginForm;
-        // const geeForm = document.querySelector(".geetest_form").children;
-        const geeRes = this.captchaObj.getValidate();
+
+        let geeParams = {};
+        if (this.isGeeTestEnabled) {
+          // const geeForm = document.querySelector(".geetest_form").children;
+          const geeRes = this.captchaObj.getValidate();
+          geeParams = {
+            // geetest
+            user_id: localStorage.getItem("uuidForEcs"),
+            client_type: "Web",
+            challenge: geeRes.geetest_challenge, // geeForm[0].value,
+            validate: geeRes.geetest_validate, // geeForm[1].value,
+            seccode: geeRes.geetest_seccode, // geeForm[2].value,
+          };
+        }
         // 以下网络请求失败,直接报网络异常错误
         loginResponse = await this.$http.post(
           "/api/ecs_core/verifyCode/gt/login",
@@ -539,12 +562,7 @@ export default {
             domain: this.schoolDomain,
             rootOrgId: this.QECSConfig.ROOT_ORG_ID,
             alwaysOK: true,
-            // geetest
-            user_id: localStorage.getItem("uuidForEcs"),
-            client_type: "Web",
-            challenge: geeRes.geetest_challenge, // geeForm[0].value,
-            validate: geeRes.geetest_validate, // geeForm[1].value,
-            seccode: geeRes.geetest_seccode, // geeForm[2].value,
+            ...geeParams,
           }
         );
       } else {
@@ -634,6 +652,7 @@ export default {
           // (JSON.parse(localStorage.getItem("userIds")) || []).length > 5;
 
           this.$Spin.hide();
+          this.$Message.destroy();
         } catch (error) {
           window._hmt.push([
             "_trackEvent",
@@ -749,6 +768,37 @@ export default {
 
       await this.checkRemoteApp();
     },
+    async checkGeeTestConfig() {
+      try {
+        const fileSever = VUE_APP_CONFIG_FILE_SEVER_URL;
+
+        const res = await fetch(
+          fileSever +
+            "/org_properties/geetestConfig.json" +
+            "?" +
+            Date.now() +
+            Math.random()
+        );
+        if (res.ok) {
+          const json = await res.json();
+          this.GeeTestConfig = json;
+        } else {
+          this.$Message.error({
+            content: "获取远程配置文件出错,请重新打开程序!",
+            duration: 15,
+            closable: true,
+          });
+          return;
+        }
+      } catch (e) {
+        this.$Message.error({
+          content: "获取远程配置文件出错,请重新打开程序!",
+          duration: 15,
+          closable: true,
+        });
+        return;
+      }
+    },
     async checkRemoteApp() {
       if (!isElectron()) {
         return;