Skip to content

Commit

Permalink
fix(projects): 修复未登录时会调用获取用户路由的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jan 22, 2022
1 parent 4f9d544 commit 21bab1f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/service/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function fetchUserInfo() {
* @param userId - 用户id
* @description 后端根据用户id查询到对应的角色类型,并将路由筛选出对应角色的路由数据返回前端
*/
export function fetchUserRoutes(userId: string = 'soybean') {
export function fetchUserRoutes(userId: string) {
return mockRequest.post<ApiRoute.Route>('/getUserRoutes', { userId });
}

Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/route/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Router } from 'vue-router';
import { defineStore } from 'pinia';
import { fetchUserRoutes } from '@/service';
import { transformAuthRouteToMenu, transformAuthRoutesToVueRoutes, getCacheRoutes } from '@/utils';
import { getUserInfo, transformAuthRouteToMenu, transformAuthRoutesToVueRoutes, getCacheRoutes } from '@/utils';
import type { GlobalMenuOption } from '@/interface';
import { useTabStore } from '../tab';

Expand Down Expand Up @@ -31,7 +31,9 @@ export const useRouteStore = defineStore('route-store', {
async initDynamicRoute(router: Router) {
const { initHomeTab } = useTabStore();

const { data } = await fetchUserRoutes();
const { userId } = getUserInfo();
if (!userId) return;
const { data } = await fetchUserRoutes(userId);
if (data) {
this.routeHomeName = data.home;
this.menus = transformAuthRouteToMenu(data.routes);
Expand Down

0 comments on commit 21bab1f

Please sign in to comment.