254 lines
8.9 KiB
C#
254 lines
8.9 KiB
C#
using Mini.Common;
|
|
using Air.Model.AirAdminViewModel;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Mini.Services.Bas;
|
|
using Mini.Web.WebHelper;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
namespace Mini.Web.Areas.Admin.Controllers
|
|
{
|
|
public class MenuController : BaseController
|
|
{
|
|
private readonly IBasLeftMenuService _basLeftMenuService;
|
|
private readonly IBasModuleMenuService _basModuleMenuService;
|
|
private readonly IHostingEnvironment _hostingEnvironment;
|
|
private ValidationErrors errors = new ValidationErrors();
|
|
public MenuController(IBasLeftMenuService basLeftMenuService, IBasModuleMenuService basModuleMenuService,IHostingEnvironment hostingEnvironment)
|
|
{
|
|
this._basLeftMenuService = basLeftMenuService;
|
|
this._basModuleMenuService = basModuleMenuService;
|
|
this._hostingEnvironment = hostingEnvironment;
|
|
}
|
|
[AuthorizeRedirect(InitRights.CONST_菜单管理)]
|
|
[Area("Admin")]
|
|
public ActionResult Index()
|
|
{
|
|
//ToolBar
|
|
ToolBar tool = new ToolBar();
|
|
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.菜单管理, userRightId);
|
|
List<string> listBtn = new List<string>(toolbtn);
|
|
List<string> Buttons = new List<string>();
|
|
Buttons.Add("Other6");
|
|
Buttons.Add("Other7");
|
|
Buttons.Add("Other5");
|
|
Buttons.AddRange(listBtn);
|
|
tool.AllowButton(Buttons.ToArray());
|
|
// tool.AllowButton("Other4", "Other5", "Other6", "Other7", "Other3", "Other1", "Other2", "Edit", "Delete");
|
|
tool.AddOtherButton("Other1", "新增模块菜单", "icon-add", "AddBas_ModuleMenu_Click", true);
|
|
tool.AddOtherButton("Other2", "新增系统菜单", "icon-add", "AddBas_leftMemu_Click", true);
|
|
tool.AddOtherButton("Other5", "刷新", "icon-reload", "Reload_Click", true);
|
|
tool.AddOtherButton("Other6", "展开全部", "icon-flag", "ExpandAll_Click", true);
|
|
tool.AddOtherButton("Other7", "折叠全部", "icon-show", "CollapseAll_Click", true);
|
|
tool.AddOtherButton("Other3", "向上", "icon-up", "Up_Click", true);
|
|
tool.AddOtherButton("Other4", "向下", "icon-down", "Down_Click", true);
|
|
|
|
ViewBag.ToolBar = tool;
|
|
return View();
|
|
}
|
|
|
|
|
|
#region ModuleMenu编辑
|
|
[HttpGet]
|
|
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Edit)]
|
|
[Area("Admin")]
|
|
public ActionResult ModuleEdit(int? Id)
|
|
{
|
|
if (Id.HasValue)
|
|
{
|
|
var model = _basModuleMenuService.Get(Id.Value);
|
|
if (model.RightId != null)
|
|
model.RightId = model.RightId;
|
|
return View(model);
|
|
}
|
|
return View();
|
|
}
|
|
[HttpPost]
|
|
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Edit)]
|
|
[Area("Admin")]
|
|
public JsonResult ModuleEdit(Bas_ModuleMenuModel model)
|
|
{
|
|
//if (!ModelState.IsValid)
|
|
// return JsonHandler.ValidateFailMessage();
|
|
if (model.RightId != null)
|
|
model.RightId = model.RightId;
|
|
if (model.ModuleMenuId == 0)
|
|
{
|
|
model.CTime = DateTime.Now;
|
|
_basModuleMenuService.Create(model);
|
|
return JsonHandler.InsertMessage(errors, true);
|
|
}
|
|
else
|
|
{
|
|
_basModuleMenuService.Update(model);
|
|
return JsonHandler.UpdateMessage(errors, true);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ModuleMenu删除
|
|
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Delete)]
|
|
[Area("Admin")]
|
|
public JsonResult ModuleDelete(Bas_ModuleMenuModel model)
|
|
{
|
|
if (model.ModuleMenuId <= 0)
|
|
return JsonHandler.ManageMessage("参数不对", false);
|
|
_basModuleMenuService.Delete(model);
|
|
return JsonHandler.DeleteMessage(errors, true);
|
|
}
|
|
#endregion
|
|
|
|
#region ModuleMenu修改顺序
|
|
/// <summary>
|
|
/// 修改顺序
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Area("Admin")]
|
|
public JsonResult ModuleSaveSortId(string ids, string sortIds)
|
|
{
|
|
_basModuleMenuService.Sort(ids, sortIds);
|
|
return JsonHandler.ManageMessage(errors, true);
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region LeftMenu编辑
|
|
[HttpGet]
|
|
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Other2)]
|
|
[Area("Admin")]
|
|
public ActionResult LeftMenuEdit(int? id, int? fid)
|
|
{
|
|
ViewBag.notId= Request.Query["notId"].ToString();
|
|
var model = new Bas_LeftMemuModel();
|
|
model.IsGroup = 0;
|
|
model.IsShow = 1;
|
|
if (fid.HasValue)
|
|
{
|
|
model.ParentId = fid.Value;
|
|
}
|
|
else
|
|
{
|
|
model.ParentId = null;
|
|
}
|
|
if (id.HasValue)
|
|
{
|
|
model = _basLeftMenuService.Get(id.Value);
|
|
if (model.ParentId == 0)
|
|
model.ParentId = -model.ModuleMenuId;
|
|
if (model.ParentId.HasValue)
|
|
model.ParentId = model.ParentId;
|
|
return View(model);
|
|
}
|
|
return View(model);
|
|
}
|
|
[HttpPost]
|
|
[Area("Admin")]
|
|
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Other2)]
|
|
public JsonResult LeftMenuEdit(Bas_LeftMemuModel model)
|
|
{
|
|
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return JsonHandler.ValidateFailMessage();
|
|
}
|
|
if (model.ParentId < 0)
|
|
model.ParentId = 0;
|
|
if (model.ParentId != null)
|
|
model.ParentId = model.ParentId;
|
|
if (model.MenuId == 0)
|
|
{
|
|
model.CTime = DateTime.Now;
|
|
_basLeftMenuService.Create(model);
|
|
return JsonHandler.InsertMessage(errors, true);
|
|
}
|
|
else
|
|
{
|
|
_basLeftMenuService.Update(model);
|
|
return JsonHandler.UpdateMessage(errors, true);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region LeftMenu删除
|
|
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Delete)]
|
|
[Area("Admin")]
|
|
public JsonResult LeftMenuDelete(Bas_LeftMemuModel model)
|
|
{
|
|
if (model.MenuId <= 0)
|
|
{
|
|
return JsonHandler.ManageMessage("参数不对!", false);
|
|
}
|
|
//bool result = leftMemuBiz.Delete_leftMemu(ref errors, Convert.ToDecimal(id));
|
|
_basLeftMenuService.Delete(model);
|
|
return JsonHandler.DeleteMessage(errors, true);
|
|
}
|
|
#endregion
|
|
|
|
#region LeftMenu修改顺序
|
|
/// <summary>
|
|
/// 修改顺序
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[AuthorizeToolBar(InitRights.CONST_菜单管理, InitToolBar.CONST_Other3)]
|
|
[Area("Admin")]
|
|
public JsonResult LeftMenuSaveSortId(string ids, string sortIds)
|
|
{
|
|
_basLeftMenuService.Sort(ids, sortIds);
|
|
return JsonHandler.ManageMessage(errors, true);
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 获取菜单的所有数据
|
|
/// <summary>
|
|
/// 获取菜单的所有数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Area("Admin")]
|
|
public JsonResult GetMenuTreeJson()
|
|
{
|
|
object leftMemuList = _basLeftMenuService.GetTreeList_leftMenu();
|
|
return Json(leftMemuList);
|
|
}
|
|
/// <summary>
|
|
/// 获取菜单的所有数据 更新权限
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Area("Admin")]
|
|
public JsonResult GetMenuTreeJsonByRight()
|
|
{
|
|
object leftMemuList = _basLeftMenuService.GetTreeList_leftMenu(userRightId);
|
|
return Json(leftMemuList);
|
|
}
|
|
#endregion
|
|
#region 获取模块图片
|
|
/// <summary>
|
|
/// 读取/Content/Menu 的所有模块图标
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[Area("Admin")]
|
|
public JsonResult GetMenuImg()
|
|
{
|
|
List<object> obj = new List<object>();
|
|
string[] imgExtension = new string[] { ".png", ".gif" };
|
|
string folder = _hostingEnvironment.WebRootPath+"/Content/Images/Menu";
|
|
DirectoryInfo TheFolder = new DirectoryInfo(folder);
|
|
foreach (FileInfo info in TheFolder.GetFiles())
|
|
{
|
|
if (imgExtension.Contains(info.Extension))
|
|
{
|
|
obj.Add(new { name = info.Name, imgurl = "/Content/Images/Menu/" + info.Name });
|
|
}
|
|
}
|
|
return Json(obj);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |