Переглянути джерело

feat: add basic routerGard

Damon 4 роки тому
батько
коміт
96cbb2986e

+ 1 - 5
README.md

@@ -23,8 +23,4 @@
 
 **待确定事项**:
 
-- 与```coder```系统、```eval```系统的对接方式
-
-- 登录页迁移方式(老门户有一套)
-
-- ```sass```使用与否, 若最后使用建议弃用```node-sass```,官方推荐新的```dart-sass | sass```[sass官网](https://www.sasscss.com/dart-sass) | [npm上的JS版本](https://www.npmjs.com/package/sass)
+- 与```coder```系统、```eval```系统的对接方式

+ 0 - 4
src/components/GlobalHeader.vue

@@ -8,7 +8,6 @@
       <div class="global-header-navigator-tab" @click="toPortal"><span class="global-header-navigator-tab-text">首页</span></div>
       <div class="global-header-navigator-tab" @click="toTask"><span class="global-header-navigator-tab-text">任务</span></div>
       <div class="global-header-navigator-tab" @click="toManage"><span class="global-header-navigator-tab-text">教师[临]</span></div>
-      <div class="global-header-navigator-tab" @click="toAuth"><span class="global-header-navigator-tab-text">登录[临]</span></div>
       <div class="global-header-navigator-tab"><span class="global-header-navigator-tab-text">...</span></div>
     </div>
     <div id="global-header-icon">
@@ -59,9 +58,6 @@ export default {
     toHome() {
       this.$router.push("/home");
     },
-    toAuth() {
-      this.$router.push("/auth");
-    },
   },
 };
 </script>

+ 22 - 5
src/router/index.js

@@ -1,21 +1,24 @@
 import { createRouter, createWebHistory } from "vue-router";
-import PortalPage from "@/views/PortalPage/PortalPage";
+import AuthPage from "@/views/AuthPage/AuthPage";
+import store from "@/store";
+import { ElMessage } from "element-plus";
+
 
 const routes = [
   {
     path: "/",
-    redirect: "/portal",
+    redirect: "/auth",
   },
   {
     path: "/portal",
     name: "Portal",
-    // 落地页同步加载
-    component: PortalPage,
+    component: () => import("../views/PortalPage/PortalPage.vue"),
   },
   {
     path: "/auth",
     name: "Auth",
-    component: () => import("../views/AuthPage/AuthPage.vue"),
+    // 落地页同步加载
+    component: AuthPage,
   },
   {
     path: "/task",
@@ -60,4 +63,18 @@ const router = createRouter({
   routes,
 });
 
+router.beforeEach((to, from, next) => {
+  if (to.name !== "Auth" && !store.state.user.token) {
+    ElMessage({
+      showClose: true,
+      message: "请先登录",
+      type: "warning",
+      duration: 1000,
+    });
+    next({ name: "Auth" });
+  } else {
+    next();
+  }
+});
+
 export default router;

+ 5 - 1
src/views/AuthPage/components/AuthCard.vue

@@ -323,7 +323,8 @@ export default {
                     this.$message({
                       showClose: true,
                       message: "登录成功",
-                      type: "success"
+                      type: "success",
+                      duration: 1000,
                     });
                     setTimeout(() => {
                       this.$router.push("/portal");
@@ -459,6 +460,9 @@ export default {
 
     handleSlideVerifier(verifyStatus) {
       this.cardVerified = verifyStatus;
+      if (localStorage.password && localStorage.phone && this.rememberPassword && this.cardVerified) {
+        this.handleLogin();
+      }
     },
     shakeElem(elemId) {
       let elem = document.getElementById(elemId);