Bläddra i källkod

清除自制验证码;优化constant

Michael Wang 4 år sedan
förälder
incheckning
9ab58362a9

+ 37 - 0
src/constants/constant-namelist.js

@@ -0,0 +1,37 @@
+export const VCAM_LIST = [
+  "17GuaGua Cam",
+  "91KBOX",
+  // "ASUS Virtual Camera",
+  "e2eSoft iVCam",
+  "e2eSoft VCam",
+  "FaceRig Virtual Camera",
+  // "Lenovo Virtual Camera",
+  "MagicCamera Capture",
+  "MeiSe",
+  "Virtual Cam",
+  "YY伴侣",
+  "WebcamMax Capture",
+  "Wecam",
+  "Vcam ",
+  "softcam",
+  "Vandate Virtual Camera",
+  "video2webcam",
+  "VCDCut Pro",
+  "9158虚拟视频",
+  "9158Capture",
+  "Insta360 Virtual Camera",
+  "无他直播伴侣PC客户端",
+  "无他相机电脑版",
+  "mobiola webcamera",
+  "艾米秀宝(ImiShowBox)",
+  "video2Webcam",
+  "飞翔虚拟视频",
+  "魔力秀",
+  "YY开播",
+  "无他伴侣",
+  "视频连麦",
+  "酷狗直播伴侣",
+];
+
+export const REMOTE_APP_NAME =
+  "qq;teamviewer;lookmypc;xt;winaw32;pcaquickconnect;sessioncontroller;sunloginclient;sunloginremote;wemeetapp;wechat";

+ 57 - 143
src/features/Login/Login.vue

@@ -1,23 +1,16 @@
 <template>
   <div class="home">
     <header class="header">
-      <div class="school-logo">
+      <div class="school-logo-container">
         <img
           v-show="logoPath"
-          class="logo-size"
+          class="school-logo"
           :src="logoPath"
           alt="school logo"
