king
2020-03-13 268be11f39b248920a76568135f8b7b6c4fa9e52
src/tabviews/rolemanage/index.jsx
@@ -12,7 +12,9 @@
const { Search } = Input
const { TabPane } = Tabs
const { TreeNode, DirectoryTree } = Tree
let _checkedKeys = null
let checkedKeysMap = null
let linkMap = null
let selectMap = null
export default class RoleManage extends Component {
  static propTpyes = {
@@ -72,7 +74,8 @@
          return {
            title: item.MenuName,
            key: item.MenuID,
            children: []
            children: [],
            selected: true
          }
        })
      }, () => {
@@ -107,19 +110,15 @@
      }
      if (tabKey === '') {
        let _mainMenuKeys = mainMenus.map(menu => menu.key)
        _checkedKeys = []
        let _checkMainKeys = [] // 选中的一级菜单,需判断是否含有子菜单
        let _initCheckKeys = [] // 初始选中的菜单id
        checkedKeysMap = new Map()
        linkMap = new Map()
        selectMap = new Map()
        result.data.forEach(item => {
          if (item.Selected !== 'true') return
          if (!_mainMenuKeys.includes(item.MenuID)) {
            _checkedKeys.push(item.MenuID)
          } else {
            _checkMainKeys.push(item.MenuID)
          }
          checkedKeysMap.set(item.MenuID, true)
          _initCheckKeys.push(item.MenuID)
        })
@@ -131,18 +130,12 @@
          this.getOpenNode(_tree[0], _openKeys)
        }
        _tree.forEach(item => {
          if (_checkMainKeys.includes(item.key) && !item.children) {
            _checkedKeys.push(item.key)
          }
        })
        _state.menuTrees = _tree
        _state.initCheckKeys = _initCheckKeys
        _state.checkedKeys = _checkedKeys
        _state.checkedKeys = Array.from(checkedKeysMap.keys())
        _state.menuOpenKeys = _openKeys
      } else {
        _tree = this.getTree(JSON.parse(JSON.stringify(mainMenus)), result.data)
        _tree = this.getSelectTree(JSON.parse(JSON.stringify(mainMenus)), result.data)
        _tree = _tree.filter(node => node.children)
        if (_tree[0]) {
@@ -179,12 +172,14 @@
    parents.forEach(parent => {
      parent.children = []
      options.forEach((option, index) => {
      options.forEach(option => {
        if (option.ParentID === parent.key) {
          parent.children.push({
            title: option.MenuName,
            key: option.MenuID,
            selected: option.Selected === 'true'
            selected: parent.selected && option.Selected === 'true',
            addSelf: option.OnlySelf === 'true',
            tabs: option.Tabs
          })
        }
      })
@@ -192,11 +187,75 @@
      if (parent.children.length === 0) {
        parent.children = null
      } else {
        if (_checkedKeys && parent.selected) {
          _checkedKeys = _checkedKeys.filter(key => key !== parent.key)
        if (parent.tabs) {
          let _uuid = Utils.getuuid()
          linkMap.set(_uuid, parent.key)
          if (parent.selected) {
            checkedKeysMap.set(_uuid, true)
            checkedKeysMap.delete(parent.key)
            selectMap.set(_uuid, parent.key)
          }
          parent.key = _uuid
        }
      } else {
        if (parent.selected) {
          checkedKeysMap.delete(parent.key)
        }
        if (parent.addSelf) {
          let _uuid = Utils.getuuid()
          linkMap.set(_uuid, parent.key)
          if (parent.selected) {
            checkedKeysMap.set(_uuid, true)
          }
          parent.children.unshift({
            title: parent.title + '(仅页面)',
            key: _uuid,
          })
        }
        if (parent.tabs) {
          let _uuid = Utils.getuuid()
          linkMap.set(_uuid, parent.key)
          if (parent.selected) {
            selectMap.set(_uuid, parent.key)
          }
          parent.key = _uuid
        }
        parent.children = this.getTree(parent.children, options)
      }
    })
    return parents
  }
  getSelectTree = (parents, options) => {
    parents.forEach(parent => {
      parent.children = []
      options.forEach(option => {
        if (option.ParentID === parent.key) {
          parent.children.push({
            title: option.MenuName,
            key: option.MenuID,
            tabs: option.Tabs
          })
        }
      })
      parent.key = Utils.getuuid()
      if (parent.children.length === 0) {
        parent.children = null
      } else {
        parent.children = this.getSelectTree(parent.children, options)
      }
    })
@@ -234,7 +293,6 @@
  }
  onCheck = (checkedKeys, info) => {
    console.log(checkedKeys)
    this.setState({
      checkedKeys: checkedKeys,
      halfCheckedKeys: info.halfCheckedKeys,
@@ -262,7 +320,24 @@
    if (initCheckKeys) {
      _keys = initCheckKeys
    } else {
      _keys = checkedKeys.concat(halfCheckedKeys)
      let _cKeys = checkedKeys.concat(halfCheckedKeys)
      _cKeys.forEach(key => {
        if (linkMap.has(key)) {
          _keys.push(linkMap.get(key))
        } else {
          _keys.push(key)
        }
      })
      _cKeys = new Map(_cKeys.map(key => [key, true]))
      _keys = new Map(_keys.map(key => [key, true]))
      Array.from(selectMap.keys()).forEach(key => {
        if (!_cKeys.has(key)) {
          _keys.delete(selectMap.get(key))
        }
      })
      _keys = Array.from(_keys.keys())
    }
    
    let _LText = _keys.map(key => `select '${key}' as MenuID`)
@@ -288,8 +363,13 @@
      })
      this.setState({
        submitloading: false,
        menuTrees: null,
        checkedKeys: [],
        menuOpenKeys: [],
        selectMenuTrees: null,
        selectMenuOpenKeys: []
      }, () => {
        this.getAllMenuList()
      })
    } else {
      notification.warning({