| | |
| | | import React, {Component} from 'react' |
| | | import { connect } from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Menu, Icon, notification } from 'antd' |
| | | import { Menu, Popover, Modal, notification } from 'antd' |
| | | import { EditOutlined, PlusOutlined, SettingOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import { modifyTabview, resetEditLevel, modifyMenuTree, modifyMainMenu } from '@/store/action' |
| | | import { SySMenuList } from './config' |
| | | import options from '@/store/options.js' |
| | | import zhCN from '@/locales/zh-CN/main.js' |
| | | import enUS from '@/locales/en-US/main.js' |
| | | import Utils from '@/utils/utils.js' |
| | | import Api from '@/api' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import MkIcon from '@/components/mk-icon' |
| | | import './index.scss' |
| | | |
| | | const EditSecMenu = asyncComponent(() => import('@/templates/menuconfig/editsecmenu')) |
| | | const EditThdMenu = asyncComponent(() => import('@/templates/menuconfig/editthdmenu')) |
| | | const EditSecMenu = asyncComponent(() => import('./editsecmenu')) |
| | | const EditThdMenu = asyncComponent(() => import('./editthdmenu')) |
| | | const ThawMenu = asyncComponent(() => import('@/components/thawmenu')) |
| | | const AddThdMenu = asyncComponent(() => import('./thdmenuplus')) |
| | | const ThdMenuForm = asyncComponent(() => import('./thdmenuform')) |
| | | const MenuForm = asyncComponent(() => import('./menuform')) |
| | | const { SubMenu } = Menu |
| | | |
| | | class Sidemenu extends Component { |
| | | state = { |
| | | dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, |
| | | subMenulist: [], // 二级菜单 |
| | | editMenu: null, // 编辑三级菜单时设置 |
| | | rootSubmenuKeys: null, |
| | | openKeys: null, |
| | | preview: null |
| | | preview: null, |
| | | loading: false, |
| | | thdVisible: false, |
| | | sysMenu: null, |
| | | formlist: [] |
| | | } |
| | | |
| | | async loadsubmenu (menu) { |
| | | if (!menu || !menu.MenuID) { // 没有主菜单时,清空下级菜单 |
| | | this.setState({ |
| | | subMenulist: [], |
| | | rootSubmenuKeys: [], |
| | | openKeys: [], |
| | | editMenu: null |
| | |
| | | menu = fromJS(menu).toJS() |
| | | let openKey = '' |
| | | |
| | | if (menu.children[0]) { |
| | | openKey = menu.openId || menu.children[0].MenuID |
| | | // 菜单更新时,展开原二级菜单 |
| | | if (this.props.mainMenu && menu.MenuID === this.props.mainMenu.MenuID && this.state.openKeys && this.state.openKeys[0]) { |
| | | openKey = this.state.openKeys[0] |
| | | if (menu.children.filter(m => m.MenuID === openKey).length === 0) { |
| | | openKey = '' |
| | | } |
| | | } |
| | | if (!openKey && menu.children[0]) { |
| | | openKey = menu.children[0].MenuID |
| | | } |
| | | |
| | | this.setState({ |
| | | subMenulist: menu.children, |
| | | rootSubmenuKeys: menu.children.map(item => item.MenuID), |
| | | openKeys: openKey ? [openKey] : [], |
| | | editMenu: this.props.editLevel === 'level3' ? menu.children.filter(_menu => _menu.MenuID === this.state.editMenu.MenuID)[0] : null |
| | | }) |
| | | } |
| | | |
| | | enterManageView = () => { |
| | | let menulist = SySMenuList |
| | | |
| | | if (window.GLOB.systemType === 'production') { |
| | | menulist.forEach(menu => { |
| | | menu.children = menu.children.filter(item => item.systems && item.systems.includes(window.GLOB.systemType)) |
| | | }) |
| | | |
| | | menulist = menulist.filter(menu => menu.children.length > 0) |
| | | } else { |
| | | menulist.forEach(menu => { |
| | | menu.children = menu.children.filter(item => !item.systems || item.systems.includes(options.sysType)) |
| | | }) |
| | | |
| | | menulist = menulist.filter(menu => menu.children.length > 0) |
| | | } |
| | | |
| | | this.setState({ |
| | | subMenulist: menulist, |
| | | rootSubmenuKeys: menulist.map(item => item.MenuID), |
| | | openKeys: [menulist[0].MenuID] |
| | | }) |
| | | } |
| | | |
| | | changemenu(e, menu) { |
| | | e.preventDefault() |
| | | if (this.props.editLevel !== 'HS') { |
| | | return |
| | | } |
| | | |
| | | let tabs = fromJS(this.props.tabviews).toJS() |
| | | tabs = tabs.filter(tab => { |
| | | tab.selected = false |
| | | return tab.MenuID !== menu.MenuID |
| | | }) |
| | | |
| | | if (this.props.tabviews.length !== tabs.length) { |
| | | this.props.modifyTabview(fromJS(tabs).toJS()) |
| | | } |
| | | |
| | | this.setState({}, () => { |
| | | menu.selected = true |
| | | tabs.push(menu) |
| | | this.props.modifyTabview(tabs) |
| | | }) |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu)) && nextProps.mainMenu && nextProps.mainMenu.MenuID === 'systemManageView') { |
| | | this.enterManageView() |
| | | } else if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) { |
| | | // 主菜单切换,请求2、3级菜单数据 |
| | | if (!is(fromJS(this.props.mainMenu), fromJS(nextProps.mainMenu))) { |
| | | this.loadsubmenu(nextProps.mainMenu) |
| | | } |
| | | } |
| | | |
| | | shouldComponentUpdate(nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | onOpenChange = openKeys => { |
| | |
| | | enterSubEdit = (e) => { |
| | | // 编辑二级菜单 |
| | | e.stopPropagation() |
| | | |
| | | if (this.props.mainMenu.children.length === 0) return |
| | | |
| | | this.props.resetEditLevel('level2') |
| | | } |
| | | |
| | |
| | | this.setState({editMenu: menu}) |
| | | } |
| | | |
| | | reload = () => { |
| | | const { mainMenu } = this.props |
| | | let _param = {func: 's_get_pc_menus', systemType: options.sysType, debug: 'Y'} |
| | | if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') { |
| | | _param.linkurl = window.GLOB.linkurl |
| | | } |
| | | _param.pro_sys = window.GLOB.systemType === 'production' ? 'Y' : '' |
| | | |
| | | Api.getSystemConfig(_param).then(result => { |
| | | // 登录超时 |
| | | if (!result) return |
| | | |
| | | if (result.status) { |
| | | let res = this.getMenulist(result) |
| | | let _mainMenu = res.menulist.filter(item => item.MenuID === mainMenu.MenuID)[0] |
| | | |
| | | this.props.modifyMenuTree(res.menulist) |
| | | this.props.modifyMainMenu(_mainMenu || null) |
| | | } else { |
| | | notification.error({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 10 |
| | | }) |
| | | } |
| | | this.loadsubmenu(this.props.mainMenu) |
| | | }) |
| | | } |
| | | |
| | | getMenulist = (result) => { |
| | | let iframes = ['Main/Index', 'bda/rdt', 'Home/rdt'] |
| | | let menulist = result.fst_menu.map(fst => { |
| | | let fstItem = { |
| | | MenuID: fst.MenuID, |
| | | MenuName: fst.MenuName, |
| | | PageParam: {OpenType: 'menu', linkUrl: ''}, |
| | | children: [] |
| | | } |
| | | if (fst.PageParam) { |
| | | try { |
| | | fstItem.PageParam = JSON.parse(fst.PageParam) |
| | | } catch (e) { |
| | | fstItem.PageParam = {OpenType: 'menu', linkUrl: ''} |
| | | } |
| | | } |
| | | |
| | | if (fst.snd_menu) { |
| | | fstItem.children = fst.snd_menu.map(snd => { |
| | | let sndItem = { |
| | | ParentId: fst.MenuID, |
| | | MenuID: snd.MenuID, |
| | | MenuName: snd.MenuName, |
| | | PageParam: {Icon: 'folder'}, |
| | | children: [] |
| | | } |
| | | |
| | | if (snd.PageParam) { |
| | | try { |
| | | sndItem.PageParam = JSON.parse(snd.PageParam) |
| | | } catch (e) { |
| | | sndItem.PageParam = {Icon: 'folder'} |
| | | } |
| | | } |
| | | |
| | | if (snd.trd_menu) { |
| | | sndItem.children = snd.trd_menu.map(trd => { |
| | | let trdItem = { |
| | | FstId: fst.MenuID, |
| | | ParentId: snd.MenuID, |
| | | MenuID: trd.MenuID, |
| | | MenuName: trd.MenuName, |
| | | MenuNo: trd.MenuNo, |
| | | EasyCode: trd.EasyCode, |
| | | type: 'CommonTable', // 默认值为常用表 |
| | | OpenType: 'newtab' // 打开方式 |
| | | } |
| | | |
| | | if (trd.LinkUrl && iframes.includes(trd.LinkUrl.split('?')[0])) { |
| | | trdItem.type = 'iframe' |
| | | trdItem.LinkUrl = trd.LinkUrl |
| | | trdItem.forbidden = true |
| | | } else { |
| | | try { |
| | | trdItem.PageParam = trd.PageParam ? JSON.parse(trd.PageParam) : {OpenType: 'newtab'} |
| | | } catch (e) { |
| | | trdItem.PageParam = {OpenType: 'newtab'} |
| | | } |
| | | |
| | | trdItem.type = trdItem.PageParam.Template || trdItem.type |
| | | trdItem.OpenType = trdItem.PageParam.OpenType || trdItem.OpenType |
| | | |
| | | if (trdItem.type === 'CustomPage' && this.props.memberLevel < 20) { // 会员等级大于等于20时,有编辑权限 |
| | | trdItem.forbidden = true |
| | | } |
| | | } |
| | | return trdItem |
| | | }) |
| | | } |
| | | return sndItem |
| | | }) |
| | | } |
| | | return fstItem |
| | | }) |
| | | |
| | | return { menulist } |
| | | } |
| | | |
| | | exitEdit = () => { |
| | | if (this.props.editLevel === 'level3') { |
| | | this.setState({editMenu: null}) |
| | |
| | | this.props.resetEditLevel(false) |
| | | } |
| | | |
| | | editmenu = (cell) => { |
| | | if (window.GLOB.systemType === 'production') return |
| | | |
| | | if (cell.type === 'CustomPage') { |
| | | let _param = { |
| | | MenuType: 'custom', |
| | | MenuId: cell.MenuID, |
| | | ParentId: cell.ParentId, |
| | | MenuName: cell.MenuName, |
| | | MenuNo: cell.MenuNo |
| | | } |
| | | _param = window.btoa(window.encodeURIComponent(JSON.stringify(_param))) |
| | | window.open(`#/menudesign/${_param}`) |
| | | } else if (['CommonTable', 'TreePage'].includes(cell.type)) { |
| | | sessionStorage.setItem('menuTree', JSON.stringify(this.props.menuTree)) |
| | | let _param = window.btoa(window.encodeURIComponent(JSON.stringify(cell))) |
| | | |
| | | window.open(`#/basedesign/${_param}`) |
| | | } else if (cell.type === 'BaseTable') { |
| | | sessionStorage.setItem('menuTree', JSON.stringify(this.props.menuTree)) |
| | | let _param = window.btoa(window.encodeURIComponent(JSON.stringify(cell))) |
| | | |
| | | window.open(`#/tabledesign/${_param}`) |
| | | } else if (['RolePermission', 'NewPage'].includes(cell.type)) { |
| | | let _cell = fromJS(cell).toJS() |
| | | _cell.Template = _cell.PageParam.Template |
| | | _cell.url = _cell.PageParam.url || '' |
| | | |
| | | _cell.fstMenuId = _cell.FstId |
| | | _cell.supMenuList = this.props.mainMenu.children |
| | | _cell.fstMenuList = this.props.menuTree |
| | | |
| | | this.setState({ |
| | | thdVisible: true, |
| | | loading: false, |
| | | sysMenu: _cell |
| | | }) |
| | | } else { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '当前菜单不可编辑', |
| | | duration: 5 |
| | | }) |
| | | } |
| | | } |
| | | |
| | | addSecMenu = () => { |
| | | this.setState({ |
| | | visible: true, |
| | | loading: false, |
| | | formlist: [ |
| | | { // 父级菜单 |
| | | type: 'select', |
| | | key: 'parentId', |
| | | label: '上级菜单', |
| | | initVal: this.props.mainMenu.MenuID, |
| | | required: true, |
| | | options: this.props.menuTree |
| | | }, |
| | | { // 菜单名称 |
| | | type: 'text', |
| | | key: 'menuName', |
| | | label: '菜单名称', |
| | | initVal: '', |
| | | required: true, |
| | | readonly: false |
| | | }, |
| | | { // 菜单图标 |
| | | type: 'icon', |
| | | key: 'icon', |
| | | label: '图标', |
| | | initVal: 'folder', |
| | | required: true |
| | | } |
| | | ] |
| | | }) |
| | | } |
| | | |
| | | secSubmit = () => { |
| | | this.menuFormRef.handleConfirm().then(values => { |
| | | let param = { |
| | | ParentID: values.parentId, |
| | | MenuID: Utils.getuuid(), |
| | | MenuName: values.menuName, |
| | | PageParam: JSON.stringify({ |
| | | Icon: values.icon |
| | | }) |
| | | } |
| | | param.func = 'sPC_SndMenu_Add' |
| | | param.Sort = (this.props.mainMenu.children.length + 1) * 10 |
| | | |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | Api.getCloudConfig(param).then(res => { |
| | | if (res.status) { |
| | | this.setState({ |
| | | loading: false, |
| | | visible: false |
| | | }) |
| | | MKEmitter.emit('mkUpdateMenuList') |
| | | } else { |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | notification.warning({ |
| | | top: 92, |
| | | message: res.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 三级菜单修改 |
| | | */ |
| | | thdSubmit = () => { |
| | | const { sysMenu } = this.state |
| | | |
| | | this.menuThdFormRef.handleConfirm().then(res => { |
| | | let PageParam = { |
| | | Template: sysMenu.Template, |
| | | OpenType: 'newtab' |
| | | } |
| | | |
| | | if (sysMenu.Template === 'NewPage') { |
| | | PageParam.OpenType = 'NewPage' |
| | | PageParam.url = res.url |
| | | } |
| | | |
| | | let param = { |
| | | func: 'sPC_TrdMenu_AddUpt', |
| | | FstID: res.fstMenuId, |
| | | SndID: res.ParentID, |
| | | ParentID: res.ParentID, |
| | | MenuID: sysMenu.MenuID, |
| | | MenuNo: res.MenuNo, |
| | | Template: sysMenu.Template, |
| | | MenuName: res.MenuName, |
| | | PageParam: JSON.stringify(PageParam), |
| | | LongParam: '', |
| | | LText: '', |
| | | LTexttb: '' |
| | | } |
| | | |
| | | param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') |
| | | param.secretkey = Utils.encrypt(param.LText, param.timestamp) |
| | | |
| | | this.setState({ |
| | | loading: true |
| | | }) |
| | | |
| | | Api.getCloudConfig(param).then(response => { |
| | | if (response.status) { |
| | | this.setState({ |
| | | loading: false, |
| | | thdVisible: false, |
| | | sysMenu: null |
| | | }) |
| | | MKEmitter.emit('mkUpdateMenuList') |
| | | } else { |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | notification.warning({ |
| | | top: 92, |
| | | message: response.message, |
| | | duration: 5 |
| | | }) |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | render () { |
| | | const { mainMenu, editLevel } = this.props |
| | | const { visible, loading, thdVisible } = this.state |
| | | |
| | | return ( |
| | | <aside id="mk-sidemenu-wrap" className="mk-sys-side-menu ant-menu-dark mk-edit"> |
| | | {!(this.props.editLevel === 'level2' || this.props.editLevel === 'level3') && |
| | | <aside className="mk-sys-side-menu ant-menu-dark mk-edit"> |
| | | {editLevel !== 'level2' && editLevel !== 'level3' && mainMenu ? |
| | | <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark"> |
| | | {!this.props.editLevel && <li className="sup-menu"><Icon onClick={this.enterSubEdit} className="edit-check" type="edit" /></li>} |
| | | {this.state.subMenulist && this.state.subMenulist.map((item, index) => { |
| | | <li className="sup-menu"> |
| | | <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <PlusOutlined onClick={this.addSecMenu}/> |
| | | <EditOutlined onClick={this.enterSubEdit} className={'mk-swap' + (mainMenu.children.length === 0 ? ' disabled' : '')}/> |
| | | <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={mainMenu.MenuID} Type="20"/></div> |
| | | </div> |
| | | } trigger="hover" placement="top"> |
| | | <SettingOutlined className="edit-check"/> |
| | | </Popover> |
| | | </li> |
| | | {mainMenu.children.map((item, index) => { |
| | | return ( |
| | | <SubMenu |
| | | key={item.MenuID} |
| | | title={ |
| | | <span className={!this.props.editLevel && index === 0 ? 'edit-control' : ''}> |
| | | <Icon type={item.PageParam.Icon} /> |
| | | <span className={!editLevel && index === 0 ? 'edit-control' : ''}> |
| | | <MkIcon type={item.PageParam ? item.PageParam.Icon : 'folder'} /> |
| | | <span>{item.MenuName}</span> |
| | | </span> |
| | | } |
| | | > |
| | | {!this.props.editLevel ? <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}> |
| | | <Icon onClick={(e) => {this.enterThrEdit(e, item)}} className="edit-check" type="edit" /> |
| | | </li> : null} |
| | | <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}> |
| | | <Popover overlayClassName="mk-popover-control-wrap mk-menu-control" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <div style={{display: 'inline-block', minWidth: '32px'}}><AddThdMenu mainMenu={mainMenu} supMenu={item} menuTree={this.props.menuTree}/></div> |
| | | <EditOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-swap"/> |
| | | <div style={{display: 'inline-block', minWidth: '32px'}}><ThawMenu ParentId={item.MenuID} Type="30"/></div> |
| | | </div> |
| | | } trigger="hover" placement="top"> |
| | | <SettingOutlined className="edit-check"/> |
| | | </Popover> |
| | | </li> |
| | | {item.children.map(cell => { |
| | | return ( |
| | | <Menu.Item key={cell.MenuID}> |
| | | <a href={cell.src} id={cell.MenuID} onClick={(e) => this.changemenu(e, cell)}>{cell.MenuName}</a> |
| | | <span className="editable-menu-item" onDoubleClick={() => this.editmenu(cell)}>{cell.MenuName}</span> |
| | | </Menu.Item> |
| | | ) |
| | | })} |
| | | </SubMenu> |
| | | ) |
| | | })} |
| | | </Menu>} |
| | | {this.props.editLevel === 'level2' ? |
| | | </Menu> : null} |
| | | {editLevel === 'level2' && mainMenu ? |
| | | <EditSecMenu |
| | | menulist={this.state.subMenulist} |
| | | menulist={mainMenu.children} |
| | | menuTree={this.props.menuTree} |
| | | supMenu={this.props.mainMenu} |
| | | reload={this.reload} |
| | | exitEdit={this.exitEdit} |
| | | /> : null |
| | | } |
| | | {this.props.editLevel === 'level3' && this.state.editMenu ? |
| | | {editLevel === 'level3' && mainMenu && this.state.editMenu ? |
| | | <EditThdMenu |
| | | menulist={this.state.editMenu.children} |
| | | supMenuList={this.state.subMenulist} |
| | | supMenuList={mainMenu.children} |
| | | supMenu={this.state.editMenu} |
| | | reload={this.reload} |
| | | menuTree={this.props.menuTree} |
| | | exitEdit={this.exitEdit} |
| | | /> : null |
| | | } |
| | | <Modal |
| | | title="添加菜单" |
| | | visible={visible} |
| | | onOk={this.secSubmit} |
| | | // confirmLoading={loading} |
| | | onCancel={() => this.setState({visible: false})} |
| | | destroyOnClose |
| | | > |
| | | <MenuForm |
| | | inputSubmit={this.secSubmit} |
| | | formlist={this.state.formlist} |
| | | wrappedComponentRef={(inst) => this.menuFormRef = inst} |
| | | /> |
| | | </Modal> |
| | | <Modal |
| | | title="修改菜单" |
| | | visible={thdVisible} |
| | | width={700} |
| | | onOk={this.thdSubmit} |
| | | confirmLoading={loading} |
| | | onCancel={() => {this.setState({thdVisible: false})}} |
| | | destroyOnClose |
| | | > |
| | | <ThdMenuForm |
| | | menu={this.state.sysMenu} |
| | | inputSubmit={this.thdSubmit} |
| | | wrappedComponentRef={(inst) => this.menuThdFormRef = inst} |
| | | /> |
| | | </Modal> |
| | | </aside> |
| | | ) |
| | | } |
| | | } |
| | | |
| | | const mapStateToProps = (state) => { |
| | | return { |
| | | tabviews: state.tabviews, |
| | | mainMenu: state.mainMenu, |
| | | menuTree: state.menuTree, |
| | | memberLevel: state.memberLevel, |
| | | editLevel: state.editLevel |
| | | } |
| | | } |
| | | |
| | | const mapDispatchToProps = (dispatch) => { |
| | | return { |
| | | modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)), |
| | | modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)), |
| | | modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)), |
| | | resetEditLevel: (level) => dispatch(resetEditLevel(level)) |
| | | } |
| | | } |
| | | |
| | | export default connect(mapStateToProps, mapDispatchToProps)(Sidemenu) |
| | | export default Sidemenu |