82 lines
2.2 KiB
TypeScript
82 lines
2.2 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('🔧 添加赛事活动下的赛事列表菜单...\n');
|
|
|
|
// 查找赛事活动父菜单
|
|
const activityParent = await prisma.menu.findFirst({
|
|
where: { path: '/student-activities' }
|
|
});
|
|
|
|
if (!activityParent) {
|
|
console.log('❌ 未找到赛事活动父菜单');
|
|
return;
|
|
}
|
|
|
|
// 检查是否已存在赛事列表子菜单
|
|
const existing = await prisma.menu.findFirst({
|
|
where: { path: '/student-activities/list' }
|
|
});
|
|
|
|
if (existing) {
|
|
console.log('⏭️ 赛事列表菜单已存在');
|
|
} else {
|
|
// 创建赛事列表子菜单
|
|
const listMenu = await prisma.menu.create({
|
|
data: {
|
|
name: '赛事列表',
|
|
path: '/student-activities/list',
|
|
component: 'contests/Activities',
|
|
permission: 'contest:activity:read',
|
|
sort: 0, // 排在最前面
|
|
parentId: activityParent.id,
|
|
validState: 1,
|
|
}
|
|
});
|
|
console.log('✅ 已创建: 赛事列表');
|
|
|
|
// 分配给所有租户
|
|
const tenants = await prisma.tenant.findMany({ select: { id: true } });
|
|
for (const tenant of tenants) {
|
|
await prisma.tenantMenu.create({
|
|
data: { tenantId: tenant.id, menuId: listMenu.id }
|
|
});
|
|
}
|
|
console.log('✅ 已分配给所有租户');
|
|
}
|
|
|
|
// 更新其他子菜单的排序
|
|
await prisma.menu.updateMany({
|
|
where: { path: '/student-activities/guidance' },
|
|
data: { sort: 1 }
|
|
});
|
|
await prisma.menu.updateMany({
|
|
where: { path: '/student-activities/review' },
|
|
data: { sort: 2 }
|
|
});
|
|
await prisma.menu.updateMany({
|
|
where: { path: '/student-activities/comments' },
|
|
data: { sort: 3 }
|
|
});
|
|
|
|
// 显示最终结构
|
|
console.log('\n📋 赛事活动最终菜单结构:');
|
|
const children = await prisma.menu.findMany({
|
|
where: { parentId: activityParent.id },
|
|
orderBy: { sort: 'asc' }
|
|
});
|
|
|
|
console.log(`- ${activityParent.name} (${activityParent.path})`);
|
|
children.forEach(c => {
|
|
console.log(` - ${c.name} (${c.path})`);
|
|
});
|
|
|
|
console.log('\n✅ 完成!');
|
|
}
|
|
|
|
main()
|
|
.catch(console.error)
|
|
.finally(() => prisma.$disconnect());
|