Skip to content

Commit 3cbde57

Browse files
authored
Merge pull request #1 from ballcat-projects/dev
0.3.0
2 parents a40f220 + 7dd0db5 commit 3cbde57

File tree

4 files changed

+88
-26
lines changed

4 files changed

+88
-26
lines changed

src/components/FullScreen/index.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import type { CSSProperties } from 'react';
2+
import { useState, useCallback, useEffect } from 'react';
3+
import Icon from '../Icon';
4+
5+
export type FullScreenProps = {
6+
full?: boolean;
7+
onFullChange?: (flag: boolean) => void;
8+
iconStyle?: CSSProperties;
9+
dom?: HTMLElement;
10+
};
11+
12+
export const openFullScreen = (dom?: HTMLElement) => {
13+
(dom || document.getElementsByTagName('body')[0]).requestFullscreen();
14+
};
15+
16+
export const exitFullScreen = () => document.exitFullscreen();
17+
18+
const FullScreen = ({ full, onFullChange, iconStyle, dom }: FullScreenProps) => {
19+
const [isFull, setIsFull] = useState(false);
20+
21+
const changeFull = useCallback(
22+
(flag: boolean) => {
23+
setIsFull(flag);
24+
if (onFullChange) {
25+
onFullChange(flag);
26+
}
27+
28+
// 切换成全屏 且 当前没有全屏元素
29+
if (flag && !document.fullscreenElement) {
30+
openFullScreen(dom);
31+
}
32+
// 取消全屏 且 当前有全屏元素
33+
else if (!flag && document.fullscreenElement) {
34+
document.exitFullscreen();
35+
}
36+
},
37+
[dom, onFullChange],
38+
);
39+
40+
useEffect(() => {
41+
changeFull(!!full);
42+
}, [full]);
43+
44+
useEffect(() => {
45+
const fullscreenchangeListener = () => {
46+
const flag = !!document.fullscreenElement;
47+
setIsFull(flag);
48+
if (onFullChange) {
49+
onFullChange(flag);
50+
}
51+
};
52+
document.addEventListener('fullscreenchange', fullscreenchangeListener);
53+
return () => {
54+
document.removeEventListener('fullscreenchange', fullscreenchangeListener);
55+
};
56+
}, []);
57+
58+
return (
59+
<Icon
60+
type={isFull ? 'fullscreen-exit' : 'fullscreen'}
61+
style={{ fontSize: '16px', ...iconStyle }}
62+
onClick={() => {
63+
// 外部自定义触发是否全屏
64+
if (full === undefined && onFullChange === undefined) {
65+
changeFull(!isFull);
66+
}
67+
}}
68+
/>
69+
);
70+
};
71+
72+
FullScreen.open = openFullScreen;
73+
74+
FullScreen.exit = exitFullScreen;
75+
76+
export default FullScreen;

src/components/NoticeIcon/NoticeList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import React from 'react';
44
import classNames from 'classnames';
55
// @ts-ignore
66
import styles from './NoticeList.less';
7+
import Icon from '../Icon';
78

89
export type NoticeIconTabProps = {
910
count?: number;
@@ -55,7 +56,7 @@ const NoticeList: React.FC<NoticeIconTabProps> = ({
5556
// eslint-disable-next-line no-nested-ternary
5657
const leftIcon = item.avatar ? (
5758
typeof item.avatar === 'string' ? (
58-
<Avatar className={styles.avatar} src={item.avatar} />
59+
<Avatar className={styles.avatar} src={item.avatar} icon={<Icon type="user" />} />
5960
) : (
6061
<span className={styles.iconElement}>{item.avatar}</span>
6162
)

src/components/RightContent/AvatarDropdown.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { outLogin } from '@/services/ant-design-pro/api';
1010
import { User, Token } from '@/utils/Ballcat';
1111
import I18n from '@/utils/I18nUtils';
1212
import UrlUtils from '@/utils/UrlUtils';
13+
import Icon from '../Icon';
1314

1415
export type GlobalHeaderRightProps = {
1516
exitConfirm?: boolean;
@@ -101,6 +102,7 @@ const AvatarDropdown: React.FC<GlobalHeaderRightProps> = ({ exitConfirm }) => {
101102
<span className={`${styles.action} ${styles.account}`}>
102103
<Avatar
103104
size="small"
105+
icon={<Icon type="user" />}
104106
className={styles.avatar}
105107
src={user?.info?.avatar ? UrlUtils.resolveImage(user.info.avatar) : undefined}
106108
alt="avatar"

src/components/RightContent/index.tsx

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { MoreOutlined, QuestionCircleOutlined } from '@ant-design/icons';
33
import React, { useState } from 'react';
44
import { SelectLang, useModel } from 'umi';
55
import Avatar from './AvatarDropdown';
6-
import HeaderSearch from '../HeaderSearch';
76
// @ts-ignore
87
import styles from './index.less';
98
import SettingDrawer from '@/components/SettingDrawer';
9+
import FullScreen from '../FullScreen';
1010

1111
const GlobalHeaderRight: React.FC = () => {
1212
const { initialState } = useModel('@@initialState');
1313
const [showSetting, setShowSetting] = useState(false);
14+
const [full, setFull] = useState(false);
1415

1516
if (!initialState || !initialState.settings) {
1617
return null;
@@ -24,37 +25,19 @@ const GlobalHeaderRight: React.FC = () => {
2425
}
2526
return (
2627
<Space className={className}>
27-
<HeaderSearch
28-
className={`${styles.action} ${styles.search}`}
29-
placeholder="站内搜索"
30-
defaultValue="umi ui"
31-
options={[
32-
{ label: <a href="https://umijs.org/zh/guide/umi-ui.html">umi ui</a>, value: 'umi ui' },
33-
{
34-
label: <a href="next.ant.design">Ant Design</a>,
35-
value: 'Ant Design',
36-
},
37-
{
38-
label: <a href="https://protable.ant.design/">Pro Table</a>,
39-
value: 'Pro Table',
40-
},
41-
{
42-
label: <a href="https://prolayout.ant.design/">Pro Layout</a>,
43-
value: 'Pro Layout',
44-
},
45-
]}
46-
// onSearch={value => {
47-
//
48-
// }}
49-
/>
5028
<span
5129
className={styles.action}
5230
onClick={() => {
53-
window.open('https://pro.ant.design/docs/getting-started');
31+
window.open('http://www.ballcat.cn/');
5432
}}
5533
>
5634
<QuestionCircleOutlined />
5735
</span>
36+
37+
<span className={styles.action} onClick={() => setFull(!full)}>
38+
<FullScreen full={full} onFullChange={setFull} />
39+
</span>
40+
5841
{/* 如果不需要退出确认. 移除 exitConfirm 即可 */}
5942
<Avatar exitConfirm />
6043
<SelectLang className={styles.action} />

0 commit comments

Comments
 (0)