From d59f518f466274b2caeb2e01c10c92deafe7c93b Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 09 二月 2022 11:48:29 +0800 Subject: [PATCH] 2022-02-09 --- src/components/tabview/index.jsx | 63 +++++++++++++++---------------- 1 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/components/tabview/index.jsx b/src/components/tabview/index.jsx index 9cb3e0d..d5320f5 100644 --- a/src/components/tabview/index.jsx +++ b/src/components/tabview/index.jsx @@ -2,16 +2,15 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { fromJS } from 'immutable' -import {Tabs, Icon, BackTop, notification} from 'antd' +import {Tabs, BackTop, notification} from 'antd' +import { RedoOutlined, CloseOutlined } from '@ant-design/icons' import moment from 'moment' import 'moment/locale/zh-cn' -import { toggleIsiframe, initActionPermission } from '@/store/action' +import { initActionPermission } from '@/store/action' import asyncComponent from '@/utils/asyncLoadComponent' import NotFount from '@/components/404' import options from '@/store/options.js' -import mzhCN from '@/locales/zh-CN/main.js' -import menUS from '@/locales/en-US/main.js' import MKEmitter from '@/utils/events.js' import Api from '@/api' import './index.scss' @@ -45,7 +44,6 @@ activeId: '', tabviews: null, // 鏍囩闆� iFrameHeight: 0, - dict: sessionStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS, } // 鍏抽棴tab椤碉紝閲嶆柊閫夋嫨鏄剧ず椤� @@ -64,7 +62,9 @@ if (index > -1) { let activeId = '' - if (index > 0) { + if (id !== this.state.activeId) { + activeId = this.state.activeId + } else if (index > 0) { activeId = tabs[index - 1].MenuID || '' } else if (tabs[index]) { activeId = tabs[index].MenuID || '' @@ -74,10 +74,6 @@ activeId, tabviews: tabs }) - - if (this.props.isiframe) { - this.props.toggleIsiframe(false) - } let node = document.getElementById('root').parentNode.parentNode if (node) { @@ -138,10 +134,27 @@ } } - modifyTabs = (tab, type) => { - const { tabviews } = this.state + modifyTabs = (tab, type, fixed) => { + const { tabviews, activeId } = this.state - if (type === 'plus') { + if (type === 'plus' && fixed) { + let _tabs = tabviews.filter(item => item.MenuID !== tab.MenuID) + let index = _tabs.findIndex(item => item.MenuID === activeId) + + this.setState({ + tabviews: _tabs + }, () => { + if (index > -1) { + _tabs.splice(index + 1, 0, tab) + } else { + _tabs.push(tab) + } + this.setState({ + tabviews: _tabs, + activeId: tab.MenuID + }) + }) + } else if (type === 'plus') { if (tabviews.findIndex(item => item.MenuID === tab.MenuID) > -1) { let _tabs = tabviews.filter(item => item.MenuID !== tab.MenuID) this.setState({ @@ -174,16 +187,6 @@ changeTab = (e, menu) => { e.stopPropagation() // 绐楀彛鍒囨崲 - let _isiframe = this.props.isiframe - if (menu.type === 'iframe') { - _isiframe = true - } else { - _isiframe = false - } - - if (_isiframe !== this.props.isiframe) { - this.props.toggleIsiframe(_isiframe) - } this.setState({ activeId: menu.MenuID || '' @@ -252,10 +255,6 @@ MKEmitter.addListener('closeTabView', this.closeTabView) } - UNSAFE_componentWillReceiveProps (nextProps) { - - } - /** * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 */ @@ -271,7 +270,7 @@ const { tabviews, activeId } = this.state return ( - <section id="mk-tabview-wrap" className={'mk-tabview-wrap' + (this.props.collapse ? ' collapsed' : '')}> + <section id="mk-tabview-wrap" className={'mk-tabview-wrap' + (this.props.collapse ? ' collapsed' : '') + (tabviews && tabviews.length > 0 ? ' hastab' : '')}> <div className="content-header"> {tabviews && tabviews.length > 0 && <Tabs activeKey={activeId}> @@ -280,12 +279,12 @@ <Tabs.TabPane tab={ <span className="tab-control"> - <Icon type="redo" onClick={(e) => {this.refreshTabview(e, view)}}/> + <RedoOutlined onClick={(e) => {this.refreshTabview(e, view)}}/> <span className="tab-name" onClick={(e) => {this.changeTab(e, view)}}> {view.MenuName} </span> {view.type !== 'Home' ? - <Icon type="close" onClick={(e) => {e.stopPropagation();this.closeTabView(view.MenuID)}}/> : null + <CloseOutlined onClick={(e) => {e.stopPropagation();this.closeTabView(view.MenuID)}}/> : null } </span> } @@ -314,14 +313,12 @@ const mapStateToProps = (state) => { return { collapse: state.collapse, - isiframe: state.isiframe } } const mapDispatchToProps = (dispatch) => { return { - initActionPermission: (permAction) => dispatch(initActionPermission(permAction)), - toggleIsiframe: (isiframe) => dispatch(toggleIsiframe(isiframe)) + initActionPermission: (permAction) => dispatch(initActionPermission(permAction)) } } -- Gitblit v1.8.0