From 3b103caa6bfc9ed410e67156c3ca1785bf1cecc9 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 19 八月 2022 01:15:31 +0800 Subject: [PATCH] 2022-08-19 --- src/components/tabview/index.jsx | 270 ++++++++++++++++++++++++++++++++--------------------- 1 files changed, 163 insertions(+), 107 deletions(-) diff --git a/src/components/tabview/index.jsx b/src/components/tabview/index.jsx index 7f5d069..1f95394 100644 --- a/src/components/tabview/index.jsx +++ b/src/components/tabview/index.jsx @@ -1,23 +1,24 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import {connect} from 'react-redux' -import { is, fromJS } from 'immutable' -import {Tabs, Icon, BackTop} from 'antd' +import { fromJS } from 'immutable' +import {Tabs, BackTop, notification} from 'antd' +import { RedoOutlined, CloseOutlined } from '@ant-design/icons' import moment from 'moment' import 'moment/locale/zh-cn' -import { modifyTabview, toggleIsiframe } from '@/store/action' +import { initActionPermission } from '@/store/action' import asyncComponent from '@/utils/asyncLoadComponent' import NotFount from '@/components/404' -import mzhCN from '@/locales/zh-CN/main.js' -import menUS from '@/locales/en-US/main.js' +import options from '@/store/options.js' import MKEmitter from '@/utils/events.js' - +import Api from '@/api' import './index.scss' 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')) @@ -35,85 +36,164 @@ 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 // 鏍囩椤垫暟缁� + collapse: PropTypes.bool } state = { activeId: '', tabviews: null, // 鏍囩闆� iFrameHeight: 0, - dict: localStorage.getItem('lang') !== 'en-US' ? mzhCN : menUS, } - handleTabview = (e, menu) => { - e.stopPropagation() - // 鍏抽棴tab椤碉紝閲嶆柊閫夋嫨鏄剧ず椤� + // 鍏抽棴tab椤碉紝閲嶆柊閫夋嫨鏄剧ず椤� + closeTabView = (id) => { let tabs = fromJS(this.state.tabviews).toJS() - tabs = tabs.filter(tab => { - return tab.MenuID !== menu.MenuID + let index = -1 + + tabs = tabs.filter((tab, i) => { + if (tab.MenuID === id) { + index = i + return false + } else { + return true + } }) - if (menu.selected && tabs[0]) { - tabs[0].selected = true + if (index > -1) { + let activeId = '' + 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 || '' + } + this.setState({ - activeId: tabs[0].MenuID || '' + activeId, + tabviews: tabs }) - if (this.props.isiframe) { - this.props.toggleIsiframe(false) + let node = document.getElementById('root').parentNode.parentNode + if (node) { + node.scrollTop = 0 } } - - this.props.modifyTabview(tabs) } refreshTabview = (e, menu) => { e.stopPropagation() window.GLOB.CacheMap = new Map() - MKEmitter.emit('reloadMenuView', menu.MenuID) + if (options.sysType === 'local' && window.GLOB.systemType !== 'production') { + let roledefer = new Promise(resolve => { + Api.getSystemConfig({ + func: 's_Get_TrdMenu_Role', + edition_type: 'A', + pro_sys: '' + }).then(result => { + if (!result) return + if (!result.status) { + notification.error({ + top: 92, + message: result.message, + duration: 10 + }) + } else { + let _permAction = {loaded: true} // 鎸夐挳鏉冮檺 + + if (result.UserRoles_Menu) { + result.UserRoles_Menu.forEach(menu => { + if (!menu.MenuID) return + _permAction[menu.MenuID] = true + }) + } + + this.props.initActionPermission(_permAction) + } + + resolve() + }) + }) + + // 鑾峰彇涓昏彍鍗曞弬鏁� + let menudefer = new Promise(resolve => { + Api.getAppVersion().then(() => { + resolve() + }, () => { + resolve() + }) + }) + + Promise.all([roledefer, menudefer]).then(() => { + MKEmitter.emit('reloadMenuView', menu.MenuID) + }) + } else { + MKEmitter.emit('reloadMenuView', menu.MenuID) + } + } + + modifyTabs = (tab, type, fixed) => { + const { tabviews, activeId } = this.state + + 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({ + tabviews: _tabs + }, () => { + this.setState({ + tabviews: [..._tabs, tab], + activeId: tab.MenuID + }) + }) + } else { + this.setState({ + tabviews: [...tabviews, tab], + activeId: tab.MenuID + }) + } + } else if (type === 'replace') { + this.setState({ + tabviews: tab ? [tab] : [], + activeId: tab ? tab.MenuID : '' + }) + } + + let node = document.getElementById('root').parentNode.parentNode + if (node) { + node.scrollTop = 0 + } } changeTab = (e, menu) => { e.stopPropagation() // 绐楀彛鍒囨崲 - let tabs = fromJS(this.state.tabviews).toJS() - tabs = tabs.map(tab => { - tab.selected = false - - if (tab.MenuID === menu.MenuID) { - tab.selected = true - } - - 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, activeId: menu.MenuID || '' }, () => { - if (menu.MenuID) { - MKEmitter.emit('resetActiveMenu', menu.MenuID) - } + MKEmitter.emit('resetActiveMenu', menu.MenuID || '') }) - - this.props.modifyTabview(tabs) } selectcomponent = (view) => { @@ -122,6 +202,8 @@ 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 === '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') { @@ -135,6 +217,8 @@ } 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}/>) @@ -151,55 +235,27 @@ } else { moment.locale('en') } - this.setState({ - tabviews: this.props.tabviews - }) + + if (sessionStorage.getItem('isEditState') !== 'true') { + this.setState({ + activeId: 'home_page_id', + tabviews: [{ + MenuID: 'home_page_id', + MenuName: '棣栭〉', + type: 'Home' + }] + }) + } else { + this.setState({ + activeId: '', + tabviews: [] + }) + } } componentDidMount () { - 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]) - } - } - - 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, - activeId - }) - - let node = document.getElementById('root').parentNode.parentNode - if (node) { - node.scrollTop = 0 - } - } + MKEmitter.addListener('modifyTabs', this.modifyTabs) + MKEmitter.addListener('closeTabView', this.closeTabView) } /** @@ -209,27 +265,29 @@ this.setState = () => { return } + MKEmitter.removeListener('modifyTabs', this.modifyTabs) + MKEmitter.removeListener('closeTabView', this.closeTabView) } render () { 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}> - {tabviews.map(view => { + {tabviews.map((view, index) => { return ( <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) => {this.handleTabview(e, view)}}/> : null + <CloseOutlined onClick={(e) => {e.stopPropagation();this.closeTabView(view.MenuID)}}/> : null } </span> } @@ -243,6 +301,7 @@ </div> </div> </BackTop> + {/* {options.sysType === 'local' && window.GLOB.systemType !== 'production' ? <div className="mk-water-mark">娴嬭瘯绯荤粺</div> : null} */} </Tabs.TabPane> ) })} @@ -256,17 +315,14 @@ const mapStateToProps = (state) => { return { - tabviews: state.tabviews, collapse: state.collapse, - isiframe: state.isiframe } } const mapDispatchToProps = (dispatch) => { return { - modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)), - toggleIsiframe: (isiframe) => dispatch(toggleIsiframe(isiframe)) + initActionPermission: (permAction) => dispatch(initActionPermission(permAction)) } } -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