环境:项目原因需要,需要用户根据自身的角色,公司,登陆网站,显示当前用户需要展示的页面,以及该用户需要显示执行的权限,没有权限,则不显示该权限的按键,根据表结构去实现逻辑,实现用户管理
表逻辑:
组织(公司|职务)《=》用户(账号)《=》角色(岗位)《=》资源(页面|权限)
create table organization
(
id bigint(19) auto_increment comment '主键id'
primary key,
name varchar(64) not null comment '组织名',
address varchar(100) null comment '地址',
code varchar(64) not null comment '编号',
icon varchar(32) null comment '图标',
pid bigint(19) null comment '父级主键',
seq tinyint(2) default 0 not null comment '排序',
create_time datetime not null comment '创建时间'
)
comment '组织机构';
create table user
(
id bigint(19) auto_increment comment '主键id'
primary key,
login_name varchar(64) not null comment '登陆名',
name varchar(64) not null comment '用户名',
password varchar(64) not null comment '密码',
openid varchar(50) null comment '微信id',
sex tinyint(2) default 0 not null comment '性别',
age tinyint(2) default 0 null comment '年龄',
phone varchar(20) null comment '手机号',
user_type tinyint(2) default 0 not null comment '用户类别',
status tinyint(2) default 0 not null comment '用户状态',
organization_id int default 0 not null comment '所属机构',
create_time datetime not null comment '创建时间',
constraint IDx_user_login_name
unique (login_name)
)
comment '用户';
create table role
(
id bigint(19) auto_increment comment '主键id'
primary key,
name varchar(64) not null comment '角色名',
seq tinyint(2) default 0 not null comment '排序号',
description varchar(255) null comment '简介',
status tinyint(2) default 0 not null comment '状态'
)
comment '角色';
create table user_role
(
id bigint(19) auto_increment comment '主键id'
primary key,
user_id bigint(19) not null comment '用户id',
role_id bigint(19) not null comment '角色id'
)
comment '用户角色';
create index idx_user_role_ids
on Longi.user_role (user_id, role_id);
create table resource
(
id bigint(19) auto_increment comment '主键',
name varchar(64) not null comment '资源名称',
url varchar(100) null comment '资源路径',
description varchar(255) null comment '资源介绍',
icon varchar(32) null comment '资源图标',
pid bigint(19) null comment '父级资源id',
seq bigint default 0 not null comment '排序',
status tinyint(2) default 0 not null comment '状态',
resource_type bigint default 0 not null comment '资源类别',
create_time datetime not null comment '创建时间',
constraint resource_id_uindex
unique (id)
)
comment '资源';
create table role_resource
(
id bigint(19) auto_increment comment '主键id'
primary key,
role_id bigint(19) not null comment '角色id',
resource_id bigint(19) not null comment '资源id'
)
comment '角色资源';
create index idx_role_resource_ids
on Longi.role_resource (role_id, resource_id);
实现效果:
PS:这个页面是资源页面,其他逻辑还要自己去实现前后台交互,根据表结构实现,非常方便,个人就是这样实现的,祝好运~