fix(projects): fix login success message [修复登录成功的消息提示]
This commit is contained in:
parent
f2b580fc06
commit
810398abb8
@ -1,4 +1,4 @@
|
|||||||
import { unref } from 'vue';
|
import { unref, nextTick } from 'vue';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { router } from '@/router';
|
import { router } from '@/router';
|
||||||
import { fetchLogin, fetchUserInfo } from '@/service';
|
import { fetchLogin, fetchUserInfo } from '@/service';
|
||||||
@ -40,12 +40,14 @@ export const useAuthStore = defineStore('auth-store', {
|
|||||||
clearAuthStorage();
|
clearAuthStorage();
|
||||||
this.$reset();
|
this.$reset();
|
||||||
|
|
||||||
resetTabStore();
|
|
||||||
resetRouteStore();
|
|
||||||
|
|
||||||
if (route.meta.requiresAuth) {
|
if (route.meta.requiresAuth) {
|
||||||
toLogin();
|
toLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
resetTabStore();
|
||||||
|
resetRouteStore();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 处理登录后成功或失败的逻辑
|
* 处理登录后成功或失败的逻辑
|
||||||
@ -58,6 +60,8 @@ export const useAuthStore = defineStore('auth-store', {
|
|||||||
const loginSuccess = await this.loginByToken(backendToken);
|
const loginSuccess = await this.loginByToken(backendToken);
|
||||||
|
|
||||||
if (loginSuccess) {
|
if (loginSuccess) {
|
||||||
|
await route.initAuthRoute();
|
||||||
|
|
||||||
// 跳转登录后的地址
|
// 跳转登录后的地址
|
||||||
toLoginRedirect();
|
toLoginRedirect();
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ interface RouteState {
|
|||||||
authRouteMode: ImportMetaEnv['VITE_AUTH_ROUTE_MODE'];
|
authRouteMode: ImportMetaEnv['VITE_AUTH_ROUTE_MODE'];
|
||||||
/** 是否初始化了权限路由 */
|
/** 是否初始化了权限路由 */
|
||||||
isInitAuthRoute: boolean;
|
isInitAuthRoute: boolean;
|
||||||
/** 动态路由是否初始化失败 */
|
|
||||||
failedInitDynamicRoute: boolean;
|
|
||||||
/** 路由首页name(前端静态路由时生效,后端动态路由该值会被后端返回的值覆盖) */
|
/** 路由首页name(前端静态路由时生效,后端动态路由该值会被后端返回的值覆盖) */
|
||||||
routeHomeName: AuthRoute.AllRouteKey;
|
routeHomeName: AuthRoute.AllRouteKey;
|
||||||
/** 菜单 */
|
/** 菜单 */
|
||||||
@ -41,7 +39,6 @@ export const useRouteStore = defineStore('route-store', {
|
|||||||
state: (): RouteState => ({
|
state: (): RouteState => ({
|
||||||
authRouteMode: import.meta.env.VITE_AUTH_ROUTE_MODE,
|
authRouteMode: import.meta.env.VITE_AUTH_ROUTE_MODE,
|
||||||
isInitAuthRoute: false,
|
isInitAuthRoute: false,
|
||||||
failedInitDynamicRoute: false,
|
|
||||||
routeHomeName: transformRoutePathToRouteName(import.meta.env.VITE_ROUTE_HOME_PATH),
|
routeHomeName: transformRoutePathToRouteName(import.meta.env.VITE_ROUTE_HOME_PATH),
|
||||||
menus: [],
|
menus: [],
|
||||||
searchMenus: [],
|
searchMenus: [],
|
||||||
@ -109,6 +106,8 @@ export const useRouteStore = defineStore('route-store', {
|
|||||||
},
|
},
|
||||||
/** 初始化动态路由 */
|
/** 初始化动态路由 */
|
||||||
async initDynamicRoute() {
|
async initDynamicRoute() {
|
||||||
|
const { initHomeTab } = useTabStore();
|
||||||
|
|
||||||
const { userId } = localStg.get('userInfo') || {};
|
const { userId } = localStg.get('userInfo') || {};
|
||||||
|
|
||||||
if (!userId) {
|
if (!userId) {
|
||||||
@ -121,8 +120,10 @@ export const useRouteStore = defineStore('route-store', {
|
|||||||
this.routeHomeName = data.home;
|
this.routeHomeName = data.home;
|
||||||
this.handleUpdateRootRedirect(data.home);
|
this.handleUpdateRootRedirect(data.home);
|
||||||
this.handleAuthRoute(data.routes);
|
this.handleAuthRoute(data.routes);
|
||||||
} else {
|
|
||||||
this.failedInitDynamicRoute = true;
|
initHomeTab(data.home, router);
|
||||||
|
|
||||||
|
this.isInitAuthRoute = true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/** 初始化静态路由 */
|
/** 初始化静态路由 */
|
||||||
@ -130,21 +131,15 @@ export const useRouteStore = defineStore('route-store', {
|
|||||||
const auth = useAuthStore();
|
const auth = useAuthStore();
|
||||||
const routes = filterAuthRoutesByUserPermission(staticRoutes, auth.userInfo.userRole);
|
const routes = filterAuthRoutesByUserPermission(staticRoutes, auth.userInfo.userRole);
|
||||||
this.handleAuthRoute(routes);
|
this.handleAuthRoute(routes);
|
||||||
|
this.isInitAuthRoute = true;
|
||||||
},
|
},
|
||||||
/** 初始化权限路由 */
|
/** 初始化权限路由 */
|
||||||
async initAuthRoute() {
|
async initAuthRoute() {
|
||||||
const { initHomeTab } = useTabStore();
|
if (this.authRouteMode === 'dynamic') {
|
||||||
|
|
||||||
const isDynamicRoute = this.authRouteMode === 'dynamic';
|
|
||||||
if (isDynamicRoute) {
|
|
||||||
await this.initDynamicRoute();
|
await this.initDynamicRoute();
|
||||||
} else {
|
} else {
|
||||||
await this.initStaticRoute();
|
await this.initStaticRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
initHomeTab(this.routeHomeName, router);
|
|
||||||
|
|
||||||
this.isInitAuthRoute = !this.failedInitDynamicRoute;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user