HomeController.cs
4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using HHECS.Application.Service;
using HHECS.Model.ClassComparer;
using HHECS.Model.Entities;
using HHECS.Web.Models;
using HHECS.WebCommon.Entities;
using HHECS.WebCommon.Http;
using HHECS.WebCommon.Json;
using HHECS.WebCommon.SystemHelp.Log;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace HHECS.Web.Controllers
{
//[Authorize]
public class HomeController : BaseController
{
private readonly PermissionService _permissionService;
public HomeController(PermissionService permissionService)
{
_permissionService = permissionService;
}
public IActionResult Index()
{
ResponseEnumJosn();
return View();
}
public ActionResult Welcome()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
[HttpGet]
public string GetMenuList()
{
return ExceptionsHelp.Instance.Execute(() =>
{
var response = new Response();
var result = _permissionService.GetAllPermission("WEB");
var permissions = User.Roles.SelectMany(t => t.Permissions).Distinct(new PermissionComparer()).ToList();
WebMenu webMenu = new WebMenu();
webMenu.homeInfo = new HomeInfo() { title = "首页", href = "/Home/Welcome" };
webMenu.logoInfo = new LogoInfo() { title = "华恒机器人系统有限公司", image = "../images/logo.png", href = "" };
webMenu.menuInfo = new List<MenuInfoItem>();
List<Permission> tempPermissions = new List<Permission>();
tempPermissions = result.Data.OrderBy(t => t.OrderNum).ToList();
_permissionService.Combine(tempPermissions.FindAll(t => t.ParentId == null), tempPermissions);
List<Permission> treePermissionDtos = tempPermissions.FindAll(t => t.ParentId == null).ToList();
foreach (var module in treePermissionDtos)
{
MenuInfoItem menuInfoItem = new MenuInfoItem()
{
title = module.PermissionName,
icon = "fa fa-address-book",
href = "",
target = "_self",
child = new List<ChildItem>()
};
foreach (var dir in module.Childrens)
{
ChildItem childItem = new ChildItem()
{
title = dir.PermissionName,
icon = dir.Icon,//"fa fa-address-book",
href = "",
target = "_self",
child = new List<MenuItem>()
};
foreach (var menu in dir.Childrens)
{
MenuItem menuItem = new MenuItem()
{
title = menu.PermissionName,
icon = menu.Icon,//"fa fa-user",
href = menu.WebUrl,
target = "_self",
};
if (permissions.FindAll(t => t.Id == menu.Id).Count > 0 && menu.Visible)
{
childItem.child.Add(menuItem);
}
}
if (permissions.FindAll(t => t.Id == dir.Id).Count > 0 && dir.Visible)
{
menuInfoItem.child.Add(childItem);
}
}
webMenu.menuInfo.Add(menuInfoItem);
}
response.Result = webMenu.ToJson();
return response.ToJson();
});
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}