diff --git a/packages/plugins/src/layout.ts b/packages/plugins/src/layout.ts index 796dd20b8dd0..736d8cd9c610 100644 --- a/packages/plugins/src/layout.ts +++ b/packages/plugins/src/layout.ts @@ -38,6 +38,9 @@ export default (api: IApi) => { }) || dirname(require.resolve('antd/package.json')); antdVersion = require(`${pkgPath}/package.json`).version; } catch (e) {} + + const packageName = api.pkg.name || 'plugin-layout'; + const isAntd5 = antdVersion.startsWith('5'); const layoutFile = isAntd5 ? 'Layout.css' : 'Layout.less'; @@ -251,7 +254,7 @@ const { formatMessage } = useIntl(); { @@ -470,21 +473,28 @@ export function getRightRenderContent (opts: { ); } - - const avatar = ( - - - {opts.initialState?.name} + const showAvatar = opts.initialState?.avatar || opts.initialState?.name || opts.runtimeConfig.logout; + const disableAvatarImg = opts.initialState?.avatar === false; + const nameClassName = disableAvatarImg ? 'umi-plugin-layout-name umi-plugin-layout-hide-avatar-img' : 'umi-plugin-layout-name'; + const avatar = + showAvatar ? ( + + {!disableAvatarImg ? + ( + + ) : null} + {opts.initialState?.name} - ); + ) : null; + if (opts.loading) { return ( @@ -494,6 +504,11 @@ export function getRightRenderContent (opts: { ); } + // 如果没有打开Locale,并且头像为空就取消掉这个返回的内容 + {{^Locale}} + if(!avatar) return null; + {{/Locale}} + const langMenu = { className: "umi-plugin-layout-menu", selectedKeys: [], @@ -533,6 +548,7 @@ export function getRightRenderContent (opts: { } + return (
{opts.runtimeConfig.logout ? ( @@ -617,6 +633,9 @@ ${ .umi-plugin-layout-name { margin-left: 8px; } +.umi-plugin-layout-name.umi-plugin-layout-hide-avatar-img { + margin-left: 0; +} `, });