Browse Source

优化开发和测试的domain获取方式

Michael Wang 4 years ago
parent
commit
991ce8123c

+ 1 - 1
.env.development

@@ -1,5 +1,5 @@
 VUE_APP_SKIP_CHECK_NATIVE=true
-VUE_APP_CORE_HOST_URL=https://192.168.10.38:8878
+VUE_APP_CORE_HOST_URL=https://org0.qmth.com.cn
 VUE_APP_CONFIG_FILE_SEVER_URL=https://ecs-test-static.qmth.com.cn
 VUE_APP_ROUTER_PATH=/oe-web/
 VUE_APP_PUBLIC_PATH=/oe-web/

+ 29 - 6
src/constants/constants.js

@@ -1,19 +1,42 @@
+let origin, host, protocol;
+if (process.env.VUE_APP_CORE_HOST_URL) {
+  const hostUrl = new URL(process.env.VUE_APP_CORE_HOST_URL);
+  origin = hostUrl.toString();
+  host = hostUrl.host;
+  protocol = hostUrl.protocol.replace("http", "ws"); // http: => ws:
+} else {
+  origin = window.location.origin;
+  host = window.location.host;
+  protocol = window.location.host.protocol.replace("http", "ws"); // http: => ws:
+}
+
 export const FACEID_LINENESS_URL =
   "https://api.megvii.com/faceid/liveness/v2/do?token=";
-export const TK_SERVER_HTML_URL = window.location.origin; //process.env.VUE_APP_TK_SERVER_HTML_URL;
-export const TK_SERVER_API_URL = window.location.origin; //process.env.VUE_APP_TK_SERVER_API_URL;
+
+export const TK_SERVER_HTML_URL = origin;
+
 export const VUE_APP_WK_SERVER_SOCKET =
-  // (window.location.protocol === "https:" ? "wss://" : "ws://") +
-  "wss://" + window.location.host + "/api/ws/faceBiopsy";
+  protocol + "://" + host + "/api/ws/faceBiopsy";
+
 export const VUE_APP_WK_SERVER_SOCKET_FOR_AUDIO =
-  // (window.location.protocol === "https:" ? "wss://" : "ws://") +
-  "wss://" + window.location.host + "/api/ws/fileAnswer";
+  protocol + "://" + host + "/api/ws/fileAnswer";
+
 export const VUE_APP_CONFIG_FILE_SEVER_URL =
   process.env.VUE_APP_CONFIG_FILE_SEVER_URL;
+
 export const VUE_APP_SLS_STORE_NAME = process.env.VUE_APP_SLS_STORE_NAME;
+
 export const FACE_API_MODEL_PATH =
   process.env.VUE_APP_PUBLIC_PATH + "models/20190620/";
+
 // export const EPCC_DOMAIN = "iepcc-ps.ecs.qmth.com.cn";
 export const EPCC_DOMAIN = "bds.ecs.qmth.com.cn";
 export const CUG_DOMAIN = "cug.ecs.qmth.com.cn";
 // export const CUG_DOMAIN = "ecs-test.qmth.com.cn";
+
+let domain;
+if (process.env.NODE_ENV !== "production") {
+  domain = window.localStorage.getItem("domain_in_url");
+}
+if (!domain) domain = window.location.hostname.split(".")[0];
+export const DOMAIN_IN_URL = domain + ".ecs.qmth.com.cn";

+ 3 - 6
src/features/Login/Login.vue

@@ -142,7 +142,7 @@
 <script>
 import moment from "moment";
 import { mapMutations } from "vuex";
