Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-layout): fix alway sometime show plugin-layout error #11776

Merged
merged 4 commits into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions packages/plugins/src/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -251,7 +254,7 @@ const { formatMessage } = useIntl();
<ProLayout
route={route}
location={location}
title={userConfig.title || 'plugin-layout'}
title={userConfig.title || '${packageName}'}
navTheme="dark"
siderWidth={256}
onMenuHeaderClick={(e) => {
Expand Down Expand Up @@ -470,21 +473,28 @@ export function getRightRenderContent (opts: {
);
}


const avatar = (
<span className="umi-plugin-layout-action">
<Avatar
size="small"
className="umi-plugin-layout-avatar"
src={
opts.initialState?.avatar ||
'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png'
}
alt="avatar"
/>
<span className="umi-plugin-layout-name">{opts.initialState?.name}</span>
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 ? (
<span className="umi-plugin-layout-action">
{!disableAvatarImg ?
(
<Avatar
size="small"
className="umi-plugin-layout-avatar"
src={
opts.initialState?.avatar ||
"https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png"
}
alt="avatar"
/>
) : null}
<span className={nameClassName}>{opts.initialState?.name}</span>
</span>
);
) : null;


if (opts.loading) {
return (
Expand All @@ -494,6 +504,11 @@ export function getRightRenderContent (opts: {
);
}

// 如果没有打开Locale,并且头像为空就取消掉这个返回的内容
{{^Locale}}
if(!avatar) return null;
{{/Locale}}

const langMenu = {
className: "umi-plugin-layout-menu",
selectedKeys: [],
Expand Down Expand Up @@ -533,6 +548,7 @@ export function getRightRenderContent (opts: {
}



return (
<div className="umi-plugin-layout-right anticon">
{opts.runtimeConfig.logout ? (
Expand Down Expand Up @@ -617,6 +633,9 @@ ${
.umi-plugin-layout-name {
margin-left: 8px;
}
.umi-plugin-layout-name.umi-plugin-layout-hide-avatar-img {
margin-left: 0;
}
`,
});

Expand Down
Loading