提交 9cc0e18b 作者: 方治民

feat: 新增菜单路由重定向配置、新增用户权限获取接口,用于前端鉴权、新增用户 SQL 预览文件

上级 a62b1f28
......@@ -24,7 +24,7 @@
<!-- prettier-ignore -->
- [x] 完成项目构建,开发文档编写
- [x] [conventional-changelog](https://www.cnblogs.com/mengfangui/p/12634845.html)
- [x] 用户及权限模块(菜单/按钮)
- [x] 用户及权限模块(目录/菜单/按钮),预览初始化权限配置 [SQL 脚本](./basic-auth/src/main/resources/init-test-mysql.sql)
- [x] 通用文件上传模块
- [ ] 通用字典管理模块
- [ ] XXL-JOB 定时任务模块
......@@ -8,7 +8,7 @@ spring:
name: "basic-api-app"
profiles:
include: auth
active: mock
active: dev
# DEBUG
debug: false
......@@ -63,6 +63,9 @@ public class Permission implements Serializable {
@Comment("路径")
String path;
@Comment("重定向")
String redirect;
@Comment("组件")
String component;
......@@ -107,6 +110,10 @@ public class Permission implements Serializable {
BUTTON,
}
/**
* 获取权限的元数据信息,通常是根据前端所需来输出,可自定义调整
* @return JSON 格式 Meta 元数据
*/
public JSONObject getMetaJson() {
JSONObject meta = new JSONObject();
meta.put("title", this.name);
......
......@@ -43,7 +43,7 @@ public class RegisterParam implements Serializable {
@Pattern(regexp = "^1[0-9]{10}$", message = "手机号码格式不正确")
String mobile;
@ApiModelProperty(value = "头像", example = "https://files.catbox.moe/96nu4q.jpg")
@ApiModelProperty(value = "头像", example = "https://s1.ax1x.com/2022/03/30/qggJH0.jpg")
String avatar;
@ApiModelProperty(value = "邮箱", example = "developer@yiring.com")
......
......@@ -36,21 +36,24 @@ public class PermissionParam implements Serializable {
@ApiModelProperty(value = "序号", example = "1")
Integer serial;
@ApiModelProperty(value = "标识", example = "home", required = true)
@ApiModelProperty(value = "标识", example = "Dashboard", required = true)
@NotEmpty(message = "权限标识不能为空")
String uid;
@ApiModelProperty(value = "名称", example = "主页", required = true)
@ApiModelProperty(value = "名称", example = "Dashboard", required = true)
@NotEmpty(message = "权限名称不能为空")
String name;
@ApiModelProperty(value = "路径", example = "/")
@ApiModelProperty(value = "路径", example = "/dashboard")
String path;
@ApiModelProperty(value = "组件", example = "/home")
@ApiModelProperty(value = "重定向", example = "/dashboard/workbench")
String redirect;
@ApiModelProperty(value = "组件", example = "LAYOUT")
String component;
@ApiModelProperty(value = "图标", example = "menu")
@ApiModelProperty(value = "图标", example = "ion:grid-outline")
String icon;
@ApiModelProperty(value = "是否隐藏", example = "false")
......@@ -63,6 +66,6 @@ public class PermissionParam implements Serializable {
@Builder.Default
Long pid = 0L;
@ApiModelProperty(value = "元数据", example = "{}")
@ApiModelProperty(value = "元数据", example = "{\"title\": \"routes.dashboard.dashboard\", \"hideChildrenInMenu\": true}")
String meta;
}
......@@ -51,10 +51,7 @@ public class Permissions {
List<MenuVo> list = Commons.transform(
permissions,
MenuVo.class,
(source, target) -> {
target.setMeta(source.getMetaJson());
target.setName(source.getUid());
},
(source, target) -> target.setMeta(source.getMetaJson()),
Permission.Fields.meta
);
......@@ -65,12 +62,15 @@ public class Permissions {
Map<Long, MenuVo> map = list.stream().collect(Collectors.toMap(MenuVo::getId, Function.identity()));
list.forEach(entity -> {
MenuVo vo = map.get(entity.getPid());
if (null == vo) {
MenuVo menu = map.get(entity.getPid());
if (null == menu) {
roots.add(map.get(entity.getId()));
} else {
MenuVo parent = map.get(entity.getPid());
parent.getChildren().add(entity);
if (menu.getChildren() == null) {
menu.setChildren(new ArrayList<>());
}
menu.getChildren().add(entity);
}
});
......
......@@ -4,14 +4,14 @@ package com.yiring.auth.vo.permission;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yiring.auth.domain.permission.Permission;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.List;
import lombok.*;
import lombok.experimental.FieldDefaults;
import java.io.Serializable;
import java.util.List;
/**
* 菜单输出类
* @author Jim
......@@ -36,19 +36,19 @@ public class MenuVo implements Serializable {
@JsonIgnore
Long pid;
@ApiModelProperty(value = "标识", example = "home")
@ApiModelProperty(value = "名称", example = "Dashboard")
String name;
@ApiModelProperty(value = "路径", example = "/")
@ApiModelProperty(value = "路径", example = "/dashboard")
String path;
@ApiModelProperty(value = "组件", example = "/home")
String component;
@ApiModelProperty(value = "重定向", example = "/dashboard/workbench")
String redirect;
@ApiModelProperty(value = "权限类型", example = "MENU")
Permission.Type type;
@ApiModelProperty(value = "组件", example = "LAYOUT")
String component;
@ApiModelProperty(value = "元数据", example = "{}")
@ApiModelProperty(value = "元数据", example = "{\"title\": \"routes.dashboard.dashboard\", \"hideChildrenInMenu\": true}")
JSONObject meta;
@ApiModelProperty(value = "子权限")
......
......@@ -41,7 +41,7 @@ public class UserInfoVo implements Serializable {
@ApiModelProperty(value = "介绍", example = "系统管理员")
String desc;
@ApiModelProperty(value = "头像", example = "https://files.catbox.moe/96nu4q.jpg")
@ApiModelProperty(value = "头像", example = "https://s1.ax1x.com/2022/03/30/qggJH0.jpg")
String avatar;
@ApiModelProperty("角色")
......
......@@ -41,7 +41,7 @@ public class UserMenuListVo implements Serializable {
@ApiModelProperty(value = "介绍", example = "系统管理员")
String desc;
@ApiModelProperty(value = "头像", example = "https://files.catbox.moe/96nu4q.jpg")
@ApiModelProperty(value = "头像", example = "https://s1.ax1x.com/2022/03/30/qggJH0.jpg")
String avatar;
@ApiModelProperty("角色")
......
......@@ -45,7 +45,7 @@ public class UserVo implements Serializable {
@ApiModelProperty(value = "职称", example = "系统管理员")
String title;
@ApiModelProperty(value = "头像", example = "https://files.catbox.moe/96nu4q.jpg")
@ApiModelProperty(value = "头像", example = "https://s1.ax1x.com/2022/03/30/qggJH0.jpg")
String avatar;
@ApiModelProperty(value = "是否启用", example = "true")
......
......@@ -73,15 +73,29 @@ public class UserController {
return Result.ok(userInfoVo);
}
@ApiOperation(value = "获取用户权限")
@ApiOperation(value = "获取用户菜单")
@GetMapping("getMenuList")
public Result<ArrayList<MenuVo>> getMenuList() {
User user = getLoginUser();
List<Permission> permissions = Permissions.toPermissions(user.getRoles());
List<Permission> permissions = Permissions.toPermissions(user.getRoles())
.stream()
.filter(permission -> !Permission.Type.BUTTON.equals(permission.getType()))
.collect(Collectors.toList());
List<MenuVo> vos = Permissions.toMenuTreeVo(permissions);
return Result.ok((ArrayList<MenuVo>) vos);
}
@ApiOperation(value = "获取用户权限")
@GetMapping("getPermCode")
public Result<ArrayList<String>> getPermCode() {
User user = getLoginUser();
List<Permission> permissions = Permissions.toPermissions(user.getRoles());
List<String> codes = permissions.stream()
.map(Permission::getUid)
.collect(Collectors.toList());
return Result.ok((ArrayList<String>) codes);
}
@ApiOperation(value = "分配角色")
@PostMapping("/manage/assign")
public Result<String> assign(@Valid IdParam idParam, @Valid IdsParam idsParam) {
......
/*
Navicat Premium Data Transfer
Source Server : localhost_3306
Source Server Type : MySQL
Source Server Version : 80025
Source Host : 127.0.0.1:3306
Source Schema : basic_app
Target Server Type : MySQL
Target Server Version : 80025
File Encoding : 65001
Date: 30/03/2022 17:11:44
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for sys_permission
-- ----------------------------
DROP TABLE IF EXISTS `sys_permission`;
CREATE TABLE `sys_permission` (
`id` bigint NOT NULL,
`component` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`enable` bit(1) NULL DEFAULT NULL,
`hidden` bit(1) NULL DEFAULT NULL,
`icon` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`meta` json NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`path` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`pid` bigint NULL DEFAULT NULL,
`serial` int NULL DEFAULT NULL,
`tree` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`uid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`redirect` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_n5idwm5pmlgfwvau5vrwf65ai`(`uid`) USING BTREE,
UNIQUE INDEX `UKn5idwm5pmlgfwvau5vrwf65ai`(`uid`) USING BTREE,
INDEX `IDXfgtwjg4pmylcko0v6ate29j2x`(`type`) USING BTREE,
INDEX `IDXcj5qpen847f3vkcgy7lsmqyug`(`pid`) USING BTREE,
INDEX `IDXckpwmqmt2tsu8fyefxpgwypmr`(`tree`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sys_permission
-- ----------------------------
INSERT INTO `sys_permission` VALUES (1509081714683547648, 'LAYOUT', b'1', NULL, 'ion:grid-outline', '{\"title\": \"routes.dashboard.dashboard\", \"hideChildrenInMenu\": true}', 'Dashboard', '/dashboard', 0, 1, '0', 'MENU', 'Dashboard', '/dashboard/workbench');
INSERT INTO `sys_permission` VALUES (1509082383666647040, '/dashboard/workbench/index', b'1', b'1', NULL, '{\"title\": \"routes.dashboard.workbench\", \"hideBreadcrumb\": true, \"currentActiveMenu\": \"/dashboard\"}', 'Workbench', 'workbench', 1509081714683547648, NULL, '0.1509081714683547648', 'MENU', 'Workbench', NULL);
INSERT INTO `sys_permission` VALUES (1509082892188258304, 'LAYOUT', b'1', NULL, 'simple-icons:about-dot-me', '{\"title\": \"routes.dashboard.about\", \"hideChildrenInMenu\": true}', 'About', '/about', 0, 100000, '0', 'MENU', 'About', '/about/index');
INSERT INTO `sys_permission` VALUES (1509083350738931712, '/sys/about/index', b'1', NULL, 'simple-icons:about-dot-me', '{\"title\": \"routes.dashboard.about\", \"hideMenu\": true}', 'AboutPage', 'index', 1509082892188258304, NULL, '0.1509082892188258304', 'MENU', 'AboutPage', NULL);
-- ----------------------------
-- Table structure for sys_role
-- ----------------------------
DROP TABLE IF EXISTS `sys_role`;
CREATE TABLE `sys_role` (
`id` bigint NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`uid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_o928jdlxprqf5qyw6rvor4lse`(`uid`) USING BTREE,
UNIQUE INDEX `UKo928jdlxprqf5qyw6rvor4lse`(`uid`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sys_role
-- ----------------------------
INSERT INTO `sys_role` VALUES (1509083443323998208, '管理员', 'admin');
-- ----------------------------
-- Table structure for sys_role_permissions
-- ----------------------------
DROP TABLE IF EXISTS `sys_role_permissions`;
CREATE TABLE `sys_role_permissions` (
`role_id` bigint NOT NULL,
`permissions_id` bigint NOT NULL,
PRIMARY KEY (`role_id`, `permissions_id`) USING BTREE,
INDEX `FKrg8k5oymm622ik067yjss31co`(`permissions_id`) USING BTREE,
CONSTRAINT `FKaa4k4qhr2qdj6br8p5nrb2lhb` FOREIGN KEY (`role_id`) REFERENCES `sys_role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `FKrg8k5oymm622ik067yjss31co` FOREIGN KEY (`permissions_id`) REFERENCES `sys_permission` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sys_role_permissions
-- ----------------------------
INSERT INTO `sys_role_permissions` VALUES (1509083443323998208, 1509081714683547648);
INSERT INTO `sys_role_permissions` VALUES (1509083443323998208, 1509082383666647040);
INSERT INTO `sys_role_permissions` VALUES (1509083443323998208, 1509082892188258304);
INSERT INTO `sys_role_permissions` VALUES (1509083443323998208, 1509083350738931712);
-- ----------------------------
-- Table structure for sys_user
-- ----------------------------
DROP TABLE IF EXISTS `sys_user`;
CREATE TABLE `sys_user` (
`id` bigint NOT NULL,
`avatar` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`create_time` datetime NULL DEFAULT NULL,
`deleted` bit(1) NULL DEFAULT NULL,
`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`enabled` bit(1) NULL DEFAULT NULL,
`introduction` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`last_login_ip` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`last_login_time` datetime NULL DEFAULT NULL,
`mobile` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`real_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `UK_ahtq5ew3v0kt1n7hf1sgp7p8l`(`email`) USING BTREE,
UNIQUE INDEX `UK_cvv4commjv5h4bai0h4vuqvkd`(`mobile`) USING BTREE,
UNIQUE INDEX `UK_51bvuyvihefoh4kp5syh2jpi4`(`username`) USING BTREE,
UNIQUE INDEX `UKcvv4commjv5h4bai0h4vuqvkd`(`mobile`) USING BTREE,
UNIQUE INDEX `UK51bvuyvihefoh4kp5syh2jpi4`(`username`) USING BTREE,
UNIQUE INDEX `UKahtq5ew3v0kt1n7hf1sgp7p8l`(`email`) USING BTREE,
INDEX `IDXeyi36w6acltgl5j4ujw0wlsyt`(`enabled`) USING BTREE,
INDEX `IDXner7sjf2kjerehlptwipdlst9`(`deleted`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sys_user
-- ----------------------------
INSERT INTO `sys_user` VALUES (1509080860341571584, 'https://s1.ax1x.com/2022/03/30/qggJH0.jpg', '2022-03-30 16:11:29', b'0', NULL, b'1', '平台管理员', '0:0:0:0:0:0:0:1', '2022-03-30 16:55:40', '13012345678', '8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92', '管理员', 'admin');
-- ----------------------------
-- Table structure for sys_user_roles
-- ----------------------------
DROP TABLE IF EXISTS `sys_user_roles`;
CREATE TABLE `sys_user_roles` (
`user_id` bigint NOT NULL,
`role_id` bigint NOT NULL,
PRIMARY KEY (`role_id`, `user_id`) USING BTREE,
INDEX `FKp2804vh0ea810pitigxq5n6pn`(`user_id`) USING BTREE,
CONSTRAINT `FKp2804vh0ea810pitigxq5n6pn` FOREIGN KEY (`user_id`) REFERENCES `sys_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
CONSTRAINT `FKqwiuml6b7mjmk48u5b9hmk853` FOREIGN KEY (`role_id`) REFERENCES `sys_role` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of sys_user_roles
-- ----------------------------
INSERT INTO `sys_user_roles` VALUES (1509080860341571584, 1509083443323998208);
SET FOREIGN_KEY_CHECKS = 1;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论