刘洋 1 ano atrás
pai
commit
a16fdd52b0
4 arquivos alterados com 29 adições e 24 exclusões
  1. 7 21
      src/App.vue
  2. 4 1
      src/api/apiConfig/index.js
  3. 1 0
      src/pages/login.vue
  4. 17 2
      src/router/index.js

+ 7 - 21
src/App.vue

@@ -1,10 +1,3 @@
-<template>
-  <router-view v-slot="{ Component }">
-    <transition name="zoom-fade" mode="out-in" appear v-if="showApp">
-      <component :is="Component" />
-    </transition>
-  </router-view>
-</template>
 <script setup name="App">
 import { getUrlParam } from "./utils";
 import LibForWeixin from "./utils/LibForWeixin";
@@ -15,24 +8,17 @@ const router = useRouter();
 const appStore = useAppStore();
 const userStore = useUserStore();
 const code = getUrlParam("code");
-const showApp = ref(false);
 let pattern =
   /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
 
 if (userStore.openId || code) {
   router.push({ name: "WxLogin", query: { code } });
-  setTimeout(() => {
-    showApp.value = true;
-  }, 10);
-} else {
-  if (
-    pattern.test(location.hostname) ||
-    location.hostname === "apply-test.qmth.com.cn"
-  ) {
-    //如果是ip访问
-    showApp.value = true;
-  } else {
-    LibForWeixin.auth();
-  }
 }
 </script>
+<template>
+  <router-view v-slot="{ Component }">
+    <transition name="zoom-fade" mode="out-in" appear>
+      <component :is="Component" />
+    </transition>
+  </router-view>
+</template>

+ 4 - 1
src/api/apiConfig/index.js

@@ -127,7 +127,10 @@ axiosInstance.interceptors.response.use(
     if (error?.response?.data?.message) {
       error.message = error?.response?.data?.message;
     }
-    const whiteUrls = ["/api/student/login/get/openid"];
+    const whiteUrls = [
+      "/api/student/login/get/openid",
+      "/api/student/login/for/wechat",
+    ];
     !whiteUrls.includes(error?.config?.url) && showToast(error.message);
     return Promise.reject(error);
   }

+ 1 - 0
src/pages/login.vue

@@ -74,6 +74,7 @@ const account = ref("");
 const password = ref("");
 const passwordShow = ref(false);
 const onSubmit = () => {
+  console.log("1");
   login({ account: account.value, password: password.value }).then((res) => {
     if (res?.id) {
       userStore.setLoginInfo(res);

+ 17 - 2
src/router/index.js

@@ -6,6 +6,7 @@ import {
 import routes from "./routes";
 import LibForWeixin from "@/utils/LibForWeixin";
 import { useUserStore, useAppStore } from "@/store";
+import { getUrlParam } from "../utils";
 
 const router = createRouter({
   // history: createWebHistory(import.meta.env.VITE_BASE),
@@ -17,11 +18,26 @@ const router = createRouter({
     behavior: "smooth",
   }),
 });
+let pattern =
+  /^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$/;
 const whiteList = ["Login", "WxLogin"];
 router.beforeEach(async (to, from, next) => {
   console.log("to:", to);
+  const code = getUrlParam("code");
   const appStore = useAppStore();
-  if (!appStore.globalConfig && to.name !== "WxLogin") {
+  const userStore = useUserStore();
+  if (
+    !userStore.openId &&
+    !code &&
+    !(
+      pattern.test(location.hostname) ||
+      location.hostname === "apply-test.qmth.com.cn"
+    )
+  ) {
+    LibForWeixin.auth();
+    return;
+  }
+  if (!appStore.globalConfig && to.name !== "WxLogin" && userStore.openId) {
     let config = await appStore.getGlobalConfig();
     if (((config && !config?.taskTitle) || !config) && to.name !== "Login") {
       next({ name: "Login", replace: true });
@@ -41,7 +57,6 @@ router.beforeEach(async (to, from, next) => {
     next();
     return;
   }
-  const userStore = useUserStore();
   if (!userStore.loginInfo) {
     next({ name: "Login", replace: true });
   } else {