完善权限系统
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user