Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DataCenter_Core2.1_20190520
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bltdc
DataCenter_Core2.1_20190520
Commits
3afa0d2c
Commit
3afa0d2c
authored
Sep 27, 2019
by
guanzhenshan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加菜单权限控制
parent
0765965b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
0 deletions
+96
-0
dc_menu.cs
Bailun.DC.Models/Menu/dc_menu.cs
+2
-0
MenuServices.cs
Bailun.DC.Services/MenuServices.cs
+91
-0
HomeController.cs
Bailun.DC.Web/Controllers/HomeController.cs
+3
-0
Main.cshtml
Bailun.DC.Web/Views/Home/Main.cshtml
+0
-0
No files found.
Bailun.DC.Models/Menu/dc_menu.cs
View file @
3afa0d2c
...
@@ -44,5 +44,7 @@ namespace Bailun.DC.Models.Menu
...
@@ -44,5 +44,7 @@ namespace Bailun.DC.Models.Menu
/// </summary>
/// </summary>
public
int
delstatus
{
get
;
set
;
}
public
int
delstatus
{
get
;
set
;
}
public
List
<
dc_menu
>
childrens
{
get
;
set
;
}
}
}
}
}
Bailun.DC.Services/MenuServices.cs
0 → 100644
View file @
3afa0d2c
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
Dapper
;
using
MySql.Data.MySqlClient
;
using
Bailun.DC.Models.Menu
;
using
System.Linq
;
namespace
Bailun.DC.Services
{
/// <summary>
/// 采购管理服务
/// </summary>
public
class
MenuServices
{
public
List
<
Models
.
Menu
.
dc_menu
>
ListMenu
(
string
username
)
{
var
list
=
new
List
<
dc_menu
>();
var
obj
=
new
List
<
dc_menu
>();
var
sql
=
$@"select t1.* from dc_menu t1
join dc_menu_permission t2 on t1.id = t2.menuid and t2.delstatus = 0 and t2.username = '
{
username
}
'
where t1.delstatus = 0
union all
select* from dc_menu where 1 = (select isall from dc_menu_permission where username = '
{
username
}
' and isall = 1 and delstatus = 0)"
;
using
(
var
cn
=
new
MySqlConnection
(
Common
.
GlobalConfig
.
ConnectionString
))
{
if
(
cn
.
State
==
System
.
Data
.
ConnectionState
.
Closed
)
{
cn
.
Open
();
}
obj
=
cn
.
Query
<
dc_menu
>(
sql
,
null
,
null
,
true
,
2
*
60
).
ToList
();
}
foreach
(
var
item
in
obj
.
Where
(
a
=>
a
.
parentid
==
0
))
{
GetChildrens
(
item
,
obj
);
list
.
Add
(
item
);
}
return
list
;
}
/// <summary>
/// 检测用户是否有权限访问菜单
/// </summary>
/// <param name="menuname">菜单名称</param>
/// <param name="username">用户名</param>
/// <returns></returns>
public
bool
CheckPermission
(
string
menuname
,
string
username
)
{
var
sql
=
$@"select count(id) from (select t1.* from dc_menu t1
join dc_menu_permission t2 on t1.id=t2.menuid and t2.delstatus=0 and t2.username='
{
username
}
'
where t1.delstatus=0 and t1.name='
{
menuname
}
'
union all
select * from dc_menu where 1 = (select isall from dc_menu_permission where username='
{
username
}
' and isall=1 and delstatus=0)) tb"
;
using
(
var
cn
=
new
MySqlConnection
(
Common
.
GlobalConfig
.
ConnectionString
))
{
if
(
cn
.
State
==
System
.
Data
.
ConnectionState
.
Closed
)
{
cn
.
Open
();
}
var
result
=
cn
.
QueryFirstOrDefault
<
int
>(
sql
,
null
,
null
,
2
*
60
);
return
result
>
0
;
}
}
#
region
Private
private
void
GetChildrens
(
dc_menu
m
,
List
<
dc_menu
>
list
)
{
m
.
childrens
=
new
List
<
dc_menu
>();
var
childrens
=
list
.
Where
(
a
=>
a
.
parentid
==
m
.
id
);
if
(
childrens
.
Count
()
>
0
)
{
foreach
(
var
item
in
childrens
)
{
GetChildrens
(
item
,
list
);
m
.
childrens
.
Add
(
item
);
}
}
}
#
endregion
}
}
Bailun.DC.Web/Controllers/HomeController.cs
View file @
3afa0d2c
...
@@ -51,6 +51,9 @@ namespace Bailun.DC.Web.Controllers
...
@@ -51,6 +51,9 @@ namespace Bailun.DC.Web.Controllers
HttpContext
.
Response
.
Cookies
.
Append
(
"companyid"
,
companyid
+
""
);
HttpContext
.
Response
.
Cookies
.
Append
(
"companyid"
,
companyid
+
""
);
var
listMenu
=
new
Services
.
MenuServices
().
ListMenu
(
username
);
ViewBag
.
menus
=
listMenu
;
return
View
();
return
View
();
}
}
...
...
Bailun.DC.Web/Views/Home/Main.cshtml
View file @
3afa0d2c
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment