refactor: 系统权限模块重构,迁移至PostgreSQL并对齐新设计

- 切换数据库为PostgreSQL,更新依赖与配置
- 重构权限体系,使用sys_user/sys_role/sys_menu等新实体替代旧模型
- 移除旧的用户角色/权限/系统设置相关代码与实体
- 新增字典、菜单管理模块与基础CRUD接口
- 优化鉴权逻辑,基于菜单权限标识进行接口校验
- 前端同步更新API、路由与权限控制逻辑
- 删除冗余的v-permission指令与相关代码
This commit is contained in:
andyesfly committed 2026-08-19 14:11:34 +08:00
1 parent 98c22f6afb
commit 0a8103f33d
67 files changed
+3263 -1924

No files matched your search

+19 -22
View File
@@ -4,9 +4,9 @@ import { AuthService } from "../service/auth.service";
import { TokenUtil } from "../util/token";
import { PermissionService } from "../service/permission.service";
import { InjectRepository } from "@midwayjs/sequelize";
import User from "../entity/user.entity";
import UserRole from "../entity/userRole.entity";
import Role from "../entity/role.entity";
import SysUser from "../entity/sysUser.entity";
import SysUserRole from "../entity/sysUserRole.entity";
import SysRole from "../entity/sysRole.entity";
@Controller("/api/auth")
export class AuthController {
@@ -22,14 +22,14 @@ export class AuthController {
@Inject()
ctx!: Context;
@InjectRepository(User)
userModel!: typeof User;
@InjectRepository(SysUser)
userModel!: typeof SysUser;
@InjectRepository(UserRole)
userRoleModel!: typeof UserRole;
@InjectRepository(SysUserRole)
userRoleModel!: typeof SysUserRole;
@InjectRepository(Role)
roleModel!: typeof Role;
@InjectRepository(SysRole)
roleModel!: typeof SysRole;
@Post("/login")
async login(@Body() body: { username: string; password: string }) {
@@ -110,14 +110,7 @@ export class AuthController {
const decoded = this.tokenUtil.verifyToken(token);
const userId = decoded.userId;
const user = await this.userModel.findByPk(userId, {
include: [
{
model: this.userRoleModel,
include: [this.roleModel]
}
]
});
const user = await this.userModel.findByPk(userId);
if (!user) {
return {
code: 404,
@@ -125,8 +118,13 @@ export class AuthController {
};
}
const permissions = await this.permissionService.getUserPermissions(userId);
const roles = (user as any).userRoles?.map((ur: any) => ur.role?.code).filter(Boolean) || [];
const userRoles = await this.userRoleModel.findAll({
where: { userId },
include: [this.roleModel]
});
const roles = userRoles.map(ur => ur.role?.roleCode).filter(Boolean) || [];
const menus = await this.permissionService.getUserMenus(userId);
return {
code: 200,
@@ -134,10 +132,9 @@ export class AuthController {
data: {
id: user.id,
username: user.username,
nickname: user.nickname || user.username,
avatar: user.avatar,
realName: user.realName,
roles,
permissions
menus
}
};
} catch (error: any) {