From 9a82bce9cf0ed4a51c1b0b0669eaa38cedbace07 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 16 七月 2020 16:35:58 +0800 Subject: [PATCH] 2020-07-16 --- src/components/header/index.jsx | 277 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 243 insertions(+), 34 deletions(-) diff --git a/src/components/header/index.jsx b/src/components/header/index.jsx index cd58ef4..c34965b 100644 --- a/src/components/header/index.jsx +++ b/src/components/header/index.jsx @@ -4,33 +4,36 @@ import {connect} from 'react-redux' import { is, fromJS } from 'immutable' import moment from 'moment' -import {Dropdown, Menu, Icon, Modal, Form, notification, Switch, Button } from 'antd' +import {Dropdown, Menu, Icon, Modal, Form, notification, Switch, Button, Input } from 'antd' import asyncComponent from '@/utils/asyncComponent' import { toggleCollapse, modifyMainMenu, + modifyTabview, resetState, resetDebug, resetEditState, resetEditLevel, initPermission, + modifyDataManager, initActionPermission, initMenuPermission, logout } from '@/store/action' import Api from '@/api' import options from '@/store/options.js' -import zhCN from '@/locales/zh-CN/header.js' -import enUS from '@/locales/en-US/header.js' +import zhCN from '@/locales/zh-CN/main.js' +import enUS from '@/locales/en-US/main.js' import Utils from '@/utils/utils.js' import avatar from '@/assets/img/avatar.jpg' import Resetpwd from './resetpwd' import LoginForm from './loginform' import './index.scss' -const EditMenu = asyncComponent(() => import('./editmenu')) +const EditMenu = asyncComponent(() => import('@/templates/headerconfig')) const { confirm } = Modal +const { Search } = Input class Header extends Component { static propTpyes = { @@ -43,14 +46,16 @@ state = { menulist: null, // 涓�绾ц彍鍗� visible: false, // 淇敼瀵嗙爜妯℃�佹 - dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS, + dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, confirmLoading: false, userName: sessionStorage.getItem('User_Name'), logourl: window.GLOB.mainlogo, loginVisible: false, loginLoading: false, avatar: avatar, - systems: [] + systems: [], + searchkey: '', + thdMenuList: [] } handleCollapse = () => { @@ -96,14 +101,14 @@ }) notification.success({ top: 92, - message: this.state.dict['header.password.resetsuccess'], + message: this.state.dict['main.password.resetsuccess'], duration: 2 }) } else { notification.warning({ top: 92, message: result.message, - duration: 10 + duration: 5 }) this.setState({ confirmLoading: false @@ -122,10 +127,10 @@ // 閫�鍑虹櫥褰� let _this = this confirm({ - title: this.state.dict['header.logout.hint'], + title: this.state.dict['main.logout.hint'], content: '', - okText: this.state.dict['header.confirm'], - cancelText: this.state.dict['header.cancel'], + okText: this.state.dict['main.confirm'], + cancelText: this.state.dict['main.cancel'], onOk() { sessionStorage.clear() _this.props.logout() @@ -150,9 +155,12 @@ async loadmenu () { // 鑾峰彇涓昏彍鍗� - let _param = {func: 'sPC_Get_MainMenu', systemType: options.systemType} + let _param = {func: 'sPC_Get_MainMenu', systemType: options.sysType} if (sessionStorage.getItem('isEditState') === 'true') { // 缂栬緫鐘舵�佹椂锛岃幏鍙栦竴绾ц彍鍗曪紝澧炲姞鍙傛暟debug _param.debug = 'Y' + } + if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { + _param.linkurl = window.GLOB.linkurl } let result = await Api.getSystemConfig(_param) @@ -192,11 +200,15 @@ }), systems: result.Systems.filter(sys => sys.LinkUrl1 && sys.AppKey !== window.GLOB.appkey) }) + + if (result.dataM) { + this.props.modifyDataManager(true) + } } else { notification.error({ top: 92, message: result.message, - duration: 15 + duration: 10 }) } } @@ -222,7 +234,7 @@ notification.error({ top: 92, message: result.message, - duration: 15 + duration: 10 }) } @@ -232,7 +244,12 @@ // 鑾峰彇涓昏彍鍗曞弬鏁� let promiseMenu = new Promise(resolve => { - Api.getSystemConfig({func: 'sPC_Get_MainMenu', systemType: options.systemType}).then(result => { + let _param = {func: 'sPC_Get_MainMenu', systemType: options.sysType} + if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { + _param.linkurl = window.GLOB.linkurl + } + + Api.getSystemConfig(_param).then(result => { let mainMenu = null if (result && result.status) { if (result.debug === 'true') { // 鏄惁涓篸ebug妯″紡锛屽嵆鍙鍒惰彍鍗曞弬鏁� @@ -266,11 +283,15 @@ }), systems: result.Systems.filter(sys => sys.LinkUrl1 && sys.AppKey !== window.GLOB.appkey) }) + + if (result.dataM) { + this.props.modifyDataManager(true) + } } else if (result) { notification.error({ top: 92, message: result.message, - duration: 15 + duration: 10 }) } @@ -296,6 +317,13 @@ } changeEditState = (state) => { + const { menulist } = this.state + + if (!state) { // 閫�鍑虹紪杈戯紝椤甸潰鍒锋柊 + window.location.reload() + return + } + // 淇敼缂栬緫鐘舵�� let UserID = sessionStorage.getItem('CloudUserID') let LoginUID = sessionStorage.getItem('CloudLoginUID') @@ -319,6 +347,32 @@ _userName = sessionStorage.getItem('CloudUserName') } + if (window.GLOB.systemType === 'production' && state) { + this.props.resetEditLevel('HS') + this.props.modifyMainMenu({ + MenuID: 'systemManageView' + }) + + this.setState({ + userName: _userName, + avatar: _avatar + }) + this.props.resetEditState(state) + + return + } else if (window.GLOB.systemType === 'production' && !state) { + this.props.resetEditLevel(false) + this.props.modifyMainMenu(menulist[0] || '') + + this.setState({ + userName: _userName, + avatar: _avatar + }) + this.props.resetEditState(state) + + return + } + this.setState({ menulist: null, userName: _userName, @@ -329,7 +383,7 @@ this.props.resetEditState(state) } - if (state && this.props.sysRoles.length === 0 && this.props.permFuncField.length === 0) { + if (state && this.props.sysRoles.length === 0 && this.props.permFuncField.length === 0 && window.GLOB.systemType !== 'production') { Api.getSystemConfig({func: 'sPC_Get_Roles_sModular'}).then(res => { if (res.status) { let _permFuncField = [] @@ -380,6 +434,23 @@ _avatar = Utils.getrealurl(res.icon) // 澶村儚 } + if (window.GLOB.systemType === 'production') { + this.props.resetEditLevel('HS') + this.props.modifyMainMenu({ + MenuID: 'systemManageView' + }) + + this.setState({ + loginVisible: false, + loginLoading: false, + userName: res.UserName, + avatar: _avatar + }) + this.props.resetEditState(true) + + return + } + this.setState({ menulist: null, loginVisible: false, @@ -397,7 +468,7 @@ notification.error({ top: 92, message: res.message, - duration: 15 + duration: 10 }) } }) @@ -412,9 +483,9 @@ enterEditManage = () => { const { editLevel } = this.props - if (editLevel === 'level4') return + if (editLevel === 'HS') return - this.props.resetEditLevel('level4') + this.props.resetEditLevel('HS') this.props.modifyMainMenu({ MenuID: 'systemManageView' }) @@ -424,6 +495,11 @@ * @description 閫�鍑虹鐞嗙晫闈㈣彍鍗� */ exitManage = () => { + if (window.GLOB.systemType === 'production') { // 姝e紡绯荤粺鐗堟湰鍗囩骇鍚庯紝椤甸潰鍒锋柊 + window.location.reload() + return + } + this.props.resetEditState(true) this.props.resetEditLevel(false) this.reload() @@ -437,6 +513,46 @@ changeSystem = (system) => { let _param = window.btoa('ud=' + sessionStorage.getItem('UserID') + '&sd=' + sessionStorage.getItem('SessionUid') + '&ld=' + sessionStorage.getItem('LoginUID') + '&un=' + sessionStorage.getItem('User_Name')) window.location.href = system.LinkUrl1 + '#/ssologin/' + _param + } + + dropdownMenuChange = (visible) => { + this.setState({searchkey: ''}, () => { + if (visible) { + setTimeout(() => { + let input = document.getElementById('thdMenu-search') + + if (input) { + input.focus() + } + }, 500) + } + }) + } + + selectMenu = (item) => { + const { tabviews } = this.props + + let menu = JSON.parse(JSON.stringify(item)) + menu.selected = true + + let index = 0 + let isexit = false + let tabs = tabviews.map((tab, i) => { + tab.selected = false + + if (tab.MenuID === menu.MenuID) { + tab.selected = true + isexit = true + } + + return tab + }) + + if (!isexit) { + tabs.splice(index + 1, 0, menu) + } + + this.props.modifyTabview(tabs) } UNSAFE_componentWillMount () { @@ -455,21 +571,59 @@ if (!result) return if (result.status) { let _permMenus = {} + let menulist = [] + if (result.UserRoles) { + let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt'] + result.UserRoles.forEach(role => { role.RoleMenu.forEach(menu => { if (!menu.MenuID) return _permMenus[menu.MenuID] = true + + let _type = '' + if (menu.LinkUrl) { + if (menu.LinkUrl === 'CommonTable') { + _type = 'CommonTable' + } else if (menu.LinkUrl === 'DataManage') { + _type = 'DataManage' + } else if (iframes.includes(menu.LinkUrl.split('?')[0])) { + _type = 'iframe' + } + } + + if (_type !== 'iframe') { + let pageParam = {} + try { + pageParam = JSON.parse(menu.PageParam) + } catch (e) { + pageParam = {} + } + _type = pageParam.Template || _type + } + + menulist.push({ + MenuID: menu.MenuID, + MenuName: menu.MenuName, + MenuNo: menu.MenuNo || '', + EasyCode: menu.EasyCode || '', + LinkUrl: menu.LinkUrl, + type: _type + }) }) }) } + this.setState({ + thdMenuList: menulist + }) + this.props.initMenuPermission(_permMenus) } else { notification.error({ top: 92, message: result.message, - duration: 15 + duration: 10 }) } }) @@ -479,25 +633,38 @@ return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) } + gotoDoc = () => { + if (options.sysType === 'local' && window.GLOB.mainSystemApi) { + let ssodomain = window.GLOB.mainSystemApi.replace('/webapi/dostars', '') + let url = `${ssodomain}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}` + window.open(url) + } else if (options.sysType === 'SSO' || options.sysType === 'cloud') { + window.open(`${window.location.href.replace(/\/index.html(.*)|\/#(.*)/ig, '')}/doc/index.html#?appkey=${window.GLOB.appkey}&LoginUID=${sessionStorage.getItem('LoginUID')}`) + } + } + render () { + const { thdMenuList, searchkey } = this.state + const menu = ( <Menu overlayclassname="header-dropdown"> {this.props.debug && <Menu.Item key="0"> - {this.state.dict['header.edit']} + {this.state.dict['main.edit']} <Switch size="small" className="edit-switch" disabled={!!this.props.editLevel} checked={this.props.editState} onChange={this.changeEditState} /> </Menu.Item>} - {!this.props.editState ? <Menu.Item key="1" onClick={this.changePassword}>{this.state.dict['header.password']}</Menu.Item> : null} + {!this.props.editState ? <Menu.Item key="1" onClick={this.changePassword}>{this.state.dict['main.password']}</Menu.Item> : null} {/* {this.state.systems.length > 0 ? <Menu.SubMenu title="鍒囨崲绯荤粺"> {this.state.systems.map((system, index) => ( <Menu.Item className="header-subSystem" key={'sub' + index} onClick={() => {this.changeSystem(system)}}> {system.AppName} </Menu.Item> ))} </Menu.SubMenu> : null} */} - <Menu.Item key="2" onClick={this.logout}>{this.state.dict['header.logout']}</Menu.Item> + <Menu.Item key="2" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item> + <Menu.Item key="3" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item> </Menu> ) return ( - <header className="header-container ant-menu-dark"> + <header className="header-container ant-menu-dark" id="main-header-container"> <div className={this.props.collapse ? "collapse header-logo" : "header-logo"}><img src={this.state.logourl} alt=""/></div> <div className={this.props.collapse ? "collapse header-collapse" : "header-collapse"} onClick={this.handleCollapse}> <Icon type={this.props.collapse ? 'menu-unfold' : 'menu-fold'} /> @@ -512,16 +679,19 @@ </li> ) })} - {this.props.editState && (!this.props.editLevel || this.props.editLevel === 'level4') ? - <li key="HS" onClick={this.enterEditManage} className={this.props.editLevel === 'level4' ? 'active' : ''}> + {this.props.editState && (!this.props.editLevel || this.props.editLevel === 'HS') ? + <li key="HS" onClick={this.enterEditManage} className={this.props.editLevel === 'HS' ? 'active' : ''}> <span>HS</span> </li> : null } </ul> : null } - {this.props.editLevel === 'level4' ? <Button className="level4-close" type="primary" onClick={this.exitManage}>閫�鍑�</Button> : null} + {this.props.editLevel === 'HS' ? <Button className="level4-close" type="primary" onClick={this.exitManage}>閫�鍑�</Button> : null} {/* 杩涘叆缂栬緫鎸夐挳 */} {this.props.editState && !this.props.editLevel ? <Icon onClick={this.enterEdit} className="edit-check" type="edit" /> : null} + {/* {this.props.editState && !this.props.editLevel && options.sysType === 'local' && window.GLOB.systemType !== 'production' ? + <a href="#/mobmanage" target="_blank" className="mobile" type="edit"> 搴旂敤绠$悊 <Icon type="arrow-right" /></a> : null + } */} {/* 缂栬緫鑿滃崟 */} {this.props.editLevel === 'level1' ? <EditMenu menulist={this.state.menulist} reload={this.reload} exitEdit={this.exitEdit}/> : null} {/* 澶村儚銆佺敤鎴峰悕 */} @@ -533,11 +703,47 @@ </span> </div> </Dropdown> + {/* 鑿滃崟鎼滅储 */} + {!this.props.editState && thdMenuList.length > 0 ? + <Dropdown overlayClassName="menu-select-dropdown" getPopupContainer={() => document.getElementById('main-header-container')} overlay={ + <div> + <Search + placeholder="" + id="thdMenu-search" + value={searchkey} + onChange={e => this.setState({searchkey: e.target.value})} + style={{ minWidth: '200px' }} + onSearch={(val, e) => {e.stopPropagation()}} + onClick={(e) => {e.stopPropagation()}} + /> + <div className="menu-select-box"> + <Menu> + {thdMenuList.map(option => { + if (searchkey) { + if ( + option.MenuName.toLowerCase().indexOf(searchkey.toLowerCase()) >= 0 || + option.MenuNo.toLowerCase().indexOf(searchkey.toLowerCase()) >= 0 || + option.EasyCode.toLowerCase().indexOf(searchkey.toLowerCase()) >= 0 + ) { + return <Menu.Item key={option.MenuID} onClick={() => this.selectMenu(option)}>{option.MenuName}</Menu.Item> + } else { + return null + } + } + return <Menu.Item key={option.MenuID} onClick={() => this.selectMenu(option)}>{option.MenuName}</Menu.Item> + })} + </Menu> + </div> + </div> + } trigger={['click']} className="search-menu" placement="bottomRight" onVisibleChange={this.dropdownMenuChange}> + <Icon className="search-menu" type="search" /> + </Dropdown> : null + } {/* 淇敼瀵嗙爜 */} <Modal - title={this.state.dict['header.password']} - okText={this.state.dict['header.confirm']} - cancelText={this.state.dict['header.cancel']} + title={this.state.dict['main.password']} + okText={this.state.dict['main.confirm']} + cancelText={this.state.dict['main.cancel']} visible={this.state.visible} onOk={this.resetPwdSubmit} confirmLoading={this.state.confirmLoading} @@ -548,9 +754,9 @@ </Modal> {/* 缂栬緫鐘舵�佺櫥褰� */} <Modal - title={this.state.dict['header.login.develop']} - okText={this.state.dict['header.confirm']} - cancelText={this.state.dict['header.cancel']} + title={this.state.dict['main.login.develop']} + okText={this.state.dict['main.confirm']} + cancelText={this.state.dict['main.cancel']} visible={this.state.loginVisible} onOk={this.loginSubmit} width={'430px'} @@ -567,6 +773,7 @@ const mapStateToProps = (state) => { return { + tabviews: state.tabviews, collapse: state.collapse, selectmenu: state.selectedMainMenu, debug: state.debug, @@ -581,12 +788,14 @@ const mapDispatchToProps = (dispatch) => { return { toggleCollapse: (collapse) => dispatch(toggleCollapse(collapse)), + modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)), modifyMainMenu: (selectmenu) => dispatch(modifyMainMenu(selectmenu)), resetEditState: (state) => dispatch(resetEditState(state)), resetEditLevel: (level) => dispatch(resetEditLevel(level)), initActionPermission: (permRoles, permAction) => dispatch(initActionPermission(permRoles, permAction)), initPermission: (sysRoles, permFuncField) => dispatch(initPermission(sysRoles, permFuncField)), initMenuPermission: (permMenus) => dispatch(initMenuPermission(permMenus)), + modifyDataManager: (dataManager) => dispatch(modifyDataManager(dataManager)), resetState: () => dispatch(resetState()), resetDebug: () => dispatch(resetDebug()), logout: () => dispatch(logout()) -- Gitblit v1.8.0