From 813363f0d43eba315999d64c22f6703343ef735e Mon Sep 17 00:00:00 2001 From: wojiaoyishang Date: Mon, 20 Jan 2025 21:38:08 +0800 Subject: [PATCH] =?UTF-8?q?Update:=20=EF=BC=88=E6=AD=A5=E9=AA=A4=E5=A4=87?= =?UTF-8?q?=E4=BB=BD=EF=BC=89=E6=9B=B4=E6=96=B0=E9=83=A8=E9=97=A8=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/common/script/admin.py | 2 +- applications/view/system/dept.py | 29 ++++++++++++++----- templates/system/dept/add.html | 18 ++++++------ templates/system/dept/edit.html | 27 ++++++++++-------- templates/system/dept/main.html | 44 +++++++++++++---------------- templates/system/power/main.html | 13 ++++----- 6 files changed, 72 insertions(+), 61 deletions(-) diff --git a/applications/common/script/admin.py b/applications/common/script/admin.py index 35c9cff..83ece0c 100644 --- a/applications/common/script/admin.py +++ b/applications/common/script/admin.py @@ -301,7 +301,7 @@ powerdata = [ ), Power( id=26, - name='用户删除', + name='权限删除', type='2', code='system:power:remove', url='', diff --git a/applications/view/system/dept.py b/applications/view/system/dept.py index 20e4a09..68a324c 100644 --- a/applications/view/system/dept.py +++ b/applications/view/system/dept.py @@ -2,7 +2,7 @@ from flask import Blueprint, render_template, request, jsonify from applications.common import curd from applications.common.utils import validate -from applications.common.utils.http import success_api, fail_api +from applications.common.utils.http import success_api, fail_api, table_api from applications.common.utils.rights import authorize from applications.common.utils.validate import str_escape from applications.extensions import db @@ -21,11 +21,26 @@ def main(): @bp.post('/data') @authorize("system:dept:main", log=True) def data(): - data = Dept.query.order_by(Dept.sort).all() - res = { - "data": DeptSchema(many=True).dump(data) - } - return jsonify(res) + dept = Dept.query.order_by(Dept.sort).all() + data = DeptSchema(many=True).dump(dept) + + # 创建一个字典,用于存储每个节点的子节点 + tree = {} + for item in data: + item["children"] = [] + tree[item["id"]] = item + + # 构建树形结构 + root_nodes = [] + for item in data: + parent_id = item["parent_id"] if item["parent_id"] != 0 else None + if parent_id is None: + root_nodes.append(item) + else: + if parent_id in tree: + tree[parent_id]["children"].append(item) + + return table_api(msg="请求成功", data=root_nodes) @bp.get('/add') @@ -108,7 +123,7 @@ def dis_enable(): @authorize("system:dept:edit", log=True) def update(): json = request.get_json(force=True) - #id = json.get("deptId"), + # id = json.get("deptId"), id = str_escape(json.get("deptId")) data = { "dept_name": validate.str_escape(json.get("deptName")), diff --git a/templates/system/dept/add.html b/templates/system/dept/add.html index 6935c35..cdc8e3a 100644 --- a/templates/system/dept/add.html +++ b/templates/system/dept/add.html @@ -18,28 +18,28 @@
-
-
-
-
@@ -52,9 +52,9 @@
-
- +
+
@@ -68,11 +68,11 @@
- - diff --git a/templates/system/dept/edit.html b/templates/system/dept/edit.html index d219c21..4bfd682 100644 --- a/templates/system/dept/edit.html +++ b/templates/system/dept/edit.html @@ -12,21 +12,21 @@
-
-
-
@@ -34,7 +34,7 @@
-
@@ -42,7 +42,7 @@
-
@@ -61,17 +61,20 @@
-
- +
+
+ class="layui-textarea"> + {% if dept.address %} + {{ dept.address }} + {% endif %} +
@@ -79,12 +82,12 @@
- - diff --git a/templates/system/dept/main.html b/templates/system/dept/main.html index 651d856..1c1f164 100644 --- a/templates/system/dept/main.html +++ b/templates/system/dept/main.html @@ -7,8 +7,8 @@
-
-
+
+
@@ -34,13 +34,13 @@ @@ -71,8 +70,7 @@ {% include 'system/common/footer.html' %}