mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 05:09:21 +08:00
feat: 超管账户切换
This commit is contained in:
+9
@@ -1,6 +1,7 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -54,6 +55,14 @@ public class AuthController {
|
||||
return ApiResponse.success(loginVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "切换账户", description = "超级管理员切换到指定用户账户,角色保持为super")
|
||||
@PostMapping("/switch/{userId}")
|
||||
public ApiResponse<LoginVO> switchAccount(
|
||||
@Parameter(description = "目标用户ID") @PathVariable Long userId) {
|
||||
LoginVO loginVO = userService.switchAccount(userId);
|
||||
return ApiResponse.success(loginVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户权限码", description = "获取当前登录用户的权限码列表")
|
||||
@GetMapping("/codes")
|
||||
public ApiResponse<List<String>> getAccessCodes() {
|
||||
|
||||
+13
-2
@@ -5,9 +5,12 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UserFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserMenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserMenuService;
|
||||
@@ -67,8 +70,16 @@ public class UserController {
|
||||
|
||||
@Operation(summary = "获取用户菜单", description = "根据用户角色获取对应的菜单,用于前端动态路由")
|
||||
@GetMapping("/menu")
|
||||
public ApiResponse<List<UserMenuVO>> getUserRoutes() {
|
||||
List<UserMenuVO> userMenuVOS = userMenuService.getUserRoutes();
|
||||
public ApiResponse<List<UserMenuVO>> getUserMenus() {
|
||||
List<UserMenuVO> userMenuVOS = userMenuService.getUserMenus();
|
||||
return ApiResponse.success(userMenuVOS);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询用户列表", description = "分页查询用户列表,支持多种过滤条件")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageResultVO<UserVO>> getUserPage(
|
||||
@Valid @RequestBody PageQueryDTO<UserFilterDTO> pageQuery) {
|
||||
PageResultVO<UserVO> pageResult = userService.getUserPage(pageQuery);
|
||||
return ApiResponse.success(pageResult);
|
||||
}
|
||||
}
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.sys.model.dto.user;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 用户分页查询过滤DTO
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "用户分页查询过滤DTO")
|
||||
public class UserFilterDTO {
|
||||
|
||||
/**
|
||||
* 用户名称(模糊查询)
|
||||
*/
|
||||
@Schema(description = "用户名称(模糊查询)", example = "张")
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 登录账号(模糊查询)
|
||||
*/
|
||||
@Schema(description = "登录账号(模糊查询)", example = "admin")
|
||||
private String loginCode;
|
||||
|
||||
/**
|
||||
* 手机号码(精确查询)
|
||||
*/
|
||||
@Schema(description = "手机号码(精确查询)", example = "13800138000")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 用户角色
|
||||
*/
|
||||
@Schema(description = "用户角色", example = "user", allowableValues = { "user", "admin", "super" })
|
||||
private String role;
|
||||
|
||||
/**
|
||||
* 公司ID
|
||||
*/
|
||||
@Schema(description = "公司ID", example = "1")
|
||||
private Long companyId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
@Schema(description = "部门ID", example = "1")
|
||||
private Long departmentId;
|
||||
|
||||
/**
|
||||
* 岗位ID
|
||||
*/
|
||||
@Schema(description = "岗位ID", example = "1")
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 状态查询
|
||||
*/
|
||||
@Schema(description = "用户状态", example = "0", allowableValues = { "0", "1", "2", "3" })
|
||||
private Integer status;
|
||||
}
|
||||
+1
-1
@@ -15,5 +15,5 @@ public interface UserMenuService {
|
||||
*
|
||||
* @return 路由列表
|
||||
*/
|
||||
List<UserMenuVO> getUserRoutes();
|
||||
List<UserMenuVO> getUserMenus();
|
||||
}
|
||||
|
||||
+19
@@ -2,11 +2,14 @@ package top.xyquan.ecomdmbbackend.modules.sys.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RefreshTokenDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UserFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
@@ -77,4 +80,20 @@ public interface UserService extends IService<UserPO> {
|
||||
* @return 新的登录响应
|
||||
*/
|
||||
LoginVO refreshToken(RefreshTokenDTO refreshTokenDTO);
|
||||
|
||||
/**
|
||||
* 切换账户
|
||||
*
|
||||
* @param userId 目标用户ID
|
||||
* @return 登录响应
|
||||
*/
|
||||
LoginVO switchAccount(Long userId);
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
*
|
||||
* @param pageQuery 分页查询条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageResultVO<UserVO> getUserPage(PageQueryDTO<UserFilterDTO> pageQuery);
|
||||
}
|
||||
|
||||
+28
-9
@@ -3,11 +3,13 @@ package top.xyquan.ecomdmbbackend.modules.sys.service.impl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.CompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.org.service.PositionCompanyMenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.MenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserMenuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.MenuService;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserMenuService;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.service.UserService;
|
||||
import top.xyquan.ecomdmbbackend.utils.SecurityUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,24 +25,41 @@ public class UserMenuServiceImpl implements UserMenuService {
|
||||
private final MenuService menuService;
|
||||
private final CompanyMenuService companyMenuService;
|
||||
private final PositionCompanyMenuService positionCompanyMenuService;
|
||||
private final CurrentUserContext currentUserContext;
|
||||
private final UserService userService;
|
||||
|
||||
public UserMenuServiceImpl(MenuService menuService,
|
||||
CompanyMenuService companyMenuService,
|
||||
PositionCompanyMenuService positionCompanyMenuService,
|
||||
CurrentUserContext currentUserContext) {
|
||||
UserService userService) {
|
||||
this.menuService = menuService;
|
||||
this.companyMenuService = companyMenuService;
|
||||
this.positionCompanyMenuService = positionCompanyMenuService;
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserMenuVO> getUserRoutes() {
|
||||
// 获取当前用户信息
|
||||
String userRole = currentUserContext.getCurrentUserRole();
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long positionId = currentUserContext.getCurrentUserPositionId();
|
||||
public List<UserMenuVO> getUserMenus() {
|
||||
// 从Security上下文获取用户ID
|
||||
Long userId = SecurityUtils.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new RuntimeException("用户未登录");
|
||||
}
|
||||
|
||||
// 从数据库查询用户信息
|
||||
UserPO user = userService.getById(userId);
|
||||
if (user == null) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
|
||||
// 检查用户状态
|
||||
if (user.getStatus() != 0) {
|
||||
throw new RuntimeException("用户状态异常");
|
||||
}
|
||||
|
||||
// 获取用户角色和其他信息
|
||||
String userRole = user.getRole();
|
||||
Long companyId = user.getCompanyId();
|
||||
Long positionId = user.getPositionId();
|
||||
|
||||
List<MenuVO> menus;
|
||||
|
||||
|
||||
+114
-8
@@ -8,11 +8,14 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.mapper.UserMapper;
|
||||
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
|
||||
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.ChangePasswordDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.LoginDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RefreshTokenDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.RegisterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UpdateUserInfoDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.dto.user.UserFilterDTO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.po.UserPO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.LoginVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.model.vo.UserVO;
|
||||
@@ -26,6 +29,8 @@ import top.xyquan.ecomdmbbackend.utils.RefreshTokenPayload;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 系统用户服务实现类
|
||||
@@ -263,14 +268,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
throw new BusinessException("刷新令牌已过期");
|
||||
}
|
||||
|
||||
// 从刷新令牌中获取用户ID
|
||||
String userId = jwtUtils.getUserIdFromToken(refreshTokenDTO.getRefreshToken());
|
||||
if (userId == null) {
|
||||
// 从刷新令牌中获取负载信息
|
||||
RefreshTokenPayload refreshPayload = jwtUtils.getRefreshPayloadFromToken(refreshTokenDTO.getRefreshToken());
|
||||
if (refreshPayload.getUserId() == null) {
|
||||
throw new BusinessException("刷新令牌格式错误");
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
UserPO user = this.getById(Long.valueOf(userId));
|
||||
UserPO user = this.getById(Long.valueOf(refreshPayload.getUserId()));
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
@@ -280,27 +285,128 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements
|
||||
throw new BusinessException("用户状态异常,无法刷新令牌");
|
||||
}
|
||||
|
||||
// 生成新的登录响应
|
||||
return generateLoginResponse(user);
|
||||
// 生成新的登录响应,继承刷新token中的角色
|
||||
return generateLoginResponseWithRole(user, refreshPayload.getRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoginVO switchAccount(Long userId) {
|
||||
// 查询目标用户信息
|
||||
UserPO targetUser = this.getById(userId);
|
||||
if (targetUser == null) {
|
||||
throw new BusinessException("目标用户不存在");
|
||||
}
|
||||
|
||||
// 检查目标用户状态
|
||||
if (targetUser.getStatus() != 0) {
|
||||
throw new BusinessException("目标用户状态异常,无法切换");
|
||||
}
|
||||
|
||||
// 生成登录响应,角色保持为super
|
||||
return generateLoginResponseWithRole(targetUser, "super");
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResultVO<UserVO> getUserPage(PageQueryDTO<UserFilterDTO> pageQuery) {
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<UserPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
UserFilterDTO filter = pageQuery.getFilters();
|
||||
if (filter != null) {
|
||||
// 用户名称模糊查询
|
||||
if (StringUtils.hasText(filter.getRealName())) {
|
||||
queryWrapper.like(UserPO::getRealName, filter.getRealName());
|
||||
}
|
||||
|
||||
// 登录账号模糊查询
|
||||
if (StringUtils.hasText(filter.getLoginCode())) {
|
||||
queryWrapper.like(UserPO::getLoginCode, filter.getLoginCode());
|
||||
}
|
||||
|
||||
// 手机号码精确查询
|
||||
if (StringUtils.hasText(filter.getPhone())) {
|
||||
queryWrapper.eq(UserPO::getPhone, filter.getPhone());
|
||||
}
|
||||
|
||||
// 用户角色查询
|
||||
if (StringUtils.hasText(filter.getRole())) {
|
||||
queryWrapper.eq(UserPO::getRole, filter.getRole());
|
||||
}
|
||||
|
||||
// 公司ID查询
|
||||
if (filter.getCompanyId() != null) {
|
||||
queryWrapper.eq(UserPO::getCompanyId, filter.getCompanyId());
|
||||
}
|
||||
|
||||
// 部门ID查询
|
||||
if (filter.getDepartmentId() != null) {
|
||||
queryWrapper.eq(UserPO::getDepartmentId, filter.getDepartmentId());
|
||||
}
|
||||
|
||||
// 岗位ID查询
|
||||
if (filter.getPositionId() != null) {
|
||||
queryWrapper.eq(UserPO::getPositionId, filter.getPositionId());
|
||||
}
|
||||
|
||||
// 状态查询
|
||||
if (filter.getStatus() != null) {
|
||||
queryWrapper.eq(UserPO::getStatus, filter.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
// 按创建时间倒序排列
|
||||
queryWrapper.orderByDesc(UserPO::getCreateTime);
|
||||
|
||||
// 执行分页查询
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<UserPO> page =
|
||||
new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(
|
||||
pageQuery.getPage(), pageQuery.getPageSize());
|
||||
|
||||
com.baomidou.mybatisplus.extension.plugins.pagination.Page<UserPO> result = this.page(page, queryWrapper);
|
||||
|
||||
// 转换为VO
|
||||
List<UserVO> userVOList = result.getRecords().stream()
|
||||
.map(this::convertToUserVO)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建分页结果
|
||||
return PageResultVO.create(userVOList, result.getTotal(), pageQuery.getPage(), pageQuery.getPageSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为UserVO
|
||||
*/
|
||||
private UserVO convertToUserVO(UserPO user) {
|
||||
UserVO userVO = new UserVO();
|
||||
BeanUtils.copyProperties(user, userVO);
|
||||
return userVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成登录响应
|
||||
*/
|
||||
private LoginVO generateLoginResponse(UserPO user) {
|
||||
return generateLoginResponseWithRole(user, user.getRole());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成登录响应(指定角色)
|
||||
*/
|
||||
private LoginVO generateLoginResponseWithRole(UserPO user, String role) {
|
||||
LoginVO loginVO = new LoginVO();
|
||||
|
||||
// 生成访问令牌负载信息(包含完整用户信息)
|
||||
AccessTokenPayload accessPayload = AccessTokenPayload.builder()
|
||||
.userId(user.getId().toString())
|
||||
.companyId(user.getCompanyId())
|
||||
.role(user.getRole())
|
||||
.role(role != null ? role : user.getRole())
|
||||
.positionId(user.getPositionId())
|
||||
.build();
|
||||
|
||||
// 生成刷新令牌负载信息(只包含用户ID)
|
||||
// 生成刷新令牌负载信息(包含用户ID和角色)
|
||||
RefreshTokenPayload refreshPayload = RefreshTokenPayload.builder()
|
||||
.userId(user.getId().toString())
|
||||
.role(role != null ? role : user.getRole())
|
||||
.build();
|
||||
|
||||
// 生成访问令牌和刷新令牌
|
||||
|
||||
@@ -72,6 +72,7 @@ public class JwtUtils {
|
||||
|
||||
return Jwts.builder()
|
||||
.setSubject(payload.getUserId())
|
||||
.claim("role", payload.getRole())
|
||||
.claim("tokenType", payload.getTokenType())
|
||||
.setIssuedAt(now)
|
||||
.setExpiration(expiryDate)
|
||||
@@ -111,6 +112,27 @@ public class JwtUtils {
|
||||
return generateToken(payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从刷新令牌中获取负载信息
|
||||
*
|
||||
* @param token 刷新令牌
|
||||
* @return 刷新令牌负载信息
|
||||
*/
|
||||
public RefreshTokenPayload getRefreshPayloadFromToken(String token) {
|
||||
initKey();
|
||||
Claims claims = Jwts.parserBuilder()
|
||||
.setSigningKey(key)
|
||||
.build()
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
|
||||
return RefreshTokenPayload.builder()
|
||||
.userId(claims.getSubject())
|
||||
.role(getStringFromClaims(claims, "role"))
|
||||
.tokenType(getStringFromClaims(claims, "tokenType"))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 从JWT令牌中获取完整的负载信息
|
||||
*
|
||||
|
||||
+5
@@ -20,6 +20,11 @@ public class RefreshTokenPayload {
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户角色
|
||||
*/
|
||||
private String role;
|
||||
|
||||
/**
|
||||
* 令牌类型
|
||||
*/
|
||||
|
||||
@@ -100,3 +100,10 @@ export async function logoutApi() {
|
||||
export async function getAccessCodesApi() {
|
||||
return requestClient.get<string[]>('/auth/codes');
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换账户(超级管理员功能)
|
||||
*/
|
||||
export async function switchAccountApi(userId: number) {
|
||||
return requestClient.post<AuthApi.LoginResult>(`/auth/switch/${userId}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { UserDTO, UserVO } from './types';
|
||||
|
||||
/**
|
||||
* 用户管理API
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
export async function getUserInfoApi() {
|
||||
return requestClient.get<UserVO.UserInfoVO>('/user/info');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新用户信息
|
||||
*/
|
||||
export async function updateUserInfoApi(data: UserDTO.UpdateUserInfoDTO) {
|
||||
return requestClient.put<UserVO.UserInfoVO>('/user/info', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
export async function changePasswordApi(data: UserDTO.ChangePasswordDTO) {
|
||||
return requestClient.post<void>('/user/change-password', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传用户头像
|
||||
*/
|
||||
export async function uploadAvatarApi(file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return requestClient.post<UserVO.UserInfoVO>('/user/upload-avatar', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户菜单
|
||||
*/
|
||||
export async function getUserMenuApi() {
|
||||
return requestClient.get<UserVO.UserMenuVO[]>('/user/menu');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
*/
|
||||
export async function getUserPageApi(params: PageQueryDTO<UserDTO.UserFilterDTO>) {
|
||||
return requestClient.post<PageResultVO<UserVO.UserInfoVO>>('/user/page', params);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 用户管理模块API导出
|
||||
*/
|
||||
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* 用户管理模块类型定义导出
|
||||
*/
|
||||
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 用户管理模块DTO类型定义
|
||||
*/
|
||||
|
||||
export namespace UserDTO {
|
||||
/** 更新用户信息参数 */
|
||||
export interface UpdateUserInfoDTO {
|
||||
/** 用户名称 */
|
||||
realName?: string;
|
||||
/** 头像图片ID */
|
||||
avatarImageId?: number;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
/** 修改密码参数 */
|
||||
export interface ChangePasswordDTO {
|
||||
/** 旧密码 */
|
||||
oldPassword: string;
|
||||
/** 新密码 */
|
||||
newPassword: string;
|
||||
}
|
||||
|
||||
/** 用户过滤条件 */
|
||||
export interface UserFilterDTO {
|
||||
/** 用户名称(模糊查询) */
|
||||
realName?: string;
|
||||
/** 登录账号(模糊查询) */
|
||||
loginCode?: string;
|
||||
/** 手机号码(精确查询) */
|
||||
phone?: string;
|
||||
/** 用户角色 */
|
||||
role?: string;
|
||||
/** 公司ID */
|
||||
companyId?: number;
|
||||
/** 部门ID */
|
||||
departmentId?: number;
|
||||
/** 岗位ID */
|
||||
positionId?: number;
|
||||
/** 状态查询 */
|
||||
status?: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 用户管理模块VO类型定义
|
||||
*/
|
||||
|
||||
export namespace UserVO {
|
||||
/** 用户信息 */
|
||||
export interface UserInfoVO {
|
||||
/** 用户编号 */
|
||||
id: number;
|
||||
/** 公司id */
|
||||
companyId?: number;
|
||||
/** 部门id */
|
||||
departmentId?: number;
|
||||
/** 岗位id */
|
||||
positionId?: number;
|
||||
/** 登录账号 */
|
||||
loginCode: string;
|
||||
/** 手机号码 */
|
||||
phone?: string;
|
||||
/** 用户名称 */
|
||||
realName: string;
|
||||
/** 头像路径 */
|
||||
avatar?: string;
|
||||
/** 关联角色(user-普通账户 company-公司账户 super-超管账户) */
|
||||
role: string;
|
||||
/** 密码安全级别(0-初始 1-很弱 2-弱 3-安全 4-很安全) */
|
||||
pwdSecurityLevel?: number;
|
||||
/** 密码最后更新时间 */
|
||||
pwdUpdateTime?: string;
|
||||
/** 最后登录ip */
|
||||
lastLoginIp?: string;
|
||||
/** 最后登录时间 */
|
||||
lastLoginDate?: string;
|
||||
/** 冻结时间 */
|
||||
freezeDate?: string;
|
||||
/** 冻结原因 */
|
||||
freezeCause?: string;
|
||||
/** 状态(0-正常 1-删除 2-停用 3-冻结) */
|
||||
status: number;
|
||||
/** 备注信息 */
|
||||
remark?: string;
|
||||
/** 创建时间 */
|
||||
createTime: string;
|
||||
/** 更新时间 */
|
||||
updateTime: string;
|
||||
}
|
||||
|
||||
/** 用户菜单信息 */
|
||||
export interface UserMenuVO {
|
||||
/** 路由名称 (必填,用于 Vue Router 的 name 属性) */
|
||||
name: string;
|
||||
/** 路由路径 */
|
||||
path: string;
|
||||
/** 页面组件路径 (字符串类型,指向组件文件路径) */
|
||||
component: string;
|
||||
/** 重定向地址 */
|
||||
redirect?: string;
|
||||
/** 路由元信息 */
|
||||
meta: RouteMeta;
|
||||
/** 子路由列表 (扁平化处理,不嵌套) */
|
||||
children?: UserMenuVO[];
|
||||
}
|
||||
|
||||
/** 路由元信息 */
|
||||
export interface RouteMeta {
|
||||
/** 路由ID */
|
||||
id: number;
|
||||
/** 父路由ID */
|
||||
parentId?: number;
|
||||
/** 路由标题 */
|
||||
title: string;
|
||||
/** 路由图标 */
|
||||
icon?: string;
|
||||
/** 顺序 */
|
||||
order?: number;
|
||||
/** 路由类型 (catalog-目录,menu-菜单,button-按钮,embedded-内联,link-外链) */
|
||||
type: string;
|
||||
/** 是否显示在菜单中 (0-否 1-是) */
|
||||
visible?: number;
|
||||
/** 状态 (0-禁用 1-启用) */
|
||||
status?: number;
|
||||
/** 是否缓存 */
|
||||
keepAlive?: boolean;
|
||||
/** 是否超级菜单 (0-否 1-是) */
|
||||
superMenu?: number;
|
||||
/** 权限码列表 */
|
||||
access?: string[];
|
||||
/** 是否隐藏菜单 */
|
||||
hideInMenu?: boolean;
|
||||
/** 是否隐藏面包屑 */
|
||||
hideInBreadcrumb?: boolean;
|
||||
/** 是否隐藏标签页 */
|
||||
hideInTabs?: boolean;
|
||||
/** 是否固定标签页 */
|
||||
affixTab?: boolean;
|
||||
/** 是否在菜单中显示子菜单 */
|
||||
showChildrenInMenu?: boolean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { Form, Select, Card, Avatar, message, Spin } from 'ant-design-vue'
|
||||
import { useVbenModal } from '@vben/common-ui'
|
||||
import { useAccessStore } from '@vben/stores'
|
||||
import { switchAccountApi } from '#/api/core/auth'
|
||||
import { getCompanyPageApi } from '#/api/organization/company'
|
||||
import { getUserPageApi } from '#/api/system/user'
|
||||
import type { CompanyVO } from '#/api/organization/company/types'
|
||||
import type { UserVO } from '#/api/system/user/types'
|
||||
import type { PageQueryDTO } from '#/types/common'
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref()
|
||||
const formData = ref({
|
||||
companyId: undefined as number | undefined,
|
||||
userId: undefined as number | undefined,
|
||||
})
|
||||
|
||||
// 公司相关数据
|
||||
const companyList = ref<CompanyVO.CompanyInfoVO[]>([])
|
||||
const companyLoading = ref(false)
|
||||
const companySearchValue = ref('')
|
||||
const companyPage = ref(1)
|
||||
const companyPageSize = ref(20)
|
||||
const companyHasMore = ref(true)
|
||||
|
||||
// 用户相关数据
|
||||
const userList = ref<UserVO.UserInfoVO[]>([])
|
||||
const userLoading = ref(false)
|
||||
const userSearchValue = ref('')
|
||||
const userPage = ref(1)
|
||||
const userPageSize = ref(20)
|
||||
const userHasMore = ref(true)
|
||||
|
||||
// 选中的用户信息
|
||||
const selectedUser = ref<UserVO.UserInfoVO | null>(null)
|
||||
|
||||
// 公司选项
|
||||
const companyOptions = computed(() =>
|
||||
companyList.value.map(company => ({
|
||||
label: company.name,
|
||||
value: company.id,
|
||||
company
|
||||
}))
|
||||
)
|
||||
|
||||
// 用户选项
|
||||
const userOptions = computed(() =>
|
||||
userList.value.map(user => ({
|
||||
label: `${user.realName} (${user.loginCode})`,
|
||||
value: user.id,
|
||||
user
|
||||
}))
|
||||
)
|
||||
|
||||
// 监听公司选择变化
|
||||
watch(() => formData.value.companyId, (newCompanyId) => {
|
||||
if (newCompanyId) {
|
||||
// 重置用户数据
|
||||
formData.value.userId = undefined
|
||||
userList.value = []
|
||||
userPage.value = 1
|
||||
userHasMore.value = true
|
||||
selectedUser.value = null
|
||||
// 加载该公司的用户
|
||||
loadUsers()
|
||||
}
|
||||
})
|
||||
|
||||
// 监听用户选择变化
|
||||
watch(() => formData.value.userId, (newUserId) => {
|
||||
if (newUserId) {
|
||||
const user = userList.value.find(u => u.id === newUserId)
|
||||
selectedUser.value = user || null
|
||||
} else {
|
||||
selectedUser.value = null
|
||||
}
|
||||
})
|
||||
|
||||
// 加载公司列表
|
||||
const loadCompanies = async (reset = false) => {
|
||||
if (companyLoading.value) return
|
||||
|
||||
try {
|
||||
companyLoading.value = true
|
||||
|
||||
if (reset) {
|
||||
companyList.value = []
|
||||
companyPage.value = 1
|
||||
companyHasMore.value = true
|
||||
}
|
||||
|
||||
const params: PageQueryDTO<{ name?: string }> = {
|
||||
page: companyPage.value,
|
||||
pageSize: companyPageSize.value,
|
||||
filters: {
|
||||
name: companySearchValue.value || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
const result = await getCompanyPageApi(params)
|
||||
|
||||
if (reset) {
|
||||
companyList.value = result.records
|
||||
} else {
|
||||
companyList.value.push(...result.records)
|
||||
}
|
||||
|
||||
companyHasMore.value = result.records.length === companyPageSize.value
|
||||
companyPage.value++
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载公司列表失败:', error)
|
||||
message.error('加载公司列表失败')
|
||||
} finally {
|
||||
companyLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 加载用户列表
|
||||
const loadUsers = async (reset = false) => {
|
||||
if (userLoading.value || !formData.value.companyId) return
|
||||
|
||||
try {
|
||||
userLoading.value = true
|
||||
|
||||
if (reset) {
|
||||
userList.value = []
|
||||
userPage.value = 1
|
||||
userHasMore.value = true
|
||||
}
|
||||
|
||||
const params: PageQueryDTO<{ realName?: string; loginCode?: string; companyId?: number }> = {
|
||||
page: userPage.value,
|
||||
pageSize: userPageSize.value,
|
||||
filters: {
|
||||
realName: userSearchValue.value || undefined,
|
||||
loginCode: userSearchValue.value || undefined,
|
||||
companyId: formData.value.companyId,
|
||||
}
|
||||
}
|
||||
|
||||
const result = await getUserPageApi(params)
|
||||
|
||||
if (reset) {
|
||||
userList.value = result.records
|
||||
} else {
|
||||
userList.value.push(...result.records)
|
||||
}
|
||||
|
||||
userHasMore.value = result.records.length === userPageSize.value
|
||||
userPage.value++
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载用户列表失败:', error)
|
||||
message.error('加载用户列表失败')
|
||||
} finally {
|
||||
userLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 公司搜索
|
||||
const handleCompanySearch = (value: string) => {
|
||||
companySearchValue.value = value
|
||||
loadCompanies(true)
|
||||
}
|
||||
|
||||
// 用户搜索
|
||||
const handleUserSearch = (value: string) => {
|
||||
userSearchValue.value = value
|
||||
loadUsers(true)
|
||||
}
|
||||
|
||||
// 公司下拉框滚动加载更多
|
||||
const handleCompanyScroll = (e: any) => {
|
||||
const { target } = e
|
||||
if (target.scrollTop + target.offsetHeight === target.scrollHeight && companyHasMore.value) {
|
||||
loadCompanies()
|
||||
}
|
||||
}
|
||||
|
||||
// 用户下拉框滚动加载更多
|
||||
const handleUserScroll = (e: any) => {
|
||||
const { target } = e
|
||||
if (target.scrollTop + target.offsetHeight === target.scrollHeight && userHasMore.value) {
|
||||
loadUsers()
|
||||
}
|
||||
}
|
||||
|
||||
// 切换账户
|
||||
const handleSwitchAccount = async () => {
|
||||
console.log('🔄 切换账户函数被调用', { userId: formData.value.userId })
|
||||
|
||||
if (!formData.value.userId) {
|
||||
message.warning('请选择要切换的用户')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
modalApi.setState({ loading: true })
|
||||
console.log('📡 开始调用切换账户接口...')
|
||||
|
||||
const result = await switchAccountApi(formData.value.userId)
|
||||
console.log('✅ 切换账户接口调用成功', result)
|
||||
|
||||
// 设置新的token
|
||||
const accessStore = useAccessStore()
|
||||
accessStore.setTokens(
|
||||
result.accessToken,
|
||||
result.refreshToken,
|
||||
result.accessTokenExpiresAt,
|
||||
result.refreshTokenExpiresAt
|
||||
)
|
||||
|
||||
// 重置权限检查状态,让路由守卫重新生成菜单和路由
|
||||
accessStore.setIsAccessChecked(false)
|
||||
|
||||
message.success('切换账户成功')
|
||||
modalApi.close()
|
||||
|
||||
// 刷新页面
|
||||
window.location.reload()
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('切换账户失败:', error)
|
||||
message.error(error?.message || '切换账户失败')
|
||||
} finally {
|
||||
modalApi.setState({ loading: false })
|
||||
}
|
||||
}
|
||||
|
||||
// 创建模态框
|
||||
const [ModalComponent, modalApi] = useVbenModal({
|
||||
onCancel() {
|
||||
console.log('❌ 模态框取消按钮被点击')
|
||||
modalApi.close()
|
||||
},
|
||||
onConfirm: async () => {
|
||||
console.log('🎯 模态框确认按钮被点击')
|
||||
await handleSwitchAccount()
|
||||
},
|
||||
})
|
||||
|
||||
// 打开模态框
|
||||
function openModal() {
|
||||
modalApi.open()
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
companyId: undefined,
|
||||
userId: undefined,
|
||||
}
|
||||
selectedUser.value = null
|
||||
// 加载公司列表
|
||||
loadCompanies(true)
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function closeModal() {
|
||||
modalApi.close()
|
||||
}
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open: openModal,
|
||||
close: closeModal,
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<ModalComponent
|
||||
title="切换账户"
|
||||
width="800px"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
layout="vertical"
|
||||
class="mt-4"
|
||||
>
|
||||
<Form.Item label="选择公司" required>
|
||||
<Select
|
||||
v-model:value="formData.companyId"
|
||||
placeholder="请选择公司"
|
||||
show-search
|
||||
:filter-option="false"
|
||||
:loading="companyLoading"
|
||||
@search="handleCompanySearch"
|
||||
@popup-scroll="handleCompanyScroll"
|
||||
>
|
||||
<template #notFoundContent>
|
||||
<div v-if="companyLoading" class="text-center py-4">
|
||||
<Spin size="small" />
|
||||
<div class="mt-2">加载中...</div>
|
||||
</div>
|
||||
<div v-else class="text-center py-4 text-gray-400">
|
||||
暂无数据
|
||||
</div>
|
||||
</template>
|
||||
<Select.Option
|
||||
v-for="option in companyOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="选择用户" required>
|
||||
<Select
|
||||
v-model:value="formData.userId"
|
||||
placeholder="请选择用户"
|
||||
show-search
|
||||
:filter-option="false"
|
||||
:loading="userLoading"
|
||||
:disabled="!formData.companyId"
|
||||
@search="handleUserSearch"
|
||||
@popup-scroll="handleUserScroll"
|
||||
>
|
||||
<template #notFoundContent>
|
||||
<div v-if="userLoading" class="text-center py-4">
|
||||
<Spin size="small" />
|
||||
<div class="mt-2">加载中...</div>
|
||||
</div>
|
||||
<div v-else-if="!formData.companyId" class="text-center py-4 text-gray-400">
|
||||
请先选择公司
|
||||
</div>
|
||||
<div v-else class="text-center py-4 text-gray-400">
|
||||
暂无数据
|
||||
</div>
|
||||
</template>
|
||||
<Select.Option
|
||||
v-for="option in userOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
|
||||
<!-- 用户信息展示 -->
|
||||
<Card v-if="selectedUser" title="用户信息" class="mt-4">
|
||||
<div class="flex items-center space-x-4">
|
||||
<Avatar :src="selectedUser.avatar" size="large">
|
||||
{{ selectedUser.realName?.charAt(0) }}
|
||||
</Avatar>
|
||||
<div class="flex-1">
|
||||
<div class="font-medium text-lg">{{ selectedUser.realName }}</div>
|
||||
<div class="text-gray-500">登录账号: {{ selectedUser.loginCode }}</div>
|
||||
<div class="text-gray-500">手机号码: {{ selectedUser.phone || '-' }}</div>
|
||||
<div class="text-gray-500">角色: {{ selectedUser.role }}</div>
|
||||
<div class="text-gray-500">状态: {{ selectedUser.status === 1 ? '正常' : '禁用' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</ModalComponent>
|
||||
</template>
|
||||
@@ -20,6 +20,7 @@ import { openWindow } from '@vben/utils';
|
||||
import { $t } from '#/locales';
|
||||
import { useAuthStore } from '#/store';
|
||||
import LoginForm from '#/views/_core/authentication/login.vue';
|
||||
import SwitchAccountModal from '#/components/SwitchAccountModal.vue';
|
||||
|
||||
const notifications = ref<NotificationItem[]>([
|
||||
{
|
||||
@@ -60,35 +61,55 @@ const showDot = computed(() =>
|
||||
notifications.value.some((item) => !item.isRead),
|
||||
);
|
||||
|
||||
const menus = computed(() => [
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_DOC_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
// 切换账户模态框引用
|
||||
const switchAccountModalRef = ref();
|
||||
|
||||
const menus = computed(() => {
|
||||
const menuItems = [];
|
||||
|
||||
// 只有超级管理员才显示切换账户功能
|
||||
if (accessStore.userRole === 'super') {
|
||||
menuItems.push({
|
||||
handler: () => {
|
||||
switchAccountModalRef.value?.open();
|
||||
},
|
||||
icon: MdiGithub, // 临时使用现有图标
|
||||
text: '切换账户',
|
||||
});
|
||||
}
|
||||
|
||||
menuItems.push(
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_DOC_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: BookOpenText,
|
||||
text: $t('ui.widgets.document'),
|
||||
},
|
||||
icon: BookOpenText,
|
||||
text: $t('ui.widgets.document'),
|
||||
},
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_GITHUB_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(VBEN_GITHUB_URL, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: MdiGithub,
|
||||
text: 'GitHub',
|
||||
},
|
||||
icon: MdiGithub,
|
||||
text: 'GitHub',
|
||||
},
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(`${VBEN_GITHUB_URL}/issues`, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: CircleHelp,
|
||||
text: $t('ui.widgets.qa'),
|
||||
},
|
||||
]);
|
||||
{
|
||||
handler: () => {
|
||||
openWindow(`${VBEN_GITHUB_URL}/issues`, {
|
||||
target: '_blank',
|
||||
});
|
||||
},
|
||||
icon: CircleHelp,
|
||||
text: $t('ui.widgets.qa'),
|
||||
}
|
||||
);
|
||||
|
||||
return menuItems;
|
||||
});
|
||||
|
||||
const avatar = computed(() => {
|
||||
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
|
||||
@@ -154,4 +175,7 @@ watch(
|
||||
<LockScreen :avatar @to-login="handleLogout" />
|
||||
</template>
|
||||
</BasicLayout>
|
||||
|
||||
<!-- 切换账户模态框 -->
|
||||
<SwitchAccountModal ref="switchAccountModalRef" />
|
||||
</template>
|
||||
|
||||
@@ -25,14 +25,12 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
||||
return await generateAccessible(preferences.app.accessMode, {
|
||||
...options,
|
||||
fetchMenuListAsync: async () => {
|
||||
console.log('🚀 开始获取用户菜单路由...');
|
||||
message.loading({
|
||||
content: `${$t('common.loadingMenu')}...`,
|
||||
duration: 1.5,
|
||||
});
|
||||
try {
|
||||
const routes = await getUserMenuApi();
|
||||
console.log('✅ 获取用户菜单路由成功:', routes);
|
||||
return routes;
|
||||
} catch (error) {
|
||||
console.error('❌ 获取用户菜单路由失败:', error);
|
||||
|
||||
@@ -87,21 +87,14 @@ function setupAccessGuard(router: Router) {
|
||||
|
||||
// 是否已经生成过动态路由
|
||||
if (accessStore.isAccessChecked) {
|
||||
console.log('✅ 动态路由已生成,跳过');
|
||||
return true;
|
||||
}
|
||||
|
||||
console.log('🚀 开始生成动态路由...');
|
||||
console.log('📊 当前访问模式:', preferences.app.accessMode);
|
||||
|
||||
// 生成路由表
|
||||
// 当前登录用户拥有的角色标识列表
|
||||
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
|
||||
const userRoles = userInfo.roles ?? [];
|
||||
|
||||
console.log('👤 用户信息:', userInfo);
|
||||
console.log('🎭 用户角色:', userRoles);
|
||||
|
||||
// 生成菜单和路由
|
||||
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
||||
roles: userRoles,
|
||||
@@ -110,9 +103,6 @@ function setupAccessGuard(router: Router) {
|
||||
routes: accessRoutes,
|
||||
});
|
||||
|
||||
console.log('📋 可访问菜单:', accessibleMenus);
|
||||
console.log('🛣️ 可访问路由:', accessibleRoutes);
|
||||
|
||||
// 保存菜单信息和路由信息
|
||||
accessStore.setAccessMenus(accessibleMenus);
|
||||
accessStore.setAccessRoutes(accessibleRoutes);
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'FileRepository',
|
||||
path: '/media/file-repository',
|
||||
component: () => import('#/views/media/file-repository/index.vue'),
|
||||
component: () => import('#/views/media/file/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:folder',
|
||||
title: '文件仓库',
|
||||
@@ -22,7 +22,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'ImageRepository',
|
||||
path: '/media/image-repository',
|
||||
component: () => import('#/views/media/image-repository/index.vue'),
|
||||
component: () => import('#/views/media/image/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:image',
|
||||
title: '图片仓库',
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'CompanyManagement',
|
||||
path: '/organization/company-management',
|
||||
component: () => import('#/views/organization/company-management/index.vue'),
|
||||
component: () => import('#/views/organization/company/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:building',
|
||||
title: '公司管理',
|
||||
@@ -22,7 +22,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'DepartmentManagement',
|
||||
path: '/organization/department-management',
|
||||
component: () => import('#/views/organization/department-management/index.vue'),
|
||||
component: () => import('#/views/organization/department/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:users',
|
||||
title: '部门管理',
|
||||
@@ -31,7 +31,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'PositionManagement',
|
||||
path: '/organization/position-management',
|
||||
component: () => import('#/views/organization/position-management/index.vue'),
|
||||
component: () => import('#/views/organization/position/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:briefcase',
|
||||
title: '岗位管理',
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'ShopManagement',
|
||||
path: '/shop/shop-management',
|
||||
component: () => import('#/views/shop/shop-management/index.vue'),
|
||||
component: () => import('#/views/shop/shop/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:store',
|
||||
title: '店铺管理',
|
||||
@@ -22,7 +22,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'ProductManagement',
|
||||
path: '/shop/product-management',
|
||||
component: () => import('#/views/shop/product-management/index.vue'),
|
||||
component: () => import('#/views/shop/product/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:package',
|
||||
title: '商品管理',
|
||||
@@ -31,7 +31,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'OrderManagement',
|
||||
path: '/shop/order-management',
|
||||
component: () => import('#/views/shop/order-management/index.vue'),
|
||||
component: () => import('#/views/shop/order/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:shopping-cart',
|
||||
title: '订单管理',
|
||||
@@ -40,7 +40,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'PromotionFeeManagement',
|
||||
path: '/shop/promotion-fee-management',
|
||||
component: () => import('#/views/shop/promotion-fee-management/index.vue'),
|
||||
component: () => import('#/views/shop/promotion-fee/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:credit-card',
|
||||
title: '推广费管理',
|
||||
@@ -57,7 +57,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'OrderStatusConfig',
|
||||
path: '/shop/config-management/order-status',
|
||||
component: () => import('#/views/shop/config-management/order-status-config/index.vue'),
|
||||
component: () => import('#/views/shop/config/order-status-config/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:list-checks',
|
||||
title: '订单状态类型',
|
||||
@@ -66,7 +66,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'PromotionFeeTypeConfig',
|
||||
path: '/shop/config-management/promotion-fee-type',
|
||||
component: () => import('#/views/shop/config-management/promotion-fee-type-config/index.vue'),
|
||||
component: () => import('#/views/shop/config/promotion-fee-type-config/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:percent',
|
||||
title: '推广费用类型',
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'MenuManagement',
|
||||
path: '/system/menu-management',
|
||||
component: () => import('#/views/system/menu-management/index.vue'),
|
||||
component: () => import('#/views/system/menu/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:menu',
|
||||
title: '菜单管理',
|
||||
|
||||
+3
-3
@@ -112,9 +112,9 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { Modal, Button, message } from 'ant-design-vue';
|
||||
import ShopFormModal from '#/views/shop/shop-management/components/ShopFormModal.vue';
|
||||
import ProductFormModal from '#/views/shop/product-management/components/ProductFormModal.vue';
|
||||
import ProductSpecModal from '#/views/shop/product-management/components/ProductSpecModal.vue';
|
||||
import ShopFormModal from '#/views/shop/shop/components/ShopFormModal.vue';
|
||||
import ProductFormModal from '#/views/shop/product/components/ProductFormModal.vue';
|
||||
import ProductSpecModal from '#/views/shop/product/components/ProductSpecModal.vue';
|
||||
|
||||
interface Props {
|
||||
visible: boolean;
|
||||
|
||||
@@ -11,7 +11,7 @@ interface BasicUserInfo {
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
avatar: string;
|
||||
avatar?: string;
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
|
||||
@@ -51,6 +51,10 @@ interface AccessState {
|
||||
* refreshToken过期时间戳
|
||||
*/
|
||||
refreshTokenExpiresAt: number | null;
|
||||
/**
|
||||
* 用户角色
|
||||
*/
|
||||
userRole: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,6 +152,24 @@ export const useAccessStore = defineStore('core-access', {
|
||||
if (refreshTokenExpiresAt) {
|
||||
this.refreshTokenExpiresAt = refreshTokenExpiresAt;
|
||||
}
|
||||
|
||||
// 从accessToken中提取用户角色
|
||||
if (accessToken) {
|
||||
try {
|
||||
const parts = accessToken.split('.');
|
||||
if (parts.length === 3 && parts[1]) {
|
||||
const payload = JSON.parse(atob(parts[1]));
|
||||
this.userRole = payload.role || null;
|
||||
} else {
|
||||
this.userRole = null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('解析token失败:', error);
|
||||
this.userRole = null;
|
||||
}
|
||||
} else {
|
||||
this.userRole = null;
|
||||
}
|
||||
},
|
||||
unlockScreen() {
|
||||
this.isLockScreen = false;
|
||||
@@ -164,6 +186,7 @@ export const useAccessStore = defineStore('core-access', {
|
||||
'accessCodes',
|
||||
'isLockScreen',
|
||||
'lockScreenPassword',
|
||||
'userRole',
|
||||
],
|
||||
},
|
||||
state: (): AccessState => ({
|
||||
@@ -178,6 +201,7 @@ export const useAccessStore = defineStore('core-access', {
|
||||
loginExpired: false,
|
||||
refreshToken: null,
|
||||
refreshTokenExpiresAt: null,
|
||||
userRole: null,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BasicUserInfo } from '@vben-core/typings';
|
||||
|
||||
/** 用户信息 */
|
||||
interface UserInfo extends BasicUserInfo {
|
||||
interface UserInfo extends Omit<BasicUserInfo, 'userId' | 'username'> {
|
||||
/**
|
||||
* 用户编号
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user