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 | 247 +++++++++++++++++++++++++------------------------ 1 files changed, 125 insertions(+), 122 deletions(-) diff --git a/src/components/tabview/index.jsx b/src/components/tabview/index.jsx index 2637efe..ce5a0e8 100644 --- a/src/components/tabview/index.jsx +++ b/src/components/tabview/index.jsx @@ -2,63 +2,70 @@ 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 enUS from 'antd/es/locale/en_US' -import zhCN from 'antd/es/locale/zh_CN' +import {Tabs, Icon, BackTop} from 'antd' import moment from 'moment' import 'moment/locale/zh-cn' -import {modifyTabview, toggleIsiframe, refreshTabView} from '@/store/action' +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 ManageTable = asyncComponent(() => import('@/tabviews/managetable')) const Iframe = asyncComponent(() => import('@/tabviews/iframe')) -const DataManage = asyncComponent(() => import('@/tabviews/datamanage')) const RoleManage = asyncComponent(() => import('@/tabviews/rolemanage')) -const TabForm = asyncComponent(() => import('@/tabviews/tabform')) const FormTab = asyncComponent(() => import('@/tabviews/formtab')) -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) => { 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) @@ -68,17 +75,13 @@ e.stopPropagation() window.GLOB.CacheMap = new Map() - let _menu = { - MenuID: menu.MenuID, - position: 'view' - } - this.props.refreshTabView(_menu) + 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 @@ -89,8 +92,26 @@ 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) @@ -100,56 +121,29 @@ // 鏍规嵁tab椤典腑鑿滃崟淇℃伅锛岄�夋嫨鎵�闇�鐨勭粍浠� if (view.type === 'Home') { return (<Home MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) - } else if (view.type === 'CommonTable') { + } 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 === 'ManageTable') { - return (<ManageTable MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID}/>) - } else if (view.type === 'DataManage') { - return (<DataManage 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 === 'TabForm') { - return (<TabForm MenuNo={view.MenuNo} MenuID={view.MenuID} MenuName={view.MenuName} key={view.MenuID} param={view.param}/>) } 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} 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 () { @@ -164,25 +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))) { + 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 @@ -192,61 +203,54 @@ } } + /** + * @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"> - {['CommonTable', 'FormTab'].includes(view.type) ? - <Icon type="redo" onClick={(e) => {this.refreshTabview(e, view)}}/> : null - } - <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' && view.type !== 'ManageTable' ? - <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> ) } @@ -263,9 +267,8 @@ const mapDispatchToProps = (dispatch) => { return { modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)), - refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)), toggleIsiframe: (isiframe) => dispatch(toggleIsiframe(isiframe)) } } -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