feat: request && login && router【e6939e22】(不包括 login.vue 和 request.ts)
This commit is contained in:
@@ -85,7 +85,7 @@ export const useAccessStore = defineStore('core-access', {
|
||||
},
|
||||
persist: {
|
||||
// 持久化
|
||||
pick: ['accessToken', 'refreshToken', 'accessCodes'],
|
||||
pick: ['accessToken', 'refreshToken', 'accessCodes'], // TODO @芋艿:accessCodes 不持久化
|
||||
},
|
||||
state: (): AccessState => ({
|
||||
accessCodes: [],
|
||||
|
||||
@@ -11,7 +11,7 @@ interface BasicUserInfo {
|
||||
*/
|
||||
realName: string;
|
||||
/**
|
||||
* 用户角色
|
||||
* 用户角色(TODO 已废弃,add by 芋艿)
|
||||
*/
|
||||
roles?: string[];
|
||||
/**
|
||||
|
||||
@@ -1,20 +1,43 @@
|
||||
import type { BasicUserInfo } from '@vben-core/typings';
|
||||
import type { RouteMeta, RouteRecordRaw } from 'vue-router';
|
||||
|
||||
/** 用户信息 */
|
||||
interface UserInfo extends BasicUserInfo {
|
||||
/**
|
||||
* 用户描述
|
||||
*/
|
||||
desc: string;
|
||||
|
||||
/**
|
||||
* 首页地址
|
||||
*/
|
||||
homePath: string;
|
||||
|
||||
/**
|
||||
* accessToken
|
||||
*/
|
||||
token: string;
|
||||
}
|
||||
|
||||
export type { UserInfo };
|
||||
/** 权限信息 */
|
||||
interface AuthPermissionInfo {
|
||||
|
||||
user: UserInfo;
|
||||
roles: string[];
|
||||
permissions: string[];
|
||||
menus: AppRouteRecordRaw[];
|
||||
|
||||
}
|
||||
|
||||
/** 路由元信息 */
|
||||
interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
|
||||
|
||||
children?: AppRouteRecordRaw[];
|
||||
component?: any;
|
||||
componentName?: string;
|
||||
components?: any;
|
||||
fullPath?: string;
|
||||
icon?: string;
|
||||
keepAlive?: boolean;
|
||||
meta: RouteMeta;
|
||||
name: string;
|
||||
parentId?: number;
|
||||
props?: any;
|
||||
sort?: number;
|
||||
visible?: boolean;
|
||||
|
||||
}
|
||||
|
||||
export type { UserInfo, AuthPermissionInfo, AppRouteRecordRaw };
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import type { Router, RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import type { ExRouteRecordRaw, MenuRecordRaw } from '@vben-core/typings';
|
||||
import type { ExRouteRecordRaw, MenuRecordRaw, RouteRecordStringComponent } from '@vben-core/typings';
|
||||
|
||||
import { filterTree, mapTree } from '@vben-core/shared/utils';
|
||||
import { filterTree, mapTree, isHttpUrl } from '@vben-core/shared/utils';
|
||||
import type { AppRouteRecordRaw } from '@vben/types'; // TODO @芋艿:这里的报错,解决
|
||||
|
||||
/**
|
||||
* 根据 routes 生成菜单列表
|
||||
@@ -78,4 +79,76 @@ async function generateMenus(
|
||||
return finalMenus;
|
||||
}
|
||||
|
||||
export { generateMenus };
|
||||
/**
|
||||
* 转换后端菜单数据为路由数据
|
||||
* @param menuList 后端菜单数据
|
||||
* @param parent 父级菜单
|
||||
* @returns 路由数据
|
||||
*/
|
||||
function convertServerMenuToRouteRecordStringComponent(
|
||||
menuList: AppRouteRecordRaw[],
|
||||
parent = '',
|
||||
): RouteRecordStringComponent[] {
|
||||
const menus: RouteRecordStringComponent[] = [];
|
||||
menuList.forEach((menu) => {
|
||||
// 处理顶级链接菜单
|
||||
if (isHttpUrl(menu.path) && menu.parentId === 0) {
|
||||
const urlMenu: RouteRecordStringComponent = {
|
||||
component: 'IFrameView',
|
||||
meta: {
|
||||
hideInMenu: !menu.visible,
|
||||
icon: menu.icon,
|
||||
link: menu.path,
|
||||
orderNo: menu.sort,
|
||||
title: menu.name,
|
||||
},
|
||||
name: menu.name,
|
||||
path: `/${menu.path}/index`,
|
||||
};
|
||||
menus.push(urlMenu);
|
||||
return;
|
||||
} else if (menu.children && menu.parentId === 0) {
|
||||
menu.component = 'BasicLayout';
|
||||
} else if (!menu.children) {
|
||||
menu.component = menu.component as string;
|
||||
}
|
||||
if (menu.component === 'Layout') {
|
||||
menu.component = 'BasicLayout';
|
||||
}
|
||||
|
||||
if (menu.children && menu.parentId !== 0) {
|
||||
menu.component = '';
|
||||
}
|
||||
|
||||
// path
|
||||
if (parent) {
|
||||
menu.path = `${parent}/${menu.path}`;
|
||||
}
|
||||
|
||||
if (!menu.path.startsWith('/')) {
|
||||
menu.path = `/${menu.path}`;
|
||||
}
|
||||
|
||||
const buildMenu: RouteRecordStringComponent = {
|
||||
component: menu.component,
|
||||
meta: {
|
||||
hideInMenu: !menu.visible,
|
||||
icon: menu.icon,
|
||||
keepAlive: menu.keepAlive,
|
||||
orderNo: menu.sort,
|
||||
title: menu.name,
|
||||
},
|
||||
name: menu.name,
|
||||
path: menu.path,
|
||||
};
|
||||
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
buildMenu.children = convertServerMenuToRouteRecordStringComponent(menu.children, menu.path);
|
||||
}
|
||||
|
||||
menus.push(buildMenu);
|
||||
});
|
||||
return menus;
|
||||
}
|
||||
|
||||
export { generateMenus, convertServerMenuToRouteRecordStringComponent };
|
||||
|
||||
@@ -30,7 +30,8 @@ async function generateRoutesByBackend(
|
||||
|
||||
const routes = convertRoutes(menuRoutes, layoutMap, normalizePageMap);
|
||||
|
||||
return routes;
|
||||
// add by 芋艿:合并静态路由和动态路由
|
||||
return [...options.routes, ...routes];
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return [];
|
||||
|
||||
Reference in New Issue
Block a user