完善权限系统

This commit is contained in:
BBIT-Kai
2025-12-08 18:11:48 +08:00
parent c53926afd6
commit dbdc222541
1503 changed files with 132197 additions and 885 deletions
+41
View File
@@ -24,3 +24,44 @@ def format_datetime(dt: datetime, tz="Asia/Shanghai"):
def safe_round(value, ndigits=2, default=None):
return round(value, ndigits) if value is not None else default
def build_dept_tree(depts):
dept_map = {d["id"]: d for d in depts}
roots = []
for d in depts:
pid = d["pid"]
if pid and pid in dept_map:
dept_map[pid]["children"].append(d)
else:
# pid 为 0 或不存在 → 顶层
roots.append(d)
return roots
def build_menu_tree(items):
item_map = {item["id"]: item for item in items}
tree = []
for item in items:
pid = item["pid"]
if pid and pid in item_map:
item_map[pid]["children"].append(item)
else:
tree.append(item)
return tree
from uuid import UUID
def is_valid_uuid(value: str):
try:
UUID(value)
return True
except:
return False