| | |
| | | import React, {Component} from 'react' |
| | | import { connect } from 'react-redux' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Menu, notification, Popover, Modal, Spin } from 'antd' |
| | | import { EditOutlined, SwapOutlined, PlusOutlined, UnlockOutlined, SettingOutlined } from '@ant-design/icons' |
| | | import { Menu, Popover, Modal, notification } from 'antd' |
| | | import { SwapOutlined, PlusOutlined, SettingOutlined } from '@ant-design/icons' |
| | | import moment from 'moment' |
| | | |
| | | import asyncComponent from '@/utils/asyncComponent' |
| | | import { resetEditLevel, modifyMenuTree, modifyMainMenu } from '@/store/action' |
| | | import options from '@/store/options.js' |
| | | import { resetEditLevel } from '@/store/action' |
| | | import Utils from '@/utils/utils.js' |
| | | import Api from '@/api' |
| | | import MKEmitter from '@/utils/events.js' |
| | | import MkIcon from '@/components/mk-icon' |
| | |
| | | |
| | | const EditSecMenu = asyncComponent(() => import('./editsecmenu')) |
| | | const EditThdMenu = asyncComponent(() => import('./editthdmenu')) |
| | | const TransferForm = asyncComponent(() => import('@/templates/zshare/basetransferform')) |
| | | 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 = { |
| | | 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 |
| | |
| | | } |
| | | |
| | | 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 |
| | | }) |
| | | } |
| | | |
| | | changemenu(e, menu) { |
| | | e.preventDefault() |
| | | if (this.props.editLevel !== 'HS') { |
| | | return |
| | | } |
| | | |
| | | MKEmitter.emit('modifyTabs', menu, 'plus') |
| | | } |
| | | |
| | | componentDidMount () { |
| | | window.addEventListener('storage', (e) => { |
| | | if (e.key !== 'menuUpdate') return |
| | | |
| | | this.reload() |
| | | }) |
| | | shouldComponentUpdate (nextProps, nextState) { |
| | | return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState)) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | |
| | | // 主菜单切换,请求2、3级菜单数据 |
| | | 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') |
| | | } |
| | | |
| | |
| | | e.stopPropagation() |
| | | this.props.resetEditLevel('level3') |
| | | this.setState({editMenu: menu}) |
| | | } |
| | | |
| | | reload = () => { |
| | | const { mainMenu } = this.props |
| | | let _param = {func: 's_get_pc_menus', systemType: options.sysType, debug: 'Y'} |
| | | _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.replace('&', '&') |
| | | 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 = () => { |
| | |
| | | } |
| | | _param = window.btoa(window.encodeURIComponent(JSON.stringify(_param))) |
| | | window.open(`#/menudesign/${_param}`) |
| | | } else { |
| | | } else if (['RolePermission', 'NewPage'].includes(cell.type)) { |
| | | 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 |
| | | }) |
| | | } |
| | | } |
| | | |
| | | 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.getSystemConfig(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.getSystemConfig(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 } = this.state |
| | | |
| | | let isnew = true |
| | | const { visible, loading, thdVisible } = this.state |
| | | |
| | | return ( |
| | | <aside className="mk-sys-side-menu ant-menu-dark mk-edit"> |
| | | {!(editLevel === 'level2' || editLevel === 'level3') && |
| | | {editLevel !== 'level2' && editLevel !== 'level3' && mainMenu ? |
| | | <Menu openKeys={this.state.openKeys} onOpenChange={this.onOpenChange} mode="inline" theme="dark"> |
| | | {!editLevel && mainMenu ? <li className="sup-menu"><EditOutlined onClick={this.enterSubEdit} className="edit-check"/></li> : null} |
| | | {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}/> |
| | | <SwapOutlined 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} |
| | |
| | | </span> |
| | | } |
| | | > |
| | | {!editLevel ? <li className={'ant-menu-item ' + (item.children.length > 0 ? 'sub-menu' : '')}> |
| | | {!isnew ? <EditOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="edit-check"/> : |
| | | <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"> |
| | | <PlusOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-edit-menu"/> |
| | | <SwapOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-edit-menu mk-swap"/> |
| | | <UnlockOutlined onClick={(e) => {this.enterThrEdit(e, item)}} className="mk-edit-menu"/> |
| | | <div style={{display: 'inline-block', minWidth: '32px'}}><AddThdMenu mainMenu={mainMenu} supMenu={item} menuTree={this.props.menuTree}/></div> |
| | | <SwapOutlined 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> : null} |
| | | </Popover> |
| | | </li> |
| | | {item.children.map(cell => { |
| | | return ( |
| | | <Menu.Item key={cell.MenuID}> |
| | | {editLevel !== 'HS' ? |
| | | <span className="editable-menu-item" onDoubleClick={() => this.editmenu(cell)}>{cell.MenuName}</span> : |
| | | <a href={cell.src} id={cell.MenuID} onClick={(e) => this.changemenu(e, cell)}>{cell.MenuName}</a> |
| | | } |
| | | <span className="editable-menu-item" onDoubleClick={(e) => {e.stopPropagation();this.editmenu(cell)}}>{cell.MenuName}</span> |
| | | </Menu.Item> |
| | | ) |
| | | })} |
| | | </SubMenu> |
| | | ) |
| | | })} |
| | | </Menu>} |
| | | {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 |
| | | } |
| | | {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} |
| | | exitEdit={this.exitEdit} |
| | | /> : null |
| | | } |
| | | <Modal |
| | | title="解冻菜单" |
| | | width={600} |
| | | title="添加菜单" |
| | | visible={visible} |
| | | onOk={this.thawMemuSubmit} |
| | | confirmLoading={this.state.confirmLoading} |
| | | onCancel={this.thawMemuCancel} |
| | | onOk={this.secSubmit} |
| | | // confirmLoading={loading} |
| | | onCancel={() => this.setState({visible: false})} |
| | | destroyOnClose |
| | | > |
| | | {!this.state.thawmenulist ? <Spin style={{marginLeft: 'calc(50% - 22px)', marginTop: '70px', marginBottom: '70px'}} size="large" /> : |
| | | <TransferForm onChange={(vals) => this.setState({targetKeys: vals})} menulist={this.state.thawmenulist}/>} |
| | | <MenuForm |
| | | inputSubmit={this.secSubmit} |
| | | formlist={this.state.formlist} |
| | | wrappedComponentRef={(inst) => this.menuFormRef = inst} |
| | | /> |
| | | </Modal> |
| | | <Modal |
| | | title="修改菜单" |
| | | visible={thdVisible} |
| | | width={600} |
| | | 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 mapDispatchToProps = (dispatch) => { |
| | | return { |
| | | modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)), |
| | | modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)), |
| | | resetEditLevel: (level) => dispatch(resetEditLevel(level)) |
| | | } |
| | | } |