feat: RBAC
This commit is contained in:
@@ -7,27 +7,30 @@ enum PermissionType {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await prisma.sysUser.upsert({
|
||||
where: { account: 'admin' },
|
||||
update: {},
|
||||
create: {
|
||||
name: '管理员',
|
||||
account: 'admin',
|
||||
password: '$2a$10$rWb52cHK1hrWuQQg3LiOJ.crDfIqjoOIoglGM96a.Ao1DL/dQwKCu',
|
||||
passwordSalt: '$2a$10$rWb52cHK1hrWuQQg3LiOJ.',
|
||||
status: 1,
|
||||
},
|
||||
});
|
||||
const menus = [
|
||||
{ name: '用户管理', path: 'user', type: PermissionType.Menu },
|
||||
{ name: '角色管理', path: 'role', type: PermissionType.Menu },
|
||||
{ name: '菜单管理', path: 'menu', type: PermissionType.Menu },
|
||||
{ name: '系统配置', path: 'config', type: PermissionType.Menu },
|
||||
{ name: '资源管理', path: 'resource', type: PermissionType.Menu },
|
||||
];
|
||||
|
||||
for (const menu of menus) {
|
||||
// 创建菜单
|
||||
await prisma.$transaction(async (_prisma) => {
|
||||
await prisma.$transaction(async (_prisma) => {
|
||||
const user = await _prisma.sysUser.upsert({
|
||||
where: { account: 'admin' },
|
||||
update: {},
|
||||
create: {
|
||||
name: '管理员',
|
||||
account: 'admin',
|
||||
password:
|
||||
'$2a$10$rWb52cHK1hrWuQQg3LiOJ.crDfIqjoOIoglGM96a.Ao1DL/dQwKCu',
|
||||
passwordSalt: '$2a$10$rWb52cHK1hrWuQQg3LiOJ.',
|
||||
status: 1,
|
||||
gender: 0,
|
||||
},
|
||||
});
|
||||
|
||||
for (const menu of menus) {
|
||||
const { id: resourceId } = await _prisma.sysResource.create({
|
||||
data: menu,
|
||||
});
|
||||
@@ -39,8 +42,24 @@ async function main() {
|
||||
await _prisma.sysResourcePermission.create({
|
||||
data: { resourceId, permissionId },
|
||||
});
|
||||
}
|
||||
|
||||
// 创建角色并关联
|
||||
const role = await _prisma.sysRole.create({
|
||||
data: {
|
||||
name: '管理员',
|
||||
code: 'admin',
|
||||
status: 1,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await _prisma.sysUserRole.create({
|
||||
data: {
|
||||
userId: user.id,
|
||||
roleId: role.id,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user