Skip to content

Commit

Permalink
fix(projects): fix login success message [修复登录成功的消息提示]
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Nov 18, 2022
1 parent f2b580f commit 810398a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
12 changes: 8 additions & 4 deletions src/store/modules/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unref } from 'vue';
import { unref, nextTick } from 'vue';
import { defineStore } from 'pinia';
import { router } from '@/router';
import { fetchLogin, fetchUserInfo } from '@/service';
Expand Down Expand Up @@ -40,12 +40,14 @@ export const useAuthStore = defineStore('auth-store', {
clearAuthStorage();
this.$reset();

resetTabStore();
resetRouteStore();

if (route.meta.requiresAuth) {
toLogin();
}

nextTick(() => {
resetTabStore();
resetRouteStore();
});
},
/**
* 处理登录后成功或失败的逻辑
Expand All @@ -58,6 +60,8 @@ export const useAuthStore = defineStore('auth-store', {
const loginSuccess = await this.loginByToken(backendToken);

if (loginSuccess) {
await route.initAuthRoute();

// 跳转登录后的地址
toLoginRedirect();

Expand Down
21 changes: 8 additions & 13 deletions src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ interface RouteState {
authRouteMode: ImportMetaEnv['VITE_AUTH_ROUTE_MODE'];
/** 是否初始化了权限路由 */
isInitAuthRoute: boolean;
/** 动态路由是否初始化失败 */
failedInitDynamicRoute: boolean;
/** 路由首页name(前端静态路由时生效,后端动态路由该值会被后端返回的值覆盖) */
routeHomeName: AuthRoute.AllRouteKey;
/** 菜单 */
Expand All @@ -41,7 +39,6 @@ export const useRouteStore = defineStore('route-store', {
state: (): RouteState => ({
authRouteMode: import.meta.env.VITE_AUTH_ROUTE_MODE,
isInitAuthRoute: false,
failedInitDynamicRoute: false,
routeHomeName: transformRoutePathToRouteName(import.meta.env.VITE_ROUTE_HOME_PATH),
menus: [],
searchMenus: [],
Expand Down Expand Up @@ -109,6 +106,8 @@ export const useRouteStore = defineStore('route-store', {
},
/** 初始化动态路由 */
async initDynamicRoute() {
const { initHomeTab } = useTabStore();

const { userId } = localStg.get('userInfo') || {};

if (!userId) {
Expand All @@ -121,30 +120,26 @@ export const useRouteStore = defineStore('route-store', {
this.routeHomeName = data.home;
this.handleUpdateRootRedirect(data.home);
this.handleAuthRoute(data.routes);
} else {
this.failedInitDynamicRoute = true;

initHomeTab(data.home, router);

this.isInitAuthRoute = true;
}
},
/** 初始化静态路由 */
async initStaticRoute() {
const auth = useAuthStore();
const routes = filterAuthRoutesByUserPermission(staticRoutes, auth.userInfo.userRole);
this.handleAuthRoute(routes);
this.isInitAuthRoute = true;
},
/** 初始化权限路由 */
async initAuthRoute() {
const { initHomeTab } = useTabStore();

const isDynamicRoute = this.authRouteMode === 'dynamic';
if (isDynamicRoute) {
if (this.authRouteMode === 'dynamic') {
await this.initDynamicRoute();
} else {
await this.initStaticRoute();
}

initHomeTab(this.routeHomeName, router);

this.isInitAuthRoute = !this.failedInitDynamicRoute;
}
}
});

1 comment on commit 810398a

@vercel
Copy link

@vercel vercel bot commented on 810398a Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.