initial commit
This commit is contained in:
54
src/app.ts
Normal file
54
src/app.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
// 运行时配置
|
||||
import * as AntdIcons from '@ant-design/icons';
|
||||
import React from 'react';
|
||||
|
||||
type MenuItem = {
|
||||
icon?: string | React.ReactNode;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
type AntdIconComponent = React.ComponentType;
|
||||
|
||||
// 临时屏蔽 React findDOMNode 警告,通常来自第三方库
|
||||
const originalWarn = console.error;
|
||||
console.error = (...args: Parameters<typeof console.error>) => {
|
||||
if (
|
||||
typeof args[0] === 'string' &&
|
||||
args[0].includes('findDOMNode is deprecated')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
originalWarn(...args);
|
||||
};
|
||||
|
||||
// 全局初始化数据配置,用于 Layout 用户信息和权限初始化
|
||||
// 更多信息见文档:https://umijs.org/docs/api/runtime-config#getinitialstate
|
||||
export async function getInitialState(): Promise<{ name: string }> {
|
||||
return { name: '@umijs/max' };
|
||||
}
|
||||
|
||||
export const layout = () => {
|
||||
return {
|
||||
logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
|
||||
menuDataRender: (menuData: MenuItem[]) => {
|
||||
return menuData.map((item) => {
|
||||
const iconName = typeof item.icon === 'string' ? item.icon : undefined;
|
||||
const isIconName = iconName
|
||||
? /(Outlined|Filled|TwoTone)$/.test(iconName)
|
||||
: false;
|
||||
const IconComponent = isIconName
|
||||
? (AntdIcons[iconName as keyof typeof AntdIcons] as AntdIconComponent)
|
||||
: undefined;
|
||||
return {
|
||||
...item,
|
||||
icon: IconComponent ? React.createElement(IconComponent) : item.icon,
|
||||
};
|
||||
});
|
||||
},
|
||||
token: {
|
||||
layout: {
|
||||
bgLayout: 'none', // Remove gradients and glows
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user