mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
5.0
This commit is contained in:
@@ -19,6 +19,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,14 @@ public class UserContext {
|
||||
UserContext.tokenGetter = tokenGetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户id
|
||||
* @return 返回id,没有返回-1
|
||||
*/
|
||||
public static Long getUserId() {
|
||||
return Optional.ofNullable(getUser()).map(User::getUserId).orElse(-1L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户
|
||||
*
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package com.gitee.sop.adminbackend.common.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 菜单类型
|
||||
* @author 六如
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MenuTypeEnum implements IntEnum {
|
||||
MENU(0, "菜单"),
|
||||
IFRAME(1, "iframe"),
|
||||
LINK(2, "外链"),
|
||||
BUTTON(3, "按钮");
|
||||
|
||||
private final Integer value;
|
||||
|
||||
private final String description;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.gitee.sop.adminbackend.common.util;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
public class DateUtil {
|
||||
|
||||
static DateTimeFormatter FORMATTER_FRONT = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
|
||||
static DateTimeFormatter FORMATTER_YMDHMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static String formatFrontDate(LocalDateTime localDateTime) {
|
||||
return FORMATTER_FRONT.format(localDateTime);
|
||||
}
|
||||
|
||||
public static String formatYmdhms(LocalDateTime localDateTime) {
|
||||
return FORMATTER_YMDHMS.format(localDateTime);
|
||||
}
|
||||
|
||||
}
|
@@ -60,7 +60,7 @@ public class SysResource {
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 路由重定向
|
||||
* 菜单图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
|
@@ -12,5 +12,4 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class SysResourceService implements LambdaService<SysResource, SysResourceMapper> {
|
||||
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import com.gitee.sop.adminbackend.service.sys.dto.SysRoleResourceDTO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -50,4 +51,10 @@ public class SysRoleResourceService implements LambdaService<SysRoleResource, Sy
|
||||
.listUniqueValue(SysRoleResource::getResourceId);
|
||||
}
|
||||
|
||||
public List<Long> listRoleResource(Collection<Long> roleIds) {
|
||||
return this.query()
|
||||
.in(SysRoleResource::getRoleId, roleIds)
|
||||
.listUniqueValue(SysRoleResource::getResourceId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,11 +2,17 @@ package com.gitee.sop.adminbackend.service.sys;
|
||||
|
||||
import com.gitee.fastmybatis.core.support.LambdaService;
|
||||
import com.gitee.sop.adminbackend.common.user.User;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.dao.entity.SysRole;
|
||||
import com.gitee.sop.adminbackend.dao.entity.SysUserRole;
|
||||
import com.gitee.sop.adminbackend.dao.mapper.SysRoleMapper;
|
||||
import com.gitee.sop.adminbackend.dao.mapper.SysUserRoleMapper;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.SysRoleDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -18,6 +24,9 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class SysUserRoleService implements LambdaService<SysUserRole, SysUserRoleMapper> {
|
||||
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
|
||||
/**
|
||||
* 设置用户角色
|
||||
*
|
||||
@@ -52,4 +61,14 @@ public class SysUserRoleService implements LambdaService<SysUserRole, SysUserRol
|
||||
.listUniqueValue(SysUserRole::getRoleId);
|
||||
}
|
||||
|
||||
public List<SysRoleDTO> listUserRoles(Long userId) {
|
||||
List<Long> roleIds = this.listUserRoleIds(userId);
|
||||
if (roleIds.isEmpty()) {
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
return sysRoleMapper.query()
|
||||
.in(SysRole::getId, roleIds)
|
||||
.list(sysRole -> CopyUtil.copyBean(sysRole, SysRoleDTO::new));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,99 @@
|
||||
package com.gitee.sop.adminbackend.service.sys;
|
||||
|
||||
import com.gitee.fastmybatis.core.util.TreeUtil;
|
||||
import com.gitee.sop.adminbackend.common.enums.MenuTypeEnum;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.dao.entity.SysResource;
|
||||
import com.gitee.sop.adminbackend.dao.entity.SysRoleResource;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.MenuTreeDTO;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.MenuTreeDTO.Meta;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.SysRoleDTO;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.UserPermissionDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Service
|
||||
public class UserPermissionService {
|
||||
|
||||
@Autowired
|
||||
private SysResourceService sysResourceService;
|
||||
@Autowired
|
||||
private SysRoleResourceService sysRoleResourceService;
|
||||
@Autowired
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
||||
public UserPermissionDTO getUserPermission(Long userId) {
|
||||
List<SysRoleDTO> sysRoleDTOS = sysUserRoleService.listUserRoles(userId);
|
||||
if (sysRoleDTOS.isEmpty()) {
|
||||
return UserPermissionDTO.empty();
|
||||
}
|
||||
|
||||
Set<Long> roleIds = sysRoleDTOS.stream().map(SysRoleDTO::getId).collect(Collectors.toSet());
|
||||
List<String> roleCodes = sysRoleDTOS.stream().map(SysRoleDTO::getCode).distinct().collect(Collectors.toList());
|
||||
|
||||
// 角色对应的资源
|
||||
List<Long> resourceIds = sysRoleResourceService.query()
|
||||
.in(SysRoleResource::getRoleId, roleIds)
|
||||
.listUniqueValue(SysRoleResource::getResourceId);
|
||||
|
||||
// 获取按钮权限
|
||||
List<String> permissions = sysResourceService.query()
|
||||
.eq(SysResource::getMenuType, MenuTypeEnum.BUTTON.getValue())
|
||||
.in(SysResource::getId, resourceIds)
|
||||
.listUniqueValue(SysResource::getAuths);
|
||||
|
||||
UserPermissionDTO userPermissionDTO = new UserPermissionDTO();
|
||||
userPermissionDTO.setRoles(roleCodes);
|
||||
userPermissionDTO.setPermissions(permissions);
|
||||
return userPermissionDTO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户菜单
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 返回菜单树
|
||||
*/
|
||||
public List<MenuTreeDTO> listUserMenuTree(Long userId) {
|
||||
List<Long> roleIds = sysUserRoleService.listUserRoleIds(userId);
|
||||
if (roleIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Long> resourceIds = sysRoleResourceService.listRoleResource(roleIds);
|
||||
if (resourceIds.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<SysResource> list = sysResourceService.query()
|
||||
.in(SysResource::getId, resourceIds)
|
||||
.eq(SysResource::getMenuType, MenuTypeEnum.MENU)
|
||||
.list();
|
||||
|
||||
return convert(list);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private List<MenuTreeDTO> convert(List<SysResource> list) {
|
||||
List<MenuTreeDTO> menuTreeDTOS = list.stream()
|
||||
.map(sysResource -> {
|
||||
MenuTreeDTO menuTreeDTO = CopyUtil.copyBean(sysResource, MenuTreeDTO::new);
|
||||
Meta meta = CopyUtil.copyBean(sysResource, Meta::new);
|
||||
menuTreeDTO.setMeta(meta);
|
||||
return menuTreeDTO;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return TreeUtil.convertTree(menuTreeDTOS, 0L);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,131 @@
|
||||
package com.gitee.sop.adminbackend.service.sys.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.gitee.fastmybatis.core.support.TreeNode;
|
||||
import com.gitee.sop.adminbackend.common.jackson.convert.annotation.Bool;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 菜单资源
|
||||
*
|
||||
* @author 六如
|
||||
* @see <a href="https://pure-admin.cn/pages/routerMenu/#%E8%B7%AF%E7%94%B1%E5%92%8C%E8%8F%9C%E5%8D%95%E9%85%8D%E7%BD%AE">...</a>
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
public class MenuTreeDTO implements TreeNode<MenuTreeDTO, Long> {
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 路由名称(必须保持唯一)
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 路由重定向(默认跳转地址)
|
||||
*/
|
||||
private String redirect;
|
||||
|
||||
/**
|
||||
* 父级id
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 路由元信息
|
||||
*/
|
||||
private Meta meta;
|
||||
|
||||
private List<MenuTreeDTO> children;
|
||||
|
||||
@Override
|
||||
public Long takeId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long takeParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 路由元信息,通俗来说就是路由上的额外信息 https://router.vuejs.org/zh/guide/advanced/meta.html#%E8%B7%AF%E7%94%B1%E5%85%83%E4%BF%A1%E6%81%AF
|
||||
*/
|
||||
@Data
|
||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||
public static class Meta {
|
||||
/**
|
||||
* 菜单名称(兼容国际化、非国际化,如果用国际化的写法就必须在根目录的locales文件夹下对应添加)
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 菜单图标
|
||||
*/
|
||||
private String icon;
|
||||
|
||||
/**
|
||||
* 右侧图标
|
||||
*/
|
||||
private String extraIcon;
|
||||
|
||||
/**
|
||||
* 菜单(是否显示该菜单)
|
||||
*/
|
||||
@Bool
|
||||
private Integer showLink;
|
||||
|
||||
/**
|
||||
* 父级菜单(是否显示父级菜单
|
||||
*/
|
||||
@Bool
|
||||
private Integer showParent;
|
||||
|
||||
/**
|
||||
* 链接地址(需要内嵌的`iframe`链接地址)
|
||||
*/
|
||||
private String frameSrc;
|
||||
|
||||
/**
|
||||
* 加载动画(内嵌的`iframe`页面是否开启首次加载动画)
|
||||
*/
|
||||
@Bool
|
||||
private Integer frameLoading;
|
||||
|
||||
/**
|
||||
* 缓存页面
|
||||
*/
|
||||
@Bool
|
||||
private Integer keepAlive;
|
||||
|
||||
/**
|
||||
* 标签页(当前菜单名称或自定义信息禁止添加到标签页)
|
||||
*/
|
||||
@Bool
|
||||
private Integer hiddenTag;
|
||||
|
||||
/**
|
||||
* 菜单激活
|
||||
*/
|
||||
private String activePath;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer rank;
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package com.gitee.sop.adminbackend.service.sys.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class SysRoleDTO {
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 角色code
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.gitee.sop.adminbackend.service.sys.dto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class UserPermissionDTO {
|
||||
|
||||
/**
|
||||
* 用户角色code
|
||||
*/
|
||||
private List<String> roles;
|
||||
|
||||
/**
|
||||
* 用户按钮级别code
|
||||
*/
|
||||
private List<String> permissions;
|
||||
|
||||
public static UserPermissionDTO empty() {
|
||||
UserPermissionDTO userPermissionDTO = new UserPermissionDTO();
|
||||
userPermissionDTO.setRoles(new ArrayList<>());
|
||||
userPermissionDTO.setPermissions(new ArrayList<>());
|
||||
return userPermissionDTO;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.gitee.sop.adminbackend.service.sys.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户角色信息
|
||||
* @author 六如
|
||||
*/
|
||||
@Data
|
||||
public class UserRoleInfoDTO {
|
||||
|
||||
private Long userId;
|
||||
|
||||
private List<Long> roleIds;
|
||||
|
||||
private List<String> roleCodes;
|
||||
|
||||
}
|
@@ -6,16 +6,18 @@ import com.gitee.sop.adminbackend.common.enums.StatusEnum;
|
||||
import com.gitee.sop.adminbackend.common.exception.BizException;
|
||||
import com.gitee.sop.adminbackend.common.manager.UserCacheManager;
|
||||
import com.gitee.sop.adminbackend.common.util.CopyUtil;
|
||||
import com.gitee.sop.adminbackend.common.util.DateUtil;
|
||||
import com.gitee.sop.adminbackend.common.util.GenerateUtil;
|
||||
import com.gitee.sop.adminbackend.common.util.JwtUtil;
|
||||
import com.gitee.sop.adminbackend.dao.entity.SysUser;
|
||||
import com.gitee.sop.adminbackend.service.sys.SysUserService;
|
||||
import com.gitee.sop.adminbackend.service.sys.UserPermissionService;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.UserPermissionDTO;
|
||||
import com.gitee.sop.adminbackend.service.sys.login.dto.LoginDTO;
|
||||
import com.gitee.sop.adminbackend.service.sys.login.dto.LoginForm;
|
||||
import com.gitee.sop.adminbackend.service.sys.login.dto.LoginResult;
|
||||
import com.gitee.sop.adminbackend.service.sys.login.dto.LoginUser;
|
||||
import com.gitee.sop.adminbackend.service.sys.login.enums.RegTypeEnum;
|
||||
import com.google.common.collect.Sets;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -25,7 +27,6 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -39,9 +40,10 @@ public class LoginService {
|
||||
|
||||
@Autowired
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Autowired
|
||||
private UserCacheManager userCacheManager;
|
||||
@Autowired
|
||||
private UserPermissionService userPermissionService;
|
||||
|
||||
|
||||
public LoginUser login(LoginDTO loginDTO) {
|
||||
@@ -74,20 +76,14 @@ public class LoginService {
|
||||
// 创建token
|
||||
String token = this.createToken(sysUser.getId());
|
||||
loginUser.setAccessToken(token);
|
||||
if ("admin".equals(sysUser.getUsername())) {
|
||||
// ROLE
|
||||
loginUser.setRoles(Sets.newHashSet("admin"));
|
||||
// *:*:* 表示所有权限
|
||||
loginUser.setPermissions(Sets.newHashSet("*:*:*"));
|
||||
} else {
|
||||
// TODO:其它角色权限
|
||||
loginUser.setRoles(Sets.newHashSet());
|
||||
loginUser.setPermissions(Sets.newHashSet());
|
||||
}
|
||||
UserPermissionDTO userPermission = userPermissionService.getUserPermission(loginUser.getUserId());
|
||||
// 角色权限
|
||||
loginUser.setRoles(userPermission.getRoles());
|
||||
loginUser.setPermissions(userPermission.getPermissions());
|
||||
// 设置token过期时间
|
||||
String value = Configs.getValue(ConfigKeyEnum.JWT_TIMEOUT_DAYS);
|
||||
LocalDateTime expireDate = LocalDateTime.now().plusDays(NumberUtils.toInt(value));
|
||||
loginUser.setExpires(expireDate.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss")));
|
||||
loginUser.setExpires(DateUtil.formatFrontDate(expireDate));
|
||||
return loginUser;
|
||||
}
|
||||
|
||||
|
@@ -3,7 +3,7 @@ package com.gitee.sop.adminbackend.service.sys.login.dto;
|
||||
import com.gitee.sop.adminbackend.common.user.User;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
@@ -56,9 +56,9 @@ public class LoginUser implements User {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private Set<String> roles;
|
||||
private List<String> roles;
|
||||
|
||||
private Set<String> permissions;
|
||||
private List<String> permissions;
|
||||
|
||||
private String accessToken;
|
||||
|
||||
|
@@ -36,13 +36,25 @@ public class SysResourceController {
|
||||
@Autowired
|
||||
private SysRoleResourceService sysRoleResourceService;
|
||||
|
||||
/**
|
||||
* 获取菜单树
|
||||
*
|
||||
* @return 返回分页结果
|
||||
*/
|
||||
@GetMapping("/tree")
|
||||
public Result<List<SysResourceVO>> tree() {
|
||||
List<SysResource> list = sysResourceService.listAll();
|
||||
List<SysResourceVO> retList = CopyUtil.copyList(list, SysResourceVO::new);
|
||||
return Result.ok(retList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部资源
|
||||
*
|
||||
* @return 返回分页结果
|
||||
*/
|
||||
@GetMapping("/listAll")
|
||||
public Result<List<SysResourceVO>> tree() {
|
||||
public Result<List<SysResourceVO>> listAll() {
|
||||
List<SysResource> list = sysResourceService.listAll();
|
||||
List<SysResourceVO> retList = CopyUtil.copyList(list, SysResourceVO::new);
|
||||
return Result.ok(retList);
|
||||
|
@@ -0,0 +1,35 @@
|
||||
package com.gitee.sop.adminbackend.controller.sys;
|
||||
|
||||
import com.gitee.sop.adminbackend.common.context.UserContext;
|
||||
import com.gitee.sop.adminbackend.common.resp.Result;
|
||||
import com.gitee.sop.adminbackend.service.sys.UserPermissionService;
|
||||
import com.gitee.sop.adminbackend.service.sys.dto.MenuTreeDTO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("sys/userperm")
|
||||
public class UserPermissionController {
|
||||
|
||||
@Autowired
|
||||
private UserPermissionService userPermissionService;
|
||||
|
||||
/**
|
||||
* 获取当前登录用户菜单
|
||||
*
|
||||
* @return 返回菜单树
|
||||
*/
|
||||
@GetMapping("listCurrentUserMenu")
|
||||
public Result<List<MenuTreeDTO>> listCurrentUserMenu() {
|
||||
List<MenuTreeDTO> menuTreeDTOS = userPermissionService.listUserMenuTree(UserContext.getUserId());
|
||||
return Result.ok(menuTreeDTOS);
|
||||
}
|
||||
|
||||
}
|
@@ -1,12 +1,10 @@
|
||||
package com.gitee.sop.adminbackend.controller.sys.param;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.gitee.sop.adminbackend.common.jackson.convert.annotation.Bool;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,29 +17,26 @@ public class SysResourceAddParam {
|
||||
/**
|
||||
* 菜单类型(0代表菜单、1代表iframe、2代表外链、3代表按钮)
|
||||
*/
|
||||
@NotNull
|
||||
@NotNull(message = "菜单类型必填")
|
||||
private Integer menuType;
|
||||
|
||||
/**
|
||||
* 菜单名称
|
||||
* 菜单名称, menuType=0时必填
|
||||
*/
|
||||
@NotBlank
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 路由名称
|
||||
* 路由名称, menuType=0时必填
|
||||
*/
|
||||
@NotBlank
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
* 路由路径, menuType=0时必填
|
||||
*/
|
||||
@NotBlank
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 路由路径
|
||||
* 组件路径
|
||||
*/
|
||||
private String component;
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package com.gitee.sop.adminbackend.controller.sys.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -41,9 +42,9 @@ public class LoginResultVO {
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
private Set<String> roles;
|
||||
private List<String> roles;
|
||||
|
||||
private Set<String> permissions;
|
||||
private List<String> permissions;
|
||||
|
||||
private String accessToken;
|
||||
|
||||
|
@@ -1,156 +1,12 @@
|
||||
// 模拟后端动态生成路由
|
||||
import { defineFakeRoute } from "vite-plugin-fake-server/client";
|
||||
import { system } from "@/router/enums";
|
||||
|
||||
const apiRouters = [
|
||||
{
|
||||
path: "/serve",
|
||||
meta: {
|
||||
title: "服务管理",
|
||||
icon: "ri:server-line",
|
||||
rank: 10
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/serve/api",
|
||||
name: "ServeApi",
|
||||
meta: {
|
||||
title: "接口管理",
|
||||
roles: ["admin"]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/doc",
|
||||
meta: {
|
||||
title: "文档管理",
|
||||
icon: "ep:document",
|
||||
rank: 10
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/doc/setting",
|
||||
name: "DocSetting",
|
||||
meta: {
|
||||
title: "基础配置",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/doc/list",
|
||||
name: "DocList",
|
||||
meta: {
|
||||
title: "文档列表",
|
||||
roles: ["admin"]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: "/isv",
|
||||
meta: {
|
||||
title: "ISV管理",
|
||||
icon: "ri:shield-user-line",
|
||||
rank: 10
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/isv/list",
|
||||
name: "IsvList",
|
||||
meta: {
|
||||
title: "ISV列表",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/isv/perm/permGroup",
|
||||
name: "IsvPermPermGroup",
|
||||
meta: {
|
||||
title: "分组管理",
|
||||
roles: ["admin"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// ,
|
||||
// {
|
||||
// path: "/sys",
|
||||
// meta: {
|
||||
// title: "系统管理",
|
||||
// icon: "ri:settings-2-line",
|
||||
// rank: 10
|
||||
// },
|
||||
// children: [
|
||||
// {
|
||||
// path: "/admin/user/index",
|
||||
// name: "AdminUser",
|
||||
// meta: {
|
||||
// title: "用户管理",
|
||||
// roles: ["admin"]
|
||||
// }
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
];
|
||||
|
||||
const systemManagementRouter = {
|
||||
path: "/system",
|
||||
meta: {
|
||||
icon: "ri:settings-3-line",
|
||||
title: "menus.pureSysManagement",
|
||||
rank: system
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: "/system/user/index",
|
||||
name: "SystemUser",
|
||||
meta: {
|
||||
icon: "ri:admin-line",
|
||||
title: "menus.pureUser",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/system/role/index",
|
||||
name: "SystemRole",
|
||||
meta: {
|
||||
icon: "ri:admin-fill",
|
||||
title: "menus.pureRole",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/system/menu/index",
|
||||
name: "SystemMenu",
|
||||
meta: {
|
||||
icon: "ep:menu",
|
||||
title: "menus.pureSystemMenu",
|
||||
roles: ["admin"]
|
||||
}
|
||||
},
|
||||
{
|
||||
path: "/system/dept/index",
|
||||
name: "SystemDept",
|
||||
meta: {
|
||||
icon: "ri:git-branch-line",
|
||||
title: "menus.pureDept",
|
||||
roles: ["admin"]
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export default defineFakeRoute([
|
||||
{
|
||||
url: "/get-async-routes",
|
||||
method: "get",
|
||||
response: () => {
|
||||
return {
|
||||
success: true,
|
||||
data: apiRouters.concat(systemManagementRouter)
|
||||
};
|
||||
return [];
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
@@ -1,4 +1,9 @@
|
||||
import { http } from "@/utils/http";
|
||||
import { createUrl, http } from "@/utils/http";
|
||||
|
||||
// 后端请求接口
|
||||
const apiUrl: any = createUrl({
|
||||
listMenu: "sys/userperm/listCurrentUserMenu"
|
||||
});
|
||||
|
||||
type Result = {
|
||||
success: boolean;
|
||||
@@ -6,5 +11,6 @@ type Result = {
|
||||
};
|
||||
|
||||
export const getAsyncRoutes = () => {
|
||||
return http.request<Result>("get", "/get-async-routes");
|
||||
return http.request<Result>("get", apiUrl.listMenu);
|
||||
// return http.request<Result>("get", "/get-async-routes");
|
||||
};
|
||||
|
23
sop-admin/sop-admin-frontend/src/utils/perm.ts
Normal file
23
sop-admin/sop-admin-frontend/src/utils/perm.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* 按钮权限定义
|
||||
*/
|
||||
export const PermCode = {
|
||||
// 接口管理按钮权限
|
||||
api: {
|
||||
// 更新
|
||||
update: "api:table-btn:update",
|
||||
// 启用/禁用
|
||||
updateStatus: "api:table-btn:updateStatus"
|
||||
},
|
||||
// 文档列表按钮定义
|
||||
doc: {
|
||||
// 发布
|
||||
publish: "doc:table-btn:publish",
|
||||
// 下线
|
||||
offline: "doc:table-btn:offline",
|
||||
// 同步
|
||||
sync: "doc:table-btn:sync",
|
||||
// 同步所有接口
|
||||
syncAll: "doc:page-btn:sync"
|
||||
}
|
||||
};
|
@@ -1,12 +1,14 @@
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { api } from "@/api/doc";
|
||||
import { PermCode } from "@/utils/perm";
|
||||
import {
|
||||
type ButtonsCallBackParams,
|
||||
type PlusColumn,
|
||||
useTable
|
||||
} from "plus-pro-components";
|
||||
import { YesOrNoEnum } from "@/model/enums";
|
||||
import { hasPerms } from "@/utils/auth";
|
||||
|
||||
export function useDocList() {
|
||||
const tabsData = ref<Array<any>>([
|
||||
@@ -45,6 +47,8 @@ export function useDocList() {
|
||||
);
|
||||
};
|
||||
|
||||
// 按钮权限code
|
||||
const btnCode = PermCode.doc;
|
||||
// 表格字段定义
|
||||
const tableColumns: PlusColumn[] = [
|
||||
{
|
||||
@@ -129,7 +133,7 @@ export function useDocList() {
|
||||
search();
|
||||
});
|
||||
},
|
||||
show: (row: any) => row.isFolder === 1
|
||||
show: (row: any) => hasPerms(btnCode.publish) && row.isFolder === 1
|
||||
},
|
||||
{
|
||||
text: "下线",
|
||||
@@ -155,7 +159,7 @@ export function useDocList() {
|
||||
search();
|
||||
});
|
||||
},
|
||||
show: (row: any) => row.isFolder === 1
|
||||
show: (row: any) => hasPerms(btnCode.offline) && row.isFolder === 1
|
||||
},
|
||||
{
|
||||
text: row => (row.isPublish ? "下线" : "发布"),
|
||||
@@ -181,7 +185,10 @@ export function useDocList() {
|
||||
search();
|
||||
});
|
||||
},
|
||||
show: (row: any) => row.isFolder === 0
|
||||
show: (row: any) => {
|
||||
const perm = row.isPublish ? btnCode.offline : btnCode.publish;
|
||||
return hasPerms(perm) && row.isFolder === 0;
|
||||
}
|
||||
},
|
||||
{
|
||||
text: "同步",
|
||||
@@ -210,7 +217,8 @@ export function useDocList() {
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
show: () => hasPerms(btnCode.sync)
|
||||
}
|
||||
];
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { useDocList } from "./index";
|
||||
import { Search } from "@element-plus/icons-vue";
|
||||
import { hasPerms } from "@/utils/auth";
|
||||
defineOptions({
|
||||
name: "DocList"
|
||||
});
|
||||
@@ -65,7 +66,11 @@ const {
|
||||
</el-input>
|
||||
</template>
|
||||
<template #toolbar>
|
||||
<el-button type="primary" @click="handleSyncApi">
|
||||
<el-button
|
||||
v-if="hasPerms('doc:page-btn:sync')"
|
||||
type="primary"
|
||||
@click="handleSyncApi"
|
||||
>
|
||||
同步全部接口
|
||||
</el-button>
|
||||
</template>
|
||||
|
@@ -8,6 +8,8 @@ import {
|
||||
import { ElMessage } from "element-plus";
|
||||
import { RegSource, StatusEnum, YesOrNoEnum } from "@/model/enums";
|
||||
import { api } from "@/api/serveApi";
|
||||
import { hasPerms } from "@/utils/auth";
|
||||
import { PermCode } from "@/utils/perm";
|
||||
|
||||
const isAdd = ref(false);
|
||||
|
||||
@@ -195,6 +197,8 @@ export const tableColumns: PlusColumn[] = [
|
||||
width: 160
|
||||
}
|
||||
];
|
||||
// 表格按钮权限
|
||||
const btnCode = PermCode.api;
|
||||
// 表格按钮定义
|
||||
actionButtons.value = [
|
||||
{
|
||||
@@ -204,13 +208,13 @@ actionButtons.value = [
|
||||
props: {
|
||||
type: "primary"
|
||||
},
|
||||
show: computed(() => true),
|
||||
onClick(params: ButtonsCallBackParams) {
|
||||
isAdd.value = false;
|
||||
editFormData.value = Object.assign({}, params.row);
|
||||
dlgTitle.value = "修改接口";
|
||||
dlgShow.value = true;
|
||||
}
|
||||
},
|
||||
show: () => hasPerms(btnCode.update)
|
||||
},
|
||||
{
|
||||
// 启用/禁用
|
||||
@@ -235,7 +239,8 @@ actionButtons.value = [
|
||||
ElMessage.success("修改成功");
|
||||
search();
|
||||
});
|
||||
}
|
||||
},
|
||||
show: () => hasPerms(btnCode.updateStatus)
|
||||
}
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user