feat(nav): 新增前台公开导航页与后台导航管理
新增模块
- Nav 模型(applications/models/admin_nav.py):公开导航表,与 admin_power 解耦
- NavOutSchema / NavManageSchema(applications/schemas/admin_nav.py)
- 前台公开视图 applications/view/public/nav.py:/site/、/site/category/<name>、/site/api/navs,无需登录
- 后台管理视图 applications/view/system/nav.py:CRUD + 启用/禁用,挂入 system_bp
- 前台模板 templates/public/{base,index,category}.html(独立配色,无需登录即可访问)
- 后台模板 templates/system/nav/{main,add,edit}.html(Layui table + form)
调整
- applications/view/__init__.py:注册前台蓝图到根
- applications/view/system/__init__.py:注册后台 nav 子蓝图
- applications/common/script/admin.py:admin init/export 支持 navs 数组
- applications/common/script/app_data/init.json:新增 10 条导航种子 + 4 条 system:nav 权限
数据库
- 新增 public_nav 表(含 category 索引)
- migration: 38751d88d42c_add_public_nav_table.py
This commit is contained in:
@@ -75,6 +75,9 @@ def import_logic(file_path, is_force):
|
||||
db.session.query(Role).delete()
|
||||
db.session.query(Power).delete()
|
||||
db.session.query(Dept).delete()
|
||||
# 新增:清空 Nav 表
|
||||
from applications.models import Nav
|
||||
db.session.query(Nav).delete()
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
@@ -134,7 +137,17 @@ def import_logic(file_path, is_force):
|
||||
user.role = roles
|
||||
db.session.commit()
|
||||
|
||||
click.echo(f"导入成功! 新增: 部门{count_dept}, 权限{count_power}, 角色{count_role}, 用户{count_user}")
|
||||
# 5. 导入公开导航(Nav 表)
|
||||
from applications.models import Nav
|
||||
count_nav = 0
|
||||
for item in raw_data.get("navs", []):
|
||||
item = parse_time(item)
|
||||
if not Nav.query.get(item.get('id')) if item.get('id') else True:
|
||||
db.session.add(Nav(**item))
|
||||
count_nav += 1
|
||||
db.session.commit()
|
||||
|
||||
click.echo(f"导入成功! 新增: 部门{count_dept}, 权限{count_power}, 角色{count_role}, 用户{count_user}, 导航{count_nav}")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
@@ -184,7 +197,8 @@ def export_data(name):
|
||||
"depts": [],
|
||||
"powers": [],
|
||||
"roles": [],
|
||||
"users": []
|
||||
"users": [],
|
||||
"navs": []
|
||||
}
|
||||
|
||||
# 1. 导出部门
|
||||
@@ -204,6 +218,10 @@ def export_data(name):
|
||||
u_dict['role_ids'] = [r.id for r in u.role]
|
||||
data["users"].append(u_dict)
|
||||
|
||||
# 5. 导出公开导航
|
||||
from applications.models import Nav
|
||||
data["navs"] = [model_to_dict(n) for n in Nav.query.order_by(Nav.category, Nav.sort, Nav.id).all()]
|
||||
|
||||
try:
|
||||
with open(file_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, cls=DateEncoder, ensure_ascii=False, indent=4)
|
||||
|
||||
@@ -464,6 +464,58 @@
|
||||
"sort": 2,
|
||||
"create_time": "2023-01-01 10:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 60,
|
||||
"name": "导航管理",
|
||||
"type": "1",
|
||||
"code": "system:nav:main",
|
||||
"url": "/system/nav/",
|
||||
"open_type": "_iframe",
|
||||
"parent_id": "1",
|
||||
"icon": "layui-icon layui-icon-link",
|
||||
"sort": 9,
|
||||
"create_time": "2026-09-05 14:30:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 61,
|
||||
"name": "导航新增",
|
||||
"type": "2",
|
||||
"code": "system:nav:add",
|
||||
"url": "",
|
||||
"open_type": "",
|
||||
"parent_id": "60",
|
||||
"icon": "",
|
||||
"sort": 1,
|
||||
"create_time": "2026-09-05 14:30:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 62,
|
||||
"name": "导航编辑",
|
||||
"type": "2",
|
||||
"code": "system:nav:edit",
|
||||
"url": "",
|
||||
"open_type": "",
|
||||
"parent_id": "60",
|
||||
"icon": "",
|
||||
"sort": 2,
|
||||
"create_time": "2026-09-05 14:30:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 63,
|
||||
"name": "导航删除",
|
||||
"type": "2",
|
||||
"code": "system:nav:remove",
|
||||
"url": "",
|
||||
"open_type": "",
|
||||
"parent_id": "60",
|
||||
"icon": "",
|
||||
"sort": 3,
|
||||
"create_time": "2026-09-05 14:30:00",
|
||||
"enable": 1
|
||||
}
|
||||
],
|
||||
"roles": [
|
||||
@@ -485,7 +537,18 @@
|
||||
"details": "只有查看,没有增删改权限",
|
||||
"sort": 2,
|
||||
"create_time": "2023-01-01 10:00:00",
|
||||
"power_ids": [1, 3, 4, 9, 12, 13, 17, 18, 44, 48]
|
||||
"power_ids": [
|
||||
1,
|
||||
3,
|
||||
4,
|
||||
9,
|
||||
12,
|
||||
13,
|
||||
17,
|
||||
18,
|
||||
44,
|
||||
48
|
||||
]
|
||||
}
|
||||
],
|
||||
"users": [
|
||||
@@ -499,7 +562,9 @@
|
||||
"remark": "要是不能把握时机,就要终身蹭蹬,一事无成!",
|
||||
"avatar": "/static/system/admin/images/avatar.jpg",
|
||||
"dept_id": 1,
|
||||
"role_ids": [1]
|
||||
"role_ids": [
|
||||
1
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
@@ -511,7 +576,9 @@
|
||||
"remark": "要是不能把握时机,就要终身蹭蹬,一事无成!",
|
||||
"avatar": "/static/system/admin/images/avatar.jpg",
|
||||
"dept_id": 1,
|
||||
"role_ids": [2]
|
||||
"role_ids": [
|
||||
2
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
@@ -525,5 +592,127 @@
|
||||
"dept_id": 7,
|
||||
"role_ids": []
|
||||
}
|
||||
],
|
||||
"navs": [
|
||||
{
|
||||
"category": "开发工具",
|
||||
"title": "GitHub",
|
||||
"url": "https://github.com",
|
||||
"description": "全球最大开源代码托管平台",
|
||||
"icon": "layui-icon layui-icon-website",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "开发工具",
|
||||
"title": "Stack Overflow",
|
||||
"url": "https://stackoverflow.com",
|
||||
"description": "全球程序员问答社区",
|
||||
"icon": "layui-icon layui-icon-help",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "开发工具",
|
||||
"title": "MDN Web Docs",
|
||||
"url": "https://developer.mozilla.org",
|
||||
"description": "Web 开发权威文档",
|
||||
"icon": "layui-icon layui-icon-read",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "开发工具",
|
||||
"title": "Gitee",
|
||||
"url": "https://gitee.com",
|
||||
"description": "国内代码托管平台",
|
||||
"icon": "layui-icon layui-icon-website",
|
||||
"sort": 4,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "AI 工具",
|
||||
"title": "ChatGPT",
|
||||
"url": "https://chat.openai.com",
|
||||
"description": "OpenAI 出品的对话式 AI",
|
||||
"icon": "layui-icon layui-icon-console",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "AI 工具",
|
||||
"title": "Claude",
|
||||
"url": "https://claude.ai",
|
||||
"description": "Anthropic 出品的 AI 助手",
|
||||
"icon": "layui-icon layui-icon-console",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "AI 工具",
|
||||
"title": "通义千问",
|
||||
"url": "https://tongyi.aliyun.com",
|
||||
"description": "阿里云出品的国产大模型",
|
||||
"icon": "layui-icon layui-icon-console",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "设计资源",
|
||||
"title": "Dribbble",
|
||||
"url": "https://dribbble.com",
|
||||
"description": "全球设计灵感社区",
|
||||
"icon": "layui-icon layui-icon-picture",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "设计资源",
|
||||
"title": "Behance",
|
||||
"url": "https://www.behance.net",
|
||||
"description": "Adobe 旗下的设计师作品集平台",
|
||||
"icon": "layui-icon layui-icon-picture",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
},
|
||||
{
|
||||
"category": "设计资源",
|
||||
"title": "优设",
|
||||
"url": "https://www.uisdc.com",
|
||||
"description": "国内优秀设计师导航",
|
||||
"icon": "layui-icon layui-icon-picture",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 14:30:00"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user