Browse Source

1.修改登录逻辑。2.路由改为历史模式。

jiaxiaoqiang 1 year ago
parent
commit
e058a8f1d2
3 changed files with 11 additions and 7 deletions
  1. 4 3
      src/layout/components/header.vue
  2. 5 2
      src/plugins/permission.ts
  3. 2 2
      src/router/index.ts

+ 4 - 3
src/layout/components/header.vue

@@ -58,8 +58,8 @@
               <el-dropdown-item command="b">退出登录</el-dropdown-item>
               <!--              <el-dropdown-item command="c" divided>Action 3</el-dropdown-item>-->
               <el-dropdown-item command="c"
-                >{{ notice ? "关闭" : "打开" }}触摸提示</el-dropdown-item
-              >
+                >{{ notice ? "关闭" : "打开" }}触摸提示
+              </el-dropdown-item>
             </el-dropdown-menu>
           </template>
         </el-dropdown>
@@ -130,7 +130,8 @@ const handleCommand = (command: string | number | object) => {
   if (command === "b") {
     logoutApi().then(() => {
       localStorage.setItem("token", "");
-      location.reload();
+      // location.reload();
+      router.replace("/login");
     });
   }
   if (command === "c") {

+ 5 - 2
src/plugins/permission.ts

@@ -2,6 +2,7 @@ import router from "@/router";
 import NProgress from "@/utils/nprogress";
 import { useDictionaryStore } from "@/store/modules/dictionary";
 import { getUserDicts } from "@/api/auth";
+
 export function setupPermission() {
   // 白名单路由
   const whiteList: string[] = ["client-traceability"]; //由于包含动态路由,这里面存储的是路由的name而不是path
@@ -23,8 +24,10 @@ export function setupPermission() {
     const hasToken = localStorage.getItem("token");
     if (hasToken) {
       if (to.path === "/login") {
-        // 如果已登录,跳转首页
-        next({ path: "/" });
+        // 如果已登录,跳转首页,并且清空token
+        localStorage.setItem("token", "");
+        next();
+        // next({ path: "/" });
         NProgress.done();
       } else {
         const dictStore = useDictionaryStore();

+ 2 - 2
src/router/index.ts

@@ -1,4 +1,4 @@
-import { createRouter, createWebHashHistory } from "vue-router";
+import { createRouter, createWebHistory } from "vue-router";
 
 const moduleFiles: any = import.meta.glob("./modules/*.ts", { eager: true });
 
@@ -23,7 +23,7 @@ const configRoutes = Object.keys(moduleFiles).reduce(
  * 创建路由
  */
 const router = createRouter({
-  history: createWebHashHistory(),
+  history: createWebHistory(),
   routes: configRoutes,
   // 刷新时,滚动条位置还原
   scrollBehavior: () => ({ left: 0, top: 0 }),