From 3f34d376d35e0fefa3432b0203417a6f90ed3444 Mon Sep 17 00:00:00 2001 From: 13404089107 <puwei@sinata.cn> Date: 星期二, 25 二月 2025 09:00:17 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/H5/threeSide --- management/src/components/RightContent/AvatarDropdown.tsx | 134 ++++++-------------------------------------- 1 files changed, 20 insertions(+), 114 deletions(-) diff --git a/management/src/components/RightContent/AvatarDropdown.tsx b/management/src/components/RightContent/AvatarDropdown.tsx index 1d419ab..2d09633 100644 --- a/management/src/components/RightContent/AvatarDropdown.tsx +++ b/management/src/components/RightContent/AvatarDropdown.tsx @@ -1,13 +1,9 @@ -import { outLogin } from '@/services/ant-design-pro/api'; -import { LogoutOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons'; -import { useEmotionCss } from '@ant-design/use-emotion-css'; -import { history, useModel } from '@umijs/max'; -import { Spin } from 'antd'; -import { stringify } from 'querystring'; -import type { MenuInfo } from 'rc-menu/lib/interface'; -import React, { useCallback } from 'react'; +import { outLogin } from './service'; +import { LogoutOutlined } from '@ant-design/icons'; +import { useModel } from '@umijs/max'; +import React from 'react'; import { flushSync } from 'react-dom'; -import HeaderDropdown from '../HeaderDropdown'; +import './style.less'; export type GlobalHeaderRightProps = { menu?: boolean; @@ -17,120 +13,30 @@ export const AvatarName = () => { const { initialState } = useModel('@@initialState'); // - + const { currentUser } = initialState || {}; return <span className="anticon">{currentUser?.userName || '超级管理员'}</span>; }; export const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ menu, children }) => { - /** - * 退出登录,并且将当前的 url 保存 - */ - const loginOut = async () => { - // await outLogin(); - const { search, pathname } = window.location; - const urlParams = new URL(window.location.href).searchParams; - /** 此方法会跳转到 redirect 参数所在的位置 */ - const redirect = urlParams.get('redirect'); - // Note: There may be security issues, please note - if (window.location.pathname !== '/login' && !redirect) { - // history.replace({ - // pathname: '/login', - // search: stringify({ - // redirect: pathname + search, - // }), - // }); - } - }; - const actionClassName = useEmotionCss(({ token }) => { - return { - display: 'flex', - height: '48px', - marginLeft: 'auto', - overflow: 'hidden', - alignItems: 'center', - padding: '0 8px', - cursor: 'pointer', - borderRadius: token.borderRadius, - '&:hover': { - backgroundColor: token.colorBgTextHover, - }, - }; - }); + const { initialState, setInitialState } = useModel('@@initialState'); - const onMenuClick = useCallback( - (event: MenuInfo) => { - const { key } = event; - if (key === 'logout') { - localStorage.clear(); - flushSync(() => { - setInitialState((s) => ({ ...s, currentUser: undefined })); - }); - loginOut(); - return; - } - history.push(`/account/${key}`); - }, - [setInitialState], - ); - const loading = ( - <span className={actionClassName}> - <Spin - size="small" - style={{ - marginLeft: 8, - marginRight: 8, - }} - /> - </span> - ); + const onMenuClick = async () => { + await outLogin(); + localStorage.clear(); + flushSync(() => { + setInitialState((s) => ({ ...s, currentUser: undefined })); + }); - if (!initialState) { - return loading; } - const { currentUser } = initialState; - - if (!currentUser || !currentUser.userName) { - return loading; - } - - const menuItems = [ - ...(menu - ? [ - { - key: 'center', - icon: <UserOutlined />, - label: '个人中心', - }, - { - key: 'settings', - icon: <SettingOutlined />, - label: '个人设置', - }, - { - type: 'divider' as const, - }, - ] - : []), - { - key: 'logout', - icon: <LogoutOutlined />, - label: '退出登录', - }, - ]; - - return ( - <HeaderDropdown - menu={{ - selectedKeys: [], - onClick: onMenuClick, - items: menuItems, - }} - > - {children} - </HeaderDropdown> - ); + return <div style={{ display: 'flex', alignItems: 'center', color: '#000' }}> + <div className='unread' > + <div>未读提醒</div> + <div style={{ border: '1px solid red', borderRadius: '50%', width: '18px', lineHeight: '18px', marginLeft: '5px', textAlign: 'center', color: 'red' }}>1</div> + </div> + <div className="logoOut" onClick={onMenuClick}>退出登录<LogoutOutlined style={{ marginLeft: '5px' }} /></div> + </div> }; -- Gitblit v1.7.1