king
2021-12-22 5223edbcccfed84a33a706e5637ee65a61f377aa
src/mob/components/navbar/normal-navbar/menusetting/menutable/index.jsx
@@ -1,18 +1,21 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Table, Button, Modal, Icon } from 'antd'
import { Table, Button, Modal } from 'antd'
import { ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons'
import MenuForm from '../menuform'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import MkIcon from '@/components/mk-icon'
// import MKEmitter from '@/utils/events.js'
import './index.scss'
const { confirm } = Modal
class MenuTable extends Component {
  static propTpyes = {
    menus: PropTypes.object,    // 卡片行信息
    menus: PropTypes.array,     // 卡片行信息
    cols: PropTypes.array,      // 字段集
  }
  state = {
@@ -22,9 +25,12 @@
      { title: '菜单名称', dataIndex: 'name', key: 'name' },
      { title: '菜单参数', dataIndex: 'MenuNo', key: 'MenuNo' },
      { title: '菜单属性', dataIndex: 'property', key: 'property',  render: text => {
        const trans = {menu: '菜单', link: '链接', linkmenu: '关联菜单'}
        const trans = {menu: '菜单', link: '链接', linkmenu: '关联菜单', sysmenu: '系统页'}
        return trans[text]
      }},
      { title: '图标', dataIndex: 'icon', key: 'icon',  render: (text, record) => {
        return text ? <MkIcon type={text} /> : ''
      }},
      { title: '是否隐藏', dataIndex: 'hidden', key: 'hidden',  render: (text, record) => {
        const trans = {'true': '是', 'false': '否'}
@@ -34,8 +40,8 @@
        (<div>
          <Button type="link" style={{padding: '0 5px', marginRight: '5px'}} onClick={() => this.editMenu(record)}>编辑</Button>
          <Button type="link" style={{color: '#ff4d4f', padding: '0 5px', marginRight: '5px'}} onClick={() => this.delMenu(record)}>删除</Button>
          <Icon type="arrow-up" style={{color: '#26C281', cursor: 'pointer', padding: '0 5px', marginRight: '5px'}} onClick={() => this.moveUp(record)}/>
          <Icon type="arrow-down" style={{color: '#ff4d4f', cursor: 'pointer', padding: '0 5px'}} onClick={() => this.moveDown(record)}/>
          <ArrowUpOutlined style={{color: '#26C281', cursor: 'pointer', padding: '0 5px', marginRight: '5px'}} onClick={() => this.moveUp(record)}/>
          <ArrowDownOutlined style={{color: '#ff4d4f', cursor: 'pointer', padding: '0 5px'}} onClick={() => this.moveDown(record)}/>
        </div>)
      }
    ]
@@ -80,20 +86,10 @@
    const _this = this
    confirm({
      title: (record.property === 'classify' && record.sublist.length > 0 ? '菜单下含有子菜单,' : '') + '确定删除吗?',
      title: '确定删除吗?',
      content: '',
      onOk() {
        _this.setState({data: data.filter(item => item.MenuID !== record.MenuID)})
        let uuids = [record.MenuID]
        record.sublist && record.sublist.forEach(item => {
          uuids.push(item.MenuID)
          item.sublist && item.sublist.forEach(cell => {
            uuids.push(cell.MenuID)
          })
        })
        MKEmitter.emit('delButtons', uuids)
      },
      onCancel() {}
    })
@@ -117,21 +113,38 @@
    this.menuRef.handleConfirm().then(res => {
      let _menu = {...editMenu, ...res}
      let _data = fromJS(data).toJS()
      if (!_menu.MenuID) {
        _menu.MenuID = Utils.getuuid()
        this.setState({data: [...data, _menu], editMenu: null, visible: false})
        _data.push(_menu)
      } else {
        this.setState({
          editMenu: null,
          visible: false,
          data: data.map(item => {
            if (item.MenuID === _menu.MenuID) {
              return _menu
            } else {
              return item
            }
          })
        _data = _data.map(item => {
          if (item.MenuID === _menu.MenuID) {
            return _menu
          } else {
            return item
          }
        })
      }
      if (editMenu.MenuID && editMenu.property === 'menu' && _menu.property !== 'menu') {
        const _this = this
        confirm({
          content: '菜单将被重置,确定修改吗?',
          onOk() {
            _data = _data.map(item => {
              if (item.MenuID === _menu.MenuID) {
                item.MenuID = Utils.getuuid()
              }
              return item
            })
            _this.setState({data: _data, editMenu: null, visible: false})
          },
          onCancel() {}
        })
      } else {
        this.setState({data: _data, editMenu: null, visible: false})
      }
    })
  }
@@ -151,6 +164,7 @@
  }
  render() {
    const { cols } = this.props
    const { columns, data, visible, editMenu } = this.state
    return (
@@ -165,7 +179,7 @@
        <Modal
          title="编辑"
          visible={visible}
          width={600}
          width={900}
          maskClosable={false}
          onOk={this.menuSubmit}
          onCancel={() => { this.setState({ visible: false }) }}
@@ -173,6 +187,7 @@
        >
          <MenuForm
            menu={editMenu}
            cols={cols}
            inputSubmit={this.menuSubmit}
            wrappedComponentRef={(inst) => this.menuRef = inst}
          />