fix(health): 修复媒体库和轮播图菜单不可见 — parent_id/permission/menu_roles 三重修复

种子迁移 m20260510_000137 存在三个问题导致菜单不显示:
1. parent_id 查找用了错误条件(path='/health'),改为 title='内容运营'
2. menu INSERT 缺少 permission 字段
3. 缺少 menu_roles 关联(admin/operator)
同时新增 BannerManage.tsx 前端页面
This commit is contained in:
iven
2026-05-10 19:07:20 +08:00
parent 09725acad7
commit edb4b6557d
2 changed files with 571 additions and 10 deletions

View File

@@ -19,41 +19,45 @@ impl MigrationTrait for Migration {
// ================================================================
// Part 1: 插入"媒体库"和"轮播图管理"菜单
// ================================================================
// 运营分组: articles(40), points-rules(41), points-products(42),
// points-orders(43), offline-events(44)
// 媒体库 → 45, 轮播图管理 → 46
// 父菜单: "内容运营" (path 为空, title='内容运营', parent='健康业务')
// 媒体库 → sort 41, 轮播图管理 → sort 42
let menus: &[(&str, &str, &str, &str, i32)] = &[
let menus: &[(&str, &str, &str, &str, &str, i32)] = &[
(
"b0000003-0000-7000-8000-000000000033",
"媒体库",
"/health/media-library",
"PictureOutlined",
45,
"health.media.list",
41,
),
(
"b0000003-0000-7000-8000-000000000034",
"轮播图管理",
"/health/banners",
"SwapOutlined",
46,
"health.banners.list",
42,
),
];
for &(id, title, path, icon, sort) in menus {
for &(id, title, path, icon, perm, sort) in menus {
let sql = format!(
r#"
INSERT INTO menus (id, tenant_id, parent_id, title, path, icon, sort_order,
visible, menu_type, created_at, updated_at, created_by, updated_by, version)
visible, menu_type, permission,
created_at, updated_at, created_by, updated_by, version)
SELECT
'{id}'::uuid,
t.id,
(SELECT m.id FROM menus m WHERE m.path = '/health' AND m.tenant_id = t.id LIMIT 1),
(SELECT m.id FROM menus m
WHERE m.title = '内容运营' AND m.tenant_id = t.id AND m.deleted_at IS NULL
LIMIT 1),
'{title}',
'{path}',
'{icon}',
{sort},
true, 'page',
true, 'page', '{perm}',
NOW(), NOW(),
(SELECT u.id FROM users u WHERE u.tenant_id = t.id LIMIT 1),
(SELECT u.id FROM users u WHERE u.tenant_id = t.id LIMIT 1),
@@ -130,6 +134,28 @@ impl MigrationTrait for Migration {
)).await?;
}
// ================================================================
// Part 3.5: 将菜单关联到 admin / operator 角色
// ================================================================
for menu_path in &["/health/media-library", "/health/banners"] {
for role_code in &["admin", "operator"] {
db.execute_unprepared(&format!(
r#"
INSERT INTO menu_roles (id, menu_id, role_id, tenant_id,
created_at, updated_at, created_by, updated_by, version)
SELECT gen_random_uuid(), m.id, r.id, m.tenant_id,
NOW(), NOW(), r.id, r.id, 1
FROM menus m
JOIN roles r ON r.tenant_id = m.tenant_id AND r.code = '{role_code}' AND r.deleted_at IS NULL
WHERE m.path = '{menu_path}' AND m.deleted_at IS NULL
AND NOT EXISTS (
SELECT 1 FROM menu_roles mr WHERE mr.menu_id = m.id AND mr.role_id = r.id
)
"#
)).await?;
}
}
// ================================================================
// Part 4: 插入"首页推荐"文章分类
// ================================================================
@@ -154,6 +180,17 @@ impl MigrationTrait for Migration {
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
// 删除菜单角色绑定
db.execute_unprepared(
"DELETE FROM menu_roles
WHERE menu_id IN (
SELECT id FROM menus
WHERE path IN ('/health/media-library', '/health/banners')
)",
)
.await
.ok();
// 删除菜单
for path in &["/health/media-library", "/health/banners"] {
db.execute_unprepared(&format!("DELETE FROM menus WHERE path = '{path}'"))