refactor: 优化权限管理与登录流程,修复细节问题

1.  调整仪表盘图标从DeviceOutlined为MonitorOutlined
2.  新增403无权访问页面与路由配置
3.  完善权限存储与路由守卫逻辑
4.  修复用户信息获取与token持久化问题
5.  补充普通管理员权限初始化与补丁脚本
6.  优化后端用户服务与认证控制器逻辑
7.  调整登录表单交互与请求流程
This commit is contained in:
andyesfly committed 2026-05-28 16:25:26 +08:00
1 parent 3d7eb12103
commit 2534723842
9 files changed
+259 -50

No files matched your search

+19 -3
View File
@@ -5,6 +5,8 @@ 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";
@Controller("/api/auth")
export class AuthController {
@@ -23,6 +25,12 @@ export class AuthController {
@InjectRepository(User)
userModel!: typeof User;
@InjectRepository(UserRole)
userRoleModel!: typeof UserRole;
@InjectRepository(Role)
roleModel!: typeof Role;
@Post("/login")
async login(@Body() body: { username: string; password: string }) {
try {
@@ -102,7 +110,14 @@ export class AuthController {
const decoded = this.tokenUtil.verifyToken(token);
const userId = decoded.userId;
const user = await this.userModel.findByPk(userId);
const user = await this.userModel.findByPk(userId, {
include: [
{
model: this.userRoleModel,
include: [this.roleModel]
}
]
});
if (!user) {
return {
code: 404,
@@ -111,6 +126,7 @@ export class AuthController {
}
const permissions = await this.permissionService.getUserPermissions(userId);
const roles = (user as any).userRoles?.map((ur: any) => ur.role?.code).filter(Boolean) || [];
return {
code: 200,
@@ -120,7 +136,7 @@ export class AuthController {
username: user.username,
nickname: user.nickname || user.username,
avatar: user.avatar,
roles: [],
roles,
permissions
}
};
@@ -131,4 +147,4 @@ export class AuthController {
};
}
}
}
}