Преглед изворни кода

修复部分账号登录后路由跳转404

Yue пре 2 година
родитељ
комит
0ac964973a
3 измењених фајлова са 27 додато и 9 уклоњено
  1. 3 0
      src/stores/_auth.ts
  2. 23 8
      src/stores/_menu.ts
  3. 1 1
      src/views/account/SignIn.vue

+ 3 - 0
src/stores/_auth.ts

@@ -3,6 +3,7 @@ import { defineStore } from "pinia"
 import JwtService from "@/core/services/JwtService"
 import apis from "@/api"
 import storages from "@/core/utils/storages"
+import appStore from "."
 
 export interface User {
   userName: string
@@ -21,6 +22,7 @@ export const useAuthStore = defineStore("auth", () => {
     isAuthenticated.value = true
     errors.value = {}
     user.value = authUser
+    console.log("AUTHUSER", authUser)
     storages.setItem(USER_KEY, JSON.stringify(authUser))
     JwtService.saveToken(authUser.token)
   }
@@ -34,6 +36,7 @@ export const useAuthStore = defineStore("auth", () => {
     user.value = null
     errors.value = []
     storages.removeItem(USER_KEY)
+    appStore.menuStore.removeMenus()
     JwtService.destroyToken()
   }
 

+ 23 - 8
src/stores/_menu.ts

@@ -7,7 +7,11 @@ import { MenuRouteMaps } from "@/router/menuMap"
 import router, { to404 } from "@/router"
 import apis from "@/api"
 import configs from "@/core/config/Index"
-
+enum UserType {
+  System = "0",
+  ZhengFu = "1",
+  Company = "2",
+}
 export const useMenuStore = defineStore("meun", () => {
   const MENU_KEY = "fun_menu"
   let menuData: Array<FunctionMenu> = JSON.parse(Stroage.getItem(MENU_KEY) || "[]")
@@ -81,20 +85,20 @@ export const useMenuStore = defineStore("meun", () => {
   const formatterRoutes = (funs: Array<FunctionMenu>, withChild = true) => {
     //router.addRoute(configs.MAIN_ROUTER_NAME, homeRouter)
     if (funs && funs.length) {
-      funs.forEach((v) => {
-        formatterRouteItem(v, withChild)
-      })
+      for (let i = 0; i < funs.length; i++) {
+        formatterRouteItem(funs[i], withChild, i == 0)
+      }
     }
     router.addRoute(to404)
     //console.log("===========", router.getRoutes());
   }
-  const formatterRouteItem = (fun: FunctionMenu, withChild = true) => {
+  const formatterRouteItem = (fun: FunctionMenu, withChild = true, isFirst = false) => {
     const menu: MenuRouteMap | undefined = MenuRouteMaps.find((v) => v.path == fun.url)
     if (menu?.component == null) {
       if (withChild && fun.children && fun.children.length) {
-        fun.children.forEach((v) => {
-          formatterRouteItem(v)
-        })
+        for (let i = 0; i < fun.children.length; i++) {
+          formatterRouteItem(fun.children[i], withChild, i == 0 && isFirst)
+        }
       }
       return
     }
@@ -108,6 +112,17 @@ export const useMenuStore = defineStore("meun", () => {
         breadcrumbs: getBreadcrumbs(fun),
       },
     }
+
+    if (isFirst) {
+      //动态配置首页跳转路由 默认菜单第一项下的第一个页面
+      const mainRouter = router.getRoutes().find((v) => {
+        return v.name == configs.MAIN_ROUTER_NAME
+      })
+      //console.log("MR", mainRouter)
+      if (mainRouter) {
+        mainRouter.redirect = item.path
+      }
+    }
     routes.value.push(item)
 
     router.addRoute(configs.MAIN_ROUTER_NAME, item)

+ 1 - 1
src/views/account/SignIn.vue

@@ -49,7 +49,7 @@ const onSubmitLogin = async (values: any) => {
       // Go to page after successfully login
       //router.push({ name: "dashboard" })
       appStore.menuStore.reLoadMenus()?.then(() => {
-        let queryRedirectPath = "/DataBoard/index"
+        let queryRedirectPath = "/"
         if (router.currentRoute.value.redirectedFrom?.fullPath) {
           queryRedirectPath = router.currentRoute.value.redirectedFrom?.fullPath
         }