-import { FACE_API_MODEL_PATH } from "@/constants/constants";
+import { FACE_API_MODEL_PATH, DOMAIN_IN_URL } from "@/constants/constants";
 import DevTools from "./DevTools.vue";
 import nativeExe, { fileExists } from "@/utils/nativeExe";
 import {
@@ -190,9 +190,6 @@ export default {
   },
   data() {
     return {
-      domainInUrl:
-        this.$route.params.domain ||
-        window.location.hostname.split(".")[0] + ".ecs.qmth.com.cn",
       QECSConfig: {},
       loginType: "STUDENT_CODE",
       errorInfo: "",
@@ -268,7 +265,7 @@ export default {
       );
     },
     schoolDomain() {
-      const domain = this.domainInUrl;
+      const domain = DOMAIN_IN_URL;
       if (!domain || !domain.includes("qmth.com.cn")) {
         this.$Message.error({
           content: "机构地址出错,请关闭程序后再登录。",
@@ -745,7 +742,7 @@ export default {
         const res = await fetch(
           fileSever +
             "/org_properties/byOrgDomain/" +
-            this.domainInUrl +
+            DOMAIN_IN_URL +
             "/studentClientConfig.json" +
             "?" +
             Date.now() +

+ 2 - 6
src/features/OfflineExam/OfflineExamList.vue

@@ -107,10 +107,7 @@
 
 <script>
 import { mapState as globalMapState, mapGetters } from "vuex";
-import {
-  TK_SERVER_HTML_URL,
-  TK_SERVER_API_URL,
-} from "@/constants/constants.js";
+import { TK_SERVER_HTML_URL } from "@/constants/constants.js";
 import OfflineExamModal from "./OfflineExamModal.vue";
 
 export default {
@@ -157,7 +154,7 @@ export default {
       window.name = JSON.stringify(user);
       window.location.href =
         TK_SERVER_HTML_URL +
-        "/admin/preview_paper/" +
+        "/oe-admin/preview_paper/" +
         course.paperId +
         "?isback=true";
     },
@@ -171,7 +168,6 @@ export default {
       setTimeout(() => (this.disableDownloadPaperBtn = false), 10 * 1000);
 
       window.location.href =
-        TK_SERVER_API_URL +
         "/api/ecs_ques/paper/export/" +
         course.paperId +
         "/PAPER/" +

+ 42 - 42
src/main.js

@@ -36,51 +36,51 @@ if (process.env.NODE_ENV !== "production") {
   console.log("环境检查: process.env.NODE_ENV === " + process.env.NODE_ENV);
 }
 
-if (process.env.NODE_ENV === "development") {
-  console.log("非生产环境:准备自动登录");
-  (async () => {
-    if (window.sessionStorage.getItem("token")) {
-      console.log("非生产环境: 已有token,自动登录");
-      return;
-    }
-    console.log("非生产环境: 没有token,自动登录");
+// if (process.env.NODE_ENV === "development") {
+//   console.log("非生产环境:准备自动登录");
+//   (async () => {
+//     if (window.sessionStorage.getItem("token")) {
+//       console.log("非生产环境: 已有token,自动登录");
+//       return;
+//     }
+//     console.log("非生产环境: 没有token,自动登录");
 
-    const response = await fetch("/api/ecs_core/auth/login", {
-      method: "POST",
-      headers: {
-        "Content-Type": "application/json;charset=UTF-8",
-      },
-      body: JSON.stringify({
-        domain: process.env.VUE_APP_LOGIN_DOMAIN,
-        accountValue: process.env.VUE_APP_LOGIN_ACCOUNT_VALUE,
-        password: process.env.VUE_APP_LOGIN_PASSWORD,
-        accountType: process.env.VUE_APP_LOGIN_ACCOUNTTYPE,
-      }),
-    });
-    let data = await response.json();
-    if (data.token) {
-      window.sessionStorage.setItem("token", data.token);
-      window.localStorage.setItem("key", data.key);
-      window.localStorage.setItem("domain", process.env.VUE_APP_LOGIN_DOMAIN);
+//     const response = await fetch("/api/ecs_core/auth/login", {
+//       method: "POST",
+//       headers: {
+//         "Content-Type": "application/json;charset=UTF-8",
+//       },
+//       body: JSON.stringify({
+//         domain: process.env.VUE_APP_LOGIN_DOMAIN,
+//         accountValue: process.env.VUE_APP_LOGIN_ACCOUNT_VALUE,
+//         password: process.env.VUE_APP_LOGIN_PASSWORD,
+//         accountType: process.env.VUE_APP_LOGIN_ACCOUNTTYPE,
+//       }),
+//     });
+//     let data = await response.json();
+//     if (data.token) {
+//       window.sessionStorage.setItem("token", data.token);
+//       window.localStorage.setItem("key", data.key);
+//       window.localStorage.setItem("domain", process.env.VUE_APP_LOGIN_DOMAIN);
 
-      const student = await (
-        await fetch("/api/ecs_core/student/getStudentInfoBySession", {
-          method: "GET",
-          headers: {
-            "Content-Type": "application/json;charset=UTF-8",
-            key: data.key,
-            token: data.token,
-          },
-        })
-      ).json();
-      const user = { ...data, ...student };
+//       const student = await (
+//         await fetch("/api/ecs_core/student/getStudentInfoBySession", {
+//           method: "GET",
+//           headers: {
+//             "Content-Type": "application/json;charset=UTF-8",
+//             key: data.key,
+//             token: data.token,
+//           },
+//         })
+//       ).json();
+//       const user = { ...data, ...student };
 
-      window.localStorage.setItem("user-for-reload", JSON.stringify(user));
-    } else {
-      console.log(data.desc);
-    }
-  })();
-}
+//       window.localStorage.setItem("user-for-reload", JSON.stringify(user));
+//     } else {
+//       console.log(data.desc);
+//     }
+//   })();
+// }
 
 if (
   process.env.NODE_ENV === "development" &&

+ 1 - 1
src/mixins/mixins.js

@@ -135,7 +135,7 @@ Vue.mixin({
           },
         });
       } else {
-        this.$router.push("/login/" + localStorage.getItem("domain") + cause);
+        this.$router.push("/login/" + cause);
       }
     },
   },

+ 2 - 1
src/utils/axios.js

@@ -136,7 +136,7 @@ qmInstance.interceptors.response.use(
             },
           });
         } else {
-          router.push("/login/" + localStorage.getItem("domain"));
+          router.push("/login/");
         }
       }
       wk_token = null;
@@ -228,6 +228,7 @@ qmInstance.defaults.timeout = 30 * 1000; //超时时间
 qmInstance.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest"; //标识这是一个 ajax 请求
 
 qmInstance.get = cachingGet(qmInstance.get, [
+  /\/api\/exam_question\/question\/\?question_id/,
   /\/api\/exam_question\/paper_struct\/\?exam_record_id=/,
   /\/api\/ecs_oe_student\/examQuestion\/getQuestionContent\?questionId=.*&exam_record_id=/,
   // /\/api\/ecs_exam_work\/exam\/\d+$/,

+ 2 - 7
src/views/NotFoundComponent.vue

@@ -4,25 +4,20 @@
 
     <br />
     <br />
-    <div v-if="domain">
+    <div>
       <i-button size="large" class="qm-primary-button" long @click="goLogin">
         返回登录页
       </i-button>
     </div>
-
-    <div v-else>请关闭页面,重新登录!</div>
   </div>
 </template>
 
 <script>
 export default {
   name: "Page404",
-  data() {
-    return { domain: localStorage.getItem("domain") };
-  },
   methods: {
     goLogin() {
-      this.$router.push("/login/" + localStorage.getItem("domain"));
+      this.$router.push("/login/");
     },
   },
 };