using Estsh.Core.Controllers;
using Estsh.Core.IServices;
using Estsh.Core.Model.Result;
using Estsh.Core.Models;
using Estsh.Core.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections;
/***************************************************************************************************
*
* 更新人:sitong.dong
* 描述:菜单模块控制类
* 修改时间:2022.06.22
* 修改日志:系统迭代升级
*
**************************************************************************************************/
namespace Estsh.Core.Web.Controllers
{
///
/// 菜单模块控制类
///
public class MenuController : BaseController
{
private IMenuService service;
public MenuController(IMenuService _service)
{
service = _service;
}
//
// GET: /Menu/
public ActionResult Index()
{
return View();
}
///
/// 加载首页功能菜单
///
///
public ActionResult getHomeMenuById(string menuId)
{
Hashtable result = new Hashtable();
if (CurrentEmp != null)
{
result = service.getHomeMenuList(CurrentEmp, menuId);
}
return Json(result);
}
///
/// 加载Main页功能主菜单
///
///
public ActionResult getMainMenuById(string menuId)
{
Hashtable result = new Hashtable();
if (CurrentEmp != null)
{
result = service.getMainMenuList(CurrentEmp, menuId);
}
return Json(result);
}
///
/// 加载Main页功能子菜单
///
///
public ActionResult getChildMenuById(string menuId)
{
string path = HttpContext.Request.PathBase;
if (path.EndsWith("/"))
{
path = path.Substring(0, path.Length - 1);
}
Hashtable result = new Hashtable();
if (CurrentEmp != null)
{
result = service.getChildMenuList(CurrentEmp, menuId, path);
}
return Json(result);
}
///
/// 加载非Tab的Main页功能子菜单
///
///
public ActionResult getNoNTabChildMenuById(string menuId)
{
string path = HttpContext.Request.PathBase;
if (path.EndsWith("/"))
{
path = path.Substring(0, path.Length - 1);
}
Hashtable result = new Hashtable();
if (CurrentEmp != null)
{
result = service.getNoNTabChildMenuList(CurrentEmp, menuId, path);
}
return Json(result);
}
///
/// 获取菜单管理列表数据
///
/// 菜单名称
/// 分页
/// 排序方式
/// 排序列
///
public ActionResult getMenuListByPage(String menuName, Pager pager, String direction, String sort, String enabled = "Y")
{
Hashtable result = new Hashtable();
result.Add("pager.pageNo", pager.pageNo);
Hashtable dataHt = service.getMenuListByPage(menuName, pager, direction, sort, enabled);
result.Add("rows", dataHt["dataList"]);
result.Add("pager.totalRows", dataHt["totalCount"]);
result.Add("sort", sort);
result.Add("direction", direction);
return Json(result);
}
///
/// 获取父节点菜单下拉列表数据
///
///
public ActionResult getSelectMenu()
{
Hashtable result = new Hashtable();
List menuList = service.getSelectMenu();
result.Add("list", menuList);
return Json(result);
}
///
/// 保存菜单数据
///
///
public ActionResult saveMenu()
{
String editType = Request.Form["editType"].ToString();
SysWebMenu menu = new SysWebMenu();
menu.Name = Request.Form["menuName"].ToString();
menu.ParentId = int.Parse(Request.Form["parentId"]);
menu.Url = Request.Form["url"].ToString();
menu.IconUrl = Request.Form["iconUrl"].ToString();
menu.IconOpenUrl = Request.Form["iconOpenUrl"].ToString();
menu.IconCloseUrl = Request.Form["iconCloseUrl"].ToString();
menu.IconSkin = Request.Form["iconSkin"].ToString();
menu.Enabled = Request.Form["enabled"].ToString();
menu.Description = Request.Form["description"].ToString();
menu.SortNum = int.Parse(Request.Form["sortNum"]);
String message = "";
String flag = "";
if (editType != null && editType.Trim().Equals("edit"))
{
try
{
menu.UpdateUserId = CurrentEmp.EmpId;
menu.MenuId = int.Parse(Request.Form["menuId"]);
service.updateMenu(menu);
message = "修改成功";
flag = "OK";
}
catch (Exception e)
{
message = "修改失败!";
flag = "Fail";
}
}
else
{
try
{
menu.CreateUserId = CurrentEmp.EmpId;
this.service.saveMenu(menu);
message = "添加成功";
flag = "OK";
}
catch (Exception e)
{
message = "添加失败!";
flag = "Fail";
}
}
Hashtable result = new Hashtable();
result.Add("message", message);
result.Add("flag", flag);
return Json(result);
}
///
/// 查看菜单详情
///
///
///
public ActionResult getMenuDetail(String menuId)
{
List menus = this.service.getMenuDetail(menuId);
if (menus != null && menus.Count > 0)
{
ViewData.Add("menuId", menus[0].MenuId);
ViewData.Add("name", menus[0].Name);
ViewData.Add("description", menus[0].Description);
ViewData.Add("url", menus[0].Url);
ViewData.Add("parentId", menus[0].ParentId);
ViewData.Add("iconUrl", menus[0].IconUrl);
ViewData.Add("iconOpenUrl", menus[0].IconOpenUrl);
ViewData.Add("iconCloseUrl", menus[0].IconCloseUrl);
ViewData.Add("iconSkin", menus[0].IconSkin);
ViewData.Add("enabled", menus[0].Enabled);
ViewData.Add("sortNum", menus[0].SortNum);
}
return View("viewMenu");
}
///
/// 编辑菜单
///
///
///
public ActionResult editMenu(String menuId)
{
if (!string.IsNullOrEmpty(menuId))
{
List menus = service.getMenuDetail(menuId);
if (menus != null & menus.Count > 0)
{
ViewData.Add("editType", "edit");
ViewData.Add("menuId", menuId);
ViewData.Add("name", menus[0].Name);
ViewData.Add("description", menus[0].Description);
ViewData.Add("url", menus[0].Url);
ViewData.Add("parentId", menus[0].ParentId);
ViewData.Add("iconUrl", menus[0].IconUrl);
ViewData.Add("iconOpenUrl", menus[0].IconOpenUrl);
ViewData.Add("iconCloseUrl", menus[0].IconCloseUrl);
ViewData.Add("iconSkin", menus[0].IconSkin);
ViewData.Add("enabled", menus[0].Enabled);
ViewData.Add("sortNum", menus[0].SortNum);
}
}
else
{
ViewData.Add("editType", "new");
}
return View("editMenu");
}
///
/// 删除菜单
///
///
///
public ActionResult deleteMenu(String ids)
{
int delCount = 0;
try
{
delCount = service.deleteMenu(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 启用
///
///
///
public ActionResult onEnable(String ids)
{
int delCount = 0;
try
{
delCount = this.service.EnableData(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 禁用
///
///
///
public ActionResult onDisable(String ids)
{
int delCount = 0;
try
{
delCount = this.service.DisableData(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 获取操作权限
///
///
public ActionResult getButtonList()
{
List result = new List();
String path = Request.PathBase;
if (path.EndsWith("/"))
{
path = path.Substring(0, path.Length - 1);
}
Uri? uri = Request.GetTypedHeaders().Referer;
string urlStr = string.Empty;
if (uri != null)
{
urlStr = uri.AbsolutePath;
if (!string.IsNullOrEmpty(path))
{
urlStr = urlStr.Substring(urlStr.LastIndexOf(path) + path.Length);
}
if (uri.AbsoluteUri.Split('?').Length > 1)
{
urlStr = urlStr + "?" + uri.AbsoluteUri.Split('?')[1];
}
}
string opType = HttpContext.Request.Form["opType"];
string gridName = HttpContext.Request.Form["gridName"];
if (CurrentEmp != null && !string.IsNullOrEmpty(urlStr))
{
result = service.getOpMenuList(CurrentEmp, urlStr, opType, gridName);
}
return Json(result);
}
///
/// 获取小尺寸工具栏
///
///
public ActionResult getMinToolbar()
{
List result = new List();
try
{
String path = Request.PathBase;
if (path.EndsWith("/"))
{
path = path.Substring(0, path.Length - 1);
}
Uri? uri = Request.GetTypedHeaders().Referer;
string urlStr = string.Empty;
if (uri != null)
{
urlStr = uri.AbsolutePath;
if (!string.IsNullOrEmpty(path))
{
urlStr = urlStr.Substring(urlStr.LastIndexOf(path) + path.Length);
}
if (uri.AbsoluteUri.Split('?').Length > 1)
{
urlStr = urlStr + "?" + uri.AbsoluteUri.Split('?')[1];
}
}
string opType = HttpContext.Request.Form["opType"];
if (CurrentEmp != null && !string.IsNullOrEmpty(urlStr))
{
result.Add(service.getMinToolbar(CurrentEmp, urlStr, opType));
}
}
catch (Exception e)
{
result.Add(e.Message);
}
return Json(result);
}
}
}