HomeController.cs
4.78 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using HHECS.DAQWebClient.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
namespace HHECS.DAQWebClient.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
return View();
}
public IActionResult Welcome()
{
return View();
}
[HttpGet]
public IActionResult SystemMenu()
{
var systemMenuEntities = new List<SystemMenuEntity>();
//using (SystemMenuDbContext dbContext = new SystemMenuDbContext())
//{
// systemMenuEntities = dbContext.SystemMenus.Where(s => s.id > 0).ToList();
//}
SystemMenu rootNode = new SystemMenu()
{
Id = 0,
Icon = "",
Href = "",
Title = "根目录",
};
GetTreeNodeListByNoLockedDTOArray(systemMenuEntities, rootNode);
MenusInfoResultDTO menusInfoResultDTO = new MenusInfoResultDTO
{
MenuInfo = rootNode.Child,
LogoInfo = new LogoInfo(),
HomeInfo = new HomeInfo()
};
return new JsonResult(menusInfoResultDTO);
}
/// <summary>
/// 递归处理数据
/// </summary>
/// <param name="systemMenuEntities"></param>
/// <param name="rootNode"></param>
private static void GetTreeNodeListByNoLockedDTOArray(List<SystemMenuEntity> systemMenuEntities, SystemMenu rootNode)
{
if (systemMenuEntities == null || systemMenuEntities.Count <= 0)
{
return;
}
var childreDataList = systemMenuEntities.Where(p => p.pid == rootNode.Id);
if (childreDataList != null && childreDataList.Any())
{
rootNode.Child = new List<SystemMenu>();
foreach (var item in childreDataList)
{
SystemMenu treeNode = new SystemMenu()
{
Id = item.id,
Icon = item.icon,
Href = item.href,
Title = item.title,
};
rootNode.Child.Add(treeNode);
}
foreach (var item in rootNode.Child)
{
GetTreeNodeListByNoLockedDTOArray(systemMenuEntities, item);
}
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
/// <summary>
/// 菜单结果对象
/// </summary>
public class MenusInfoResultDTO
{
/// <summary>
/// 权限菜单树
/// </summary>
public List<SystemMenu> MenuInfo { get; set; } = new List<SystemMenu>();
/// <summary>
/// logo
/// </summary>
public LogoInfo LogoInfo { get; set; } = new LogoInfo();
/// <summary>
/// Home
/// </summary>
public HomeInfo HomeInfo { get; set; } = new HomeInfo();
}
public class LogoInfo
{
public string Title { get; set; } = "一个牛逼的免费前端框架";
public string Image { get; set; } = "images/logo.png";
public string Href { get; set; } = "";
}
public class HomeInfo
{
public string Title { get; set; } = "首页";
public string Href { get; set; } = "page/welcome-1.html?t=1";
}
/// <summary>
/// 树结构对象
/// </summary>
public class SystemMenu
{
/// <summary>
/// 数据ID
/// </summary>
public long Id { get; set; }
/// <summary>
/// 父级ID
/// </summary>
public long PId { get; set; }
/// <summary>
/// 节点名称
/// </summary>
public string Title { get; set; } = null!;
/// <summary>
/// 节点地址
/// </summary>
public string Href { get; set; } = null!;
/// <summary>
/// 新开Tab方式
/// </summary>
public string Target { get; set; } = "_self";
/// <summary>
/// 菜单图标样式
/// </summary>
public string Icon { get; set; } = null!;
/// <summary>
/// 排序
/// </summary>
public int Sort { get; set; }
/// <summary>
/// 子集
/// </summary>
public List<SystemMenu> Child { get; set; } = new List<SystemMenu>();
}
}