From 554f8096e1f384f14b9424f5142d63f90c72a3eb Mon Sep 17 00:00:00 2001
From: hejianhao <15708179461@qq.com>
Date: 星期一, 19 五月 2025 22:57:46 +0800
Subject: [PATCH] H5接口对接
---
management/src/components/RightContent/AvatarDropdown.tsx | 151 ++++++++++++-------------------------------------
1 files changed, 38 insertions(+), 113 deletions(-)
diff --git a/management/src/components/RightContent/AvatarDropdown.tsx b/management/src/components/RightContent/AvatarDropdown.tsx
index 1d419ab..5992bda 100644
--- a/management/src/components/RightContent/AvatarDropdown.tsx
+++ b/management/src/components/RightContent/AvatarDropdown.tsx
@@ -1,13 +1,10 @@
-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, getUnreadCount } from './service';
+import { LogoutOutlined } from '@ant-design/icons';
+import { useModel } from '@umijs/max';
+import React, { useEffect, useState } from 'react';
+import { Access, history, useAccess } from 'umi';
import { flushSync } from 'react-dom';
-import HeaderDropdown from '../HeaderDropdown';
+import './style.less';
export type GlobalHeaderRightProps = {
menu?: boolean;
@@ -17,120 +14,48 @@
export const AvatarName = () => {
const { initialState } = useModel('@@initialState');
//
-
+
const { currentUser } = initialState || {};
+ console.log('currentUser currentUser currentUser currentUser',currentUser)
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 [unreadCount, setUnreadCount] = useState(0);
+ const { currentUser } = initialState || {};
+ useEffect(() => {
+ // const timer = setInterval(() => {
+ // getUnreadCount().then((res: any) => {
+ // setUnreadCount(res.data || 0);
+ // });
+ // }, 1000 * 5)
- const loading = (
- <span className={actionClassName}>
- <Spin
- size="small"
- style={{
- marginLeft: 8,
- marginRight: 8,
- }}
- />
- </span>
- );
+ // return () => clearInterval(timer);
+ }, []);
- if (!initialState) {
- return loading;
+
+ const onMenuClick = async () => {
+ await outLogin();
+ localStorage.clear();
+ history.push('/login');
+ flushSync(() => {
+ setInitialState((s) => ({ ...s, currentUser: undefined }));
+ });
+
}
- 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,
- },
- ]
- : []),
+ return <div style={{ display: 'flex', alignItems: 'center', color: '#000' }}>
{
- key: 'logout',
- icon: <LogoutOutlined />,
- label: '退出登录',
- },
- ];
-
- return (
- <HeaderDropdown
- menu={{
- selectedKeys: [],
- onClick: onMenuClick,
- items: menuItems,
- }}
- >
- {children}
- </HeaderDropdown>
- );
+ unreadCount > 0 &&
+ <div className='unread' onClick={() => { history.push('/message-notification/list') }}>
+ <div>未读提醒</div>
+ <div style={{ border: '1px solid red', borderRadius: '50%', width: '18px', lineHeight: '16px', marginLeft: '5px', textAlign: 'center', color: 'red', flexShrink: 0 }}>{unreadCount}</div>
+ </div>
+ }
+ <div style={{ marginRight: '25px' }} >{currentUser?.userName || '超级管理员'}</div>
+ <div className="logoOut" onClick={onMenuClick}>退出登录<LogoutOutlined style={{ marginLeft: '5px' }} /></div>
+ </div>
};
--
Gitblit v1.7.1