SysModuleController.cs
7.75 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
using Hh.Mes.Pojo.System;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.POJO.ViewModel;
using Hh.Mes.Service.SystemAuth;
using Hh.Mes.Service.WebService.Base;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using WebMvc.Aop;
namespace WebMvc
{
/// <summary>
/// 模块管理
/// </summary>
[Area("base")]
public class SysModuleController : BaseController
{
private readonly SysModuleService service;
private readonly List<CheckBoxItem> defaultBtns;
private readonly int MaxAreas = 3;
public SysModuleController(IAuth authUtil, SysModuleService service) : base(authUtil)
{
this.service = service;
this.service.sysWebUser = authUtil.GetCurrentUser().User;
defaultBtns = service.DefaultBtns;
}
// GET: /SysModule/
[Authenticate]
public ActionResult Index()
{
return View();
}
[Authenticate]
public ActionResult Assign()
{
return View();
}
/// <summary>
/// 常用按钮展示页面
/// </summary>
/// <param name="moduleId">菜单Id</param>
/// <returns></returns>
[Authenticate]
public IActionResult CommonBtn(int moduleId)
{
var user = _authUtil.GetCurrentUser();
var module = user.Modules.SingleOrDefault(u => u.Id == moduleId);
ViewBag.Name = $"{module.ParentName}/{module.Name}";
ViewBag.ModuleId = moduleId;
var areaBtns = new List<AreaBtnModel>();
for (int i = 1; i <= MaxAreas; i++)
{
var areaBtnItem = new AreaBtnModel
{
Area = i.ToString(),
};
var data = module?.Elements.Where(x => x.AreaMenus.Equals(i.ToString())).ToList();
if (data.Any())
{
var btns = data.Where(btn => defaultBtns.Select(x => x.Value).Contains(btn.DomId)).Select(n => new CheckBoxItem
{
Text = n.Name,
Value = n.DomId,
Icon = n.Icon,
BtnClass = n.Class,
Sort = (int)n.Sort,
Checked = true
}).ToList();
var disenableBtns = defaultBtns.Where(x => !btns.Select(b => b.Value).Contains(x.Value)).ToList();
btns.AddRange(disenableBtns);
areaBtnItem.CheckBoxItems = btns;
}
else
{
areaBtnItem.CheckBoxItems = defaultBtns;
}
areaBtns.Add(areaBtnItem);
}
return View(areaBtns);
}
/// <summary>
/// 更新常用按钮
/// </summary>
/// <param name="moduleId">菜单页面编号</param>
/// <param name="area1">区域1按钮集合</param>
/// <param name="area2">区域2按钮集合</param>
/// <param name="area3">区域3按钮集合</param>
/// <returns></returns>
[HttpPost]
public IActionResult SaveChanageCommonBtn(int moduleId, List<string> area1, List<string> area2, List<string> area3)
{
try
{
var modulesView = _authUtil.GetCurrentUser().Modules;
service.SaveChanageCommonBtn(moduleId, area1, area2, area3, modulesView);
return Content($"操作成功,请手动关闭页面!");
}
catch (Exception ex)
{
return Content($"操作失败,{ex.Message}");
}
}
/// <summary>
/// 加载特定用户的模块
/// </summary>
/// <param name="firstId">The user identifier.</param>
/// <returns>System.String.</returns>
public string LoadForUser(int firstId)
{
var modules = service.LoadForUser(firstId);
return Serialize(modules);
}
/// <summary>
/// 根据某用户ID获取可访问某模块的菜单项
/// </summary>
/// <returns></returns>
public string LoadMenusForUser(int moduleId, int firstId)
{
var menus = service.LoadMenusForUser(moduleId, firstId);
return Serialize(menus);
}
/// <summary>
/// 加载角色模块
/// </summary>
/// <param name="firstId">The role identifier.</param>
/// <returns>System.String.</returns>
public string LoadForRole(int firstId)
{
var modules = service.LoadForRole(firstId);
return Serialize(modules);
}
/// <summary>
/// 根据某角色ID获取可访问某模块的菜单项
/// </summary>
/// <returns></returns>
public string LoadMenusForRole(int moduleId, int firstId)
{
var menus = service.LoadMenusForRole(moduleId, firstId);
return Serialize(menus);
}
/// <summary>
/// 获取发起页面的菜单权限
/// </summary>
/// <returns>System.String.</returns>
public string LoadAuthorizedMenus(string modulecode, string AreaMenus)
{
var user = _authUtil.GetCurrentUser();
var module = user.Modules.Find(u => u.Code == modulecode);
if (module != null)
{
var moduleMenus = module.Elements.FindAll(u => u.AreaMenus == AreaMenus);
return Serialize(moduleMenus);
}
return "";
}
#region 添加编辑模块
//添加模块
[HttpPost]
[XSSFilter]
public string Add(SysModule model)
{
model.Url = model.Url ?? "";
return Serialize(service.Ins(model));
}
//修改模块
[HttpPost]
[XSSFilter]
public string Update(SysModule model)
{
model.Url = model.Url ?? "";
return Serialize(service.Upd(model));
}
/// <summary>
/// 删除模块
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
[HttpPost]
public string Delete(int[] ids)
{
return Serialize(service.DelById(ids));
}
#endregion 添加编辑模块
/// <summary>
/// 加载当前用户可访问模块的菜单
/// </summary>
/// <param name="moduleId">The module identifier.</param>
/// <returns>System.String.</returns>
public string LoadMenus(int moduleId)
{
var user = _authUtil.GetCurrentUser();
var data = new Response();
if (moduleId != 0)
{
var module = user.Modules.SingleOrDefault(u => u.Id == moduleId);
if (module != null)
{
data.Result = module.Elements;
data.Count = module.Elements.Count();
}
}
return Serialize(data);
}
//添加菜单
[HttpPost]
[XSSFilter]
public string AddMenu(SysModuleElement model)
{
return Serialize(service.AddMenu(model, this.service.sysWebUser.Account));
}
//添加菜单
[HttpPost]
[XSSFilter]
public string UpdateMenu(SysModuleElement model)
{
return Serialize(service.UpdateMenu(model));
}
/// <summary>
/// 删除菜单
/// </summary>
[HttpPost]
public string DelMenu(params int[] ids)
{
return Serialize(service.DelMenu(ids));
}
}
}