From 53b9fb93d0376eb02bb996935f1720b4e95cd897 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 12 十月 2022 14:41:06 +0800 Subject: [PATCH] 2022-10-12 --- src/components/tabview/index.jsx | 89 +++++++++++++++++--------------------------- 1 files changed, 35 insertions(+), 54 deletions(-) diff --git a/src/components/tabview/index.jsx b/src/components/tabview/index.jsx index 9cb3e0d..ffb0f08 100644 --- a/src/components/tabview/index.jsx +++ b/src/components/tabview/index.jsx @@ -2,16 +2,14 @@ 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 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' @@ -19,22 +17,13 @@ const Home = asyncComponent(() => import('@/tabviews/home')) const CustomPage = asyncComponent(() => import('@/tabviews/custom')) const CommonTable = asyncComponent(() => import('@/tabviews/commontable')) +// const BaseTable = asyncComponent(() => import('@/tabviews/basetable')) const CalendarPage = asyncComponent(() => import('@/tabviews/calendar')) const TreePage = asyncComponent(() => import('@/tabviews/treepage')) -const VerupTable = asyncComponent(() => import('@/tabviews/verupmanage')) -const ScriptTable = asyncComponent(() => import('@/tabviews/scriptmanage')) const TabManage = asyncComponent(() => import('@/tabviews/tabmanage')) const Iframe = asyncComponent(() => import('@/tabviews/iframe')) const RoleManage = asyncComponent(() => import('@/tabviews/rolemanage')) const FormTab = asyncComponent(() => import('@/tabviews/formtab')) - -let service = '' - -if (process.env.NODE_ENV === 'production') { - service = document.location.origin + '/' + window.GLOB.service + 'zh-CN/' -} else { - service = window.GLOB.location + '/' + window.GLOB.service + 'zh-CN/' -} class TabViews extends Component { static propTpyes = { @@ -45,7 +34,6 @@ activeId: '', tabviews: null, // 鏍囩闆� iFrameHeight: 0, - dict: sessionStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS, } // 鍏抽棴tab椤碉紝閲嶆柊閫夋嫨鏄剧ず椤� @@ -64,7 +52,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 +64,6 @@ activeId, tabviews: tabs }) - - if (this.props.isiframe) { - this.props.toggleIsiframe(false) - } let node = document.getElementById('root').parentNode.parentNode if (node) { @@ -114,7 +100,7 @@ }) } - this.props.initActionPermission(_permAction) + window.GLOB.mkActions = _permAction } resolve() @@ -138,10 +124,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 +177,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 || '' @@ -196,28 +189,24 @@ // 鏍规嵁tab椤典腑鑿滃崟淇℃伅锛岄�夋嫨鎵�闇�鐨勭粍浠� if (view.type === 'Home') { return (<Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) - } else if (view.type === 'CommonTable' || view.type === 'ManageTable') { + } else if (view.type === 'CommonTable') { return (<CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) + // } else if (view.type === 'BaseTable') { + // return (<BaseTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) } else if (view.type === 'CustomPage') { return (<CustomPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) } else if (view.type === 'TreePage') { return (<TreePage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) } else if (view.type === 'CalendarPage') { return (<CalendarPage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) - } else if (view.type === 'VerupTable') { - return (<VerupTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) - } else if (view.type === 'ScriptTable') { - return (<ScriptTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) } else if (view.type === 'TabManage') { return (<TabManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) } else if (view.type === 'RolePermission') { return (<RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) - } else if (view.type === 'appRolePermission') { - return (<RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) } else if (view.type === 'FormTab') { return (<FormTab MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) } else if (view.type === 'iframe') { - return (<Iframe key={view.MenuID} MenuID={view.MenuID} MenuNo={view.MenuNo} title={view.MenuName} MenuName={view.MenuName} url={service + view.LinkUrl}/>) + return (<Iframe key={view.MenuID} MenuID={view.MenuID} MenuNo={view.MenuNo} title={view.MenuName} MenuName={view.MenuName} url={window.GLOB.baseurl + 'zh-CN/' + view.LinkUrl}/>) } else { return (<NotFount key={view.MenuID} />) } @@ -252,10 +241,6 @@ MKEmitter.addListener('closeTabView', this.closeTabView) } - UNSAFE_componentWillReceiveProps (nextProps) { - - } - /** * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 */ @@ -271,7 +256,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 +265,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,15 +299,11 @@ const mapStateToProps = (state) => { return { collapse: state.collapse, - isiframe: state.isiframe } } const mapDispatchToProps = (dispatch) => { - return { - initActionPermission: (permAction) => dispatch(initActionPermission(permAction)), - toggleIsiframe: (isiframe) => dispatch(toggleIsiframe(isiframe)) - } + return {} } export default connect(mapStateToProps, mapDispatchToProps)(TabViews) \ No newline at end of file -- Gitblit v1.8.0