From 453ee91b22c9e21f3e16d9d1ad31eb21c7f4f507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=87=AA=E5=B8=A6=E5=A4=A7=E4=BD=AC=E6=B0=94=E5=9C=BA?= <188633308@qq.com> Date: Mon, 14 Jun 2021 10:34:16 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BE=A7=E8=BE=B9=E5=B1=95=E5=BC=80?= =?UTF-8?q?=E7=BC=A9=E8=B5=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/main/_layout/header/index.jsx | 29 ++++++++++++++++++- .../src/views/main/_layout/sider/index.jsx | 25 ++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/web-react/src/views/main/_layout/header/index.jsx b/web-react/src/views/main/_layout/header/index.jsx index 6452b78..d51fe0e 100644 --- a/web-react/src/views/main/_layout/header/index.jsx +++ b/web-react/src/views/main/_layout/header/index.jsx @@ -3,14 +3,41 @@ import { Layout, Badge } from 'antd' import { AntIcon, Container } from 'components' import Logo from '../logo' import User from './user' +import store from 'store' + +const { getState, subscribe, dispatch } = store export default class index extends Component { + + state = { + ...getState('layout') + } + + constructor(props) { + super(props) + + this.unsubscribe = subscribe('layout', (state) => { + this.setState(state) + }) + } + + componentWillUnmount() { + this.unsubscribe() + } + + onCollapsed() { + dispatch({ + type: 'TOGGLE_COLLAPSED', + siderCollapsed: !this.state.siderCollapsed + }) + } + render() { return (
- + this.onCollapsed()}> diff --git a/web-react/src/views/main/_layout/sider/index.jsx b/web-react/src/views/main/_layout/sider/index.jsx index 65b26a1..ce01f66 100644 --- a/web-react/src/views/main/_layout/sider/index.jsx +++ b/web-react/src/views/main/_layout/sider/index.jsx @@ -3,9 +3,12 @@ import { Layout } from 'antd' import Swiper, { Mousewheel, Scrollbar } from 'swiper' import 'swiper/swiper-bundle.css' import Menu from './menu' +import store from 'store' Swiper.use([Mousewheel, Scrollbar]) +const { getState, subscribe } = store + let timer, swiper @@ -31,7 +34,17 @@ const UpdateSwiper = () => { export default class index extends Component { - state = {} + state = { + ...getState('layout') + } + + constructor(props) { + super(props) + + this.unsubscribe = subscribe('layout', (state) => { + this.setState(state) + }) + } componentDidMount() { swiper = new Swiper('#layout--swiper-container', siderSwiperOptions) @@ -41,6 +54,10 @@ export default class index extends Component { }) } + componentWillUnmount() { + this.unsubscribe() + } + updateSwiper() { UpdateSwiper() } @@ -52,7 +69,11 @@ export default class index extends Component { render() { return ( - +