From ea34e669b45f86793017621a0dc3f9a71aa3276b Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 23 二月 2021 18:23:26 +0800 Subject: [PATCH] 2021-02-23 --- src/components/tabview/index.jsx | 295 ++++++++++++++++++++++++++++++---------------------------- 1 files changed, 154 insertions(+), 141 deletions(-) diff --git a/src/components/tabview/index.jsx b/src/components/tabview/index.jsx index ed5a8b2..ce5a0e8 100644 --- a/src/components/tabview/index.jsx +++ b/src/components/tabview/index.jsx @@ -2,61 +2,86 @@ import PropTypes from 'prop-types' import {connect} from 'react-redux' import { is, fromJS } from 'immutable' -import {Tabs, Icon, Button, ConfigProvider, message, BackTop} from 'antd' -import {modifyTabview, toggleIsiframe} from '@/store/action' -// 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' -import mzhCN from '@/locales/zh-CN/main.js' -import menUS from '@/locales/en-US/main.js' +import {Tabs, Icon, BackTop} from 'antd' import moment from 'moment' import 'moment/locale/zh-cn' + +import { modifyTabview, toggleIsiframe } 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 './index.scss' +const Home = asyncComponent(() => import('@/tabviews/home')) +const CustomPage = asyncComponent(() => import('@/tabviews/custom')) +const CommonTable = asyncComponent(() => import('@/tabviews/commontable')) +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 Comps = {} -let service = window.GLOB.service ? (/\/$/.test(window.GLOB.service) ? window.GLOB.service : window.GLOB.service + '/') : '' +let service = '' if (process.env.NODE_ENV === 'production') { - service = document.location.origin + '/' + service + 'zh-CN/' + service = document.location.origin + '/' + window.GLOB.service + 'zh-CN/' } else { - service = 'http://qingqiumarket.cn/' + service + 'zh-CN/' + service = window.GLOB.location + '/' + window.GLOB.service + 'zh-CN/' } -class Header extends Component { +class TabViews extends Component { static propTpyes = { collapse: PropTypes.bool, tabviews: PropTypes.array // 鏍囩椤垫暟缁� } state = { + activeId: '', 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 + dict: localStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS, } - handleTabview (e, menu) { + handleTabview = (e, menu) => { e.stopPropagation() // 鍏抽棴tab椤碉紝閲嶆柊閫夋嫨鏄剧ず椤� - let tabs = JSON.parse(JSON.stringify(this.state.tabviews)) + let tabs = fromJS(this.state.tabviews).toJS() tabs = tabs.filter(tab => { return tab.MenuID !== menu.MenuID }) - if (menu.selected) { - tabs[0] && (tabs[0].selected = true) + if (menu.selected && tabs[0]) { + tabs[0].selected = true + this.setState({ + activeId: tabs[0].MenuID || '' + }) + + if (this.props.isiframe) { + this.props.toggleIsiframe(false) + } } this.props.modifyTabview(tabs) } - changeTab (e, menu) { + refreshTabview = (e, menu) => { + e.stopPropagation() + window.GLOB.CacheMap = new Map() + + MKEmitter.emit('reloadMenuView', menu.MenuID) + } + + changeTab = (e, menu) => { e.stopPropagation() // 绐楀彛鍒囨崲 - let tabs = JSON.parse(JSON.stringify(this.state.tabviews)) + let tabs = fromJS(this.state.tabviews).toJS() tabs = tabs.map(tab => { tab.selected = false @@ -67,59 +92,58 @@ return tab }) + if (menu) { + 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({ - tabviews: tabs + tabviews: tabs, + activeId: menu.MenuID || '' + }, () => { + if (menu.MenuID) { + MKEmitter.emit('resetActiveMenu', menu.MenuID) + } }) this.props.modifyTabview(tabs) } - selectcomponent (view) { + selectcomponent = (view) => { // 鏍规嵁tab椤典腑鑿滃崟淇℃伅锛岄�夋嫨鎵�闇�鐨勭粍浠� 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} MenuName={view.MenuName} key={view.MenuID}/>) + return (<Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) + } else if (view.type === 'CommonTable' || view.type === 'ManageTable') { + return (<CommonTable 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 (<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} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) + return (<RoleManage MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) } else if (view.type === 'FormTab') { - return (<Comps.FormTab MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) + return (<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} 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={service + view.LinkUrl}/>) } else { return (<NotFount key={view.MenuID} />) } - } - - resetWindow (view) { - // 绐楀彛鍦╥frame涓庢櫘閫氶〉闈㈠垏鎹㈡椂锛屼慨鏀瑰乏渚ц彍鍗曟爮鏍峰紡 - if (!view) return - let _isiframe = this.props.isiframe - if (view && view.type === 'iframe') { - _isiframe = true - } else { - _isiframe = false - } - - if (_isiframe !== this.props.isiframe) { - this.props.toggleIsiframe(_isiframe) - } - } - - copyMenuNo = (e) => { - e.stopPropagation() - let oInput = document.createElement('input') - oInput.value = e.target.dataset.menuno || '' - document.body.appendChild(oInput) - oInput.select() - document.execCommand('Copy') - oInput.className = 'oInput' - oInput.style.display = 'none' - message.success(this.state.dict['main.copy.success']) } UNSAFE_componentWillMount () { @@ -134,47 +158,42 @@ } componentDidMount () { - let home = { - MenuID: '1576117946681plembmkk9akkv8sn0vtdfdsfaf', - MenuName: '棣栭〉', - MenuNo: 'MESOrderDetailMwe', - PageParam: {}, - id: 1, - selected: true, - src: '', - text: '棣栭〉', - type: 'Home' + if (sessionStorage.getItem('isEditState') !== 'true') { + let home = { + MenuID: 'home_page_id', + MenuName: this.state.dict['main.homepage'], + selected: true, + type: 'Home' + } + this.props.modifyTabview([home]) } - this.props.modifyTabview([home]) } UNSAFE_componentWillReceiveProps (nextProps) { if (nextProps.tabviews && !is(fromJS(this.state.tabviews), fromJS(nextProps.tabviews))) { - // tab绐楀彛椤靛鍔犳垨鍒犻櫎 - if (nextProps.tabviews.length > this.state.tabviews.length) { - // 鏌ョ湅鏂皌ab椤甸渶瑕佺粍浠舵槸鍚﹀姞杞� - let MenuIDs = this.state.tabviews.map(tab => {return tab.MenuID}) - let newtab = nextProps.tabviews.filter(tab => !MenuIDs.includes(tab.MenuID))[0] - 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 === '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] + + // 绐楀彛鍦╥frame涓庢櫘閫氶〉闈㈠垏鎹㈡椂锛屼慨鏀瑰乏渚ц彍鍗曟爮鏍峰紡 + let activeId = '' + if (view) { + let _isiframe = this.props.isiframe + if (view.type === 'iframe') { + _isiframe = true + } else { + _isiframe = false } + + if (_isiframe !== this.props.isiframe) { + this.props.toggleIsiframe(_isiframe) + } + + activeId = view.MenuID } // 淇濆瓨淇敼鏍囩闆� this.setState({ - tabviews: nextProps.tabviews + tabviews: nextProps.tabviews, + activeId }) let node = document.getElementById('root').parentNode.parentNode @@ -184,60 +203,54 @@ } } - // shouldComponentUpdate(nextProps, nextState) { - // return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) - // } + /** + * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊 + */ + componentWillUnmount () { + this.setState = () => { + return + } + } render () { - const { tabviews } = this.state - let view = tabviews.filter(tab => tab.selected)[0] - this.resetWindow(view) - let selectedTabId = view ? view.MenuID : '' + const { tabviews, activeId } = this.state return ( - <section className={'flex-container content-box' + (this.props.collapse ? ' collapsed' : '')}> - <ConfigProvider locale={this.state.locale}> - <div className="content-header"> - {tabviews && tabviews.length > 0 && - <Tabs activeKey={selectedTabId}> - {tabviews.map(view => { - return ( - <Tabs.TabPane - className="test" - tab={ - <span className="tab-control"> - <span className="tab-name" onClick={(e) => {this.changeTab(e, view)}}> - {view.MenuName} - </span> - {view.type !== 'Home' ? <Icon type="close" onClick={(e) => {this.handleTabview(e, view)}}/> : null} + <section id="mk-tabview-wrap" className={'mk-tabview-wrap' + (this.props.collapse ? ' collapsed' : '')}> + <div className="content-header"> + {tabviews && tabviews.length > 0 && + <Tabs activeKey={activeId}> + {tabviews.map(view => { + return ( + <Tabs.TabPane + tab={ + <span className="tab-control"> + <Icon type="redo" onClick={(e) => {this.refreshTabview(e, view)}}/> + <span className="tab-name" onClick={(e) => {this.changeTab(e, view)}}> + {view.MenuName} </span> - } - key={view.MenuID} - > - {this.selectcomponent(view)} - {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> + {view.type !== 'Home' ? + <Icon type="close" onClick={(e) => {this.handleTabview(e, view)}}/> : null + } + </span> + } + key={view.MenuID} + > + {this.selectcomponent(view)} + <BackTop> + <div className="ant-back-top"> + <div className="ant-back-top-content"> + <div className="ant-back-top-icon"></div> </div> - </BackTop> - </Tabs.TabPane> - ) - })} - </Tabs> - } - </div> - </ConfigProvider> + </div> + </BackTop> + {options.sysType === 'local' && window.GLOB.systemType !== 'production' ? <div className="mk-water-mark">娴嬭瘯绯荤粺</div> : null} + </Tabs.TabPane> + ) + })} + </Tabs> + } + </div> </section> ) } @@ -258,4 +271,4 @@ } } -export default connect(mapStateToProps, mapDispatchToProps)(Header) \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(TabViews) \ No newline at end of file -- Gitblit v1.8.0