chore: user apikeys
This commit is contained in:
+12
-10
@@ -1,5 +1,6 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import { logout } from '@/pages/login/apis';
|
||||
import { useAccessMarkedRoutes } from '@@/plugin-access';
|
||||
import { useModel } from '@@/plugin-model';
|
||||
import { ProLayout } from '@ant-design/pro-components';
|
||||
@@ -106,18 +107,19 @@ export default (props: any) => {
|
||||
// });
|
||||
const runtimeConfig = {
|
||||
...initialInfo,
|
||||
logout: () => {
|
||||
console.log('logout');
|
||||
logout: async (userInfo) => {
|
||||
console.log('logout', userInfo);
|
||||
await logout();
|
||||
navigate(loginPath);
|
||||
},
|
||||
notFound: <div>not found</div>
|
||||
notFound: <span>404 not found</span>
|
||||
};
|
||||
console.log(
|
||||
'clientRoute==========2=',
|
||||
console.log('clientRoute==========2=', {
|
||||
props,
|
||||
clientRoutes,
|
||||
runtimeConfig,
|
||||
initialInfo
|
||||
);
|
||||
});
|
||||
|
||||
// 现在的 layout 及 wrapper 实现是通过父路由的形式实现的, 会导致路由数据多了冗余层级, proLayout 消费时, 无法正确展示菜单, 这里对冗余数据进行过滤操作
|
||||
const newRoutes = filterRoutes(
|
||||
@@ -153,12 +155,12 @@ export default (props: any) => {
|
||||
navigate('/');
|
||||
}}
|
||||
onPageChange={(route) => {
|
||||
console.log('onRouteChange', route);
|
||||
console.log('onRouteChange', initialState, route);
|
||||
const { location } = history;
|
||||
// 如果没有登录,重定向到 login
|
||||
// if (!initialState?.currentUser && location.pathname !== loginPath) {
|
||||
// history.push(loginPath);
|
||||
// }
|
||||
if (!initialState?.currentUser && location.pathname !== loginPath) {
|
||||
history.push(loginPath);
|
||||
}
|
||||
}}
|
||||
formatMessage={userConfig.formatMessage || formatMessage}
|
||||
menu={{ locale: userConfig.locale }}
|
||||
|
||||
+23
-25
@@ -4,10 +4,9 @@ import avatarImg from '@/assets/images/avatar.png';
|
||||
import {
|
||||
GlobalOutlined,
|
||||
LogoutOutlined,
|
||||
SettingOutlined,
|
||||
SunOutlined
|
||||
SettingOutlined
|
||||
} from '@ant-design/icons';
|
||||
import { useNavigate } from '@umijs/max';
|
||||
import { history } from '@umijs/max';
|
||||
import { Avatar, Dropdown, Menu, Spin, version } from 'antd';
|
||||
|
||||
export function getRightRenderContent(opts: {
|
||||
@@ -26,10 +25,10 @@ export function getRightRenderContent(opts: {
|
||||
}
|
||||
|
||||
const showAvatar =
|
||||
opts.initialState?.avatar ||
|
||||
opts.initialState?.name ||
|
||||
opts.initialState?.currentUser?.avatar ||
|
||||
opts.initialState?.currentUser?.username ||
|
||||
opts.runtimeConfig.logout;
|
||||
const disableAvatarImg = opts.initialState?.avatar === false;
|
||||
const disableAvatarImg = opts.initialState?.currentUser?.avatar === false;
|
||||
const nameClassName = disableAvatarImg
|
||||
? 'umi-plugin-layout-name umi-plugin-layout-hide-avatar-img'
|
||||
: 'umi-plugin-layout-name';
|
||||
@@ -39,11 +38,13 @@ export function getRightRenderContent(opts: {
|
||||
<Avatar
|
||||
size="small"
|
||||
className="umi-plugin-layout-avatar"
|
||||
src={opts.initialState?.avatar || avatarImg}
|
||||
src={opts.initialState?.currentUser?.avatar || avatarImg}
|
||||
alt="avatar"
|
||||
/>
|
||||
) : null}
|
||||
<span className={nameClassName}>{opts.initialState?.name}</span>
|
||||
<span className={nameClassName}>
|
||||
{opts.initialState?.currentUser?.username}
|
||||
</span>
|
||||
</span>
|
||||
) : null;
|
||||
|
||||
@@ -58,8 +59,6 @@ export function getRightRenderContent(opts: {
|
||||
// 如果没有打开Locale,并且头像为空就取消掉这个返回的内容
|
||||
if (!avatar) return null;
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const langMenu = {
|
||||
className: 'umi-plugin-layout-menu',
|
||||
selectedKeys: [],
|
||||
@@ -73,21 +72,21 @@ export function getRightRenderContent(opts: {
|
||||
</>
|
||||
),
|
||||
onClick: () => {
|
||||
navigate('/profile');
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'theme',
|
||||
label: (
|
||||
<>
|
||||
<SunOutlined />
|
||||
外观
|
||||
</>
|
||||
),
|
||||
onClick: () => {
|
||||
console.log('theme');
|
||||
history.push('/profile');
|
||||
}
|
||||
},
|
||||
// {
|
||||
// key: 'theme',
|
||||
// label: (
|
||||
// <>
|
||||
// <SunOutlined />
|
||||
// 外观
|
||||
// </>
|
||||
// ),
|
||||
// onClick: () => {
|
||||
// console.log('theme');
|
||||
// }
|
||||
// },
|
||||
{
|
||||
key: 'lang',
|
||||
label: (
|
||||
@@ -109,14 +108,13 @@ export function getRightRenderContent(opts: {
|
||||
</>
|
||||
),
|
||||
onClick: () => {
|
||||
opts?.runtimeConfig?.logout?.(opts.initialState);
|
||||
opts?.runtimeConfig?.logout?.(opts.initialState.currentUser);
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
// antd@5 和 4.24 之后推荐使用 menu,性能更好
|
||||
|
||||
console.log('version+++++++++=', opts.runtimeConfig, version);
|
||||
let dropdownProps;
|
||||
if (version.startsWith('5.') || version.startsWith('4.24.')) {
|
||||
dropdownProps = { menu: langMenu };
|
||||
|
||||
Reference in New Issue
Block a user