From 6e0b5b55bd9aeaf3485afebb06d103d23cce2a46 Mon Sep 17 00:00:00 2001 From: java110 <928255095@qq.com> Date: Mon, 24 Aug 2020 09:19:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/pages/dev/privilege/privilege.js | 7 +- .../frame/staffPrivilege/staffPrivilege.html | 22 +++- .../frame/staffPrivilege/staffPrivilege.js | 110 +++++++++++++++++- 3 files changed, 128 insertions(+), 11 deletions(-) diff --git a/public/pages/dev/privilege/privilege.js b/public/pages/dev/privilege/privilege.js index ad4ef561e..c7544bc00 100644 --- a/public/pages/dev/privilege/privilege.js +++ b/public/pages/dev/privilege/privilege.js @@ -115,6 +115,8 @@ console.log(data); if (data.action == 'model' || data.action == 'ready') { + //默认合并 + $("#jstree_privilege").jstree("close_all"); return; } let _selected = data.node.state.selected; @@ -138,12 +140,9 @@ } else { $that.deletePrivilege(_selectPrivileges); } - - console.log(_d, _selectPrivileges); - - }); + }, _doJsTreeData: function (_privileges) { diff --git a/public/pages/frame/staffPrivilege/staffPrivilege.html b/public/pages/frame/staffPrivilege/staffPrivilege.html index c251f1628..239069107 100644 --- a/public/pages/frame/staffPrivilege/staffPrivilege.html +++ b/public/pages/frame/staffPrivilege/staffPrivilege.html @@ -1,7 +1,7 @@
-
+
@@ -10,7 +10,6 @@ 权限ID 权限名称 - 权限描述 隶属权限组ID 隶属权限组名称 状态 @@ -24,10 +23,7 @@ {{privilege.pId}} - {{privilege.name}} - - - {{privilege.description}} + {{privilege.pName}} {{privilege.pgId}} @@ -57,6 +53,20 @@
+
+
+

+ 树形结构 +

+
+
+ +
+ +
+ +
+
diff --git a/public/pages/frame/staffPrivilege/staffPrivilege.js b/public/pages/frame/staffPrivilege/staffPrivilege.js index 76c34faba..c9ec180c7 100644 --- a/public/pages/frame/staffPrivilege/staffPrivilege.js +++ b/public/pages/frame/staffPrivilege/staffPrivilege.js @@ -30,6 +30,7 @@ function(json){ var _staffPrivilegeInfo = JSON.parse(json); vc.component.staffPrivilegeInfo.privileges = _staffPrivilegeInfo.datas; + $that._initJsTreePrivilege(_staffPrivilegeInfo.datas); },function(){ console.log('请求失败处理'); @@ -38,7 +39,114 @@ _openDeleteStaffPrivilegeModel:function(_staffPrivilege){ _staffPrivilege.staffId = vc.component.staffPrivilegeInfo._currentStaffId; vc.emit('deleteStaffPrivilege','openStaffPrivilegeModel',_staffPrivilege); - } + }, + _initJsTreePrivilege: function (_privileges) { + + let _data = $that._doJsTreeData(_privileges); + $.jstree.destroy() + $("#jstree_privilege").jstree({ + "checkbox": { + "keep_selected_style": false + }, + + 'state': { //一些初始化状态 + "opened": false, + }, + 'core': { + 'data': _data + } + }); + $('#jstree_privilege').on("changed.jstree", function (e, data) { + + }); + + }, + _doJsTreeData: function (_privileges) { + let _mGroupTree = []; + //构建 第一层菜单组 + _privileges.forEach(pItem => { + let _includeGroup = false; + for (let _mgIndex = 0; _mgIndex < _mGroupTree.length; _mgIndex++) { + if (pItem.gId == _mGroupTree[_mgIndex].gId) { + _includeGroup = true; + } + } + + if (!_includeGroup) { + let _groupItem = { + id: 'g_' + pItem.gId, + gId: pItem.gId, + text: pItem.gName, + state: { + opened: false + }, + children: [] + }; + $that._doJsTreeMenuData(_groupItem); + _mGroupTree.push(_groupItem); + } + }); + return _mGroupTree; + }, + _doJsTreeMenuData: function (_groupItem) { + let _privileges = $that.staffPrivilegeInfo.privileges; + + //构建菜单 + let _children = _groupItem.children; + for (let _pIndex = 0; _pIndex < _privileges.length; _pIndex++) { + if (_groupItem.gId == _privileges[_pIndex].gId) { + let _includeMenu = false; + for (let _mgIndex = 0; _mgIndex < _children.length; _mgIndex++) { + if (_privileges[_pIndex].mId == _children[_mgIndex].mId) { + _includeMenu = true; + } + } + if (!_includeMenu) { + let _menuItem = { + id: 'm_' + _privileges[_pIndex].mId, + mId: _privileges[_pIndex].mId, + text: _privileges[_pIndex].mName, + state: { + opened: false + }, + children: [] + }; + $that._doJsTreePrivilegeData(_menuItem); + _children.push(_menuItem); + } + + } + } + }, + _doJsTreePrivilegeData: function (_menuItem) { + let _privileges = $that.staffPrivilegeInfo.privileges; + //构建菜单 + let _children = _menuItem.children; + for (let _pIndex = 0; _pIndex < _privileges.length; _pIndex++) { + if (_menuItem.mId == _privileges[_pIndex].mId) { + let _includePrivilege = false; + for (let _mIndex = 0; _mIndex < _children.length; _mIndex++) { + if (_privileges[_pIndex].pId == _children[_mIndex].pId) { + _includePrivilege = true; + } + } + if (!_includePrivilege) { + let _selected = false; + let _privilegeItem = { + id: 'p_' + _privileges[_pIndex].pId, + pId: _privileges[_pIndex].pId, + text: _privileges[_pIndex].pName, + state: { + opened: false, + selected: _selected + } + }; + _children.push(_privilegeItem); + } + + } + } + }, } });