From bf24b61a7170d8b026eb3234c6714fab3548f9f1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 04 六月 2025 10:45:13 +0800
Subject: [PATCH] 2025-06-04

---
 src/tabviews/rolemanage/index.jsx | 1038 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 977 insertions(+), 61 deletions(-)

diff --git a/src/tabviews/rolemanage/index.jsx b/src/tabviews/rolemanage/index.jsx
index 2c13a08..4801d55 100644
--- a/src/tabviews/rolemanage/index.jsx
+++ b/src/tabviews/rolemanage/index.jsx
@@ -1,68 +1,878 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { BackTop, Card, Col, Row } from 'antd'
+import { Card, Col, Row, Menu, notification, Spin, Input, Tabs, Button, Tree, Empty, Select } from 'antd'
+import { BankOutlined } from '@ant-design/icons'
+import md5 from 'md5'
+
 import Api from '@/api'
-import Loading from '@/components/loading'
-import zhCN from '@/locales/zh-CN/main.js'
-import enUS from '@/locales/en-US/main.js'
+import Utils from '@/utils/utils.js'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
+
+const { Search } = Input
+const { TabPane } = Tabs
+const { TreeNode, DirectoryTree } = Tree
+
+let linkMap = new Map()
+let selectMap = null
 
 export default class RoleManage extends Component {
   static propTpyes = {
-    MenuNo: PropTypes.string, // 鑿滃崟鍙傛暟
-    MenuID: PropTypes.string // 鑿滃崟Id
+    MenuID: PropTypes.string  // 鑿滃崟Id
   }
 
   state = {
-    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
-    searchlist: null,
-    actions: null,
-    columns: null,
-    select: null,
-    data: null,
-    total: 0,
     loading: true,
-    param: {
-      pageIndex: 1,
-      pageSize: 10,
-      orderColumn: '',
-      orderType: '',
-      search: ''
-    },
-    fixed: {}
+    loadingTree: false,
+    loadingAppTree: false,
+    roleList: null,
+    filterRoleList: [],
+    selectRoleId: '',
+    mainMenus: null,
+    menuTrees: null,
+    checkedKeys: [],
+    menuOpenKeys: [],
+    selectMenuTrees: null,
+    selectMenuOpenKeys: [],
+    primarykey: '',
+    submitloading: false,
+    initCheckKeys: null,
+    activeKey: 'manage',
+    appTrees: null,
+    appCheckedKeys: [],
+    appOpenKeys: [],
+    applist: [],
+    selectApp: null,
+    selectSubApp: null,
+    selectAppTrees: null,
+    selectAppOpenKeys: [],
   }
 
-  async loadconfig () {
+  /**
+   * @description 鑾峰彇瑙掕壊鍒楄〃
+   */
+  getRoleList = async () => {
     let param = {
-      func: 'sPC_Get_TreePage',
-      MenuNo: this.props.MenuNo
+      func: 's_rolemenu_get_list'
     }
-    let result = await Api.commonInterface(param)
-    if (result.status) {
-      
-    }
-  }
+    let result = await Api.getSystemConfig(param)
 
-  async loadmaindata (pageIndex = 1, pageSize = 10, orderColumn = '', orderType = '', search = '') {
-    // 鑾峰彇鍒楄〃鏁版嵁
-    let result = await Api.getMainTableData(this.props.MenuNo, pageIndex, pageSize, orderColumn, orderType, search)
     if (result.status) {
       this.setState({
-        data: result.data.map((item, index) => {
-          item.key = index
-          item.rows = item.mkrows
-          return item
-        }),
-        total: result.total,
-        loading: false
+        roleList: result.data,
+        filterRoleList: result.data || []
+      })
+    } else {
+      notification.warning({
+        top: 92,
+        message: result.message,
+        duration: 5
       })
     }
   }
 
+  getAppList = () => {
+    let param = {
+      func: 's_get_kei'
+    }
+
+    Api.getSystemConfig(param).then(result => {
+      if (result.status) {
+        let applist = result.data.map(item => {
+          item.sublist = item.data_detail || []
+          item.sublist = item.sublist.map(cell => {
+            cell.ID = cell.d_id
+            return cell
+          })
+
+          return item
+        })
+        let selectApp = applist[0] || null
+
+        this.setState({ applist, selectApp })
+      } else {
+        notification.warning({
+          top: 92,
+          message: result.message,
+          duration: 5
+        })
+      }
+    })
+  }
+
+  /**
+   * @description 鑾峰彇涓�绾ц彍鍗曪紝鐢ㄤ簬鏋勫缓缁撴瀯鏍�
+   */
+  getMainMenuList = async () => {
+    let param = {
+      func: 's_rolemenu_get_FstMenu',
+      version: 1
+    }
+    let result = await Api.getSystemConfig(param)
+
+    if (result.status) {
+      this.setState({
+        loadingTree: true,
+        loading: false,
+        mainMenus: result.data.map(item => {
+          return {
+            title: item.langname ? item.MenuName + '(' + item.langname + ')' : item.MenuName,
+            key: item.MenuID,
+            children: [],
+            selected: true
+          }
+        })
+      }, () => {
+        this.getAllMenuList()
+      })
+    } else {
+      this.setState({
+        loading: false
+      })
+      notification.warning({
+        top: 92,
+        message: result.message,
+        duration: 5
+      })
+    }
+  }
+
+  /**
+   * @description 鑾峰彇鎵�鏈夎彍鍗曡妭鐐癸紝褰㈡垚鏉冮檺鏍�
+   */
+  getAllMenuList = async () => {
+    const { mainMenus } = this.state
+
+    let param = {
+      func: 's_rolemenu_get_FunMenu',
+      RoleID: '',
+      SelectedType: '',
+      version: 1
+    }
+
+    let result = await Api.getSystemConfig(param)
+
+    if (result.status) {
+      let _openKeys = []
+      // MenuID锛堣彍鍗旾d锛夈�丮enuName锛堣彍鍗曞悕绉帮級銆丱nlySelf锛堝�间负true锛岃〃绀轰笁绾ц彍鍗曪紝澧炲姞-浠呴〉闈級銆乀ype锛堣彍鍗曠骇鍒級
+      // ParentID锛堢埗绾d锛夈�丼elected锛堟槸鍚﹂�変腑-宸插け鏁堬級銆乀abs锛� 鏍囩绫诲瀷锛夈�乀ypeCharOne 鑿滃崟绫诲瀷PC鎴栧叾浠�
+      // result.data.forEach(item => { // 娴嬭瘯
+      //   if (item.ParentID === '0') {
+      //     item.ParentID = item.TypeCharOne
+      //   }
+      // })
+      // let map = new Map() // 鍘婚噸
+
+      // result.data = result.data.filter(item => {
+      //   if (map.has(item.ParentID + item.MenuID)) return false
+
+      //   map.set(item.ParentID + item.MenuID, true)
+        
+      //   return true
+      // })
+
+      let _tree = this.getTree(fromJS(mainMenus).toJS(), result.data)
+      if (_tree[0]) {
+        if (_tree[0].key.indexOf('PC') > -1 && _tree[0].children) {
+          // _openKeys = _tree[0].children.map(cell => cell.key)
+          this.getOpenNode(_tree[0].children[0], _openKeys)
+        } else {
+          this.getOpenNode(_tree[0], _openKeys)
+        }
+      }
+
+      this.setState({
+        loadingTree: false,
+        menuTrees: _tree,
+        menuOpenKeys: _openKeys
+      }, () => {
+        if (this.state.selectRoleId) {
+          this.getSelectMenuList()
+        }
+      })
+    } else {
+      this.setState({
+        loadingTree: false
+      })
+      notification.warning({
+        top: 92,
+        message: result.message,
+        duration: 5
+      })
+    }
+  }
+
+  /**
+   * @description 閫夋嫨瑙掕壊涓斿瓨鍦ㄦ潈闄愭爲鏃讹紝鑾峰彇宸插垎閰嶇粨鏋�
+   */
+  getSelectMenuList = async () => {
+    const { selectRoleId, menuTrees, activeKey } = this.state
+    if (!menuTrees || !selectRoleId || activeKey !== 'manage') return
+
+    let param = {
+      func: 's_rolemenu_get_Menulist',
+      RoleID: selectRoleId,
+      version: 1
+    }
+
+    this.setState({
+      loadingTree: true
+    })
+
+    let result = await Api.getSystemConfig(param)
+
+    if (result.status) {
+      let _openKeys = []
+
+      let _initKeys = result.data.map(item => item.MenuID)
+      _initKeys = Array.from(new Set(_initKeys))
+
+      selectMap = new Map()
+      this.getCheckedKeys(fromJS(menuTrees).toJS(), _initKeys)
+
+      if (menuTrees[0]) {
+        if (menuTrees[0].key.indexOf('PC') > -1 && menuTrees[0].children) {
+          this.getOpenNode(menuTrees[0].children[0], _openKeys)
+        } else {
+          this.getOpenNode(menuTrees[0], _openKeys)
+        }
+      }
+
+      let _openkeys = []
+      let Keys = result.data.map(item => item.MenuID)
+      let _tree = this.getSelectTree(fromJS(menuTrees).toJS(), Keys)
+
+      if (_tree[0]) {
+        if (_tree[0].key.indexOf('PC') > -1 && _tree[0].children) {
+          this.getOpenNode(_tree[0].children[0], _openkeys)
+        } else {
+          this.getOpenNode(_tree[0], _openkeys)
+        }
+      }
+
+      this.setState({
+        loadingTree: false,
+        initCheckKeys: _initKeys,
+        checkedKeys: Array.from(selectMap.keys()),
+        menuOpenKeys: _openKeys,
+        selectMenuTrees: _tree,
+        selectMenuOpenKeys: _openkeys
+      })
+    } else {
+      this.setState({
+        loadingTree: false
+      })
+      notification.warning({
+        top: 92,
+        message: result.message,
+        duration: 5
+      })
+    }
+  }
+
+  /**
+   * @description 閫夋嫨瑙掕壊涓斿瓨鍦ㄦ潈闄愭爲鏃讹紝鑾峰彇宸插垎閰嶇粨鏋�
+   */
+  getSelectAppNodeList = async () => {
+    const { selectRoleId, selectSubApp, selectApp, appTrees, activeKey } = this.state
+
+    if (!appTrees || !selectRoleId || activeKey !== 'app' || !selectSubApp || !selectApp) return
+
+    let param = {
+      func: 's_rolemenu_get_Menulist',
+      RoleID: selectRoleId,
+      TypeCharOne: selectApp.kei_no,
+      typename: selectSubApp.typename,
+      lang: selectSubApp.lang,
+      version: 1
+    }
+
+    this.setState({
+      loadingAppTree: true
+    })
+
+    let result = await Api.getSystemConfig(param)
+
+    if (result.status) {
+      let _initKeys = result.data.map(item => item.MenuID)
+      _initKeys = Array.from(new Set(_initKeys))
+      let _checkedKeys = []
+
+      let getCheckedKeys = (parents) => {
+        parents.forEach(item => {
+          if (_initKeys.includes(item.key)) {
+            if (item.children && item.children.length > 0) {
+              getCheckedKeys(item.children)
+            } else {
+              _checkedKeys.push(item.key)
+            }
+          }
+        })
+      }
+
+      getCheckedKeys(appTrees)
+
+      let _openKeys = []
+      let getOpenNode = (parentNode) => {
+        if (parentNode && parentNode.children && parentNode.children.length > 0) {
+          _openKeys.push(parentNode.key)
+          parentNode.children.forEach(node => {
+            getOpenNode(node)
+          })
+        }
+      }
+      getOpenNode(appTrees[0])
+
+      let Keys = result.data.map(item => item.MenuID)
+      let _tree = this.getSelectTree(fromJS(appTrees).toJS(), Keys)
+
+
+      let _openkeys = []
+      let _getOpenNode = (parentNode) => {
+        if (parentNode && parentNode.children && parentNode.children.length > 0) {
+          _openkeys.push(parentNode.key)
+          parentNode.children.forEach(node => {
+            _getOpenNode(node)
+          })
+        }
+      }
+      _getOpenNode(_tree[0])
+
+      this.setState({
+        loadingAppTree: false,
+        appInitCheckKeys: _initKeys,
+        appCheckedKeys: _checkedKeys,
+        appOpenKeys: _openKeys,
+        selectAppTrees: _tree,
+        selectAppOpenKeys: _openkeys
+      })
+    } else {
+      this.setState({
+        loadingAppTree: false
+      })
+      notification.warning({
+        top: 92,
+        message: result.message,
+        duration: 5
+      })
+    }
+  }
+
+  /**
+   * @description 鑾峰彇灞曞紑鑺傜偣
+   */
+  getOpenNode = (parentNode, keys) => {
+    if (parentNode.children) {
+      keys.push(parentNode.key)
+      parentNode.children.forEach(node => {
+        this.getOpenNode(node, keys)
+      })
+    }
+  }
+
+  /**
+   * @description 鑾峰彇鏉冮檺鍒嗛厤鏍�
+   */
+  getTree = (parents, options, addSelf) => {
+    parents.forEach(parent => {
+      parent.children = []
+
+      // 娣诲姞鑿滃崟鐨勫瓙鍏冪礌
+      options.forEach(option => {
+        if (option.ParentID === parent.key) {
+          parent.children.push({
+            title: option.MenuName,
+            key: option.MenuID,
+            addSelf: option.OnlySelf === 'true',
+            // tabs: option.Tabs
+          })
+        }
+      })
+
+      if (parent.children.length === 0) {
+        parent.children = null
+        // 閽堝鏍囩锛岀敓鎴愭柊鐨刬d锛屽苟淇濆瓨鍏宠仈鍏崇郴锛堟爣绛句笉鍞竴锛�
+        // if (parent.tabs) {
+        //   let _uuid = Utils.getuuid()
+        //   linkMap.set(_uuid, parent.key)
+
+        //   parent.originKey = parent.key
+        //   parent.key = _uuid
+        // }
+      } else {
+        // 涓夌骇鑿滃崟鍒涘缓瀛愰」
+        if (parent.addSelf) {
+          let _uuid = Utils.getuuid()
+          linkMap.set(_uuid, parent.key)
+          parent.subKey = _uuid
+
+          parent.children.unshift({
+            title: parent.title + '(浠呴〉闈�)',
+            key: _uuid,
+            // isSubView: true
+          })
+        } else if (addSelf) {
+          let _uuid = Utils.getuuid()
+          linkMap.set(_uuid, parent.key)
+          parent.subKey = _uuid
+
+          parent.children.unshift({
+            title: parent.title + '(琛ㄦ牸)',
+            key: _uuid,
+          })
+        }
+
+        // 閽堝鏍囩锛岀敓鎴愭柊鐨刬d锛屽苟淇濆瓨鍏宠仈鍏崇郴锛堟爣绛句笉鍞竴锛�
+        // if (parent.tabs) {
+        //   let _uuid = Utils.getuuid()
+        //   linkMap.set(_uuid, parent.key)
+          
+        //   parent.originKey = parent.key
+        //   parent.key = _uuid
+        // }
+
+        parent.children = this.getTree(parent.children, options, parent.addSelf)
+      }
+    })
+    return parents
+  }
+
+  /**
+   * @description 鑾峰彇宸查�夋嫨鐨勮妭鐐�
+   */
+  getCheckedKeys = (parents, initKeys) => {
+    parents.forEach(parent => {
+      if ((parent.originKey && initKeys.indexOf(parent.originKey) > -1) || initKeys.indexOf(parent.key) > -1) {
+        if (parent.children) {
+          if (parent.subKey) {
+            selectMap.set(parent.subKey, true)
+          }
+          this.getCheckedKeys(parent.children, initKeys)
+        } else {
+          selectMap.set(parent.key, true)
+        }
+      }
+    })
+  }
+
+  /**
+   * @description 鐢熸垚宸插垎閰嶆潈闄愮殑缁撴瀯鏍�
+   */
+  getSelectTree = (parents, options) => {
+    return parents.filter(parent => {
+      if ((parent.originKey && options.indexOf(parent.originKey) > -1) || options.indexOf(parent.key) > -1) {
+        if (parent.children) {
+          parent.children = this.getSelectTree(parent.children, options)
+          if (parent.children.length === 0) {
+            parent.children = null
+          }
+        }
+        return true
+      // } else if (parent.isSubView) {
+      //   return true
+      }
+      return false
+    })
+  }
+
+  /**
+   * @description 瑙掕壊鍒囨崲
+   */
+  changeRole = (role) => {
+    const { selectRoleId } = this.state
+
+    if (selectRoleId === role.RoleID) return
+
+    this.setState({
+      selectRoleId: role.RoleID
+    }, () => {
+      this.getSelectMenuList()
+      this.getSelectAppNodeList()
+    })
+  }
+
+  /**
+   * @description 鑾峰彇鏍戣妭鐐�
+   */
+  renderTreeNodes = (data) => {
+    return data.map(item => {
+      if (item.children) {
+        return (
+          <TreeNode title={item.title} key={item.key} dataRef={item}>
+            {this.renderTreeNodes(item.children)}
+          </TreeNode>
+        )
+      }
+      return <TreeNode key={item.key} showIcon={true} {...item} isLeaf />
+    })
+  }
+
+  /**
+   * @description 鑺傜偣閫夋嫨浜嬩欢
+   */
+  onCheck = (checkedKeys, info) => {
+    this.setState({
+      checkedKeys: checkedKeys,
+      halfCheckedKeys: info.halfCheckedKeys,
+      initCheckKeys: null
+    })
+  }
+
+  /**
+   * @description 鑺傜偣閫夋嫨浜嬩欢
+   */
+  onAppCheck = (checkedKeys, info) => {
+    this.setState({
+      appCheckedKeys: checkedKeys,
+      appHalfCheckedKeys: info.halfCheckedKeys,
+      appInitCheckKeys: null
+    })
+  }
+
+  /**
+   * @description 鎻愪氦宸查�夌殑鏉冮檺
+   */
+  roleSubmit = () => {
+    const { checkedKeys, halfCheckedKeys, selectRoleId, initCheckKeys } = this.state
+
+    let _keys = []
+    
+    if (initCheckKeys) {
+      _keys = initCheckKeys
+    } else {
+      let _cKeys = checkedKeys.concat(halfCheckedKeys)
+      _cKeys.forEach(key => {
+        if (linkMap.has(key)) {
+          _keys.push(linkMap.get(key))
+        } else {
+          _keys.push(key)
+        }
+      })
+
+      _keys = Array.from(new Set(_keys))
+    }
+
+    let param = {
+      func: 's_rolemenu_sub',
+      RoleID: selectRoleId,
+      RoleMenu: _keys.map(key => {
+        return {MenuID: key}
+      })
+    }
+
+    let localParam = fromJS(param).toJS()
+    localParam.func = 's_rolemenu_sub_local'
+
+    this.setState({
+      submitloading: true
+    })
+
+    Api.getSystemConfig(param).then(result => {
+      if (result.status) {
+        notification.success({
+          top: 92,
+          message: '淇濆瓨鎴愬姛',
+          duration: 2
+        })
+        this.setState({
+          submitloading: false
+        }, () => {
+          this.getSelectMenuList()
+          this.clearBackSqlCache()
+        })
+        if (window.GLOB.mainSystemApi) {
+          Api.genericInterface(localParam).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
+          })
+        }
+      } else {
+        this.setState({
+          submitloading: false
+        })
+        notification.warning({
+          top: 92,
+          message: result.message,
+          duration: 5
+        })
+      }
+    })
+  }
+
+  clearBackSqlCache = () => {
+    if (!window.backend) return
+
+    Api.cacheInterface({}).then(res => {
+      if (!res.status) {
+        notification.warning({
+          top: 92,
+          message: res.message || '缂撳瓨娓呯┖澶辫触锛�',
+          duration: 5
+        })
+      }
+    })
+  }
+
+  /**
+   * @description 鎻愪氦宸查�夌殑鏉冮檺
+   */
+  appRoleSubmit = () => {
+    const { selectApp, selectSubApp, appCheckedKeys, appHalfCheckedKeys, selectRoleId, appInitCheckKeys } = this.state
+
+    let _keys = []
+
+    if (appInitCheckKeys) {
+      _keys = appInitCheckKeys
+    } else {
+      _keys = appCheckedKeys.concat(appHalfCheckedKeys)
+    }
+
+    let param = {
+      func: 's_rolemenu_sub',
+      RoleID: selectRoleId,
+      TypeCharOne: selectApp.kei_no,
+      typename: selectSubApp.typename,
+      lang: selectSubApp.lang,
+      RoleMenu: _keys.map(key => {
+        return {MenuID: key}
+      })
+    }
+
+    let localParam = fromJS(param).toJS()
+    localParam.func = 's_rolemenu_sub_local'
+
+    this.setState({
+      submitloading: true
+    })
+
+    Api.getSystemConfig(param).then(result => {
+      if (result.status) {
+        notification.success({
+          top: 92,
+          message: '淇濆瓨鎴愬姛',
+          duration: 2
+        })
+        this.setState({
+          submitloading: false
+        }, () => {
+          this.getSelectAppNodeList()
+        })
+        
+        if (window.GLOB.mainSystemApi) {
+          Api.genericInterface(localParam).then(res => {
+            if (!res.status) {
+              notification.warning({
+                top: 92,
+                message: res.message,
+                duration: 5
+              })
+            }
+          })
+        }
+      } else {
+        this.setState({
+          submitloading: false
+        })
+        notification.warning({
+          top: 92,
+          message: result.message,
+          duration: 5
+        })
+      }
+    })
+  }
+
+  reloadMenuView = (menuId) => {
+    const { MenuID } = this.props
+
+    if (MenuID !== menuId) return
+
+    this.setState({
+      loading: true,
+      loadingTree: false,
+      roleList: null,
+      filterRoleList: [],
+      selectRoleId: '',
+      mainMenus: null,
+      menuTrees: null,
+      checkedKeys: [],
+      appCheckedKeys: [],
+      menuOpenKeys: [],
+      selectMenuTrees: null,
+      selectMenuOpenKeys: [],
+      primarykey: '',
+      submitloading: false,
+      initCheckKeys: null,
+      appInitCheckKeys: null,
+      activeKey: 'manage',
+      appTrees: null,
+      appOpenKeys: [],
+      applist: [],
+      selectApp: null,
+      selectSubApp: null,
+      selectAppTrees: null,
+      selectAppOpenKeys: []
+    })
+    this.getRoleList()
+    this.getMainMenuList()
+    this.getAppList()
+  }
+
+  filterRole = () => {
+    const { primarykey, roleList } = this.state
+
+    let _roleList  = []
+
+    if (roleList && roleList.length > 0) {
+      _roleList = roleList.filter(role => role.RoleName.toLowerCase().indexOf(primarykey.toLowerCase()) >= 0)
+    }
+
+    this.setState({filterRoleList: _roleList})
+  }
+
+  getTreeList = () => {
+    const { selectApp, selectSubApp } = this.state
+    let param = {
+      func: 's_get_menus_roles_tree',
+      typecharone: selectApp.kei_no,
+      lang: selectSubApp.lang
+    }
+
+    param.upid = md5(window.GLOB.appkey + selectApp.kei_no + selectSubApp.typename + selectSubApp.lang)
+
+    this.setState({loadingAppTree: true})
+
+    Api.getSystemConfig(param).then(result => {
+      if (result.status) {
+        if (!result.data || result.data.length === 0) {
+          this.setState({loadingAppTree: false, appTrees: [], appInitCheckKeys: null, appCheckedKeys: [], appOpenKeys: [], selectAppTrees: [], selectAppOpenKeys: []})
+        } else {
+          this.initTrees(result.data)
+        }
+      } else {
+        this.setState({loadingAppTree: false, appTrees: [], appInitCheckKeys: null, appCheckedKeys: [], appOpenKeys: [], selectAppTrees: [], selectAppOpenKeys: []})
+        notification.warning({
+          top: 92,
+          message: result.message,
+          duration: 5
+        })
+      }
+    })
+  }
+
+  initTrees = (data) => {
+    let trees = []
+    let map = new Map()
+    let _data = data.sort((a, b) => {
+      return a.sort - b.sort
+    })
+
+    _data.forEach(menu => {
+      if (menu.ParentID === 'top') {
+        trees.push({
+          key: menu.MenuID,
+          title: menu.MenuName,
+          children: []
+        })
+      } else {
+        map.set(menu.MenuID, menu)
+      }
+    })
+
+    let reset = (m) => {
+      return m.map(n => {
+        [...map.keys()].forEach(key => {
+          if (map.get(key).ParentID === n.key) {
+            let c = map.get(key)
+            n.children.push({
+              key: c.MenuID,
+              title: c.MenuName,
+              children: []
+            })
+            map.delete(key)
+          }
+        })
+        if (n.children.length > 0) {
+          n.children = reset(n.children)
+        }
+        return n
+      })
+    }
+
+    trees = reset(trees)
+
+    let expandedKeys = this.getExpandedKeys(trees, 0, [])
+
+    this.setState({loadingAppTree: false, appInitCheckKeys: null, appCheckedKeys: [], selectAppTrees: [], selectAppOpenKeys: [], appTrees: trees, appOpenKeys: expandedKeys}, () => {
+      this.getSelectAppNodeList()
+    })
+  }
+
+  getExpandedKeys = (trees, i, keys) => {
+    if (i >= 3 || !trees[0]) return keys
+
+    keys.push(trees[0].key)
+
+    i++
+
+    if (trees[0].children && trees[0].children.length > 0) {
+      keys = this.getExpandedKeys(trees[0].children, i, keys)
+    }
+
+    return keys
+  }
+
+  changeType = (val) => {
+    this.setState({
+      activeKey: val
+    }, () => {
+      this.getSelectMenuList()
+      this.getSelectAppNodeList()
+    })
+  }
+
+  changeApp = (val) => {
+    const { applist } = this.state
+
+    let app = applist.filter(item => item.ID === val)[0]
+
+    this.setState({selectApp: app, selectSubApp: null})
+  }
+  
+  changeSubApp = (val) => {
+    const { selectApp } = this.state
+
+    let subapp = selectApp.sublist.filter(item => item.ID === val)[0]
+
+    this.setState({selectSubApp: subapp}, () => {
+      this.getTreeList()
+    })
+  }
+
   UNSAFE_componentWillMount () {
-    // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
-    this.loadconfig()
+    this.getRoleList()
+    this.getMainMenuList()
+    this.getAppList()
+  }
+
+  componentDidMount () {
+    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
+  }
+
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -70,28 +880,134 @@
   }
 
   render() {
+    const { activeKey, filterRoleList, applist, selectApp, selectSubApp, loading, loadingTree, loadingAppTree, primarykey, menuTrees, appTrees, checkedKeys, appCheckedKeys, menuOpenKeys, selectMenuTrees, selectAppTrees, selectRoleId, selectMenuOpenKeys, selectAppOpenKeys, submitloading, appOpenKeys } = this.state
+
     return (
-      <div className="rolemanage">
-        {!this.state.searchlist && <Loading />}
-        <Row gutter={16}>
-          <Col span={6}>
-            <Card title="Card title" bordered={false}>
-              Card content
-            </Card>
-          </Col>
-          <Col span={18}>
-            <Card title="Card title" bordered={false}>
-              Card content
-            </Card>
-          </Col>
-        </Row>
-        <BackTop>
-          <div className="ant-back-top">
-            <div className="ant-back-top-content">
-              <div className="ant-back-top-icon"></div>
+      <div className={'rolemanage' + (applist.length === 0 ? ' manager' : '')}>
+        {loading && <Spin size="large" />}
+        <Tabs activeKey={activeKey} type="card" onChange={this.changeType}>
+          <TabPane tab="绠$悊绯荤粺" key="manage">
+            <Row gutter={16}>
+              <Col span={5}>
+                <Card
+                  className="role-list"
+                  title={
+                    <span className="role-title">
+                      <BankOutlined />
+                      <span className="title">瑙掕壊</span>
+                      <Search placeholder="" value={primarykey} onChange={e => this.setState({primarykey: e.target.value})} onSearch={this.filterRole} />
+                    </span>
+                  }
+                  bordered={false}
+                >
+                  <Menu selectedKeys={[selectRoleId]} mode="inline">
+                    {filterRoleList.map((role) =>
+                      <Menu.Item key={role.RoleID} onClick={() => this.changeRole(role)}>{role.RoleName}</Menu.Item>
+                    )}
+                  </Menu>
+                </Card>
+              </Col>
+              <Col span={19}>
+                <Tabs defaultActiveKey="all">
+                  <TabPane tab="鏉冮檺" key="all">
+                    {selectRoleId ? <Button className="submitBtn" type="primary" loading={submitloading} onClick={this.roleSubmit}>鎻愪氦</Button> : null}
+                    {!loadingTree && menuTrees && menuTrees.length > 0 ? <Tree
+                      checkable
+                      selectable={false}
+                      defaultExpandedKeys={menuOpenKeys}
+                      autoExpandParent={true}
+                      onCheck={this.onCheck}
+                      checkedKeys={checkedKeys}
+                    >
+                      {this.renderTreeNodes(menuTrees)}
+                    </Tree> : null}
+                    {!loadingTree && (!menuTrees || menuTrees.length === 0) ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /> : null}
+                    {loadingTree ? <Spin className="load-tree" /> : null}
+                  </TabPane>
+                  <TabPane tab="宸叉巿鏉�" key="selected">
+                    {!loadingTree && selectMenuTrees && selectMenuTrees.length > 0 ? <DirectoryTree multiple defaultExpandedKeys={selectMenuOpenKeys}>
+                      {this.renderTreeNodes(selectMenuTrees)}
+                    </DirectoryTree> : null}
+                    {!loadingTree && (!selectMenuTrees || selectMenuTrees.length === 0) ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /> : null}
+                    {loadingTree ? <Spin className="load-tree" /> : null}
+                  </TabPane>
+                </Tabs>
+              </Col>
+            </Row>
+          </TabPane>
+          <TabPane tab="搴旂敤" key="app">
+            <div className="app-select">
+              <div className="mk-form-item">
+                <label>搴旂敤:</label>
+                <Select value={selectApp ? selectApp.ID : ''} onChange={this.changeApp}>
+                  {applist.map(option =>
+                    <Select.Option key={option.ID} value={option.ID}>{option.remark}</Select.Option>
+                  )}
+                </Select>
+              </div>
+              <div className="mk-form-item">
+                <label>瀛愬簲鐢�:</label>
+                <Select value={selectSubApp ? selectSubApp.ID : ''} onChange={this.changeSubApp}>
+                  {selectApp && selectApp.sublist.map(option =>
+                    <Select.Option key={option.ID} value={option.ID}>{`${option.typename}锛�${option.lang}锛塦}</Select.Option>
+                  )}
+                </Select>
+              </div>
             </div>
-          </div>
-        </BackTop>
+            <Row gutter={16}>
+              <Col span={5}>
+                <Card
+                  className="role-list"
+                  title={
+                    <span className="role-title">
+                      <BankOutlined />
+                      <span className="title">瑙掕壊</span>
+                      <Search placeholder="" value={primarykey} onChange={e => this.setState({primarykey: e.target.value})} onSearch={this.filterRole} />
+                    </span>
+                  }
+                  bordered={false}
+                >
+                  <Menu selectedKeys={[selectRoleId]} mode="inline">
+                    {filterRoleList.map((role) =>
+                      <Menu.Item key={role.RoleID} onClick={() => this.changeRole(role)}>{role.RoleName}</Menu.Item>
+                    )}
+                  </Menu>
+                </Card>
+              </Col>
+              <Col span={19}>
+                <Tabs defaultActiveKey="all">
+                  <TabPane tab="鏉冮檺" key="all">
+                    {selectSubApp && selectRoleId ? <Button className="submitBtn" type="primary" loading={submitloading} onClick={this.appRoleSubmit}>鎻愪氦</Button> : null}
+                    {selectSubApp ? <div>
+                      {!loadingAppTree && appTrees && appTrees.length > 0 ? <Tree
+                        checkable
+                        selectable={false}
+                        defaultExpandedKeys={appOpenKeys}
+                        autoExpandParent={true}
+                        onCheck={this.onAppCheck}
+                        checkedKeys={appCheckedKeys}
+                      >
+                        {this.renderTreeNodes(appTrees)}
+                      </Tree> : null}
+                      {!loadingAppTree && (!appTrees || appTrees.length === 0) ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /> : null}
+                      {loadingAppTree ? <Spin className="load-tree" /> : null}
+                    </div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={'璇烽�夋嫨瀛愬簲鐢�'} />}
+                  </TabPane>
+                  <TabPane tab="宸叉巿鏉�" key="selected">
+                    {selectSubApp ? <div>
+                      {!loadingAppTree && selectAppTrees && selectAppTrees.length > 0 ? <DirectoryTree multiple defaultExpandedKeys={selectAppOpenKeys}>
+                        {this.renderTreeNodes(selectAppTrees)}
+                      </DirectoryTree> : null}
+                      {!loadingAppTree && (!selectAppTrees || selectAppTrees.length === 0) ? <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /> : null}
+                      {loadingAppTree ? <Spin className="load-tree" /> : null}
+                    </div> : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} description={'璇烽�夋嫨瀛愬簲鐢�'} />}
+                  </TabPane>
+                </Tabs>
+              </Col>
+            </Row>
+          </TabPane>
+        </Tabs>
+        
       </div>
     )
   }

--
Gitblit v1.8.0