基於AdminLTE 多租戶權限隔離
旨在分享,整理的相對比較簡單
基於AdminLTE的企業應用開發平臺,封裝和集成多種組件,提供前端、後端整體解決方案,使得運維WEB開發更簡單
背景需求:
當前做的系統是運維自動化平臺,要做到多租戶的權限隔離,直白的說如果張三具有A,B,C三個功能,李四具備B,C,D功能權限,當用戶張三登錄時看不到D的功能菜單,當用戶李四登錄時,看不多A功能菜單,當前思路是用戶到組,組到權限
前端頁面:直接將AdminLte下的starter.html進行修改即可,下面標註幾個更改的地方
aside 標簽
<aside>
<!-- sidebar: style can be found insidebar.less -->
<section>
<ul> 功能菜單列表
</ul>
</section>
</aside>
JS代碼,從db中獲取數據,對sidebar做數據追加操作
<script>
$.ajax({
type:‘POST‘,
async:false,
url:‘testing‘,
success:function(data){
var $li,$menu_f_ul;
data=$.parseJSON(data);
$.each(data,function(index,item){
if(item.levelCode.length==6){
$li=$(‘<liclass="treeview"></li>‘);
var $menu_f=$(‘<ahref="#">\n‘+
‘<iclass="‘+item.icon+‘"></i><span>‘+item.name+‘</span>\n‘+
‘ <spanclass="pull-right-container">\n‘+
‘<i class="fafa-angle-left pull-right"></i>\n‘+
‘</span></a>‘);
$li.append($menu_f);
$menu_f_ul=$(‘<ulclass="treeview-menu"></ul>‘);
$li.append($menu_f_ul);
$("ul.sidebar-menu").append($li);
}
else if(item.levelCode.length==12){
$menu_s=$(‘<li><ahref="#" data-url="‘+item.url+‘"><iclass="‘+item.icon+‘"></i>‘+item.name+‘</a></li>‘);
$menu_f_ul.append($menu_s);
}
});
}
});
$(function(){
//首頁默認加載,通過增加active類,對每個父附錄進行展開
$("a[data-url]").click(function(evt){
loadPage($(this).data("url"));
$("ul.treeview-menu li").removeClass("active");
$(this).parent().addClass("active");
});
});
</script>
數據格式為:
[{"levelCode":"000001", "url": "", "id":"4028818a567745ec0156786cd39e000b", "name": "我的待辦","icon": "fa fa-calendar-check-o"}, {"levelCode":"000001000001", "url": "TEST", "id":"402881f25681c52a015681d472ba0000", "name":"TEST", "icon": "fa fa-bicycle"},{"levelCode": "000002", "url": "","id": "402880eb56875b7f0156876338100000", "name":"CURD DEMO", "icon": "fa fa-table"},{"levelCode": "000002000001", "url":"/user/list", "id":"402880eb56875b7f01568763ac630001", "name": "用戶列表-Dailog","icon": "fa fa-user"}, {"levelCode":"000002000002", "url": "/user/tab/list","id": "40288182579e398f0157a25ca29a0002", "name":"用戶列表-Tab", "icon": "fa fa-male"},{"levelCode": "000002000003", "url":"/user/page/list", "id":"8a8a801b58ce0f500158ce14d2c20000", "name": "用戶列表-Page","icon": "fa fa-user"}, {"levelCode":"000004", "url": "", "id":"ff80808159ea142c0159ea670fae0000", "name": "組件使用說明","icon": "fa fa-server"}, {"levelCode":"000004000001", "url": "/markdown/preview/modal","id": "ff80808159ea142c0159ea68d1e30001", "name":"窗體-modals", "icon": "fa fa-windows"},{"levelCode": "000004000002", "url":"/markdown/preview/form", "id":"402880e95a72d8a4015a738980e30000", "name": "表單-form","icon": "fa fa-edit"}, {"levelCode":"000004000003", "url": "/markdown/preview/file","id": "402880ea5aae3edf015ab1b0ec9d0017", "name":"附件上傳-file", "icon": "fa fa-file-o"},{"levelCode": "000028", "url": "","id": "402880eb58d9a6d40158d9a7b21f0000", "name":"系統工具", "icon": "fa fa-wrench"},{"levelCode": "000028000001", "url":"/markdown/list", "id":"402880e958eb83230158eb85a30f0000", "name": "我的文章","icon": "fa fa-edit"}, {"levelCode":"000028000002", "url": "/markdown/edit","id": "402880eb58d9a6d40158d9a995130001", "name":"Markdown編輯器", "icon": "fa fa-pencil"},{"levelCode": "000028000003", "url":"/generator/setting", "id":"8a8a81425a1b36e9015a1b42074b0000", "name": "代碼生成器","icon": "fa fa-list"}, {"levelCode":"000028000004", "url": "/generator/list","id": "8a8a81d65a3598d9015a360092e60000", "name":"代碼生成器測試", "icon": "fa fa-edit"},{"levelCode": "000028000005", "url":"/job/list", "id":"402880e95a72d8a4015a738bb1990001", "name": "任務管理器","icon": "fa fa-calendar-check-o"}, {"levelCode":"000028000006", "url": "/message/list","id": "8a8a83295a83a81a015a843e397b0000", "name":"消息管理器", "icon": "fa fa-list"},{"levelCode": "000030", "url": "","id": "4028818a56d407950156d41352630000", "name":"系統管理", "icon": "fa fa-tv"},{"levelCode": "000030000001", "url":"/user/page/list", "id":"4028818a56d407950156d41435830001", "name": "用戶管理","icon": "fa fa-user"}, {"levelCode":"000030000002", "url": "/dict/tree","id": "4028818a56d407950156d4160e390002", "name":"字典管理", "icon": "fa fa-book"}, {"levelCode":"000030000003", "url": "/function/tree","id": "4028818a56d407950156d41d32ab0003", "name":"功能管理", "icon": "fa fa-cog"},{"levelCode": "000030000004", "url":"/role/list", "id":"4028818a56d407950156d4ecfafa0004", "name": "角色管理","icon": "fa fa-street-view"}, {"levelCode":"000030000005", "url": "/rolefunc/list","id": "8a8a807a59634b2801596364e33d0001", "name":"角色授權", "icon": "fa fa-key"}]
前端頁面效果圖:
首頁的代碼下載、view.py及DB sql請查看github:
https://github.com/caibird1990/platform
溝通方式:[email protected]
數據參考:http://www.admineap.com/
基於AdminLTE 多租戶權限隔離