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")
|
||||
Reference in New Issue
Block a user