Browse Source

update: menu relation transformation completed

main
QM303176530 5 years ago
parent
commit
a0570c0528
  1. 29
      docker-compose.yml
  2. 2
      server/api/v1/sys_menu.go
  3. 126
      server/db/qmplus.sql
  4. 1
      server/initialize/db_table.go
  5. 2
      server/model/sys_authority.go
  6. 34
      server/model/sys_authority_menu.go
  7. 8
      server/model/sys_base_menu.go
  8. 2
      web/src/view/layout/index.vue
  9. 6
      web/src/view/superAdmin/authority/components/apis.vue
  10. 8
      web/src/view/superAdmin/authority/components/menus.vue

29
docker-compose.yml

@ -1,29 +0,0 @@
# 关于Compose文件的具体说明,请参考以下链接:
# https://docs.docker.com/compose/compose-file/
version: "3.5"
services:
# 数据库的各种配置参数,请参考以下链接:
# https://github.com/piexlmax/gin-vue-admin/blob/master/QMPlusServer/db/qmplus.sql#L4-L8
# https://github.com/piexlmax/gin-vue-admin/blob/master/QMPlusServer/static/config/config.json#L8-L14
database:
image: mysql:5.6
ports:
- 3306:3306
volumes:
- ./QMPlusServer/db:/docker-entrypoint-initdb.d
environment:
MYSQL_ROOT_PASSWORD: Aa@6447985
MYSQL_DATABASE: qmPlus
user: root
server:
build: ./QMPlusServer
ports:
- 8080:8080
- 8888:8888
environment:
MYSQLHOST: database
working_dir: /go/src/gin-vue-admin
restart: always
depends_on:
- database

2
server/api/v1/sys_menu.go

