feature: 权限列表-01
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
from flask import Blueprint, Flask
|
||||
|
||||
from .passport import passport_api
|
||||
from .rights import rights_api
|
||||
|
||||
|
||||
def register_apis(app: Flask):
|
||||
apis = Blueprint("api", __name__, url_prefix="/api/v1")
|
||||
|
||||
apis.register_blueprint(passport_api)
|
||||
apis.register_blueprint(rights_api)
|
||||
|
||||
app.register_blueprint(apis)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
from flask import Blueprint, request
|
||||
from flask_jwt_extended import jwt_required
|
||||
|
||||
from pear_admin.extensions import db
|
||||
from pear_admin.orms import RightsORM
|
||||
|
||||
rights_api = Blueprint("rights", __name__)
|
||||
|
||||
|
||||
@rights_api.get("/rights")
|
||||
@jwt_required()
|
||||
def rights_list():
|
||||
page = request.args.get("page", type=int, default=1)
|
||||
per_page = request.args.get("per_page", type=int, default=10)
|
||||
|
||||
q = db.select(RightsORM).where(RightsORM.type == "menu")
|
||||
pages = db.paginate(q, page=page, per_page=per_page, error_out=False)
|
||||
|
||||
ret = []
|
||||
|
||||
for page in pages.items:
|
||||
data = page.json()
|
||||
data["children"] = []
|
||||
for child in page.children:
|
||||
child_data = child.json()
|
||||
if child.children:
|
||||
child_data["children"] = [
|
||||
sub_child.json() for sub_child in child.children
|
||||
]
|
||||
child_data["isParent"] = True
|
||||
|
||||
data["children"].append(child_data)
|
||||
data["isParent"] = True
|
||||
ret.append(data)
|
||||
return {"code": 0, "message": "请求权限数据成功", "count": pages.total, "data": ret}
|
||||
@@ -1,3 +1,5 @@
|
||||
from sqlalchemy.orm import backref
|
||||
|
||||
from pear_admin.extensions import db
|
||||
|
||||
from ._base import BaseORM
|
||||
@@ -23,7 +25,10 @@ class RightsORM(BaseORM):
|
||||
comment="父类编号",
|
||||
)
|
||||
|
||||
# parent = db.relationship("RightsORM", remote_side=[pid]) # 自关联
|
||||
parent = db.relationship(
|
||||
"RightsORM", back_populates="children", remote_side=[id]
|
||||
) # 自关联
|
||||
children = db.relationship("RightsORM", back_populates="parent")
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
@@ -32,7 +37,7 @@ class RightsORM(BaseORM):
|
||||
"code": self.code,
|
||||
"type": self.type,
|
||||
"url": self.url,
|
||||
"icon": self.icon,
|
||||
"icon_sign": self.icon,
|
||||
"status": self.status,
|
||||
"sort": self.sort,
|
||||
"open_type": self.open_type,
|
||||
@@ -45,10 +50,10 @@ class RightsORM(BaseORM):
|
||||
return {
|
||||
"id": self.id,
|
||||
"pid": self.pid,
|
||||
"rights_id": self.id,
|
||||
"title": self.name,
|
||||
"type": type_map_dict[self.type],
|
||||
"href": self.url,
|
||||
"icon": self.icon,
|
||||
"sort": self.sort,
|
||||
"openType": self.open_type,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from flask import Flask
|
||||
|
||||
from .index import index_bp
|
||||
from .views import views_bp
|
||||
|
||||
|
||||
def register_views(app: Flask):
|
||||
app.register_blueprint(index_bp)
|
||||
app.register_blueprint(views_bp)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
views_bp = Blueprint("views", __name__, url_prefix="/views")
|
||||
|
||||
|
||||
@views_bp.get("/rights")
|
||||
def rights_view():
|
||||
return render_template("views/rights/index.html")
|
||||
@@ -0,0 +1,133 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>权限管理</title>
|
||||
<meta name="renderer" content="webkit" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1, maximum-scale=1"
|
||||
/>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div style="padding: 16px">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-body">
|
||||
<table
|
||||
class="layui-hide"
|
||||
id="rights-table"
|
||||
lay-filter="rights-table"
|
||||
></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/html" id="rights-toolbar">
|
||||
<div class="layui-btn-container">
|
||||
<button class="layui-btn layui-btn-sm" lay-event="toolbar-add">
|
||||
新增权限
|
||||
</button>
|
||||
</div>
|
||||
</script>
|
||||
<script type="text/html" id="rights-tool">
|
||||
<div class="layui-btn-container">
|
||||
<button
|
||||
class="layui-btn layui-btn-sm layui-bg-blue"
|
||||
lay-event="rights-tool-edit"
|
||||
>
|
||||
编辑
|
||||
</button>
|
||||
<button
|
||||
class="layui-btn layui-btn-sm layui-bg-red"
|
||||
lay-event="rights-tool-del"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</script>
|
||||
<script>
|
||||
layui.use(function () {
|
||||
var treeTable = layui.treeTable;
|
||||
treeTable.render({
|
||||
elem: "#rights-table",
|
||||
url: "/api/v1/rights?type=treetable", // 此处为静态模拟数据,实际使用时需换成真实接口
|
||||
height: "full-35", // 最大高度减去其他容器已占有的高度差
|
||||
toolbar: "#rights-toolbar",
|
||||
cols: [
|
||||
[
|
||||
{ type: "checkbox", fixed: "left" },
|
||||
{
|
||||
field: "id",
|
||||
title: "ID",
|
||||
width: 80,
|
||||
sort: true,
|
||||
fixed: "left",
|
||||
},
|
||||
{ field: "name", title: "权限名", width: 180 },
|
||||
{ field: "code", title: "权限标识", width: 150 },
|
||||
{
|
||||
field: "icon_sign",
|
||||
title: "图标",
|
||||
width: 90,
|
||||
templet: (d) => {
|
||||
return `<i class="${d.icon_sign}"></i> `;
|
||||
},
|
||||
},
|
||||
{ field: "open_type", title: "打开方式", width: 100 },
|
||||
{
|
||||
field: "status",
|
||||
title: "状态",
|
||||
width: 100,
|
||||
templet: (d) => {
|
||||
return `<input type="checkbox" name="status" value="${
|
||||
d.id
|
||||
}" title="启用|禁用" lay-skin="switch" ${
|
||||
d.status ? "checked" : ""
|
||||
} lay-filter="rights-table-switch-status"/>`;
|
||||
},
|
||||
},
|
||||
{
|
||||
field: "type",
|
||||
title: "类型",
|
||||
width: 100,
|
||||
templet: (d) => {
|
||||
if (d.type === "menu") {
|
||||
return `<button type="button" class="layui-btn layui-btn-sm layui-btn-radius">菜单</button>`;
|
||||
} else if (d.type === "path") {
|
||||
return `<button type="button" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal">路径</button>`;
|
||||
} else if (d.type === "auth") {
|
||||
return `<button type="button" class="layui-btn layui-btn-sm layui-btn-radius layui-bg-purple">权限</button>`;
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
fixed: "right",
|
||||
title: "操作",
|
||||
width: 120,
|
||||
align: "center",
|
||||
toolbar: "#rights-tool",
|
||||
},
|
||||
],
|
||||
],
|
||||
page: true,
|
||||
});
|
||||
|
||||
treeTable.on("toolbar(rights-table)", function (obj) {
|
||||
if (obj.event === "rights-toolbar-add") {
|
||||
console.log("新增权限");
|
||||
}
|
||||
});
|
||||
|
||||
treeTable.on("tool(rights-table)", function (obj) {
|
||||
var layEvent = obj.event;
|
||||
if (layEvent === "rights-tool-edit") {
|
||||
console.log("编辑权限");
|
||||
} else if (layEvent === "rights-tool-del") {
|
||||
console.log("删除权限");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user