refactor(plugins): 将导航/友链/关于/统计 4 模块迁出 framework 至 plugins
- 在 applications/config.py 中通过 PLUGIN_ENABLE_FOLDERS 启用 4 个业务插件
- 删除 framework 内 applications/view/system/nav.py 与 templates/system/nav/* 模板
- applications/extensions/init_plugs 移除重复的 broadcast_execute('event_init'/'event_finish')
(由 init_bps / init_script 触发,避免 Blueprint 注册冲突)
- applications/view/system/index.py:未登录访问 / 直接渲染前台公开聚合页
- templates/system/index.html:移动端首屏即折叠侧边栏
- 新增 5 个 model(Nav 字段 status→enable 兼容、NavCategory、About、Friend、VisitLog/PageStat、NavClick)
- 新增 2 个 schema(NavCategorySchema、FriendOutSchema/ManageSchema)
- admin_about/admin_friend/admin_nav_category 在 init.json 中以「网站管理」分组挂载
- .gitignore 补充一次性备份、调试截图、探针截图不入库
This commit is contained in:
@@ -37,4 +37,6 @@ def create_app():
|
||||
init_bps(app)
|
||||
init_script(app)
|
||||
|
||||
# 5) 全站访问埋点已迁移到 plugins/siteStats(@app.before_request → record_visit)
|
||||
|
||||
return app
|
||||
|
||||
@@ -472,9 +472,9 @@
|
||||
"code": "system:nav:main",
|
||||
"url": "/system/nav/",
|
||||
"open_type": "_iframe",
|
||||
"parent_id": "1",
|
||||
"parent_id": "64",
|
||||
"icon": "layui-icon layui-icon-link",
|
||||
"sort": 9,
|
||||
"sort": 1,
|
||||
"create_time": "2026-09-05 14:30:00",
|
||||
"enable": 1
|
||||
},
|
||||
@@ -516,6 +516,58 @@
|
||||
"sort": 3,
|
||||
"create_time": "2026-09-05 14:30:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 64,
|
||||
"name": "网站管理",
|
||||
"type": "0",
|
||||
"code": "",
|
||||
"url": "",
|
||||
"open_type": "",
|
||||
"parent_id": "0",
|
||||
"icon": "layui-icon layui-icon-website",
|
||||
"sort": 3,
|
||||
"create_time": "2026-09-05 17:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 65,
|
||||
"name": "关于本站",
|
||||
"type": "1",
|
||||
"code": "site:about:main",
|
||||
"url": "/system/about/",
|
||||
"open_type": "_iframe",
|
||||
"parent_id": "64",
|
||||
"icon": "layui-icon layui-icon-about",
|
||||
"sort": 2,
|
||||
"create_time": "2026-09-05 17:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 66,
|
||||
"name": "友情链接",
|
||||
"type": "1",
|
||||
"code": "site:friend:main",
|
||||
"url": "/system/friend/",
|
||||
"open_type": "_iframe",
|
||||
"parent_id": "64",
|
||||
"icon": "layui-icon layui-icon-link",
|
||||
"sort": 3,
|
||||
"create_time": "2026-09-05 17:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"id": 67,
|
||||
"name": "访问统计",
|
||||
"type": "1",
|
||||
"code": "site:stats:main",
|
||||
"url": "/system/stats/",
|
||||
"open_type": "_iframe",
|
||||
"parent_id": "64",
|
||||
"icon": "layui-icon layui-icon-chart",
|
||||
"sort": 4,
|
||||
"create_time": "2026-09-05 17:00:00",
|
||||
"enable": 1
|
||||
}
|
||||
],
|
||||
"roles": [
|
||||
@@ -601,10 +653,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "常用分类",
|
||||
@@ -613,10 +665,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "常用分类",
|
||||
@@ -625,10 +677,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "常用分类",
|
||||
@@ -637,10 +689,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 4,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -649,10 +701,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -661,10 +713,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -673,10 +725,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -685,10 +737,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 4,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -697,10 +749,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 5,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -709,10 +761,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 6,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -721,10 +773,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 7,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -733,10 +785,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 8,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -745,10 +797,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 9,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "旺珂内网",
|
||||
@@ -757,10 +809,10 @@
|
||||
"description": "内网服务,仅限本地访问)",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 10,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "常用网站",
|
||||
@@ -769,10 +821,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "常用网站",
|
||||
@@ -781,10 +833,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "常用网站",
|
||||
@@ -793,10 +845,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "常用网站",
|
||||
@@ -805,10 +857,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 4,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -817,10 +869,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -829,10 +881,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -841,10 +893,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -853,10 +905,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 4,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -865,10 +917,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 5,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -877,10 +929,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 6,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -889,10 +941,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 7,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -901,10 +953,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 8,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -913,10 +965,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 9,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -925,10 +977,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 10,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -937,10 +989,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 11,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -949,10 +1001,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 12,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -961,10 +1013,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 13,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -973,10 +1025,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 14,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -985,10 +1037,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 15,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -997,10 +1049,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 16,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -1009,10 +1061,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 17,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "休闲娱乐",
|
||||
@@ -1021,10 +1073,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 18,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1033,10 +1085,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 1,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1045,10 +1097,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 2,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1057,10 +1109,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 3,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1069,10 +1121,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 4,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1081,10 +1133,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 5,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1093,10 +1145,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 6,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1105,10 +1157,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 7,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1117,10 +1169,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 8,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1129,10 +1181,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 9,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1141,10 +1193,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 10,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1153,10 +1205,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 11,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1165,10 +1217,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 12,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1177,10 +1229,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 13,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1189,10 +1241,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 14,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1201,10 +1253,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 15,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1213,10 +1265,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 16,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1225,10 +1277,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 17,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
},
|
||||
{
|
||||
"category": "技术网站",
|
||||
@@ -1237,10 +1289,10 @@
|
||||
"description": "",
|
||||
"icon": "layui-icon-link",
|
||||
"sort": 18,
|
||||
"status": 1,
|
||||
"is_external": 1,
|
||||
"create_by": "admin",
|
||||
"create_at": "2026-09-05 15:00:00"
|
||||
"create_at": "2026-09-05 15:00:00",
|
||||
"enable": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -70,7 +70,8 @@ class BaseConfig:
|
||||
MAIL_DEFAULT_SENDER = _env_str("MAIL_DEFAULT_SENDER", MAIL_USERNAME)
|
||||
|
||||
# ---- 插件 ----
|
||||
PLUGIN_ENABLE_FOLDERS = []
|
||||
# 站点业务模块(导航 / 友链 / 关于 / 访问统计)均通过 plugins 方式开发,启用即可挂载路由
|
||||
PLUGIN_ENABLE_FOLDERS = ["navManager", "friendManager", "aboutManager", "siteStats"]
|
||||
|
||||
|
||||
class DevConfig(BaseConfig):
|
||||
|
||||
@@ -12,7 +12,7 @@ from .init_plugins import register_plugin, broadcast_execute
|
||||
|
||||
|
||||
def init_plugs(app: Flask) -> None:
|
||||
# 注册插件a
|
||||
# 注册插件 (仅 import + 注册动作)
|
||||
register_plugin(app)
|
||||
broadcast_execute(app, 'event_begin')
|
||||
|
||||
@@ -25,10 +25,10 @@ def init_plugs(app: Flask) -> None:
|
||||
init_session(app)
|
||||
init_limit(app)
|
||||
|
||||
# 系统蓝图相关
|
||||
# 系统蓝图相关(含 @template_global 等 Jinja 注入)
|
||||
init_template_directives(app)
|
||||
init_error_views(app)
|
||||
|
||||
# 初始化插件
|
||||
broadcast_execute(app, 'event_init')
|
||||
broadcast_execute(app, 'event_finish')
|
||||
|
||||
# 注:event_init / event_finish / event_context 由具体的
|
||||
# applications.view.init_bps / applications.common.script.init_script
|
||||
# 触发,避免 init_plugs 内重复调用导致 Blueprint 注册冲突
|
||||
|
||||
@@ -9,3 +9,8 @@ from .admin_user import User
|
||||
from .admin_user_role import user_role
|
||||
from .admin_mail import Mail
|
||||
from .admin_nav import Nav
|
||||
from .admin_nav_category import NavCategory
|
||||
from .admin_about import About
|
||||
from .admin_friend import Friend
|
||||
from .admin_stat import VisitLog, PageStat
|
||||
from .admin_nav_click import NavClick
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
"""
|
||||
「关于本站」内容管理。
|
||||
|
||||
单条记录表 (id=1):
|
||||
- 用于站点"关于"页面:自我介绍、备案号、联系方式、捐赠等。
|
||||
- 不限制多份:单条表单就能维护全部内容,幂等 upsert。
|
||||
|
||||
设计原则:
|
||||
- 内容字段全可空(除 id),发布前可以临时空着。
|
||||
- Markdown 字段长度无限制,存原始文本,渲染时由前端解析。
|
||||
"""
|
||||
import datetime
|
||||
from applications.extensions import db
|
||||
|
||||
|
||||
class About(db.Model):
|
||||
__tablename__ = 'site_about'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='主键')
|
||||
|
||||
# 站点名称(公开页头部)
|
||||
site_name = db.Column(db.String(120), default='', comment='站点名')
|
||||
|
||||
# 自我介绍 / 关于(Markdown 格式,前台渲染)
|
||||
content_md = db.Column(db.Text, default='', comment='关于本站正文 (Markdown)')
|
||||
|
||||
# 备案信息
|
||||
icp = db.Column(db.String(120), default='', comment='ICP 备案号')
|
||||
|
||||
# 联系信息(任选)
|
||||
contact_email = db.Column(db.String(120), default='', comment='联系邮箱')
|
||||
contact_qq = db.Column(db.String(32), default='', comment='联系 QQ')
|
||||
contact_wechat = db.Column(db.String(120), default='', comment='微信号')
|
||||
contact_telegram = db.Column(db.String(120), default='', comment='Telegram')
|
||||
contact_github = db.Column(db.String(255), default='', comment='GitHub 链接')
|
||||
|
||||
# 捐赠 / 打赏 URL(一般挂二维码图片)
|
||||
donate_url = db.Column(db.String(255), default='', comment='捐赠/打赏 URL 或二维码图片地址')
|
||||
|
||||
create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
|
||||
update_at = db.Column(
|
||||
db.DateTime,
|
||||
default=datetime.datetime.now,
|
||||
onupdate=datetime.datetime.now,
|
||||
comment='更新时间',
|
||||
)
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
return {
|
||||
'id': self.id,
|
||||
'site_name': self.site_name or '',
|
||||
'content_md': self.content_md or '',
|
||||
'icp': self.icp or '',
|
||||
'contact_email': self.contact_email or '',
|
||||
'contact_qq': self.contact_qq or '',
|
||||
'contact_wechat': self.contact_wechat or '',
|
||||
'contact_telegram': self.contact_telegram or '',
|
||||
'contact_github': self.contact_github or '',
|
||||
'donate_url': self.donate_url or '',
|
||||
'create_at': self.create_at.strftime('%Y-%m-%d %H:%M:%S') if self.create_at else '',
|
||||
'update_at': self.update_at.strftime('%Y-%m-%d %H:%M:%S') if self.update_at else '',
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
"""
|
||||
「友情链接」管理。
|
||||
|
||||
- 后台:列表 + 新增 / 编辑 / 删除 / 启用 / 禁用(与 Nav 一致接口风格)
|
||||
- 前台:公开只读
|
||||
|
||||
字段:
|
||||
- title : 友链名称
|
||||
- url : 友链 URL
|
||||
- logo : 站点头像 / favicon(可空,自动用 url 的 favicon)
|
||||
- description : 简介
|
||||
- category : 友链分组(默认「推荐友链」)
|
||||
- sort : 同分类下排序
|
||||
- enable : 1 启用,0 禁用
|
||||
- is_external: 1 新窗口打开 / 0 当前窗口
|
||||
"""
|
||||
import datetime
|
||||
from applications.extensions import db
|
||||
|
||||
|
||||
class Friend(db.Model):
|
||||
__tablename__ = 'site_friend'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='友情链接ID')
|
||||
title = db.Column(db.String(100), nullable=False, comment='名称')
|
||||
url = db.Column(db.String(255), nullable=False, comment='链接')
|
||||
logo = db.Column(db.String(255), default='', comment='Logo / favicon')
|
||||
description = db.Column(db.String(255), default='', comment='简介')
|
||||
category = db.Column(db.String(50), default='推荐友链', comment='分组', index=True)
|
||||
sort = db.Column(db.Integer, default=0, comment='排序')
|
||||
enable = db.Column(db.Integer, default=1, comment='状态(1启用,0关闭)')
|
||||
is_external = db.Column(db.Integer, default=1, comment='是否外链')
|
||||
create_by = db.Column(db.String(50), default='admin', comment='创建者')
|
||||
create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
|
||||
update_at = db.Column(
|
||||
db.DateTime,
|
||||
default=datetime.datetime.now,
|
||||
onupdate=datetime.datetime.now,
|
||||
comment='更新时间',
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'title': self.title,
|
||||
'url': self.url,
|
||||
'logo': self.logo or '',
|
||||
'description': self.description or '',
|
||||
'category': self.category or '推荐友链',
|
||||
'sort': self.sort or 0,
|
||||
'enable': self.enable,
|
||||
'is_external': self.is_external,
|
||||
'create_by': self.create_by,
|
||||
'create_at': self.create_at.strftime('%Y-%m-%d %H:%M:%S') if self.create_at else '',
|
||||
'update_at': self.update_at.strftime('%Y-%m-%d %H:%M:%S') if self.update_at else '',
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class Nav(db.Model):
|
||||
sort = db.Column(db.Integer, default=0, comment='排序')
|
||||
|
||||
# 1=启用,0=禁用(禁用后前台不再展示,后台列表仍可见)
|
||||
status = db.Column(db.Integer, default=1, comment='状态(1启用,0关闭)')
|
||||
enable = db.Column(db.Integer, default=1, comment='状态(1启用,0关闭)')
|
||||
|
||||
# 1=外链(新窗口打开),0=站内(当前窗口)
|
||||
is_external = db.Column(db.Integer, default=1, comment='是否外链')
|
||||
@@ -62,7 +62,7 @@ class Nav(db.Model):
|
||||
'description': self.description or '',
|
||||
'icon': self.icon or 'layui-icon-link',
|
||||
'sort': self.sort or 0,
|
||||
'status': self.status,
|
||||
'enable': self.enable,
|
||||
'is_external': self.is_external,
|
||||
'create_by': self.create_by,
|
||||
'create_at': self.create_at.strftime('%Y-%m-%d %H:%M:%S') if self.create_at else '',
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
"""
|
||||
导航分类表
|
||||
|
||||
Nav.category 是字符串字段,难以管理顺序/启用/图标。
|
||||
NavCategory 把"分类"提到一张独立表,允许后台做完整的 CRUD。
|
||||
|
||||
数据关系:
|
||||
- NavCategory 1 — N Nav
|
||||
- 保留 Nav.category 字符串字段为冗余存储,避免前端热路径上做 LEFT JOIN
|
||||
"""
|
||||
import datetime
|
||||
|
||||
from applications.extensions import db
|
||||
|
||||
|
||||
class NavCategory(db.Model):
|
||||
__tablename__ = 'nav_category'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='分类ID')
|
||||
|
||||
# 同名分类不能重复,方便前台 URL /site/category/<name> 用作 slug
|
||||
name = db.Column(db.String(50), nullable=False, unique=True, index=True, comment='分类名(前端分类详情 URL)')
|
||||
|
||||
# 分类图标(前端首页标题旁小图标)
|
||||
icon = db.Column(db.String(50), default='layui-icon-list', comment='layui-icon class')
|
||||
|
||||
# 分类简介(前端首页卡片标题下方描述)
|
||||
description = db.Column(db.String(255), default='', comment='分类简介')
|
||||
|
||||
# 同级别的展示顺序(前端首页自上而下)
|
||||
sort = db.Column(db.Integer, default=0, comment='排序')
|
||||
|
||||
# 1=启用,0=禁用(禁用后前台不再展示该分类,但 Nav 记录仍保留)
|
||||
enable = db.Column(db.Integer, default=1, comment='状态(1启用,0关闭)')
|
||||
|
||||
create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
|
||||
update_at = db.Column(
|
||||
db.DateTime,
|
||||
default=datetime.datetime.now,
|
||||
onupdate=datetime.datetime.now,
|
||||
comment='更新时间',
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'name': self.name,
|
||||
'icon': self.icon or 'layui-icon-list',
|
||||
'description': self.description or '',
|
||||
'sort': self.sort or 0,
|
||||
'enable': self.enable,
|
||||
'create_at': self.create_at.strftime('%Y-%m-%d %H:%M:%S') if self.create_at else '',
|
||||
'update_at': self.update_at.strftime('%Y-%m-%d %H:%M:%S') if self.update_at else '',
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
"""
|
||||
导航卡片点击埋点模型。
|
||||
|
||||
每条记录是用户点了一次某张 Nav 卡片跳出去的事件。
|
||||
- nav_id 关联 public_nav.id
|
||||
- day YYYY-MM-DD 日期
|
||||
- ip 访客 IP(用于去重 / 隐私留存期控制)
|
||||
- clicked_at 点击时间
|
||||
"""
|
||||
import datetime
|
||||
from applications.extensions import db
|
||||
|
||||
|
||||
class NavClick(db.Model):
|
||||
__tablename__ = 'site_nav_click'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='记录ID')
|
||||
nav_id = db.Column(db.Integer, nullable=False, index=True, comment='被点击的导航ID')
|
||||
day = db.Column(db.String(10), default='', index=True, comment='日期 YYYY-MM-DD')
|
||||
ip = db.Column(db.String(64), default='', comment='访客IP')
|
||||
clicked_at = db.Column(db.DateTime, default=datetime.datetime.now, index=True, comment='点击时间')
|
||||
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
「访问统计」数据模型。
|
||||
|
||||
每条记录是一次访问事件:
|
||||
- path 访问路径
|
||||
- referer 来源页(可空)
|
||||
- ua User-Agent 摘要(可空)
|
||||
- ip 访客 IP(如果能拿到)
|
||||
- day YYYY-MM-DD 日期(用于按天聚合)
|
||||
- visit_at 访问时间
|
||||
"""
|
||||
import datetime
|
||||
from applications.extensions import db
|
||||
|
||||
|
||||
class VisitLog(db.Model):
|
||||
__tablename__ = 'site_visit_log'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='记录ID')
|
||||
path = db.Column(db.String(255), default='', index=True, comment='访问路径')
|
||||
referer = db.Column(db.String(255), default='', comment='来源页')
|
||||
ua = db.Column(db.String(255), default='', comment='UA')
|
||||
ip = db.Column(db.String(64), default='', comment='访问IP')
|
||||
day = db.Column(db.String(10), default='', index=True, comment='日期 YYYY-MM-DD')
|
||||
visit_at = db.Column(db.DateTime, default=datetime.datetime.now, index=True, comment='访问时间')
|
||||
|
||||
|
||||
class PageStat(db.Model):
|
||||
"""
|
||||
路径级累计统计:每次访问做 upsert(按 path+day)。
|
||||
|
||||
字段:
|
||||
- path
|
||||
- day
|
||||
- pv 当日 / 累计 Page View
|
||||
- uv IP 去重计数(用 set 维护在内存里,但用户规模小可以按 (path, day, ip) 简单去重)
|
||||
- last_hit 最后一次访问时间
|
||||
"""
|
||||
__tablename__ = 'site_page_stat'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
path = db.Column(db.String(255), default='', index=True)
|
||||
day = db.Column(db.String(10), default='', index=True)
|
||||
pv = db.Column(db.Integer, default=0, comment='Page View')
|
||||
uv = db.Column(db.Integer, default=0, comment='独立访客数(IP 去重后)')
|
||||
uv_ip_set = db.Column(db.Text, default='', comment='独立 IP 列表 CSV')
|
||||
last_hit = db.Column(db.DateTime, default=datetime.datetime.now, comment='最近访问时间')
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
'path': self.path,
|
||||
'day': self.day,
|
||||
'pv': self.pv or 0,
|
||||
'uv': self.uv or 0,
|
||||
'last_hit': self.last_hit.strftime('%Y-%m-%d %H:%M:%S') if self.last_hit else '',
|
||||
}
|
||||
@@ -7,3 +7,5 @@ from .admin_log import LogOutSchema
|
||||
from .admin_photo import PhotoOutSchema
|
||||
from .admin_mail import MailOutSchema
|
||||
from .admin_nav import NavOutSchema, NavManageSchema
|
||||
from .admin_nav_category import NavCategorySchema
|
||||
from .admin_friend import FriendOutSchema, FriendManageSchema
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
from flask_marshmallow.sqla import SQLAlchemyAutoSchema
|
||||
|
||||
from applications.models import Friend
|
||||
|
||||
|
||||
class FriendOutSchema(SQLAlchemyAutoSchema):
|
||||
"""前台展示用:序列化 Friend 对象为 JSON"""
|
||||
class Meta:
|
||||
model = Friend
|
||||
include_fk = True
|
||||
|
||||
|
||||
class FriendManageSchema(SQLAlchemyAutoSchema):
|
||||
"""后台管理用:序列化为表格数据 / 表单回填"""
|
||||
class Meta:
|
||||
model = Friend
|
||||
include_fk = True
|
||||
@@ -0,0 +1,10 @@
|
||||
from flask_marshmallow.sqla import SQLAlchemyAutoSchema
|
||||
|
||||
from applications.models import NavCategory
|
||||
|
||||
|
||||
class NavCategorySchema(SQLAlchemyAutoSchema):
|
||||
"""导航分类序列化:用于后台 table_api 的 data 字段"""
|
||||
class Meta:
|
||||
model = NavCategory
|
||||
include_fk = True
|
||||
@@ -6,7 +6,7 @@ from applications.view.system.index import bp as index_bp
|
||||
from applications.view.system.log import bp as log_bp
|
||||
from applications.view.system.mail import bp as mail_bp
|
||||
from applications.view.system.monitor import bp as monitor_bp
|
||||
from applications.view.system.nav import bp as nav_bp
|
||||
# 4 个业务模块(nav / friend / about / stat)已迁出到 plugins/* ,下文的 register 也不再挂载
|
||||
from applications.view.system.passport import bp as passport_bp
|
||||
from applications.view.system.power import bp as power_bp
|
||||
from applications.view.system.rights import bp as right_bp
|
||||
@@ -31,6 +31,5 @@ def register_system_bps(app: Flask):
|
||||
system_bp.register_blueprint(passport_bp)
|
||||
system_bp.register_blueprint(right_bp)
|
||||
system_bp.register_blueprint(dept_bp)
|
||||
system_bp.register_blueprint(nav_bp)
|
||||
app.register_blueprint(index_bp)
|
||||
app.register_blueprint(system_bp)
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
from flask import Blueprint, render_template
|
||||
from flask_login import login_required, current_user
|
||||
from flask_login import login_required, current_user, login_fresh
|
||||
|
||||
from applications.view.public.nav import render_public_index
|
||||
|
||||
bp = Blueprint('index', __name__, url_prefix='/')
|
||||
|
||||
|
||||
# 首页
|
||||
# 首页:未登录 → 前台公开导航聚合页;已登录 → 跳到工作台
|
||||
@bp.get('/')
|
||||
@login_required
|
||||
def index():
|
||||
user = current_user
|
||||
return render_template('system/index.html', user=user)
|
||||
# 已登录用户访问根路径时,直接进后台工作台;
|
||||
# 匿名访问则直接渲染前台导航页(不重定向,地址栏保持 /)
|
||||
if current_user.is_authenticated:
|
||||
return render_template('system/index.html', user=current_user)
|
||||
return render_public_index()
|
||||
|
||||
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
"""
|
||||
后台导航管理视图(需要登录 + 权限码 system:nav:*)
|
||||
|
||||
提供 Nav 模型的 CRUD 接口,供后台管理员维护前台公开导航。
|
||||
"""
|
||||
from flask import Blueprint, render_template, request
|
||||
from flask_login import current_user
|
||||
|
||||
from applications.common.utils.http import table_api, fail_api, success_api
|
||||
from applications.common.utils.rights import authorize
|
||||
from applications.common.utils.validate import str_escape
|
||||
from applications.extensions import db
|
||||
from applications.extensions.init_limit import limiter
|
||||
from applications.models import Nav
|
||||
from applications.schemas import NavManageSchema
|
||||
|
||||
bp = Blueprint('nav', __name__, url_prefix='/nav')
|
||||
|
||||
|
||||
@bp.get('/')
|
||||
@authorize("system:nav:main")
|
||||
def main():
|
||||
"""导航管理主页"""
|
||||
return render_template('system/nav/main.html')
|
||||
|
||||
|
||||
@bp.get('/data')
|
||||
@limiter.limit("60 per minute")
|
||||
@authorize("system:nav:main")
|
||||
def data():
|
||||
"""表格数据接口"""
|
||||
keyword = str_escape(request.args.get('keyword', type=str))
|
||||
category = str_escape(request.args.get('category', type=str))
|
||||
|
||||
query = Nav.query
|
||||
if keyword:
|
||||
query = query.filter(
|
||||
db.or_(
|
||||
Nav.title.contains(keyword),
|
||||
Nav.url.contains(keyword),
|
||||
Nav.description.contains(keyword),
|
||||
)
|
||||
)
|
||||
if category:
|
||||
query = query.filter(Nav.category == category)
|
||||
|
||||
items = query.order_by(Nav.category.asc(), Nav.sort.asc(), Nav.id.asc()).all()
|
||||
data = NavManageSchema(many=True).dump(items)
|
||||
return table_api(msg="请求成功", data=data, count=len(data))
|
||||
|
||||
|
||||
@bp.get('/add')
|
||||
@authorize("system:nav:add", log=True)
|
||||
def add():
|
||||
return render_template('system/nav/add.html')
|
||||
|
||||
|
||||
@bp.post('/save')
|
||||
@authorize("system:nav:add", log=True)
|
||||
def save():
|
||||
req = request.get_json(force=True)
|
||||
try:
|
||||
nav = Nav(
|
||||
category=str_escape(req.get('category')),
|
||||
title=str_escape(req.get('title')),
|
||||
url=str_escape(req.get('url')),
|
||||
description=str_escape(req.get('description')),
|
||||
icon=str_escape(req.get('icon')) or 'layui-icon-link',
|
||||
sort=int(req.get('sort') or 0),
|
||||
status=int(req.get('status') or 1),
|
||||
is_external=int(req.get('isExternal') or 1),
|
||||
create_by=current_user.username if current_user.is_authenticated else 'admin',
|
||||
)
|
||||
db.session.add(nav)
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
return fail_api(msg=f"新增失败:{e}")
|
||||
return success_api(msg="新增成功")
|
||||
|
||||
|
||||
@bp.get('/edit')
|
||||
@authorize("system:nav:edit", log=True)
|
||||
def edit():
|
||||
nav_id = request.args.get("navId", type=int)
|
||||
nav = Nav.query.get(nav_id)
|
||||
if not nav:
|
||||
return fail_api(msg="导航不存在")
|
||||
return render_template('system/nav/edit.html', nav=nav)
|
||||
|
||||
|
||||
@bp.put('/update')
|
||||
@authorize("system:nav:edit", log=True)
|
||||
def update():
|
||||
req = request.get_json(force=True)
|
||||
nav_id = req.get('id')
|
||||
nav = Nav.query.get(nav_id)
|
||||
if not nav:
|
||||
return fail_api(msg="导航不存在")
|
||||
try:
|
||||
nav.category = str_escape(req.get('category')) or nav.category
|
||||
nav.title = str_escape(req.get('title')) or nav.title
|
||||
nav.url = str_escape(req.get('url')) or nav.url
|
||||
nav.description = str_escape(req.get('description'))
|
||||
nav.icon = str_escape(req.get('icon')) or 'layui-icon-link'
|
||||
nav.sort = int(req.get('sort') or 0)
|
||||
nav.status = int(req.get('status') or 1)
|
||||
nav.is_external = int(req.get('isExternal') or 1)
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
db.session.rollback()
|
||||
return fail_api(msg=f"更新失败:{e}")
|
||||
return success_api(msg="更新成功")
|
||||
|
||||
|
||||
@bp.delete('/remove/<int:_id>')
|
||||
@authorize("system:nav:remove", log=True)
|
||||
def remove(_id):
|
||||
nav = Nav.query.get(_id)
|
||||
if not nav:
|
||||
return fail_api(msg="导航不存在")
|
||||
db.session.delete(nav)
|
||||
db.session.commit()
|
||||
return success_api(msg="删除成功")
|
||||
|
||||
|
||||
@bp.put('/enable')
|
||||
@authorize("system:nav:edit", log=True)
|
||||
def enable():
|
||||
nav_id = request.get_json(force=True).get('navId')
|
||||
Nav.query.filter_by(id=nav_id).update({"status": 1})
|
||||
db.session.commit()
|
||||
return success_api(msg="已启用")
|
||||
|
||||
|
||||
@bp.put('/disable')
|
||||
@authorize("system:nav:edit", log=True)
|
||||
def disable():
|
||||
nav_id = request.get_json(force=True).get('navId')
|
||||
Nav.query.filter_by(id=nav_id).update({"status": 0})
|
||||
db.session.commit()
|
||||
return success_api(msg="已禁用")
|
||||
Reference in New Issue
Block a user