@ -122,7 +122,7 @@ type AuthorityIdInfo struct {
// @Produce application/json // @Produce application/json
// @Param data body api.AuthorityIdInfo true "增加menu和角色关联关系" // @Param data body api.AuthorityIdInfo true "增加menu和角色关联关系"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}" // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/addMenuAuthority [post]
// @Router /menu/GetMenuAuthority [post]
func GetMenuAuthority(c *gin.Context) { func GetMenuAuthority(c *gin.Context) {
var authorityIdInfo AuthorityIdInfo var authorityIdInfo AuthorityIdInfo
_ = c.ShouldBindJSON(&authorityIdInfo) _ = c.ShouldBindJSON(&authorityIdInfo)

126
server/db/qmplus.sql

@ -11,7 +11,7 @@
Target Server Version : 50640 Target Server Version : 50640
File Encoding : 65001 File Encoding : 65001
Date: 02/04/2020 22:37:06
Date: 05/04/2020 16:24:43
*/ */
SET NAMES utf8mb4; SET NAMES utf8mb4;
@ -3923,7 +3923,7 @@ CREATE TABLE `sys_apis` (
`authority_id` int(10) UNSIGNED NULL DEFAULT NULL, `authority_id` int(10) UNSIGNED NULL DEFAULT NULL,
`path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `path` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `description` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`group` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`api_group` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`method` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'POST', `method` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT 'POST',
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_apis_deleted_at`(`deleted_at`) USING BTREE, INDEX `idx_apis_deleted_at`(`deleted_at`) USING BTREE,
@ -3980,25 +3980,58 @@ INSERT INTO `sys_apis` VALUES (45, '2020-03-29 23:01:28', '2020-03-29 23:01:28',
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `sys_authorities`; DROP TABLE IF EXISTS `sys_authorities`;
CREATE TABLE `sys_authorities` ( CREATE TABLE `sys_authorities` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`created_at` timestamp(0) NULL DEFAULT NULL,
`updated_at` timestamp(0) NULL DEFAULT NULL,
`deleted_at` timestamp(0) NULL DEFAULT NULL,
`authority_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, `authority_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`authority_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `authority_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`parent_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `parent_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
`created_at` datetime(0) NULL DEFAULT NULL,
`updated_at` datetime(0) NULL DEFAULT NULL,
`deleted_at` datetime(0) NULL DEFAULT NULL,
PRIMARY KEY (`authority_id`) USING BTREE,
UNIQUE INDEX `authority_id`(`authority_id`) USING BTREE, UNIQUE INDEX `authority_id`(`authority_id`) USING BTREE,
INDEX `idx_authorities_deleted_at`(`deleted_at`) USING BTREE,
INDEX `idx_sys_authorities_deleted_at`(`deleted_at`) USING BTREE INDEX `idx_sys_authorities_deleted_at`(`deleted_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ---------------------------- -- ----------------------------
-- Records of sys_authorities -- Records of sys_authorities
-- ---------------------------- -- ----------------------------
INSERT INTO `sys_authorities` VALUES (2, '2019-09-08 16:18:45', '2019-09-08 16:18:45', NULL, '888', '普通用户', '0');
INSERT INTO `sys_authorities` VALUES (6, '2019-09-18 22:23:33', '2019-09-18 22:23:33', NULL, '9528', '测试角色', '0');
INSERT INTO `sys_authorities` VALUES (8, '2019-12-28 18:19:13', '2019-12-28 18:19:13', NULL, '8881', '普通用户子角色', '888');
INSERT INTO `sys_authorities` VALUES ('888', '普通用户', '0', '2020-04-04 11:44:56', NULL, NULL);
INSERT INTO `sys_authorities` VALUES ('8881', '普通用户子角色', '888', '2020-04-04 11:44:56', NULL, NULL);
INSERT INTO `sys_authorities` VALUES ('9528', '测试角色', '0', '2020-04-04 11:44:56', NULL, NULL);
-- ----------------------------
-- Table structure for sys_authority_menus
-- ----------------------------
DROP TABLE IF EXISTS `sys_authority_menus`;
CREATE TABLE `sys_authority_menus` (
`sys_authority_authority_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
`sys_base_menu_id` int(10) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`sys_authority_authority_id`, `sys_base_menu_id`) USING BTREE,
INDEX `sys_authority_authority_id`(`sys_authority_authority_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of sys_authority_menus
-- ----------------------------
INSERT INTO `sys_authority_menus` VALUES ('888', 1);
INSERT INTO `sys_authority_menus` VALUES ('888', 2);
INSERT INTO `sys_authority_menus` VALUES ('888', 3);
INSERT INTO `sys_authority_menus` VALUES ('888', 4);
INSERT INTO `sys_authority_menus` VALUES ('888', 5);
INSERT INTO `sys_authority_menus` VALUES ('888', 6);
INSERT INTO `sys_authority_menus` VALUES ('888', 17);
INSERT INTO `sys_authority_menus` VALUES ('888', 18);
INSERT INTO `sys_authority_menus` VALUES ('888', 19);
INSERT INTO `sys_authority_menus` VALUES ('888', 20);
INSERT INTO `sys_authority_menus` VALUES ('888', 21);
INSERT INTO `sys_authority_menus` VALUES ('888', 22);
INSERT INTO `sys_authority_menus` VALUES ('888', 23);
INSERT INTO `sys_authority_menus` VALUES ('888', 26);
INSERT INTO `sys_authority_menus` VALUES ('888', 33);
INSERT INTO `sys_authority_menus` VALUES ('888', 34);
INSERT INTO `sys_authority_menus` VALUES ('888', 38);
INSERT INTO `sys_authority_menus` VALUES ('888', 40);
INSERT INTO `sys_authority_menus` VALUES ('888', 41);
INSERT INTO `sys_authority_menus` VALUES ('888', 42);
-- ---------------------------- -- ----------------------------
-- Table structure for sys_base_menus -- Table structure for sys_base_menus
@ -4061,22 +4094,19 @@ INSERT INTO `sys_base_menus` VALUES (42, '2020-04-02 14:19:36', '2020-04-02 14:2
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `sys_data_authority_id`; DROP TABLE IF EXISTS `sys_data_authority_id`;
CREATE TABLE `sys_data_authority_id` ( CREATE TABLE `sys_data_authority_id` (
`sys_authority_id` int(10) UNSIGNED NOT NULL DEFAULT 0,
`data_id` int(10) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`sys_authority_id`, `data_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
`sys_authority_authority_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
`data_authority_id` varchar(255) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
PRIMARY KEY (`sys_authority_authority_id`, `data_authority_id`) USING BTREE,
INDEX `sys_authority_authority_id`(`sys_authority_authority_id`) USING BTREE,
INDEX `data_authority_id`(`data_authority_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Compact;
-- ---------------------------- -- ----------------------------
-- Records of sys_data_authority_id -- Records of sys_data_authority_id
-- ---------------------------- -- ----------------------------
INSERT INTO `sys_data_authority_id` VALUES (2, 2);
INSERT INTO `sys_data_authority_id` VALUES (2, 6);
INSERT INTO `sys_data_authority_id` VALUES (2, 8);
INSERT INTO `sys_data_authority_id` VALUES (6, 2);
INSERT INTO `sys_data_authority_id` VALUES (6, 6);
INSERT INTO `sys_data_authority_id` VALUES (8, 2);
INSERT INTO `sys_data_authority_id` VALUES (8, 6);
INSERT INTO `sys_data_authority_id` VALUES (8, 8);
INSERT INTO `sys_data_authority_id` VALUES ('888', '888');
INSERT INTO `sys_data_authority_id` VALUES ('888', '8881');
INSERT INTO `sys_data_authority_id` VALUES ('888', '9528');
-- ---------------------------- -- ----------------------------
-- Table structure for sys_menus -- Table structure for sys_menus
@ -4102,7 +4132,7 @@ CREATE TABLE `sys_menus` (
PRIMARY KEY (`id`) USING BTREE, PRIMARY KEY (`id`) USING BTREE,
INDEX `idx_menus_deleted_at`(`deleted_at`) USING BTREE, INDEX `idx_menus_deleted_at`(`deleted_at`) USING BTREE,
INDEX `idx_sys_menus_deleted_at`(`deleted_at`) USING BTREE INDEX `idx_sys_menus_deleted_at`(`deleted_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 580 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
) ENGINE = InnoDB AUTO_INCREMENT = 668 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ---------------------------- -- ----------------------------
-- Records of sys_menus -- Records of sys_menus
@ -4140,26 +4170,26 @@ INSERT INTO `sys_menus` VALUES (517, '2019-10-20 11:23:39', '2019-12-12 16:58:23
INSERT INTO `sys_menus` VALUES (518, '2019-10-20 11:27:02', '2019-12-12 16:58:27', NULL, 0, 9528, 'upload', 'upload', 0, 'view/example/upload/upload.vue', '上传下载', 'upload', 19, '26', '上传下载', '5'); INSERT INTO `sys_menus` VALUES (518, '2019-10-20 11:27:02', '2019-12-12 16:58:27', NULL, 0, 9528, 'upload', 'upload', 0, 'view/example/upload/upload.vue', '上传下载', 'upload', 19, '26', '上传下载', '5');
INSERT INTO `sys_menus` VALUES (519, '2020-02-17 16:20:47', '2020-02-24 19:45:40', NULL, 0, 9528, 'breakpoint', 'breakpoint', 0, 'view/example/breakpoint/breakpoint.vue', '断点续传', 'upload', 19, '33', '断点续传', '6'); INSERT INTO `sys_menus` VALUES (519, '2020-02-17 16:20:47', '2020-02-24 19:45:40', NULL, 0, 9528, 'breakpoint', 'breakpoint', 0, 'view/example/breakpoint/breakpoint.vue', '断点续传', 'upload', 19, '33', '断点续传', '6');
INSERT INTO `sys_menus` VALUES (520, '2020-02-24 19:48:37', '2020-03-27 20:05:38', NULL, 0, 9528, 'customer', 'customer', 0, 'view/example/customer/customer.vue', '客户列表(资源示例)', 's-custom', 19, '34', '客户列表(资源示例)', '7'); INSERT INTO `sys_menus` VALUES (520, '2020-02-24 19:48:37', '2020-03-27 20:05:38', NULL, 0, 9528, 'customer', 'customer', 0, 'view/example/customer/customer.vue', '客户列表(资源示例)', 's-custom', 19, '34', '客户列表(资源示例)', '7');
INSERT INTO `sys_menus` VALUES (560, '2019-09-19 22:05:18', '2020-04-02 22:33:49', NULL, 0, 888, 'dashbord', 'dashbord', 0, 'view/dashbord/index.vue', '仪表盘', 'setting', 0, '1', '仪表盘', '1');
INSERT INTO `sys_menus` VALUES (561, '2019-09-19 22:06:17', '2020-03-27 20:33:58', NULL, 0, 888, 'test', 'test', 0, 'view/test/index.vue', '测试菜单', 'info', 0, '2', '测试菜单', '2');
INSERT INTO `sys_menus` VALUES (562, '2019-09-19 22:06:38', '2019-12-12 16:51:31', NULL, 0, 888, 'admin', 'superAdmin', 0, 'view/superAdmin/index.vue', '超级管理员', 'user-solid', 0, '3', '超级管理员', '3');
INSERT INTO `sys_menus` VALUES (563, '2019-09-19 22:11:53', '2019-09-19 22:11:53', NULL, 0, 888, 'authority', 'authority', 0, 'view/superAdmin/authority/authority.vue', '角色管理', 's-custom', 3, '4', '角色管理', '1');
INSERT INTO `sys_menus` VALUES (564, '2019-09-19 22:13:18', '2019-12-12 16:57:20', NULL, 0, 888, 'menu', 'menu', 0, 'view/superAdmin/menu/menu.vue', '菜单管理', 's-order', 3, '5', '菜单管理', '2');
INSERT INTO `sys_menus` VALUES (565, '2019-09-19 22:13:36', '2019-12-12 16:57:30', NULL, 0, 888, 'api', 'api', 0, 'view/superAdmin/api/api.vue', 'api管理', 's-platform', 3, '6', 'api管理', '3');
INSERT INTO `sys_menus` VALUES (566, '2019-10-09 15:12:29', '2019-12-12 16:57:25', NULL, 0, 888, 'user', 'user', 0, 'view/superAdmin/user/user.vue', '用户管理', 'coordinate', 3, '17', '用户管理', '4');
INSERT INTO `sys_menus` VALUES (567, '2019-10-15 22:27:22', '2019-12-12 16:51:33', NULL, 0, 888, 'person', 'person', 1, 'view/person/person.vue', '个人信息', 'user-solid', 0, '18', '个人信息', '4');
INSERT INTO `sys_menus` VALUES (568, '2020-03-29 21:31:03', '2020-03-29 21:31:03', NULL, 0, 888, 'systemTools', 'systemTools', 0, 'view/systemTools/index.vue', '系统工具', 's-cooperation', 0, '38', '系统工具', '5');
INSERT INTO `sys_menus` VALUES (569, '2020-03-29 21:35:10', '2020-03-29 21:35:10', NULL, 0, 888, 'autoCode', 'autoCode', 0, 'view/systemTools/autoCode/index.vue', '代码生成器', 'cpu', 38, '40', '代码生成器', '1');
INSERT INTO `sys_menus` VALUES (570, '2020-03-29 21:36:26', '2020-03-29 21:36:26', NULL, 0, 888, 'formCreate', 'formCreate', 0, 'view/systemTools/formCreate/index.vue', '表单生成器', 'magic-stick', 38, '41', '表单生成器', '2');
INSERT INTO `sys_menus` VALUES (571, '2020-04-02 14:19:36', '2020-04-02 14:20:16', NULL, 0, 888, 'system', 'system', 0, 'view/systemTools/system/system.vue', '系统配置', 's-operation', 38, '42', '系统配置', '3');
INSERT INTO `sys_menus` VALUES (572, '2019-10-20 11:14:42', '2020-03-29 21:39:18', NULL, 0, 888, 'example', 'example', 0, 'view/example/index.vue', '示例文件', 's-management', 0, '19', '示例文件', '6');
INSERT INTO `sys_menus` VALUES (573, '2019-10-20 11:18:11', '2019-10-20 11:18:11', NULL, 0, 888, 'table', 'table', 0, 'view/example/table/table.vue', '表格示例', 's-order', 19, '20', '表格示例', '1');
INSERT INTO `sys_menus` VALUES (574, '2019-10-20 11:19:52', '2019-12-12 16:58:15', NULL, 0, 888, 'form', 'form', 0, 'view/example/form/form.vue', '表单示例', 'document', 19, '21', '表单示例', '2');
INSERT INTO `sys_menus` VALUES (575, '2019-10-20 11:22:19', '2019-12-12 16:58:20', NULL, 0, 888, 'rte', 'rte', 0, 'view/example/rte/rte.vue', '富文本编辑器', 'reading', 19, '22', '富文本编辑器', '3');
INSERT INTO `sys_menus` VALUES (576, '2019-10-20 11:23:39', '2019-12-12 16:58:23', NULL, 0, 888, 'excel', 'excel', 0, 'view/example/excel/excel.vue', 'excel导入导出', 's-marketing', 19, '23', 'excel导入导出', '4');
INSERT INTO `sys_menus` VALUES (577, '2019-10-20 11:27:02', '2019-12-12 16:58:27', NULL, 0, 888, 'upload', 'upload', 0, 'view/example/upload/upload.vue', '上传下载', 'upload', 19, '26', '上传下载', '5');
INSERT INTO `sys_menus` VALUES (578, '2020-02-17 16:20:47', '2020-02-24 19:45:40', NULL, 0, 888, 'breakpoint', 'breakpoint', 0, 'view/example/breakpoint/breakpoint.vue', '断点续传', 'upload', 19, '33', '断点续传', '6');
INSERT INTO `sys_menus` VALUES (579, '2020-02-24 19:48:37', '2020-03-27 20:10:02', NULL, 0, 888, 'customer', 'customer', 0, 'view/example/customer/customer.vue', '客户列表(资源示例)', 's-custom', 19, '34', '客户列表(资源示例)', '7');
INSERT INTO `sys_menus` VALUES (648, '2019-09-19 22:05:18', '2020-04-02 22:33:49', NULL, 0, 888, 'dashbord', 'dashbord', 0, 'view/dashbord/index.vue', '仪表盘', 'setting', 0, '1', '仪表盘', '1');
INSERT INTO `sys_menus` VALUES (649, '2019-09-19 22:06:17', '2020-03-27 20:33:58', NULL, 0, 888, 'test', 'test', 0, 'view/test/index.vue', '测试菜单', 'info', 0, '2', '测试菜单', '2');
INSERT INTO `sys_menus` VALUES (650, '2019-09-19 22:06:38', '2019-12-12 16:51:31', NULL, 0, 888, 'admin', 'superAdmin', 0, 'view/superAdmin/index.vue', '超级管理员', 'user-solid', 0, '3', '超级管理员', '3');
INSERT INTO `sys_menus` VALUES (651, '2019-09-19 22:11:53', '2019-09-19 22:11:53', NULL, 0, 888, 'authority', 'authority', 0, 'view/superAdmin/authority/authority.vue', '角色管理', 's-custom', 3, '4', '角色管理', '1');
INSERT INTO `sys_menus` VALUES (652, '2019-09-19 22:13:18', '2019-12-12 16:57:20', NULL, 0, 888, 'menu', 'menu', 0, 'view/superAdmin/menu/menu.vue', '菜单管理', 's-order', 3, '5', '菜单管理', '2');
INSERT INTO `sys_menus` VALUES (653, '2019-09-19 22:13:36', '2019-12-12 16:57:30', NULL, 0, 888, 'api', 'api', 0, 'view/superAdmin/api/api.vue', 'api管理', 's-platform', 3, '6', 'api管理', '3');
INSERT INTO `sys_menus` VALUES (654, '2019-10-09 15:12:29', '2019-12-12 16:57:25', NULL, 0, 888, 'user', 'user', 0, 'view/superAdmin/user/user.vue', '用户管理', 'coordinate', 3, '17', '用户管理', '4');
INSERT INTO `sys_menus` VALUES (655, '2019-10-15 22:27:22', '2019-12-12 16:51:33', NULL, 0, 888, 'person', 'person', 1, 'view/person/person.vue', '个人信息', 'user-solid', 0, '18', '个人信息', '4');
INSERT INTO `sys_menus` VALUES (656, '2020-03-29 21:31:03', '2020-03-29 21:31:03', NULL, 0, 888, 'systemTools', 'systemTools', 0, 'view/systemTools/index.vue', '系统工具', 's-cooperation', 0, '38', '系统工具', '5');
INSERT INTO `sys_menus` VALUES (657, '2020-03-29 21:35:10', '2020-03-29 21:35:10', NULL, 0, 888, 'autoCode', 'autoCode', 0, 'view/systemTools/autoCode/index.vue', '代码生成器', 'cpu', 38, '40', '代码生成器', '1');
INSERT INTO `sys_menus` VALUES (658, '2020-03-29 21:36:26', '2020-03-29 21:36:26', NULL, 0, 888, 'formCreate', 'formCreate', 0, 'view/systemTools/formCreate/index.vue', '表单生成器', 'magic-stick', 38, '41', '表单生成器', '2');
INSERT INTO `sys_menus` VALUES (659, '2020-04-02 14:19:36', '2020-04-02 14:20:16', NULL, 0, 888, 'system', 'system', 0, 'view/systemTools/system/system.vue', '系统配置', 's-operation', 38, '42', '系统配置', '3');
INSERT INTO `sys_menus` VALUES (660, '2019-10-20 11:14:42', '2020-03-29 21:39:18', NULL, 0, 888, 'example', 'example', 0, 'view/example/index.vue', '示例文件', 's-management', 0, '19', '示例文件', '6');
INSERT INTO `sys_menus` VALUES (661, '2019-10-20 11:18:11', '2019-10-20 11:18:11', NULL, 0, 888, 'table', 'table', 0, 'view/example/table/table.vue', '表格示例', 's-order', 19, '20', '表格示例', '1');
INSERT INTO `sys_menus` VALUES (662, '2019-10-20 11:19:52', '2019-12-12 16:58:15', NULL, 0, 888, 'form', 'form', 0, 'view/example/form/form.vue', '表单示例', 'document', 19, '21', '表单示例', '2');
INSERT INTO `sys_menus` VALUES (663, '2019-10-20 11:22:19', '2019-12-12 16:58:20', NULL, 0, 888, 'rte', 'rte', 0, 'view/example/rte/rte.vue', '富文本编辑器', 'reading', 19, '22', '富文本编辑器', '3');
INSERT INTO `sys_menus` VALUES (664, '2019-10-20 11:23:39', '2019-12-12 16:58:23', NULL, 0, 888, 'excel', 'excel', 0, 'view/example/excel/excel.vue', 'excel导入导出', 's-marketing', 19, '23', 'excel导入导出', '4');
INSERT INTO `sys_menus` VALUES (665, '2019-10-20 11:27:02', '2019-12-12 16:58:27', NULL, 0, 888, 'upload', 'upload', 0, 'view/example/upload/upload.vue', '上传下载', 'upload', 19, '26', '上传下载', '5');
INSERT INTO `sys_menus` VALUES (666, '2020-02-17 16:20:47', '2020-02-24 19:45:40', NULL, 0, 888, 'breakpoint', 'breakpoint', 0, 'view/example/breakpoint/breakpoint.vue', '断点续传', 'upload', 19, '33', '断点续传', '6');
INSERT INTO `sys_menus` VALUES (667, '2020-02-24 19:48:37', '2020-03-27 20:10:02', NULL, 0, 888, 'customer', 'customer', 0, 'view/example/customer/customer.vue', '客户列表(资源示例)', 's-custom', 19, '34', '客户列表(资源示例)', '7');
-- ---------------------------- -- ----------------------------
-- Table structure for sys_users -- Table structure for sys_users
@ -4235,4 +4265,10 @@ CREATE TABLE `sys_workflows` (
-- ---------------------------- -- ----------------------------
INSERT INTO `sys_workflows` VALUES (8, '2019-12-09 15:20:21', '2019-12-09 15:20:21', NULL, '测试改版1', 'test', '123123'); INSERT INTO `sys_workflows` VALUES (8, '2019-12-09 15:20:21', '2019-12-09 15:20:21', NULL, '测试改版1', 'test', '123123');
-- ----------------------------
-- View structure for 111
-- ----------------------------
DROP VIEW IF EXISTS `111`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `111` AS select `sys_base_menus`.`id` AS `id`,`sys_menus`.`menu_id` AS `menu_id`,`sys_base_menus`.`created_at` AS `created_at`,`sys_base_menus`.`updated_at` AS `updated_at`,`sys_base_menus`.`deleted_at` AS `deleted_at`,`sys_base_menus`.`menu_level` AS `menu_level`,`sys_base_menus`.`parent_id` AS `parent_id`,`sys_base_menus`.`path` AS `path`,`sys_base_menus`.`name` AS `name`,`sys_base_menus`.`hidden` AS `hidden`,`sys_base_menus`.`component` AS `component`,`sys_base_menus`.`title` AS `title`,`sys_base_menus`.`icon` AS `icon`,`sys_base_menus`.`nick_name` AS `nick_name`,`sys_base_menus`.`sort` AS `sort` from (`sys_menus` join `sys_base_menus` on((`sys_menus`.`menu_id` = `sys_base_menus`.`id`))) where (`sys_menus`.`authority_id` = 888);
SET FOREIGN_KEY_CHECKS = 1; SET FOREIGN_KEY_CHECKS = 1;

1
server/initialize/db_table.go

@ -10,7 +10,6 @@ func DBTables() {
db := global.GVA_DB db := global.GVA_DB
db.AutoMigrate(model.SysUser{}, db.AutoMigrate(model.SysUser{},
model.SysAuthority{}, model.SysAuthority{},
model.SysMenu{},
model.SysApi{}, model.SysApi{},
model.SysBaseMenu{}, model.SysBaseMenu{},
model.JwtBlacklist{}, model.JwtBlacklist{},

2
server/model/sys_authority.go

@ -30,7 +30,7 @@ func (a *SysAuthority) DeleteAuthority() (err error) {
if err != nil { if err != nil {
err = global.GVA_DB.Where("parent_id = ?", a.AuthorityId).Find(&SysAuthority{}).Error err = global.GVA_DB.Where("parent_id = ?", a.AuthorityId).Find(&SysAuthority{}).Error
if err != nil { if err != nil {
err = global.GVA_DB.Where("authority_id = ?", a.AuthorityId).First(a).Unscoped().Delete(a).Error
err = global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", a.AuthorityId).First(a).Unscoped().Delete(a).Association("SysBaseMenus").Delete(a.SysBaseMenus).Error
new(CasbinModel).clearCasbin(0, a.AuthorityId) new(CasbinModel).clearCasbin(0, a.AuthorityId)
} else { } else {
err = errors.New("此角色存在子角色不允许删除") err = errors.New("此角色存在子角色不允许删除")

34
server/model/sys_authority_menu.go

@ -1,32 +1,19 @@
package model package model
import ( import (
"fmt"
"gin-vue-admin/global" "gin-vue-admin/global"
) )
// menu需要构建的点有点多 这里关联关系表直接把所有数据拿过来 用代码实现关联 后期实现主外键模式 // menu需要构建的点有点多 这里关联关系表直接把所有数据拿过来 用代码实现关联 后期实现主外键模式
type SysMenu struct { type SysMenu struct {
SysBaseMenu SysBaseMenu
MenuId string `json:"menuId"`
MenuID string `json:"menuId"`
AuthorityId string `json:"-"` AuthorityId string `json:"-"`
Children []SysMenu `json:"children"` Children []SysMenu `json:"children"`
} }
// 为角色增加menu树 // 为角色增加menu树
func (m *SysMenu) AddMenuAuthority(menus []SysBaseMenu, authorityId string) (err error) { func (m *SysMenu) AddMenuAuthority(menus []SysBaseMenu, authorityId string) (err error) {
var menu SysMenu
global.GVA_DB.Where("authority_id = ? ", authorityId).Unscoped().Delete(&SysMenu{})
for _, v := range menus {
menu.SysBaseMenu = v
menu.AuthorityId = authorityId
menu.MenuId = fmt.Sprintf("%v", v.ID)
menu.ID = 0
err = global.GVA_DB.Create(&menu).Error
if err != nil {
return err
}
}
var auth SysAuthority var auth SysAuthority
auth.AuthorityId = authorityId auth.AuthorityId = authorityId
auth.SysBaseMenus = menus auth.SysBaseMenus = menus
@ -35,24 +22,27 @@ func (m *SysMenu) AddMenuAuthority(menus []SysBaseMenu, authorityId string) (err
} }
// 查看当前角色树 // 查看当前角色树
func (m *SysMenu) GetMenuAuthority(authorityId string) (err error, menus []SysMenu) {
err = global.GVA_DB.Where("authority_id = ?", authorityId).Find(&menus).Error
return err, menus
func (m *SysMenu) GetMenuAuthority(authorityId string) (err error, menus []SysBaseMenu) {
var a SysAuthority
err = global.GVA_DB.Preload("SysBaseMenus").Where("authority_id = ?", authorityId).First(&a).Error
return err, a.SysBaseMenus
} }
//获取动态路由树 //获取动态路由树
func (m *SysMenu) GetMenuTree(authorityId string) (err error, menus []SysMenu) { func (m *SysMenu) GetMenuTree(authorityId string) (err error, menus []SysMenu) {
err = global.GVA_DB.Where("authority_id = ? AND parent_id = ?", authorityId, 0).Order("sort", true).Find(&menus).Error
SQLstatement := "SELECT authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? AND authority_menu.parent_id = ?"
err = global.GVA_DB.Raw(SQLstatement, authorityId, 0).Scan(&menus).Error
for i := 0; i < len(menus); i++ { for i := 0; i < len(menus); i++ {
err = getChildrenList(&menus[i])
err = getChildrenList(&menus[i], SQLstatement)
} }
return err, menus return err, menus
} }
func getChildrenList(menu *SysMenu) (err error) {
err = global.GVA_DB.Where("authority_id = ? AND parent_id = ?", menu.AuthorityId, menu.MenuId).Order("sort", true).Find(&menu.Children).Error
func getChildrenList(menu *SysMenu, SQLstatement string) (err error) {
err = global.GVA_DB.Raw(SQLstatement, menu.AuthorityId, menu.MenuID).Scan(&menu.Children).Error
for i := 0; i < len(menu.Children); i++ { for i := 0; i < len(menu.Children); i++ {
err = getChildrenList(&menu.Children[i])
err = getChildrenList(&menu.Children[i], SQLstatement)
} }
return err return err
} }

8
server/model/sys_base_menu.go

@ -17,7 +17,6 @@ type SysBaseMenu struct {
Component string `json:"component"` Component string `json:"component"`
Sort string `json:"sort"` Sort string `json:"sort"`
Meta `json:"meta"` Meta `json:"meta"`
NickName string `json:"nickName"`
SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"` SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"`
Children []SysBaseMenu `json:"children"` Children []SysBaseMenu `json:"children"`
} }
@ -31,7 +30,6 @@ type Meta struct {
func (b *SysBaseMenu) AddBaseMenu() (err error) { func (b *SysBaseMenu) AddBaseMenu() (err error) {
findOne := global.GVA_DB.Where("name = ?", b.Name).Find(&SysBaseMenu{}).Error findOne := global.GVA_DB.Where("name = ?", b.Name).Find(&SysBaseMenu{}).Error
if findOne != nil { if findOne != nil {
b.NickName = b.Title
err = global.GVA_DB.Create(b).Error err = global.GVA_DB.Create(b).Error
} else { } else {
err = errors.New("存在重复name,请修改name") err = errors.New("存在重复name,请修改name")
@ -43,8 +41,7 @@ func (b *SysBaseMenu) AddBaseMenu() (err error) {
func (b *SysBaseMenu) DeleteBaseMenu(id float64) (err error) { func (b *SysBaseMenu) DeleteBaseMenu(id float64) (err error) {
err = global.GVA_DB.Where("parent_id = ?", id).First(&SysBaseMenu{}).Error err = global.GVA_DB.Where("parent_id = ?", id).First(&SysBaseMenu{}).Error
if err != nil { if err != nil {
err = global.GVA_DB.Where("id = ?", id).Delete(&b).Error
err = global.GVA_DB.Where("menu_id = ?", id).Unscoped().Delete(&SysMenu{}).Error
err = global.GVA_DB.Preload("SysAuthoritys").Where("id = ?", id).Delete(&b).Association("SysAuthoritys").Delete(b.SysAuthoritys).Error
} else { } else {
return errors.New("此菜单存在子菜单不可删除") return errors.New("此菜单存在子菜单不可删除")
} }
@ -62,14 +59,13 @@ func (b *SysBaseMenu) UpdateBaseMenu() (err error) {
upDateMap["title"] = b.Title upDateMap["title"] = b.Title
upDateMap["icon"] = b.Icon upDateMap["icon"] = b.Icon
upDateMap["sort"] = b.Sort upDateMap["sort"] = b.Sort
upDateMap["nick_name"] = b.Title
err = global.GVA_DB.Where("id = ?", b.ID).Find(&SysBaseMenu{}).Updates(upDateMap).Error err = global.GVA_DB.Where("id = ?", b.ID).Find(&SysBaseMenu{}).Updates(upDateMap).Error
err1 := global.GVA_DB.Where("menu_id = ?", b.ID).Find(&[]SysMenu{}).Updates(upDateMap).Error err1 := global.GVA_DB.Where("menu_id = ?", b.ID).Find(&[]SysMenu{}).Updates(upDateMap).Error
fmt.Printf("菜单修改时候,关联菜单err1:%v,err:%v", err1, err) fmt.Printf("菜单修改时候,关联菜单err1:%v,err:%v", err1, err)
return err return err
} }
//当前选中角色所拥有的路由
// 返回当前选中menu
func (b *SysBaseMenu) GetBaseMenuById(id float64) (err error, menu SysBaseMenu) { func (b *SysBaseMenu) GetBaseMenuById(id float64) (err error, menu SysBaseMenu) {
err = global.GVA_DB.Where("id = ?", id).First(&menu).Error err = global.GVA_DB.Where("id = ?", id).First(&menu).Error
return return

2
web/src/view/layout/index.vue

@ -22,7 +22,7 @@
<el-dropdown> <el-dropdown>
<span class="el-dropdown-link"> <span class="el-dropdown-link">
<img :src="userInfo.headerImg" height="30" width="30" /> <img :src="userInfo.headerImg" height="30" width="30" />
{{userInfo.nickName}}
{{userInfo.title}}
<i class="el-icon-arrow-down"></i> <i class="el-icon-arrow-down"></i>
</span> </span>
<el-dropdown-menu class="dropdown-group" slot="dropdown"> <el-dropdown-menu class="dropdown-group" slot="dropdown">

6
web/src/view/superAdmin/authority/components/apis.vue

@ -44,10 +44,10 @@ export default {
const apiObj = new Object() const apiObj = new Object()
apis && apis &&
apis.map(item => { apis.map(item => {
if (apiObj.hasOwnProperty(item.group)) {
apiObj[item.group].push(item)
if (apiObj.hasOwnProperty(item.apiGroup)) {
apiObj[item.apiGroup].push(item)
} else { } else {
Object.assign(apiObj, { [item.group]: [item] })
Object.assign(apiObj, { [item.apiGroup]: [item] })
} }
}) })
const apiTree = [] const apiTree = []

8
web/src/view/superAdmin/authority/components/menus.vue

@ -34,7 +34,9 @@ export default {
menuTreeIds: [], menuTreeIds: [],
menuDefaultProps: { menuDefaultProps: {
children: 'children', children: 'children',
label: 'nickName'
label: function(data){
return data.meta.title
}
} }
} }
}, },
@ -64,8 +66,8 @@ export default {
const arr = [] const arr = []
menus.map(item => { menus.map(item => {
// //
if (!menus.some(same => same.parentId === item.menuId)) {
arr.push(Number(item.menuId))
if (!menus.some(same => same.parentId === item.ID)) {
arr.push(Number(item.ID))
} }
}) })
this.menuTreeIds = arr this.menuTreeIds = arr

Loading…
Cancel
Save