// @ts-nocheck
import avatarImg from '@/assets/images/avatar.png';
import {
GlobalOutlined,
LogoutOutlined,
SettingOutlined
} from '@ant-design/icons';
import { SelectLang, history } from '@umijs/max';
import { Avatar, Dropdown, Menu, Spin, version } from 'antd';
export function getRightRenderContent(opts: {
runtimeConfig: any;
loading: boolean;
initialState: any;
setInitialState: any;
}) {
console.log('runtimeConfig==', opts.runtimeConfig, opts);
// const intl = useIntl();
if (opts.runtimeConfig.rightRender) {
return opts.runtimeConfig.rightRender(
opts.initialState,
opts.setInitialState,
opts.runtimeConfig
);
}
const showAvatar =
opts.initialState?.currentUser?.avatar ||
opts.initialState?.currentUser?.username ||
opts.runtimeConfig.logout;
const disableAvatarImg = opts.initialState?.currentUser?.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?.currentUser?.username}
) : null;
if (opts.loading) {
return (
);
}
const renderExtraActions = () => {
return (
{/* {FormattedMessage({ id: 'common.settings.language' })} */}
Language
}
>
);
};
// 如果没有打开Locale,并且头像为空就取消掉这个返回的内容
if (!avatar) return null;
const langMenu = {
className: 'umi-plugin-layout-menu',
selectedKeys: [],
items: [
{
key: 'settings',
label: (
<>
{/* {intl.formatMessage({ id: 'common.button.settings' })} */}
Settings
>
),
onClick: () => {
history.push('/profile');
}
},
// {
// key: 'theme',
// label: (
// <>
//
// 外观
// >
// ),
// onClick: () => {
// console.log('theme');
// }
// },
{
key: 'logout',
label: (
<>
{/* {intl.formatMessage({ id: 'common.button.logout' })} */}
Logout
>
),
onClick: () => {
opts?.runtimeConfig?.logout?.(opts.initialState.currentUser);
}
}
]
};
// antd@5 和 4.24 之后推荐使用 menu,性能更好
let dropdownProps;
if (version.startsWith('5.') || version.startsWith('4.24.')) {
dropdownProps = { menu: langMenu };
} else if (version.startsWith('3.')) {
dropdownProps = {
overlay: (
)
};
} else {
// 需要 antd 4.20.0 以上版本
dropdownProps = { overlay: };
}
return (
{renderExtraActions()}
{opts.runtimeConfig.logout ? (
<>
{avatar}
>
) : (
avatar
)}
);
}