-          style="
-            background: linear-gradient(to bottom, #38f6f5 0%, #8efdf4 100%);
-          "
           @load="(e) => (e.target.style = '')"
         />
       </div>
-      <a
-        class="close"
-        style="border-bottom-left-radius: 6px;"
-        @click="closeApp"
-      >
+      <a class="close" @click="closeApp">
         关闭
       </a>
     </header>
@@ -68,43 +61,27 @@
 
         <div style="margin: 0 40px 40px 40px;">
           <i-form ref="loginForm" :model="loginForm" :rules="loginFormRule">
-            <i-form-item
-              prop="accountValue"
-              style="margin-bottom: 30px; height: 42px;"
-            >
+            <i-form-item prop="accountValue" class="form-item-style">
               <i-input
                 v-model="loginForm.accountValue"
                 type="text"
                 size="large"
-                @on-blur="loginForm.accountValue && (initVerifyCode = true)"
+                @on-blur="loginForm.accountValue"
               >
                 <i-icon slot="prepend" type="ios-person"></i-icon>
               </i-input>
             </i-form-item>
-            <i-form-item
-              prop="password"
-              style="margin-bottom: 30px; height: 42px;"
-            >
+            <i-form-item prop="password" class="form-item-style">
               <i-input
                 v-model="loginForm.password"
                 type="password"
                 size="large"
                 @on-enter="loginForuser"
-                @on-blur="loginForm.accountValue && (initVerifyCode = true)"
+                @on-blur="loginForm.accountValue"
               >
                 <i-icon slot="prepend" type="ios-lock"></i-icon>
               </i-input>
             </i-form-item>
-            <i-form-item
-              prop="verifyCode"
-              style="margin-bottom: 30px; height: 42px;"
-            >
-              <VerifyCode
-                :account-value="loginForm.accountValue"
-                :init="initVerifyCode"
-                @calcVerify="calcVerify"
-              />
-            </i-form-item>
 
             <i-form-item style="position: relative;">
               <div
@@ -142,20 +119,22 @@
 <script>
 import moment from "moment";
 import { mapMutations } from "vuex";
-import { FACE_API_MODEL_PATH, DOMAIN_IN_URL } from "@/constants/constants";
-import DevTools from "./DevTools.vue";
-import nativeExe, { fileExists } from "@/utils/nativeExe";
 import {
+  FACE_API_MODEL_PATH,
+  DOMAIN_IN_URL,
   EPCC_DOMAIN,
   VUE_APP_CONFIG_FILE_SEVER_URL,
 } from "@/constants/constants";
+import { REMOTE_APP_NAME, VCAM_LIST } from "@/constants/constant-namelist";
+import DevTools from "./DevTools.vue";
+import nativeExe, { fileExists } from "@/utils/nativeExe";
 import UA, { chromeUA } from "@/utils/ua.js";
 import {
   createLog,
   createUserDetailLog,
   createEncryptLog,
 } from "@/utils/logger";
-import VerifyCode from "./VerifyCode.vue";
+import { isElectron } from "@/utils/util";
 
 // 检测devtools.  仅在chrome 72+ 有效。
 let element = new Image();
@@ -177,8 +156,7 @@ Object.defineProperty(element, "id", {
 
 /**
  * 在任何组件需要强制退出,做以下步骤
- * 1. this.$Message.info()
- * 2. this.$router.push("/login"+domain);
+ * 1. this.logout("?LogoutReason=xxx")
  * 因为在/login里会删除localStorage的token,而在router.beforeEach会检查是否有token,达到退出的目的。
  */
 
@@ -186,7 +164,6 @@ export default {
   name: "Login",
   components: {
     DevTools,
-    VerifyCode,
   },
   data() {
     return {
@@ -196,9 +173,7 @@ export default {
       loginForm: {
         accountValue: "",
         password: "",
-        verifyCode: "",
         tid: "",
-        // result: "",
       },
       loginFormRule: {
         accountValue: [
@@ -215,31 +190,8 @@ export default {
             trigger: "blur",
           },
         ],
-        verifyCode: [
-          {
-            required: true,
-            message: "请填写计算结果",
-            trigger: "blur",
-            type: "number",
-          },
-          {
-            type: "number",
-            asyncValidator: (rule, value) => {
-              return new Promise((resolve, reject) => {
-                if (value < -999 || value > 999) {
-                  reject("验证码长度不对"); // reject with error message
-                } else {
-                  resolve();
-                }
-              });
-            },
-            message: "验证码长度不对",
-            trigger: "blur",
-          },
-        ],
       },
       loginBtnLoading: false,
-      isElectron: true,
       disableLoginBtnBecauseRemoteApp: true,
       disableLoginBtnBecauseVCam: true,
       disableLoginBtnBecauseAppVersionChecker: false,
@@ -247,7 +199,6 @@ export default {
       disableLoginBtnBecauseNotAllowedNative: true,
       newVersionAvailable: false,
       VUE_APP_GIT_REPO_VERSION: process.env.VUE_APP_GIT_REPO_VERSION,
-      initVerifyCode: false,
     };
   },
   computed: {
@@ -293,14 +244,8 @@ export default {
       }
     },
     disableLoginBtn() {
-      // console.log(
-      //   this.isElectron,
-      //   this.disableLoginBtnBecauseRemoteApp,
-      //   this.disableLoginBtnBecauseVCam,
-      //   this.disableLoginBtnBecauseAppVersionChecker
-      // );
       return (
-        (this.isElectron &&
+        (isElectron() &&
           (this.disableLoginBtnBecauseRemoteApp ||
             this.disableLoginBtnBecauseVCam)) ||
         this.disableLoginBtnBecauseAppVersionChecker ||
@@ -398,8 +343,6 @@ export default {
       });
     }
 
-    this.isElectron = typeof nodeRequire != "undefined";
-
     if (
       navigator.userAgent.indexOf("WOW64") != -1 ||
       navigator.userAgent.indexOf("Win64") != -1
@@ -418,16 +361,16 @@ export default {
     window.sessionStorage.removeItem("token");
     window.sessionStorage.clear();
     window.localStorage.removeItem("key");
-    if (localStorage.getItem("user-for-reload")) {
-      const lsUser = JSON.parse(localStorage.getItem("user-for-reload"));
-      this.loginForm.accountValue =
-        process.env.NODE_ENV === "production"
-          ? ""
-          : lsUser.studentCode ||
-            (lsUser.studentCodeList && lsUser.studentCodeList[0]);
-      this.loginForm.password =
-        process.env.NODE_ENV === "production" ? "" : "180613";
-    }
+    // if (localStorage.getItem("user-for-reload")) {
+    //   const lsUser = JSON.parse(localStorage.getItem("user-for-reload"));
+    //   this.loginForm.accountValue =
+    //     process.env.NODE_ENV === "production"
+    //       ? ""
+    //       : lsUser.studentCode ||
+    //         (lsUser.studentCodeList && lsUser.studentCodeList[0]);
+    //   this.loginForm.password =
+    //     process.env.NODE_ENV === "production" ? "" : "180613";
+    // }
 
     if (
       [
@@ -438,7 +381,7 @@ export default {
       ].includes(this.$route.params.domain)
     ) {
       if (
-        typeof nodeRequire == "undefined" ||
+        !isElectron() ||
         !window.nodeRequire("fs").existsSync("multiCamera.exe")
       ) {
         this.disableLoginBtnBecauseAppVersionChecker = true;
@@ -602,8 +545,6 @@ export default {
       this.updateTimeDifference(
         moment(loginResponse.headers.date).diff(moment())
       );
-      this.initVerifyCode = false;
-      this.$nextTick(() => (this.initVerifyCode = true));
       if (data.code == "200") {
         data = data.content;
         this.errorInfo = "";
@@ -613,16 +554,23 @@ export default {
         window.localStorage.setItem("domain", this.schoolDomain);
 
         try {
-          const student = (
-            await this.$http.get(
-              "/api/ecs_core/student/getStudentInfoBySession"
-            )
-          ).data;
-          const specialty = (
-            await this.$http.get(
+          // const student = (
+          //   await this.$http.get(
+          //     "/api/ecs_core/student/getStudentInfoBySession"
+          //   )
+          // ).data;
+          // const specialty = (
+          //   await this.$http.get(
+          //     "/api/ecs_exam_work/exam_student/specialtyNameList/"
+          //   )
+          // ).data;
+
+          const [{ data: student }, { data: specialty }] = await Promise.all([
+            this.$http.get("/api/ecs_core/student/getStudentInfoBySession"),
+            this.$http.get(
               "/api/ecs_exam_work/exam_student/specialtyNameList/"
-            )
-          ).data;
+            ),
+          ]);
           const user = {
             ...data,
             ...student,
@@ -696,7 +644,7 @@ export default {
         }
       );
       // 给后台更多时间去处理 resource/uuid.js 的请求
-      await new Promise((resolve) => setTimeout(() => resolve(), 1500));
+      // await new Promise((resolve) => setTimeout(() => resolve(), 1500));
       if (!response.ok || this.newVersionAvailable) {
         if (
           response.ok &&
@@ -772,7 +720,7 @@ export default {
       await this.checkRemoteApp();
     },
     async checkRemoteApp() {
-      if (typeof nodeRequire == "undefined") {
+      if (!isElectron()) {
         return;
       }
 
@@ -851,8 +799,7 @@ export default {
       ) {
         let exe = "Project1.exe";
         if (fileExists("Project2.exe")) {
-          const remoteAppName =
-            "qq;teamviewer;lookmypc;xt;winaw32;pcaquickconnect;sessioncontroller;sunloginclient;sunloginremote;wemeetapp;wechat";
+          const remoteAppName = REMOTE_APP_NAME;
           exe = `Project2.exe "${remoteAppName}" `;
         }
         await nativeExe(exe, checkRemoteAppTxt.bind(this));
@@ -861,45 +808,10 @@ export default {
       }
     },
     async checkVCam() {
-      if (typeof nodeRequire == "undefined") {
+      if (!isElectron()) {
         return;
       }
-
-      const vcamList = [
-        "17GuaGua Cam",
-        "91KBOX",
-        // "ASUS Virtual Camera",
-        "e2eSoft iVCam",
-        "e2eSoft VCam",
-        "FaceRig Virtual Camera",
-        // "Lenovo Virtual Camera",
-        "MagicCamera Capture",
-        "MeiSe",
-        "Virtual Cam",
-        "YY伴侣",
-        "WebcamMax Capture",
-        "Wecam",
-        "Vcam ",
-        "softcam",
-        "Vandate Virtual Camera",
-        "video2webcam",
-        "VCDCut Pro",
-        "9158虚拟视频",
-        "9158Capture",
-        "Insta360 Virtual Camera",
-        "无他直播伴侣PC客户端",
-        "无他相机电脑版",
-        "mobiola webcamera",
-        "艾米秀宝(ImiShowBox)",
-        "video2Webcam",
-        "飞翔虚拟视频",
-        "魔力秀",
-        "YY开播",
-        "无他伴侣",
-        "视频连麦",
-        "酷狗直播伴侣",
-      ];
-
+      const vcamList = VCAM_LIST;
       async function checkVCamTxt() {
         let applicationNames;
         try {
@@ -990,7 +902,7 @@ export default {
       if (this.QECSConfig.LOGIN_SUPPORT.includes("NATIVE")) {
         // 检测是否是学生端。 检测是否有node。检测是否能node调用。
         const hasShell = UA.getBrowser().name === "electron-exam-shell";
-        const hasNode = typeof nodeRequire !== "undefined";
+        const hasNode = !isElectron();
         let hasFs = false;
         let hasReadFileSync = false;
         if (hasShell && hasNode) {
@@ -1114,11 +1026,6 @@ export default {
         this.logout();
       }
     },
-    calcVerify({ uuid, verifyCode }) {
-      // console.log(uuid, verifyCode);
-      this.loginForm.tid = uuid;
-      this.loginForm.verifyCode = verifyCode;
-    },
   },
 };
 </script>
@@ -1130,15 +1037,16 @@ export default {
   height: 100vh;
 }
 
-.school-logo {
+.school-logo-container {
   justify-self: flex-start;
   margin-left: 100px;
 }
 
-.logo-size {
+.school-logo {
   height: 100px;
   width: 400px;
   object-fit: cover;
+  background: linear-gradient(to bottom, #38f6f5 0%, #8efdf4 100%);
 }
 
 .header {
@@ -1181,6 +1089,11 @@ export default {
   border-top-right-radius: 6px;
 }
 
+.form-item-style {
+  margin-bottom: 30px;
+  height: 42px;
+}
+
 .close {
   position: absolute;
   top: 0;
@@ -1190,6 +1103,7 @@ export default {
   width: 80px;
   height: 40px;
   line-height: 40px;
+  border-bottom-left-radius: 6px;
 }
 
 .close:hover {

+ 12 - 29
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -112,6 +112,7 @@ import { openWS, closeWsWithoutReconnect } from "./ws.js";
 import { createNamespacedHelpers, mapState as globalMapState } from "vuex";
 const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
 import nativeExe, { fileExists } from "@/utils/nativeExe";
+import { REMOTE_APP_NAME } from "@/constants/constant-namelist";
 
 export default {
   name: "ExamingHome",
@@ -380,13 +381,13 @@ export default {
     ]),
     async initData() {
       const [
-        weixinAnswerEnabledData,
-        faceCheckEnabledData,
-        faceLivenessEnabledData,
-        examPropData,
-        examData,
-        paperStructData,
-        examQuestionListData,
+        { data: weixinAnswerEnabled },
+        { data: faceCheckEnabled },
+        { data: faceLivenessEnabled },
+        { data: examProp },
+        { data: exam },
+        { data: paperStruct },
+        { data: examQuestionListOrig },
       ] = await Promise.all([
         this.$http.get(
           "/api/ecs_exam_work/exam/weixinAnswerEnabled/" +
@@ -412,30 +413,13 @@ export default {
         ),
         this.$http.get("/api/ecs_oe_student/examQuestion/findExamQuestionList"),
       ]);
-      // console.log(weixinAnswerEnabledData, examPropData);
-
-      const [
-        weixinAnswerEnabled,
-        faceCheckEnabled,
-        faceLivenessEnabled,
-        examProp,
-        exam,
-        paperStruct,
-      ] = [
-        weixinAnswerEnabledData.data,
-        faceCheckEnabledData.data,
-        faceLivenessEnabledData.data,
-        examPropData.data,
-        examData.data,
-        paperStructData.data,
-      ];
 
       let initFaceLivenessResult = null;
       if (faceLivenessEnabled) {
         initFaceLivenessResult = await this.initFaceLiveness();
       }
 
-      let examQuestionList = examQuestionListData.data;
+      let examQuestionList = examQuestionListOrig;
 
       if (
         weixinAnswerEnabled === undefined ||
@@ -444,7 +428,7 @@ export default {
         examProp === undefined ||
         exam === undefined ||
         paperStruct === undefined ||
-        examQuestionListData === undefined ||
+        examQuestionList === undefined ||
         (faceLivenessEnabled && initFaceLivenessResult === false)
       ) {
         console.log({
@@ -454,7 +438,7 @@ export default {
           examProp,
           exam,
           paperStruct,
-          examQuestionListData,
+          examQuestionList,
           initFaceLivenessResult,
         });
         throw new Error("获取考试和试卷信息失败");
@@ -1041,8 +1025,7 @@ export default {
       ) {
         let exe = "Project1.exe";
         if (fileExists("Project2.exe")) {
-          const remoteAppName =
-            "qq;teamviewer;lookmypc;xt;winaw32;pcaquickconnect;sessioncontroller;sunloginclient;sunloginremote;wemeetapp;wechat";
+          const remoteAppName = REMOTE_APP_NAME;
           exe = `Project2.exe "${remoteAppName}" `;
         }
         await nativeExe(exe, checkRemoteAppTxt.bind(this));

+ 4 - 0
src/utils/util.js

@@ -30,3 +30,7 @@ export function setUUID() {
     localStorage.setItem("uuidForEcs", uuidForEcs);
   }
 }
+
+export function isElectron() {
+  return typeof nodeRequire != "undefined";
+}