feat: 样本管理
This commit is contained in:
34
src/app.tsx
34
src/app.tsx
@@ -1,15 +1,9 @@
|
||||
import type { Settings as LayoutSettings } from '@ant-design/pro-components';
|
||||
import { SettingDrawer } from '@ant-design/pro-components';
|
||||
import type { RequestConfig, RunTimeLayoutConfig } from '@umijs/max';
|
||||
import { history, Link, Navigate } from '@umijs/max';
|
||||
import { Modal, Spin } from 'antd';
|
||||
import React, {
|
||||
Children,
|
||||
Component,
|
||||
createContext,
|
||||
JSX,
|
||||
Suspense,
|
||||
} from 'react';
|
||||
import { history, Navigate } from '@umijs/max';
|
||||
import { Spin } from 'antd';
|
||||
import React from 'react';
|
||||
import {
|
||||
AvatarDropdown,
|
||||
AvatarName,
|
||||
@@ -18,17 +12,13 @@ import {
|
||||
SelectLang,
|
||||
} from '@/components';
|
||||
import { getInfo } from '@/services/login';
|
||||
import type { TokenType, UserInfoVO, UserVO } from '@/services/login/types';
|
||||
import type { UserInfoVO } from '@/services/login/types';
|
||||
import defaultSettings from '../config/defaultSettings';
|
||||
import { errorConfig } from './requestErrorConfig';
|
||||
import '@ant-design/v5-patch-for-react-19';
|
||||
import { getAccessToken, getRefreshToken, getTenantId } from '@/utils/auth';
|
||||
import {
|
||||
transformBackendMenuToFlatRoutes,
|
||||
transformMenuToRoutes,
|
||||
} from '@/utils/menuUtils';
|
||||
import { getAccessToken, getTenantId } from '@/utils/auth';
|
||||
|
||||
import { CACHE_KEY, useCache } from './hooks/web/useCache';
|
||||
import { MenuVO } from './services/system/menu';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const isDevOrTest = isDev || process.env.CI;
|
||||
@@ -198,7 +188,7 @@ export const request: RequestConfig = {
|
||||
};
|
||||
// 如果有token,则添加Authorization头
|
||||
if (token) {
|
||||
headers['Authorization'] = `Bearer ${getAccessToken()}`;
|
||||
headers.Authorization = `Bearer·${getAccessToken()}`;
|
||||
}
|
||||
return { url, options: { ...options, headers } };
|
||||
},
|
||||
@@ -235,20 +225,19 @@ export const request: RequestConfig = {
|
||||
// umi 4 使用 modifyRoutes
|
||||
export function patchClientRoutes({ routes }: { routes: any }) {
|
||||
const { wsCache } = useCache();
|
||||
console.log(2222);
|
||||
const globalMenus = wsCache.get(CACHE_KEY.ROLE_ROUTERS);
|
||||
const routerIndex = routes.findIndex((item: any) => item.path === '/');
|
||||
const parentId = routes[routerIndex].id;
|
||||
|
||||
if (globalMenus) {
|
||||
routes[routerIndex]['routes'].push(...loopMenuItem(globalMenus, parentId));
|
||||
routes[routerIndex].routes.push(...loopMenuItem(globalMenus, parentId));
|
||||
}
|
||||
}
|
||||
|
||||
const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
return menus.flatMap((item) => {
|
||||
let Component: React.ComponentType<any> | null = null;
|
||||
console.log(findFirstLeafRoute(item), 'item');
|
||||
// console.log(findFirstLeafRoute(item), 'item');
|
||||
if (item.component && item.component.length > 0) {
|
||||
// 防止配置了路由,但本地暂未添加对应的页面,产生的错误
|
||||
Component = React.lazy(() => {
|
||||
@@ -299,7 +288,7 @@ const loopMenuItem = (menus: any[], pId: number | string): any[] => {
|
||||
});
|
||||
};
|
||||
|
||||
const findFirstLeafRoute = (menuItem: any, parent = '/'): string | null => {
|
||||
const _findFirstLeafRoute = (menuItem: any, parent = '/'): string | null => {
|
||||
// 如果没有子菜单,返回当前路径
|
||||
|
||||
if (!menuItem.children || menuItem.children.length === 0) {
|
||||
@@ -308,7 +297,8 @@ const findFirstLeafRoute = (menuItem: any, parent = '/'): string | null => {
|
||||
|
||||
// 递归查找第一个叶子节点
|
||||
for (const child of menuItem.children) {
|
||||
const leafRoute = findFirstLeafRoute(child, menuItem.path + '/');
|
||||
// const leafRoute = findFirstLeafRoute(child, menuItem.path + "/");
|
||||
const leafRoute = _findFirstLeafRoute(child, `${menuItem.path}/`);
|
||||
if (leafRoute) {
|
||||
return leafRoute;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user