From e8edfdadb561cd83bf6e1c3e00d55b8cc2aee6d5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 17 十月 2022 17:57:34 +0800 Subject: [PATCH] 2022-10-17 --- src/menu/components/tabs/antv-tabs/dragabletabs.jsx | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/menu/components/tabs/antv-tabs/dragabletabs.jsx b/src/menu/components/tabs/antv-tabs/dragabletabs.jsx index 74ef3ef..fbb97de 100644 --- a/src/menu/components/tabs/antv-tabs/dragabletabs.jsx +++ b/src/menu/components/tabs/antv-tabs/dragabletabs.jsx @@ -1,5 +1,6 @@ import React, { Component } from 'react' import { Tabs } from 'antd' +import { is, fromJS } from 'immutable' import { DndProvider, DragSource, DropTarget } from 'react-dnd' // Drag & Drop node @@ -52,8 +53,6 @@ const newOrder = this.state.order.slice() const { children } = this.props - if (dragKey === 'tool' || hoverKey === 'tool') return - React.Children.forEach(children, c => { if (newOrder.indexOf(c.key) === -1) { newOrder.push(c.key) @@ -65,12 +64,11 @@ newOrder.splice(dragIndex, 1) newOrder.splice(hoverIndex, 0, dragKey) - let _order = newOrder.filter(item => item !== 'tool') this.setState({ - order: [..._order, 'tool'] + order: newOrder }) - this.props.tabsMove(_order) + this.props.tabsMove(newOrder) } renderTabBar = (props, DefaultTabBar) => ( @@ -83,10 +81,16 @@ </DefaultTabBar> ) + shouldComponentUpdate (nextProps, nextState) { + return !is(fromJS(this.state), fromJS(nextState)) || + !is(fromJS(nextProps.children), fromJS(this.props.children)) || + nextProps.tabPosition !== this.props.tabPosition || + nextProps.type !== this.props.type + } + render() { const { order } = this.state - const { children } = this.props - + const { children, ...resProps } = this.props const tabs = [] React.Children.forEach(children, c => { tabs.push(c) @@ -114,7 +118,7 @@ return ( <DndProvider> - <Tabs renderTabBar={this.renderTabBar} {...this.props}> + <Tabs renderTabBar={this.renderTabBar} {...resProps}> {orderTabs} </Tabs> </DndProvider> -- Gitblit v1.8.0