diff --git a/src/components/chat-container/chat-container.tsx b/src/components/chat-container/chat-container.tsx index 55c880693e6ff83d75575e4b4818f4e53bdfefd8..34416d0719d0c5117c0ff74001fbfed87cdad02c 100644 --- a/src/components/chat-container/chat-container.tsx +++ b/src/components/chat-container/chat-container.tsx @@ -426,7 +426,17 @@ export class ChatContainer extends Component< }); } + /** + * 处理全屏改变 + * + * @memberof ChatContainer + */ + handleFullScreenChange(): void { + this.setState({ isFullScreen: document.fullscreenElement !== null }); + } + componentDidMount(): void { + this.handleFullScreenChange = this.handleFullScreenChange.bind(this); const minimizeCache = localStorage.getItem( AIChatConst.MINIMIZE_STYLY_CHCHE, ); @@ -443,9 +453,14 @@ export class ChatContainer extends Component< this.registerDragDialog(); this.registerDragDialogBorder(); this.registerDragMinmize(); + document.addEventListener('fullscreenchange', this.handleFullScreenChange); } componentWillUnmount(): void { + document.removeEventListener( + 'fullscreenchange', + this.handleFullScreenChange, + ); localStorage.setItem(AIChatConst.STYLE_CACHE, JSON.stringify(this.data)); localStorage.setItem( AIChatConst.MINIMIZE_STYLY_CHCHE, @@ -473,7 +488,6 @@ export class ChatContainer extends Component< const container = this.containerRef.current; if (container) { container.requestFullscreen(); - this.setState({ isFullScreen: true }); this.props.fullscreen(true); } } @@ -487,7 +501,6 @@ export class ChatContainer extends Component< closeFullScreen(): void { if (this.state.isFullScreen) { document?.exitFullscreen(); - this.setState({ isFullScreen: false }); this.props.fullscreen(false); this.setStyle(); }