From 49f09cc6f8ff8c30a75ed1a9d6f510b69b73962a Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 12 十二月 2023 21:05:37 +0800 Subject: [PATCH] 2023-12-12 --- src/menu/components/tabs/antv-tabs/dragabletabs.jsx | 22 ++++++++++++++-------- 1 files changed, 14 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..71b5bdb 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) @@ -63,14 +62,15 @@ const dragIndex = newOrder.indexOf(dragKey) const hoverIndex = newOrder.indexOf(hoverKey) + if (dragIndex === -1) return + 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 +83,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 +120,7 @@ return ( <DndProvider> - <Tabs renderTabBar={this.renderTabBar} {...this.props}> + <Tabs renderTabBar={this.renderTabBar} {...resProps}> {orderTabs} </Tabs> </DndProvider> -- Gitblit v1.8.0