diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 1e8045a..b33ee44 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,10 @@ + + + - + - - + + @@ -28,12 +31,14 @@ - - + + - - - + + + + + @@ -42,7 +47,7 @@ - + @@ -53,18 +58,18 @@ - - + + - + - - + + @@ -72,11 +77,11 @@ - + - - + + @@ -136,10 +141,11 @@ @@ -150,10 +156,10 @@ DEFINITION_ORDER - @@ -200,12 +206,6 @@ - - - - - - @@ -314,17 +314,16 @@ - - + - + - - - + + + - - + + @@ -332,13 +331,27 @@ + + + + + + + + + + + + + + @@ -354,13 +367,6 @@ - - - - - - - @@ -557,9 +563,6 @@ - - - @@ -709,16 +712,6 @@ - - - - - - - - - - @@ -727,32 +720,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -761,16 +728,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + diff --git a/apps/system/__pycache__/urls.cpython-36.pyc b/apps/system/__pycache__/urls.cpython-36.pyc index ba70b30..917b65a 100644 Binary files a/apps/system/__pycache__/urls.cpython-36.pyc and b/apps/system/__pycache__/urls.cpython-36.pyc differ diff --git a/apps/system/__pycache__/views_role.cpython-36.pyc b/apps/system/__pycache__/views_role.cpython-36.pyc index 8ad075c..f66068b 100644 Binary files a/apps/system/__pycache__/views_role.cpython-36.pyc and b/apps/system/__pycache__/views_role.cpython-36.pyc differ diff --git a/apps/system/urls.py b/apps/system/urls.py index 9537e25..e7d858f 100644 --- a/apps/system/urls.py +++ b/apps/system/urls.py @@ -32,5 +32,7 @@ urlpatterns = [ path('rbac/role/list/', views_role.RoleListView.as_view(), name='rbac-role-list'), path('rbac/role/update/', views_role.RoleUpdateView.as_view(), name='rbac-role-update'), path('rbac/role/delete/', views_role.RoleDeleteView.as_view(), name='rbac-role-delete'), - path('rbac/role/role2user$', views_role.Role2UserView.as_view(), name="rbac-role-role2user"), + path('rbac/role/role2user/', views_role.Role2UserView.as_view(), name="rbac-role-role2user"), + path('rbac/role/role2menu/', views_role.Role2MenuView.as_view(), name="rbac-role-role2menu"), + path('rbac/role/role2menu_list/', views_role.Role2MenuListView.as_view(), name="rbac-role-role2menu_list"), ] diff --git a/apps/system/views_role.py b/apps/system/views_role.py index 3e43c34..f47f330 100644 --- a/apps/system/views_role.py +++ b/apps/system/views_role.py @@ -11,7 +11,7 @@ from django.contrib.auth import get_user_model from django.shortcuts import render from .mixin import LoginRequiredMixin -from .models import Role +from .models import Role, Menu from custom import SandboxCreateView, SandboxUpdateView User = get_user_model() @@ -79,3 +79,40 @@ class Role2UserView(LoginRequiredMixin, View): return HttpResponse(json.dumps(res), content_type='application/json') +class Role2MenuView(LoginRequiredMixin, View): + """ + 角色绑定菜单 + """ + def get(self, request): + if 'id' in request.GET and request.GET['id']: + role = get_object_or_404(Role, pk=request.GET['id']) + ret = dict(role=role) + return render(request, 'system/role_role2menu.html', ret) + + def post(self, request): + res = dict(result=False) + role = get_object_or_404(Role, pk=request.POST['id']) + tree = json.loads(self.request.POST['tree']) + role.permissions.clear() + for menu in tree: + if menu['checked'] is True: + menu_checked = get_object_or_404(Menu, pk=menu['id']) + role.permissions.add(menu_checked) + res['result'] = True + return HttpResponse(json.dumps(res), content_type='application/json') + + +class Role2MenuListView(LoginRequiredMixin, View): + """ + 获取zTree菜单列表 + """ + def get(self, request): + fields = ['id', 'name', 'parent'] + if 'id' in request.GET and request.GET['id']: + role = Role.objects.get(id=request.GET.get('id')) + role_menus = role.permissions.values(*fields) + ret = dict(data=list(role_menus)) + else: + menus = Menu.objects.all() + ret = dict(data=list(menus.values(*fields))) + return HttpResponse(json.dumps(ret), content_type='application/json') \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 5d4dbd9..3c1ad82 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/templates/system/role.html b/templates/system/role.html index accb09d..c71d519 100644 --- a/templates/system/role.html +++ b/templates/system/role.html @@ -237,6 +237,19 @@ content: ["{% url 'system:rbac-role-role2user' %}" + '?id=' + id, 'no'], }); } + + //关联菜单 + function doUpdateMenu(id) { + layer.open({ + type: 2, + title: '权限分配', + shadeClose: false, + maxmin: true, + area: ['600px', '480px'], + content: ["{% url 'system:rbac-role-role2menu' %}" + '?id=' + id, 'no'], + + }); + } {% endblock %} \ No newline at end of file diff --git a/templates/system/role_role2menu.html b/templates/system/role_role2menu.html new file mode 100644 index 0000000..10b0ef1 --- /dev/null +++ b/templates/system/role_role2menu.html @@ -0,0 +1,179 @@ +{% extends "base-layer.html" %} {% load static %} + +{% block css %} + + + +{% endblock %} +{% block main %} + + +
+
+
+ {% csrf_token %} + + + +
+
+
+
+ + +
+
+
    +
    +
    +
    +





    +
    + +
    +
    {{ role.name }}权限
    + +
    +
    +
    + +
    +
      +
      +
      +
      +
      +
      +
      +{% endblock %} + +{% block javascripts %} + + + +{% endblock %} \ No newline at end of file