diff --git a/OpenAuth.App/ModuleManagerApp.cs b/OpenAuth.App/ModuleManagerApp.cs index 1c9a0ad5..ba86c9d2 100644 --- a/OpenAuth.App/ModuleManagerApp.cs +++ b/OpenAuth.App/ModuleManagerApp.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using OpenAuth.Repository.Domain; namespace OpenAuth.App @@ -39,5 +40,25 @@ namespace OpenAuth.App } #endregion 用户/角色分配模块 + + + #region 菜单操作 + /// + /// 删除指定的菜单 + /// + /// + public void DelMenu(string[] ids) + { + UnitWork.Delete(u => ids.Contains(u.Id)); + } + + public void AddMenu(ModuleElement model) + { + UnitWork.Add(model); + } + #endregion + + + } } \ No newline at end of file diff --git a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs index c1c4a279..64f70276 100644 --- a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs +++ b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs @@ -119,16 +119,11 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(orgs); } - public string LoadModule() - { - var orgs = AuthUtil.GetCurrentUser().Modules.MapToList(); - return JsonHelper.Instance.Serialize(orgs); - } - #region 添加编辑模块 - //添加或修改模块 + //添加模块 [HttpPost] + [ValidateInput(false)] public string Add(Module model) { try @@ -143,8 +138,9 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(Result); } - //添加或修改模块 + //修改模块 [HttpPost] + [ValidateInput(false)] public string Update(Module model) { try @@ -178,7 +174,7 @@ namespace OpenAuth.Mvc.Controllers #endregion 添加编辑模块 /// - /// 加载模块的菜单 + /// 加载当前用户可访问模块的菜单 /// /// The module identifier. /// System.String. @@ -195,5 +191,41 @@ namespace OpenAuth.Mvc.Controllers }; return JsonHelper.Instance.Serialize(data); } + + //添加菜单 + [HttpPost] + [ValidateInput(false)] + public string AddMenu(ModuleElement model) + { + try + { + App.AddMenu(model); + } + catch (Exception ex) + { + Result.Code = 500; + Result.Message = ex.Message; + } + return JsonHelper.Instance.Serialize(Result); + } + + /// + /// 删除菜单 + /// + [HttpPost] + public string DelMenu(params string[] ids) + { + try + { + App.DelMenu(ids); + } + catch (Exception e) + { + Result.Code = 500; + Result.Message = e.Message; + } + + return JsonHelper.Instance.Serialize(Result); + } } } \ No newline at end of file diff --git a/OpenAuth.Mvc/Controllers/UserSessionController.cs b/OpenAuth.Mvc/Controllers/UserSessionController.cs index 10caf514..30d048bf 100644 --- a/OpenAuth.Mvc/Controllers/UserSessionController.cs +++ b/OpenAuth.Mvc/Controllers/UserSessionController.cs @@ -21,6 +21,11 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(moduleTree); } + /// + /// datatable结构的模块列表 + /// + /// + /// public string GetModules(string pId) { var query = user.Modules; @@ -36,6 +41,15 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(data); } + /// + /// 普通的List + /// + public string QueryModuleList() + { + var orgs = user.Modules.MapToList(); + return JsonHelper.Instance.Serialize(orgs); + } + /// /// 获取登录用户可访问的所有部门 /// diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index d82f9003..f361262e 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -381,8 +381,6 @@ - - diff --git a/OpenAuth.Mvc/Views/ModuleElementManager/AssignModuleElement.cshtml b/OpenAuth.Mvc/Views/ModuleElementManager/AssignModuleElement.cshtml deleted file mode 100644 index e85b9904..00000000 --- a/OpenAuth.Mvc/Views/ModuleElementManager/AssignModuleElement.cshtml +++ /dev/null @@ -1,25 +0,0 @@ -@{ - Layout = null; -} - - - - - - - -
- - -
    -
    - - -
    -
    -
    -
    - - - - \ No newline at end of file diff --git a/OpenAuth.Mvc/Views/ModuleElementManager/Index.cshtml b/OpenAuth.Mvc/Views/ModuleElementManager/Index.cshtml deleted file mode 100644 index 80308ee7..00000000 --- a/OpenAuth.Mvc/Views/ModuleElementManager/Index.cshtml +++ /dev/null @@ -1,113 +0,0 @@ -@{ - Layout = "~/Views/Shared/_LayoutNoHeader.cshtml"; -} - - -
    -
    -
    -
    -
    -
    - - - -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - - - - - \ No newline at end of file diff --git a/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml b/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml index 9d344ae3..93e8875f 100644 --- a/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml +++ b/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml @@ -9,7 +9,7 @@
      @@ -46,7 +46,7 @@ - + @@ -56,11 +56,18 @@ + - + + + + \ No newline at end of file diff --git a/OpenAuth.Mvc/js/modules.js b/OpenAuth.Mvc/js/modules.js index be3159bc..a0b9d882 100644 --- a/OpenAuth.Mvc/js/modules.js +++ b/OpenAuth.Mvc/js/modules.js @@ -7,7 +7,7 @@ layui.config({ $ = layui.jquery; var table = layui.table; var openauth = layui.openauth; - layui.droptree("/moduleManager/LoadModule", "#ParentName", "#ParentId", false); + layui.droptree("/UserSession/QueryModuleList", "#ParentName", "#ParentId", false); //主列表加载,可反复调用进行刷新 var config= {}; //table的参数,如搜索key,点击tree的id @@ -35,7 +35,7 @@ layui.config({ //左边树状机构列表 var ztree = function () { - var url = '/ModuleManager/LoadModule'; + var url = '/UserSession/QueryModuleList'; var zTreeObj; var setting = { view: { selectedMulti: false }, @@ -73,7 +73,7 @@ layui.config({ } }(); - //添加(编辑)对话框 + //添加(编辑)模块对话框 var editDlg = function() { var vm = new Vue({ el: "#formEdit" @@ -121,8 +121,58 @@ layui.config({ } }; }(); + + //添加菜单对话框 + var meditDlg = function () { + var vm = new Vue({ + el: "#mfromEdit" + }); + var update = false; //是否为更新 + var show = function (data) { + var title = update ? "编辑信息" : "添加"; + layer.open({ + title: title, + area: ["500px", "400px"], + type: 1, + content: $('#divMenuEdit'), + success: function () { + vm.$set('$data', data); + }, + end: menuList + }); + var url = "/moduleManager/AddMenu"; + if (update) { + url = "/moduleManager/UpdateMenu"; + } + //提交数据 + form.on('submit(mformSubmit)', + function (data) { + $.post(url, + data.field, + function (data) { + layer.msg(data.Message); + }, + "json"); + return false; + }); + } + return { + add: function (moduleId) { //弹出添加 + update = false; + show({ + Id: "", + ModuleId:moduleId, + SortNo: 1 + }); + }, + update: function (data) { //弹出编辑框 + update = true; + show(data); + } + }; + }(); - //监听表格内部按钮 + //监听模块表格内部按钮 table.on('tool(list)', function (obj) { var data = obj.data; if (obj.event === 'detail') { //查看 @@ -131,6 +181,15 @@ layui.config({ } }); + //监听菜单表格内部按钮 + table.on('tool(menulist)', function (obj) { + var data = obj.data; + if (obj.event === 'del') { //删除菜单 + openauth.del("/moduleManager/delMenu", + data.Id,menuList); + } + }); + //监听页面主按钮操作 var active = { @@ -141,8 +200,17 @@ layui.config({ data.map(function (e) { return e.Id; }), mainList); } - , btnAdd: function () { //添加 + , btnAdd: function () { //添加模块 editDlg.add(); + } + , btnAddMenu: function () { //添加菜单 + var checkStatus = table.checkStatus('mainList') + , data = checkStatus.data; + if (data.length != 1) { + layer.msg("请选择一个要添加菜单的模块"); + return; + } + meditDlg.add(data[0]); } , btnEdit: function () { //编辑 var checkStatus = table.checkStatus('mainList')
      名称 DomId 样式图标图标 排序号