feat(server): 添加暖记日记管理菜单种子数据 + 图标注册
Some checks failed
Main Merge / backend (push) Has been cancelled
Main Merge / frontend (push) Has been cancelled

- 新增迁移 m20260602_000301_diary_menu_seed
- 插入'日记管理'目录菜单 (BookOutlined, sort=50)
- 子菜单: 班级管理/日记审核/主题管理/贴纸管理
- 关联 admin + teacher 角色 (menu_roles)
- 图标注册: BookOutlined, ScheduleOutlined, SmileOutlined
This commit is contained in:
iven
2026-06-02 12:24:29 +08:00
parent 78018a9a64
commit 74551d48e6
3 changed files with 219 additions and 0 deletions

View File

@@ -49,6 +49,10 @@ import {
SolutionOutlined,
SwapOutlined,
WifiOutlined,
// 暖记日记模块
BookOutlined,
ScheduleOutlined,
SmileOutlined,
} from '@ant-design/icons';
import type { ReactNode } from 'react';
@@ -99,6 +103,11 @@ export const iconRegistry: Record<string, ReactNode> = {
SolutionOutlined: <SolutionOutlined />,
SwapOutlined: <SwapOutlined />,
WifiOutlined: <WifiOutlined />,
// 暖记日记模块
BookOutlined: <BookOutlined />,
ScheduleOutlined: <ScheduleOutlined />,
SmileOutlined: <SmileOutlined />,
};
export function getIcon(name?: string): ReactNode {

View File

@@ -71,6 +71,7 @@ mod m20260531_000182_create_user_settings;
mod m20260531_000183_diary_indexes_and_fts;
mod m20260531_000184_diary_seed_data;
mod m20260601_000300_diary_role_seed;
mod m20260602_000301_diary_menu_seed;
pub struct Migrator;
@@ -148,6 +149,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260531_000183_diary_indexes_and_fts::Migration),
Box::new(m20260531_000184_diary_seed_data::Migration),
Box::new(m20260601_000300_diary_role_seed::Migration),
Box::new(m20260602_000301_diary_menu_seed::Migration),
]
}
}

View File

@@ -0,0 +1,208 @@
// 暖记菜单种子 — 日记管理侧边栏菜单(班级管理/日记审核/主题管理/贴纸管理)
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let conn = manager.get_connection();
let tid = "'00000000-0000-0000-0000-000000000000'::uuid";
// 1. 创建"日记管理"顶级目录菜单
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
format!(
r#"INSERT INTO menus (id, tenant_id, parent_id, title, path, icon, sort_order, visible, menu_type, permission, created_at, updated_at, created_by, updated_by, deleted_at, version)
VALUES (
'a0000001-0000-0000-0000-000000000001'::uuid,
{tid},
NULL,
'日记管理',
NULL,
'BookOutlined',
50,
true,
'directory',
NULL,
now(), now(), {tid}, {tid}, NULL, 1
)
ON CONFLICT (id) DO NOTHING"#,
),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
// 2. 子菜单: 班级管理
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
format!(
r#"INSERT INTO menus (id, tenant_id, parent_id, title, path, icon, sort_order, visible, menu_type, permission, created_at, updated_at, created_by, updated_by, deleted_at, version)
VALUES (
'a0000001-0000-0000-0000-000000000010'::uuid,
{tid},
'a0000001-0000-0000-0000-000000000001'::uuid,
'班级管理',
'/diary/classes',
'TeamOutlined',
1,
true,
'menu',
'diary.class.manage',
now(), now(), {tid}, {tid}, NULL, 1
)
ON CONFLICT (id) DO NOTHING"#,
),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
// 3. 子菜单: 日记审核
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
format!(
r#"INSERT INTO menus (id, tenant_id, parent_id, title, path, icon, sort_order, visible, menu_type, permission, created_at, updated_at, created_by, updated_by, deleted_at, version)
VALUES (
'a0000001-0000-0000-0000-000000000020'::uuid,
{tid},
'a0000001-0000-0000-0000-000000000001'::uuid,
'日记审核',
'/diary/journals',
'FileSearchOutlined',
2,
true,
'menu',
'diary.journal.read',
now(), now(), {tid}, {tid}, NULL, 1
)
ON CONFLICT (id) DO NOTHING"#,
),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
// 4. 子菜单: 主题管理
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
format!(
r#"INSERT INTO menus (id, tenant_id, parent_id, title, path, icon, sort_order, visible, menu_type, permission, created_at, updated_at, created_by, updated_by, deleted_at, version)
VALUES (
'a0000001-0000-0000-0000-000000000030'::uuid,
{tid},
'a0000001-0000-0000-0000-000000000001'::uuid,
'主题管理',
'/diary/topics',
'ScheduleOutlined',
3,
true,
'menu',
'diary.topic.assign',
now(), now(), {tid}, {tid}, NULL, 1
)
ON CONFLICT (id) DO NOTHING"#,
),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
// 5. 子菜单: 贴纸管理
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
format!(
r#"INSERT INTO menus (id, tenant_id, parent_id, title, path, icon, sort_order, visible, menu_type, permission, created_at, updated_at, created_by, updated_by, deleted_at, version)
VALUES (
'a0000001-0000-0000-0000-000000000040'::uuid,
{tid},
'a0000001-0000-0000-0000-000000000001'::uuid,
'贴纸管理',
'/diary/stickers',
'SmileOutlined',
4,
true,
'menu',
'diary.journal.read',
now(), now(), {tid}, {tid}, NULL, 1
)
ON CONFLICT (id) DO NOTHING"#,
),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
// 6. 将日记管理目录及其子菜单关联到 admin 角色
let menu_ids = [
"a0000001-0000-0000-0000-000000000001", // 日记管理 (directory)
"a0000001-0000-0000-0000-000000000010", // 班级管理
"a0000001-0000-0000-0000-000000000020", // 日记审核
"a0000001-0000-0000-0000-000000000030", // 主题管理
"a0000001-0000-0000-0000-000000000040", // 贴纸管理
];
for mid in &menu_ids {
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
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(), '{mid}'::uuid, r.id, r.tenant_id, now(), now(), {tid}, {tid}, 1
FROM roles r
WHERE r.code = 'admin' AND r.tenant_id = {tid} AND r.deleted_at IS NULL
ON CONFLICT DO NOTHING"#,
),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
}
// 7. 也将菜单关联到 teacher 角色
for mid in &menu_ids {
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
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(), '{mid}'::uuid, r.id, r.tenant_id, now(), now(), {tid}, {tid}, 1
FROM roles r
WHERE r.code = 'teacher' AND r.tenant_id = {tid} AND r.deleted_at IS NULL
ON CONFLICT DO NOTHING"#,
),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
}
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let conn = manager.get_connection();
// 先删除 menu_roles 引用
let menu_ids = [
"a0000001-0000-0000-0000-000000000001",
"a0000001-0000-0000-0000-000000000010",
"a0000001-0000-0000-0000-000000000020",
"a0000001-0000-0000-0000-000000000030",
"a0000001-0000-0000-0000-000000000040",
];
for mid in &menu_ids {
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
format!("DELETE FROM menu_roles WHERE menu_id = '{mid}'::uuid"),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
}
// 删除菜单 (子菜单会被 CASCADE 自动删除)
conn.execute(sea_orm::Statement::from_string(
sea_orm::DatabaseBackend::Postgres,
"DELETE FROM menus WHERE id = 'a0000001-0000-0000-0000-000000000001'::uuid".to_string(),
))
.await
.map_err(|e| DbErr::Custom(e.to_string()))?;
Ok(())
}
}