Based on ASP.Net Core to develop a common framework for the background
EDITORIAL
This is my set up learning in the learning process framework, to help you if it could not be better. If you have found an error, please let me know, I will first modification.
Know, know why not duplicate-create the wheel. Because this time I found myself bored for a long time to write out the code, go look at other people, will be a kind of feeling I understood why. Not only use, but do not know why it is used.
Really, just do not knock, always learn.
Demo Address: http://app.guoddy.com
Source Address: https://github.com/jellydong/LJDAPP
data is not real save, set for the test mode, so avoid login.
development tools
1.Visual Studio 2019
2.SQL Server 2017
3.Power Design
The overall effect
Home
Menu management
)
roles and permissions configuration management
Permissions design & Why
I'm here mainly involving seven tables, four tables, three related tables.
Why this design, I think this might be the needs of most systems.
1. many to many users and roles, a user can have multiple roles, or roles, there is no design sense, a person might actually wear many hats.
2. You can give users direct grant or cancel a permission granted. Some may think this is not necessary, so if this does not involve that five tables. But I have reservations here, because in many cases, this is quite normal demand.
3. unlimited menu levels, configuration parameters based on actual demand, modify the system.
Detailed description
ObjectID
, Remark
, Status
, CreatedBy
, CreatedTime
, ModifiedBy
, ModifiedTime
, Sort
It is the default field.
SysUserInfo user table
- If the user data is large, then, this table actually only need to retain
ObjectID
,ULoginName
,ULoginPWD
on it, so you can improve the speed, no need to put all the information stored.- User and Role-many R_sysUserInfo_sysRole
- Users and Permissions items-many (direct authorize or prohibit) R_UserPermissions
Name | Explanation | Types of | Primary key |
---|---|---|---|
ObjectID | Primary key | nvarchar(50) | TRUE |
ULoginName | username | nvarchar(20) | |
ULoginPWD | password | nvarchar(50) | |
URealName | actual name | nvarchar(10) | |
UTelphone | phone | nvarchar(20) | |
UMobile | phone number | nvarchar(11) | |
UEmail | nvarchar(50) | ||
UQQ | nvarchar(20) | ||
UGender | Gender: 0 F; 1- male; 2- secrecy | int | |
UDepID | Department | nvarchar(50) | |
Remark | Remark | nvarchar(500) | |
Status | Status: 0-enable; disable 1- | int | |
CreatedBy | founder | nvarchar(50) | |
CreatedTime | Created | datetime | |
ModifiedBy | Modifier | nvarchar(50) | |
ModifiedTime | Change the time | datetime | |
Sort | Sort by value | int |
SysRole role table
- Classification of roles, such as administrators, ordinary users.
- Role User-many R_sysUserInfo_sysRole
- Role Permissions many-R_RolePermission
Name | Explanation | Types of | Primary key |
---|---|---|---|
ObjectID | Primary key | nvarchar(50) | TRUE |
RName | Role Name | varchar(50) | |
Remark | Remark | nvarchar(500) | |
Status | Status: 0-enable; disable 1- | int | |
CreatedBy | founder | nvarchar(50) | |
CreatedTime | Created | datetime | |
ModifiedBy | Modifier | nvarchar(50) | |
ModifiedTime | Change the time | datetime | |
Sort | Sort by value | int |
SysMenus menu table
- After the menu design table is a good start, change up a table. The subsequent increase in the development process
IsLast
, ;Hierarchy
removedMAction
- IsLast used to mark is not the last one, if it is our last stage to automatically increase the default method such as additions and deletions.
- Hierarchy used to mark level, in front of us that can be done is unlimited, but typically would be three, so the actual need to set system parameters, maintenance time limit can be checked.
- IsMenuShow是否作为菜单显示,也就是左侧菜单递归的,因为有部分API不需要作为菜单显示,并且授权的方式也会不一样。
- 菜单角色多对多 R_RolePermission
- 菜单权限项一对多
Name | 说明 | 类型 | 主键 |
---|---|---|---|
ObjectID | 主键 | nvarchar(50) | TRUE |
MName | 名称 | nvarchar(100) | |
MUrl | URL | nvarchar(100) | |
MArea | 区域 | nvarchar(100) | |
MController | 控制器 | nvarchar(100) | |
MIcon | 图标 | nvarchar(100) | |
IsLast | 是不是最后一级菜单:0-是;1-否 | int | |
IsMenuShow | 是不是作为菜单显示:0-是;1-否 | int | |
Remark | 备注 | nvarchar(500) | |
ParentID | 父ID | nvarchar(50) | |
Status | 状态:0-启用;1-禁用 | int | |
Hierarchy | 层级 | int | |
CreatedBy | 创建人 | nvarchar(50) | |
CreatedTime | 创建时间 | datetime | |
ModifiedBy | 修改人 | nvarchar(50) | |
ModifiedTime | 修改时间 | datetime | |
Sort | 排序值 | int |
SysFunction 菜单按钮表 (菜单权限项表)
- SysFunction一开始我是叫菜单按钮表的,我计划是查询、新增编辑删除、其他权限这样控制,但后来发现这样不好,所以全都分开,每个方法都要记录。当然为了方便,通用的方法,在增加菜单的时候会自动添加上。
- 菜单权限项菜单是多对一关系
Name | 说明 | 类型 | 主键 |
---|---|---|---|
ObjectID | 主键 | nvarchar(50) | TRUE |
FName | 名称 | nvarchar(50) | |
FFunction | 方法 | nvarchar(50) | |
FIcon | 图标 | nvarchar(50) | |
ParentID | 所属菜单 | nvarchar(50) | |
Remark | 备注 | nvarchar(500) | |
Status | 状态:0-启用;1-禁用 | int | |
CreatedBy | 创建人 | nvarchar(50) | |
CreatedTime | 创建时间 | datetime | |
ModifiedBy | 修改人 | nvarchar(50) | |
ModifiedTime | 修改时间 | datetime | |
Sort | 排序值 | int |
R_sysUserInfo_sysRole用户和角色关联表,记录用户和角色的对应关系。
R_RolePermission 角色菜单权限项关联表。
比如一个角色有用某菜单下的查询和删除权限,那么这个表应该是具有两条记录的。
R_UserPermissions 用户菜单权限项关联表。
HavePermission
记录该用户是 是否有权限:0-无权限;1-有权限
后续处理的时候,要从获取的权限记录中排除直接无权限的记录,增加有权限的。
总结
In fact, many online articles about authority, before their own look, always feel stumbled, so I finally going to do it yourself. Time to finish, and have understood. I do not know what I described here is not unclear or design is reasonable, if you have a problem, please let me know and I will correct immediately!
Do not have unrealistic expectations, hands-knock, like Power Design is the first time I used, but also the first time MarkDown write a blog.
This framework can quickly build applications, T4 template to generate code, suitable for learning. If you have questions, please contact me
Demo Address: http://app.guoddy.com
Source Address: https://github.com/jellydong/LJDAPP
data is not real save, set for the test mode, so avoid login.