From 063b983daaf51a7f1e8677bde1e9c0e618866c91 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 21 二月 2020 10:30:19 +0800 Subject: [PATCH] 2020-02-21 --- src/components/tabview/index.jsx | 147 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 101 insertions(+), 46 deletions(-) diff --git a/src/components/tabview/index.jsx b/src/components/tabview/index.jsx index a0ab705..ed5a8b2 100644 --- a/src/components/tabview/index.jsx +++ b/src/components/tabview/index.jsx @@ -2,9 +2,10 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import {Tabs, Icon, Button, ConfigProvider, message} from 'antd' +import {Tabs, Icon, Button, ConfigProvider, message, BackTop} from 'antd' import {modifyTabview, toggleIsiframe} from '@/store/action' -import asyncComponent from '@/utils/asyncComponent' +// import asyncComponent from '@/utils/asyncComponent' +import asyncComponent from '@/utils/asyncLoadComponent' import NotFount from '@/components/404' import enUS from 'antd/es/locale/en_US' import zhCN from 'antd/es/locale/zh_CN' @@ -31,54 +32,64 @@ } state = { - selectedTabId: '', // 褰撳墠閫変腑tab椤甸潰 + tabviews: null, // 鏍囩闆� iFrameHeight: 0, dict: (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') ? mzhCN : menUS, locale: (!sessionStorage.getItem('lang') || sessionStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS } - handleTabview (menu) { + handleTabview (e, menu) { + e.stopPropagation() // 鍏抽棴tab椤碉紝閲嶆柊閫夋嫨鏄剧ず椤� - let tabs = JSON.parse(JSON.stringify(this.props.tabviews)) + let tabs = JSON.parse(JSON.stringify(this.state.tabviews)) tabs = tabs.filter(tab => { - if (tab.MenuID === this.state.selectedTabId) { - tab.selected = true - } else { - tab.selected = false - } - if (menu.type === 'TabForm' || menu.type === 'iframe') { - return tab.MenuID !== menu.MenuID - } else { - return tab.MenuNo !== menu.MenuNo - } + return tab.MenuID !== menu.MenuID }) - if (menu.MenuID === this.state.selectedTabId) { + + if (menu.selected) { tabs[0] && (tabs[0].selected = true) } + this.props.modifyTabview(tabs) } - changeTab (menu) { + changeTab (e, menu) { + e.stopPropagation() // 绐楀彛鍒囨崲 - this.setState({ - selectedTabId: menu.MenuID + let tabs = JSON.parse(JSON.stringify(this.state.tabviews)) + tabs = tabs.map(tab => { + tab.selected = false + + if (tab.MenuID === menu.MenuID) { + tab.selected = true + } + + return tab }) - this.resetWindow(menu) + this.setState({ + tabviews: tabs + }) + + this.props.modifyTabview(tabs) } selectcomponent (view) { // 鏍规嵁tab椤典腑鑿滃崟淇℃伅锛岄�夋嫨鎵�闇�鐨勭粍浠� - if (view.type === 'CommonTable') { - return (<Comps.CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} key={view.MenuID}/>) + if (view.type === 'Home') { + return (<Comps.Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) + } else if (view.type === 'CommonTable') { + return (<Comps.CommonTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) } else if (view.type === 'DataManage') { - return (<Comps.DataManage MenuNo={view.MenuNo} MenuID={view.MenuID} key={view.MenuID}/>) - } else if (view.type === 'RoleManage') { - return (<Comps.RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} key={view.MenuID}/>) + return (<Comps.DataManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) + } else if (view.type === 'RolePermission') { + return (<Comps.RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) } else if (view.type === 'TabForm') { - return (<Comps.TabForm MenuNo={view.MenuNo} MenuID={view.MenuID} key={view.MenuID} param={view.param}/>) + return (<Comps.TabForm MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) + } else if (view.type === 'FormTab') { + return (<Comps.FormTab MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) } else if (view.type === 'iframe') { - return (<Comps.Iframe key={view.MenuID} title={view.MenuName} url={service + view.LinkUrl}/>) + return (<Comps.Iframe key={view.MenuID} title={view.MenuName} MenuName={view.MenuName} url={service + view.LinkUrl}/>) } else { return (<NotFount key={view.MenuID} />) } @@ -117,65 +128,109 @@ } else { moment.locale('en') } + this.setState({ + tabviews: this.props.tabviews + }) + } + + componentDidMount () { + let home = { + MenuID: '1576117946681plembmkk9akkv8sn0vtdfdsfaf', + MenuName: '棣栭〉', + MenuNo: 'MESOrderDetailMwe', + PageParam: {}, + id: 1, + selected: true, + src: '', + text: '棣栭〉', + type: 'Home' + } + this.props.modifyTabview([home]) } UNSAFE_componentWillReceiveProps (nextProps) { - if (nextProps.tabviews && !is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) { + if (nextProps.tabviews && !is(fromJS(this.state.tabviews), fromJS(nextProps.tabviews))) { // tab绐楀彛椤靛鍔犳垨鍒犻櫎 - if (nextProps.tabviews.length > this.props.tabviews.length) { + if (nextProps.tabviews.length > this.state.tabviews.length) { // 鏌ョ湅鏂皌ab椤甸渶瑕佺粍浠舵槸鍚﹀姞杞� - let MenuIDs = this.props.tabviews.map(tab => {return tab.MenuID}) + let MenuIDs = this.state.tabviews.map(tab => {return tab.MenuID}) let newtab = nextProps.tabviews.filter(tab => !MenuIDs.includes(tab.MenuID))[0] - if (!Comps.CommonTable && newtab.type === 'CommonTable') { + if (!Comps.Home && newtab.type === 'Home') { + Comps.Home = asyncComponent(() => import('@/tabviews/home')) + } else if (!Comps.CommonTable && newtab.type === 'CommonTable') { Comps.CommonTable = asyncComponent(() => import('@/tabviews/commontable')) } else if (!Comps.Iframe && newtab.type === 'iframe') { Comps.Iframe = asyncComponent(() => import('@/tabviews/iframe')) } else if (!Comps.DataManage && newtab.type === 'DataManage') { Comps.DataManage = asyncComponent(() => import('@/tabviews/datamanage')) - } else if (!Comps.RoleManage && newtab.type === 'RoleManage') { + } else if (!Comps.RoleManage && newtab.type === 'RolePermission') { Comps.RoleManage = asyncComponent(() => import('@/tabviews/rolemanage')) } else if (!Comps.TabForm && newtab.type === 'TabForm') { Comps.TabForm = asyncComponent(() => import('@/tabviews/tabform')) + } else if (!Comps.TabForm && newtab.type === 'FormTab') { + Comps.FormTab = asyncComponent(() => import('@/tabviews/formtab')) } } - // 璁剧疆閫変腑绐楀彛 - let view = nextProps.tabviews.filter(tab => tab.selected)[0] + // 淇濆瓨淇敼鏍囩闆� this.setState({ - selectedTabId: view ? view.MenuID : '' + tabviews: nextProps.tabviews }) - this.resetWindow(view) + let node = document.getElementById('root').parentNode.parentNode + if (node) { + node.scrollTop = 0 + } } } - shouldComponentUpdate(nextProps, nextState) { - return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) - } + // shouldComponentUpdate(nextProps, nextState) { + // return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) + // } render () { + const { tabviews } = this.state + let view = tabviews.filter(tab => tab.selected)[0] + this.resetWindow(view) + let selectedTabId = view ? view.MenuID : '' + return ( <section className={'flex-container content-box' + (this.props.collapse ? ' collapsed' : '')}> <ConfigProvider locale={this.state.locale}> <div className="content-header"> - {this.props.tabviews && this.props.tabviews.length > 0 && - <Tabs activeKey={this.state.selectedTabId}> - {this.props.tabviews.map(view => { + {tabviews && tabviews.length > 0 && + <Tabs activeKey={selectedTabId}> + {tabviews.map(view => { return ( <Tabs.TabPane className="test" tab={ - <span> - <span className="tab-name" onClick={() => {this.changeTab(view)}}> + <span className="tab-control"> + <span className="tab-name" onClick={(e) => {this.changeTab(e, view)}}> {view.MenuName} </span> - <Icon type="close" onClick={() => {this.handleTabview(view)}}/> + {view.type !== 'Home' ? <Icon type="close" onClick={(e) => {this.handleTabview(e, view)}}/> : null} </span> } key={view.MenuID} > {this.selectcomponent(view)} - <Button className={'main-copy ' + (view.type === 'iframe' ? 'ifr-copy' : '')} icon="copy" data-menuno={view.MenuNo} onClick={this.copyMenuNo} shape="circle" /> + {view.type !== 'CommonTable' ? + <Button + icon="copy" + shape="circle" + className={'main-copy ' + (view.type === 'iframe' ? 'ifr-copy' : '')} + data-menuno={view.MenuNo} + onClick={this.copyMenuNo} + /> : null + } + <BackTop> + <div className="ant-back-top"> + <div className="ant-back-top-content"> + <div className="ant-back-top-icon"></div> + </div> + </div> + </BackTop> </Tabs.TabPane> ) })} -- Gitblit v1.8.0