diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 285b885..4cf43e4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,16 @@ +<<<<<<< HEAD +======= + + + + + + +>>>>>>> 1-rbac - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -365,7 +360,7 @@ - + @@ -465,9 +460,7 @@ - - - + @@ -512,7 +505,7 @@ - + @@ -550,7 +543,7 @@ - + @@ -560,7 +553,7 @@ - + @@ -656,16 +649,6 @@ - - - - - - - - - - @@ -702,6 +685,102 @@ + + +<<<<<<< HEAD + + +======= + + +>>>>>>> 1-rbac + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +<<<<<<< HEAD + +======= + + +>>>>>>> 1-rbac + + + + + + + + + + + + + + + + + +<<<<<<< HEAD + +======= + +>>>>>>> 1-rbac + + + + + + @@ -712,65 +791,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +<<<<<<< HEAD +======= + + +>>>>>>> 1-rbac - + +<<<<<<< HEAD +======= + + +>>>>>>> 1-rbac diff --git a/apps/system/__pycache__/urls.cpython-36.pyc b/apps/system/__pycache__/urls.cpython-36.pyc index 458f6f4..c07abe2 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_structure.cpython-36.pyc b/apps/system/__pycache__/views_structure.cpython-36.pyc index 7a9c6fb..a79945a 100644 Binary files a/apps/system/__pycache__/views_structure.cpython-36.pyc and b/apps/system/__pycache__/views_structure.cpython-36.pyc differ diff --git a/apps/system/tests.py b/apps/system/tests.py index 7ce503c..0b4501e 100644 --- a/apps/system/tests.py +++ b/apps/system/tests.py @@ -1,3 +1,4 @@ from django.test import TestCase # Create your tests here. + diff --git a/apps/system/urls.py b/apps/system/urls.py index 3f8687c..0b99caa 100644 --- a/apps/system/urls.py +++ b/apps/system/urls.py @@ -1,4 +1,4 @@ -from django.urls import path +from django.urls import path, re_path from .views import SystemView from . import views_structure @@ -10,5 +10,6 @@ urlpatterns = [ path('basic/structure/', views_structure.StructureView.as_view(), name='basic-structure'), path('basic/structure/create/', views_structure.StructureCreateView.as_view(), name='basic-structure-create'), path('basic/structure/list/', views_structure.StructureListView.as_view(), name='basic-structure-list'), + path('basic/structure/delete/', views_structure.StructureDeleteView.as_view(), name='basic-structure-delete'), ] diff --git a/apps/system/views_structure.py b/apps/system/views_structure.py index c59c45a..bad7f8d 100644 --- a/apps/system/views_structure.py +++ b/apps/system/views_structure.py @@ -8,6 +8,7 @@ from django.views.generic.base import TemplateView from django.views.generic.base import View from django.shortcuts import render from django.shortcuts import HttpResponse +from django.shortcuts import get_object_or_404 from .mixin import LoginRequiredMixin from .models import Structure @@ -23,11 +24,17 @@ class StructureCreateView(LoginRequiredMixin, View): def get(self, request): ret = dict(structure_all=Structure.objects.all()) + if 'id' in request.GET and request.GET['id']: + structure = get_object_or_404(Structure, pk=request.GET['id']) + ret['structure'] = structure return render(request, 'system/structure/structure_create.html', ret) def post(self, request): res = dict(result=False) - structure = Structure() + if 'id' in request.POST and request.POST['id']: + structure = get_object_or_404(Structure, pk=request.POST['id']) + else: + structure = Structure() structure_form = StructureForm(request.POST, instance=structure) if structure_form.is_valid(): structure_form.save() @@ -40,4 +47,15 @@ class StructureListView(LoginRequiredMixin, View): def get(self, request): fields = ['id', 'name', 'type', 'parent__name'] ret = dict(data=list(Structure.objects.values(*fields))) + return HttpResponse(json.dumps(ret), content_type='application/json') + + +class StructureDeleteView(LoginRequiredMixin, View): + + def post(self, request): + ret = dict(result=False) + if 'id' in request.POST and request.POST['id']: + id_list = map(int, request.POST['id'].split(',')) + Structure.objects.filter(id__in=id_list).delete() + ret['result'] = True return HttpResponse(json.dumps(ret), content_type='application/json') \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 index 6162f26..c462604 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/templates/system/structure/structure.html b/templates/system/structure/structure.html index 7535829..68ea042 100644 --- a/templates/system/structure/structure.html +++ b/templates/system/structure/structure.html @@ -135,6 +135,103 @@ } }); }); - + + //checkbox全选 + $("#checkAll").on("click", function () { + if ($(this).prop("checked") === true) { + $("input[name='checkList']").prop("checked", $(this).prop("checked")); + $('#example tbody tr').addClass('selected'); + } else { + $("input[name='checkList']").prop("checked", false); + $('#example tbody tr').removeClass('selected'); + } + }); + + //批量删除 + $("#btnDelete").click(function () { + if ($("input[name='checkList']:checked").length == 0) { + layer.msg("请选择要删除的记录"); + return; + } + + var arrId = new Array(); + $("input[name='checkList']:checked").each(function () { + //alert($(this).val()); + arrId.push($(this).val()); + }); + + sId = arrId.join(','); + + layer.alert('确定删除吗?', { + title: '提示' + , icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸 + , time: 0 //不自动关闭 + , btn: ['YES', 'NO'] + , yes: function (index) { + layer.close(index); + $.ajax({ + type: "POST", + url: "{% url 'system:basic-structure-delete' %}", + data: {"id": sId, csrfmiddlewaretoken: '{{ csrf_token }}'}, + cache: false, + success: function (msg) { + if (msg.result) { + layer.alert("操作成功", {icon: 1}); + oDataTable.ajax.reload(); + } else { + //alert(msg.message); + layer.alert("操作失败", {icon: 2}); + } + return; + } + }); + } + }); + }); + + //删除单个数据 + function doDelete(id) { + layer.alert('确定删除吗?', { + title: '提示' + , icon: 3 //0:感叹号 1:对号 2:差号 3:问号 4:小锁 5:哭脸 6:笑脸 + , time: 0 //不自动关闭 + , btn: ['YES', 'NO'] + , yes: function (index) { + layer.close(index); + $.ajax({ + type: "POST", + url: "{% url 'system:basic-structure-delete' %}", + data: {"id": id, csrfmiddlewaretoken: '{{ csrf_token }}'}, //防止post数据时报 csrf_token 403 + cache: false, + success: function (msg) { + if (msg.result) { + layer.alert('删除成功', {icon: 1}); + oDataTable.ajax.reload(); + } else { + //alert(msg.message); + layer.alert('删除失败', {icon: 2}); + } + return; + } + }); + } + }); + + } + + function doUpdate(id) { + layer.open({ + type: 2, + title: '编辑', + shadeClose: false, + maxmin: true, + area: ['800px', '400px'], + content: ["{% url 'system:basic-structure-create' %}" + '?id=' + id, 'no'], + end: function () { + oDataTable.ajax.reload(); + } + }); + } + {% endblock %} diff --git a/templates/system/structure/structure_create.html b/templates/system/structure/structure_create.html index 5a47662..eced8c6 100644 --- a/templates/system/structure/structure_create.html +++ b/templates/system/structure/structure_create.html @@ -14,14 +14,16 @@

组织架构信息

+
- +
@@ -33,6 +35,7 @@