48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
const studentRole = await prisma.role.findFirst({ where: { code: 'student' } });
|
|
|
|
if (!studentRole) {
|
|
console.log('未找到学生角色');
|
|
return;
|
|
}
|
|
|
|
// 获取学生权限
|
|
const perms = await prisma.rolePermission.findMany({
|
|
where: { roleId: studentRole.id },
|
|
include: { permission: true }
|
|
});
|
|
|
|
const permCodes = perms.map(p => p.permission.code);
|
|
console.log('📋 学生权限:', permCodes.join(', '));
|
|
|
|
// 获取租户菜单
|
|
const tenantMenus = await prisma.tenantMenu.findMany({
|
|
where: { tenantId: studentRole.tenantId },
|
|
include: { menu: true }
|
|
});
|
|
|
|
// 过滤出学生能看到的菜单
|
|
const visibleMenus = tenantMenus
|
|
.filter(tm => tm.menu.permission && permCodes.includes(tm.menu.permission))
|
|
.map(tm => ({
|
|
name: tm.menu.name,
|
|
path: tm.menu.path,
|
|
permission: tm.menu.permission,
|
|
component: tm.menu.component,
|
|
}));
|
|
|
|
console.log('\n📱 学生可见菜单:');
|
|
visibleMenus.forEach(m => {
|
|
console.log(` - ${m.name}`);
|
|
console.log(` 路径: ${m.path}`);
|
|
console.log(` 权限: ${m.permission}`);
|
|
console.log(` 组件: ${m.component}`);
|
|
});
|
|
}
|
|
|
|
main().catch(console.error).finally(() => prisma.$disconnect());
|