diff --git a/OpenAuth.App/AuthorizeApp.cs b/OpenAuth.App/AuthorizeApp.cs index a6f000e4..67e862c8 100644 --- a/OpenAuth.App/AuthorizeApp.cs +++ b/OpenAuth.App/AuthorizeApp.cs @@ -11,29 +11,29 @@ namespace OpenAuth.App /// public class AuthorizeApp { - private readonly AuthoriseService _service; + private readonly AuthoriseFactory _factory; - public AuthorizeApp(AuthoriseService service) + public AuthorizeApp(AuthoriseFactory service) { - _service = service; + _factory = service; } public UserWithAccessedCtrls GetAccessedControls(string username) { - _service.LoadAuthControls(username); + var service = _factory.Create(username); var user = new UserWithAccessedCtrls { - User = _service.User, - Orgs = _service.Orgs, - Modules = _service.Modules.MapToList(), - Resources = _service.Resources, - Roles = _service.Roles + User = service.User, + Orgs = service.Orgs, + Modules = service.Modules.MapToList(), + Resources = service.Resources, + Roles = service.Roles }; foreach (var moduleView in user.Modules) { moduleView.Elements = - _service.ModuleElements.Where(u => u.ModuleId == moduleView.Id).OrderBy(u => u.Sort).ToList(); + service.ModuleElements.Where(u => u.ModuleId == moduleView.Id).OrderBy(u => u.Sort).ToList(); } user.ModuleWithChildren = user.Modules.GenerateTree(c => c.Id, c => c.ParentId); diff --git a/OpenAuth.App/ResourceManagerApp.cs b/OpenAuth.App/ResourceManagerApp.cs index 9743a84c..1c30f775 100644 --- a/OpenAuth.App/ResourceManagerApp.cs +++ b/OpenAuth.App/ResourceManagerApp.cs @@ -39,9 +39,9 @@ namespace OpenAuth.App - public void Delete(Guid id) + public void Delete(Guid[] ids) { - _resManagerService.Delete(id); + _resManagerService.Delete(ids); } public void AddOrUpdate(Resource model) diff --git a/OpenAuth.App/UserManagerApp.cs b/OpenAuth.App/UserManagerApp.cs index 07cc75e9..20cf14b2 100644 --- a/OpenAuth.App/UserManagerApp.cs +++ b/OpenAuth.App/UserManagerApp.cs @@ -47,17 +47,17 @@ namespace OpenAuth.App { if (pageindex < 1) pageindex = 1; //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪?? IEnumerable users; - int total = 0; + int records = 0; if (orgId ==Guid.Empty) { users = _repository.LoadUsers(pageindex, pagesize); - total = _repository.GetCount(); + records = _repository.GetCount(); } else { var ids = GetSubOrgIds(orgId); users = _repository.LoadInOrgs(pageindex, pagesize, ids); - total = _repository.GetUserCntInOrgs(ids); + records = _repository.GetUserCntInOrgs(ids); } var userviews = new List(); foreach (var user in users) @@ -71,7 +71,8 @@ namespace OpenAuth.App return new GridData { - total = total, + records = records, + total = (int)Math.Ceiling((double)records / pagesize), rows = userviews, page = pageindex }; @@ -103,12 +104,12 @@ namespace OpenAuth.App return view; } - public void Delete(Guid id) + public void Delete(Guid[] ids) { - _repository.Delete(u => u.Id == id); - _relevanceRepository.DeleteBy("UserOrg", id); - _relevanceRepository.DeleteBy("UserModule", id); - _relevanceRepository.DeleteBy("UserRole", id); + _repository.Delete(u => ids.Contains(u.Id)); + _relevanceRepository.DeleteBy("UserOrg", ids); + _relevanceRepository.DeleteBy("UserModule", ids); + _relevanceRepository.DeleteBy("UserRole", ids); } public void AddOrUpdate(UserView view) diff --git a/OpenAuth.Domain/Interface/ICategoryRepository.cs b/OpenAuth.Domain/Interface/ICategoryRepository.cs index e97a6e7a..081d5a22 100644 --- a/OpenAuth.Domain/Interface/ICategoryRepository.cs +++ b/OpenAuth.Domain/Interface/ICategoryRepository.cs @@ -11,7 +11,12 @@ namespace OpenAuth.Domain.Interface IEnumerable LoadInOrgs(params Guid[] orgId); int GetCategoryCntInOrgs(params Guid[] orgIds); IEnumerable LoadInOrgs(int pageindex, int pagesize, params Guid[] orgIds); - + + /// + /// 获取子分类ID + /// + Guid[] GetSubIds(Guid orgId); + void Delete(Guid id); } diff --git a/OpenAuth.Domain/OpenAuth.Domain.csproj b/OpenAuth.Domain/OpenAuth.Domain.csproj index f3dbdb3f..0c4144be 100644 --- a/OpenAuth.Domain/OpenAuth.Domain.csproj +++ b/OpenAuth.Domain/OpenAuth.Domain.csproj @@ -67,6 +67,8 @@ + + diff --git a/OpenAuth.Domain/Service/AuthoriseFactory.cs b/OpenAuth.Domain/Service/AuthoriseFactory.cs new file mode 100644 index 00000000..7bc4d1fa --- /dev/null +++ b/OpenAuth.Domain/Service/AuthoriseFactory.cs @@ -0,0 +1,31 @@ +using OpenAuth.Domain.Interface; + +namespace OpenAuth.Domain.Service +{ + /// + /// Ȩ޷乤Ƿǿ˺Ŵ + /// + public class AuthoriseFactory + { + private IUnitWork _unitWork; + + public AuthoriseFactory(IUnitWork unitWork) + { + _unitWork = unitWork; + } + public AuthoriseService Create(string loginuser) + { + if (loginuser == "System") + { + return new SystemAuthService(_unitWork); + } + else + { + return new AuthoriseService(_unitWork) + { + User = _unitWork.FindSingle(u =>u.Account == loginuser) + }; + } + } + } +} \ No newline at end of file diff --git a/OpenAuth.Domain/Service/AuthoriseService.cs b/OpenAuth.Domain/Service/AuthoriseService.cs index f536aea4..49975d07 100644 --- a/OpenAuth.Domain/Service/AuthoriseService.cs +++ b/OpenAuth.Domain/Service/AuthoriseService.cs @@ -22,14 +22,10 @@ namespace OpenAuth.Domain.Service /// public class AuthoriseService { - private IUnitWork _unitWork; + protected IUnitWork _unitWork; + protected User _user; - private User _user; - private List _modules; //用户可访问的模块 - private List _moduleElements; //用户可访问的菜单 - private List _resources; //用户可访问的资源 - private List _orgs; //用户可访问的机构 - private List _roles; //用户角色 + private List _userRoleIds; //用户角色GUID public AuthoriseService(IUnitWork unitWork) { @@ -38,32 +34,37 @@ namespace OpenAuth.Domain.Service public List Modules { - get { return _modules; } + get { return GetModulesQuery().ToList(); } } public List Roles { - get { return _roles;} + get { return GetRolesQuery().ToList(); } } public List ModuleElements { - get { return _moduleElements; } + get { return GetModuleElementsQuery().ToList(); } } public List Resources { - get { return _resources; } + get { return GetResourcesQuery().ToList(); } } public List Orgs { - get { return _orgs; } + get { return GetOrgsQuery().ToList(); } } public User User { get { return _user; } + set + { + _user = value; + _userRoleIds = _unitWork.Find(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList(); + } } public void Check(string userName, string password) @@ -76,83 +77,60 @@ namespace OpenAuth.Domain.Service _user.CheckPassword(password); } - /// - /// 加载用户可访问的所有机构/资源/菜单 - /// 李玉宝于2016-07-19 10:32:19 + /// 用户可访问的机构 /// - /// The name. - public void LoadAuthControls(string name) + /// IQueryable<Org>. + public virtual IQueryable GetOrgsQuery() { - if (name == "System") - { - _user = new User{Account = "System", Id = Guid.Empty}; - LoadForSystem(); - } - else - { - _user = _unitWork.FindSingle(u => u.Account == name); - if (_user != null) - { - LoadForUser(); - } - } - } - - /// - /// 加载用户权限 - /// 李玉宝于2016-07-19 10:20:16 - /// - /// The name. - private void LoadForUser() - { - //用户角色 - var userRoleIds = - _unitWork.Find(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList(); - - _roles = _unitWork.Find(u => userRoleIds.Contains(u.Id)).ToList(); - //用户角色与自己分配到的模块ID - var moduleIds = _unitWork.Find( - u => - (u.FirstId == _user.Id && u.Key == "UserModule") || - (u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); - //得出最终用户拥有的模块 - _modules = _unitWork.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList(); - - //用户角色与自己分配到的菜单ID - var elementIds = _unitWork.Find( - u => - (u.FirstId == _user.Id && u.Key == "UserElement") || - (u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); - //模块菜单权限 - _moduleElements = _unitWork.Find(u => elementIds.Contains(u.Id)).ToList(); - - //用户角色与自己分配到的资源ID - var resourceIds = _unitWork.Find( - u => - (u.FirstId == _user.Id && u.Key == "UserResource") || - (u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); - _resources = _unitWork.Find(u => resourceIds.Contains(u.Id)).ToList(); - - //用户角色与自己分配到的机构ID var orgids = _unitWork.Find( u => (u.FirstId == _user.Id && u.Key == "UserOrg") || - (u.Key == "RoleOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); - _orgs = _unitWork.Find(u => orgids.Contains(u.Id)).ToList(); + (u.Key == "RoleOrg" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); + return _unitWork.Find(u => orgids.Contains(u.Id)); } /// - /// 加载系统管理员权限 - /// 李玉宝于2016-07-19 10:19:31 + /// 获取用户可访问的资源 /// - private void LoadForSystem() + /// IQueryable<Resource>. + public virtual IQueryable GetResourcesQuery() { - _modules = _unitWork.Find(null).ToList(); - _moduleElements = _unitWork.Find(null).ToList(); - _roles = _unitWork.Find(null).ToList(); - _resources = _unitWork.Find(null).OrderBy(u => u.SortNo).ToList(); - _orgs = _unitWork.Find(null).OrderBy(u => u.SortNo).ToList(); + var resourceIds = _unitWork.Find( + u => + (u.FirstId == _user.Id && u.Key == "UserResource") || + (u.Key == "RoleResource" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); + return _unitWork.Find(u => resourceIds.Contains(u.Id)); + } + + /// + /// 模块菜单权限 + /// + public virtual IQueryable GetModuleElementsQuery() + { + var elementIds = _unitWork.Find( + u => + (u.FirstId == _user.Id && u.Key == "UserElement") || + (u.Key == "RoleElement" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); + return _unitWork.Find(u => elementIds.Contains(u.Id)); + } + + /// + /// 得出最终用户拥有的模块 + /// + public virtual IQueryable GetModulesQuery() + { + var moduleIds = _unitWork.Find( + u => + (u.FirstId == _user.Id && u.Key == "UserModule") || + (u.Key == "RoleModule" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId); + return _unitWork.Find(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo); + } + + //用户角色 + public virtual IQueryable GetRolesQuery() + { + return _unitWork.Find(u => _userRoleIds.Contains(u.Id)); } } } \ No newline at end of file diff --git a/OpenAuth.Domain/Service/ModuleEleManService.cs b/OpenAuth.Domain/Service/ModuleEleManService.cs index aab49bc6..e0c07745 100644 --- a/OpenAuth.Domain/Service/ModuleEleManService.cs +++ b/OpenAuth.Domain/Service/ModuleEleManService.cs @@ -24,12 +24,12 @@ namespace OpenAuth.Domain.Service public class ModuleEleManService { private readonly IUnitWork _unitWork; - private readonly AuthoriseService _authoriseService; + private readonly AuthoriseFactory _factory; - public ModuleEleManService(IUnitWork unitWork, AuthoriseService authoriseService) + public ModuleEleManService(IUnitWork unitWork, AuthoriseFactory authoriseService) { _unitWork = unitWork; - _authoriseService = authoriseService; + _factory = authoriseService; } public void AddOrUpdate(ModuleElement model) @@ -48,13 +48,13 @@ namespace OpenAuth.Domain.Service public IEnumerable LoadByModuleId(string loginuser, Guid id) { - _authoriseService.LoadAuthControls(loginuser); - if (_authoriseService.ModuleElements.Count == 0) //用户没有任何资源 + var service = _factory.Create(loginuser); + if (!service.GetModuleElementsQuery().Any()) //用户没有任何资源 { return new List(); } - var modules = _authoriseService.ModuleElements.Where(u => u.ModuleId == id).OrderBy(u =>u.Sort); + var modules = service.GetModuleElementsQuery().Where(u => u.ModuleId == id).OrderBy(u =>u.Sort); return modules; } @@ -71,16 +71,16 @@ namespace OpenAuth.Domain.Service public List LoadWithAccess(string username, string accessType, Guid firstId, Guid moduleId) { var listVms = new List(); - _authoriseService.LoadAuthControls(username); - if (_authoriseService.ModuleElements.Count == 0) //用户没有任何资源 + var service = _factory.Create(username); + if (!service.GetModuleElementsQuery().Any()) //用户没有任何资源 { return listVms; } if (moduleId == Guid.Empty) return listVms; - string modulename = _authoriseService.Modules.SingleOrDefault(u => u.Id == moduleId).Name; + string modulename = service.GetModulesQuery().SingleOrDefault(u => u.Id == moduleId).Name; - foreach (var element in _authoriseService.ModuleElements.Where(u =>u.ModuleId ==moduleId)) + foreach (var element in service.GetModuleElementsQuery().Where(u =>u.ModuleId ==moduleId)) { var accessed = _unitWork.FindSingle(u =>u.Key == accessType && u.FirstId == firstId && u.SecondId == element.Id); diff --git a/OpenAuth.Domain/Service/ModuleManService.cs b/OpenAuth.Domain/Service/ModuleManService.cs index adb5145f..03ddb227 100644 --- a/OpenAuth.Domain/Service/ModuleManService.cs +++ b/OpenAuth.Domain/Service/ModuleManService.cs @@ -24,14 +24,14 @@ namespace OpenAuth.Domain.Service { private readonly IModuleRepository _repository; private readonly IRelevanceRepository _relevanceRepository; - private readonly AuthoriseService _authoriseService; + private readonly AuthoriseFactory _factory; public ModuleManService(IModuleRepository repository, - IRelevanceRepository relevanceRepository, AuthoriseService authoriseService) + IRelevanceRepository relevanceRepository, AuthoriseFactory authoriseService) { _repository = repository; _relevanceRepository = relevanceRepository; - _authoriseService = authoriseService; + _factory = authoriseService; } /// @@ -40,27 +40,28 @@ namespace OpenAuth.Domain.Service public dynamic Load(string loginuser, Guid parentId, int pageindex, int pagesize) { - _authoriseService.LoadAuthControls(loginuser); - if (_authoriseService.Modules.Count == 0) //用户不能访问任何模块 + var service= _factory.Create(loginuser); + if (!service.GetModulesQuery().Any()) //用户不能访问任何模块 { return new { total = 0, - list = new List(), - pageCurrent = pageindex + records = 0, + page = pageindex }; } var ids = GetSubIds(parentId); - var query = _authoriseService.Modules.Where(u => parentId == Guid.Empty || (u.ParentId != null&&ids.Contains(u.ParentId.Value))); + var query = service.GetModulesQuery().Where(u => parentId == Guid.Empty || (u.ParentId != null&&ids.Contains(u.ParentId.Value))); int total = query.Count(); var modules = query.OrderBy(u=>u.CascadeId).Skip((pageindex - 1)*pagesize).Take(pagesize); return new { - total = total, - list = modules, - pageCurrent = pageindex + records = total, + total = Math.Ceiling((double)total/pagesize), + rows = modules, + page = pageindex }; } @@ -152,7 +153,7 @@ namespace OpenAuth.Domain.Service if (currentCascadeId <= objCascadeId) currentCascadeId = objCascadeId + 1; } - if (module.ParentId != null) + if (module.ParentId != null && module.ParentId != Guid.Empty) { var parentOrg = _repository.FindSingle(o => o.Id == module.ParentId); if (parentOrg != null) diff --git a/OpenAuth.Domain/Service/ResManagerService.cs b/OpenAuth.Domain/Service/ResManagerService.cs index c69f78a0..388d3c10 100644 --- a/OpenAuth.Domain/Service/ResManagerService.cs +++ b/OpenAuth.Domain/Service/ResManagerService.cs @@ -14,17 +14,17 @@ namespace OpenAuth.Domain.Service private IResourceRepository _repository; private readonly ICategoryRepository _categoryRepository; private IRelevanceRepository _relevanceRepository; - private AuthoriseService _authoriseService; + private AuthoriseFactory _factory; public ResManagerService(IResourceRepository repository, ICategoryRepository categoryRepository, IRelevanceRepository relevanceRepository, - AuthoriseService authoriseService) + AuthoriseFactory authoriseService) { _repository = repository; _categoryRepository = categoryRepository; _relevanceRepository = relevanceRepository; - _authoriseService = authoriseService; + _factory = authoriseService; } public int GetResourceCntInOrg(Guid orgId) @@ -35,7 +35,7 @@ namespace OpenAuth.Domain.Service } else { - return _repository.GetResourceCntInOrgs(GetSubOrgIds(orgId)); + return _repository.GetResourceCntInOrgs(_categoryRepository.GetSubIds(orgId)); } } @@ -49,42 +49,58 @@ namespace OpenAuth.Domain.Service /// public dynamic Load(string username, Guid categoryId, int pageindex, int pagesize) { - _authoriseService.LoadAuthControls(username); - if (_authoriseService.Resources.Count == 0) //用户没有任何资源 + var service = _factory.Create(username); + if (!service.GetResourcesQuery().Any()) //用户没有任何资源 { return new { total = 0, - pageCurrent = pageindex + page = 0, + records = 0 }; } - var subIds = GetSubOrgIds(categoryId); - var query = _authoriseService.Resources.Where(u => categoryId == Guid.Empty || + var subIds = _categoryRepository.GetSubIds(categoryId); + + + var query = service.GetResourcesQuery().Where(u => categoryId == Guid.Empty || (u.CategoryId != null && subIds.Contains(u.CategoryId.Value))); - var Resources = query.Skip((pageindex - 1) * pagesize).Take(pagesize); int total = query.Count(); + if (total <= 0) + return new + { + total = 0, + page = 0, + records = 0 + }; + + var listVms = new List(); + var resources = query.OrderBy(u => u.SortNo).Skip((pageindex - 1) * pagesize).Take(pagesize); + foreach (var element in resources) + { + var accessed = _categoryRepository.FindSingle(u => u.Id == element.CategoryId); + listVms.Add(new + { + element.Id, + element.Name, + element.Key, + element.SortNo, + element.CategoryId, + element.Status, + CategoryName = accessed != null ? accessed.Name : "" + }); + } + return new { - total = total, - list = Resources, - pageCurrent = pageindex + records = total, + total = (int)Math.Ceiling((double)total / pagesize), + rows = listVms, + page = pageindex }; } - /// - /// 获取当前节点的所有下级节点 - /// - private Guid[] GetSubOrgIds(Guid orgId) - { - if (orgId == Guid.Empty) - { - return _categoryRepository.Find(null).Select(u => u.Id).ToArray(); - } - var org = _categoryRepository.FindSingle(u => u.Id == orgId); - var orgs = _categoryRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray(); - return orgs; - } + public Resource Find(Guid id) { @@ -94,9 +110,9 @@ namespace OpenAuth.Domain.Service return resource; } - public void Delete(Guid id) + public void Delete(Guid[] ids) { - _repository.Delete(id); + _repository.Delete(u => ids.Contains(u.Id)); } public void AddOrUpdate(Resource resource) @@ -124,14 +140,14 @@ namespace OpenAuth.Domain.Service public List LoadWithAccess(string username, string accessType, Guid firstId, Guid cId) { var listVms = new List(); - _authoriseService.LoadAuthControls(username); - if (_authoriseService.Resources.Count == 0) //用户没有任何资源 + var service = _factory.Create(username); + if (!service.GetResourcesQuery().Any()) //用户没有任何资源 { return listVms; } - var subIds = GetSubOrgIds(cId); - var query = _authoriseService.Resources.Where(u => cId == Guid.Empty || (u.CategoryId != null &&subIds.Contains(u.CategoryId.Value))); + var subIds = _categoryRepository.GetSubIds(cId); + var query = service.GetResourcesQuery().Where(u => cId == Guid.Empty || (u.CategoryId != null && subIds.Contains(u.CategoryId.Value))); foreach (var element in query) { diff --git a/OpenAuth.Domain/Service/StockManagerService.cs b/OpenAuth.Domain/Service/StockManagerService.cs index 23ea9236..b99b31e8 100644 --- a/OpenAuth.Domain/Service/StockManagerService.cs +++ b/OpenAuth.Domain/Service/StockManagerService.cs @@ -13,14 +13,14 @@ namespace OpenAuth.Domain.Service { private IStockRepository _repository; private IOrgRepository _orgRepository; - private AuthoriseService _authoriseService; + private AuthoriseFactory _factory; public StockManagerService(IStockRepository repository, - IOrgRepository orgRepository, AuthoriseService service) + IOrgRepository orgRepository, AuthoriseFactory service) { _repository = repository; _orgRepository = orgRepository; - _authoriseService = service; + _factory = service; } /// @@ -29,8 +29,8 @@ namespace OpenAuth.Domain.Service public dynamic Load(string username, Guid orgId, int pageindex, int pagesize) { - _authoriseService.LoadAuthControls(username); - if (_authoriseService.Orgs.Count == 0) //用户没有任何可见机构 + var service = _factory.Create(username); + if (service.Orgs.Count == 0) //用户没有任何可见机构 { return new { @@ -39,13 +39,13 @@ namespace OpenAuth.Domain.Service }; } - var orgIds = _authoriseService.Orgs.Select(u => u.Id).ToArray(); //用户可访问的机构ID + var orgIds = service.Orgs.Select(u => u.Id).ToArray(); //用户可访问的机构ID var orgs = _orgRepository.GetSubOrgs(orgId) //点击的节点与用户可访问的机构合并 .Where(u => orgIds.Contains(u.Id)) .Select(u => u.Id).ToArray(); - var keys = _authoriseService.Resources.Select(r => r.Key); //用户可访问的资源的KEY列表 + var keys = service.Resources.Select(r => r.Key); //用户可访问的资源的KEY列表 Expression> exp = u => u.OrgId != null &&orgs.Contains(u.OrgId.Value) && (u.Viewable == "" || keys.Contains(u.Viewable)); var stocks = _repository.Find(pageindex, pagesize, "", exp); diff --git a/OpenAuth.Domain/Service/SystemAuthService.cs b/OpenAuth.Domain/Service/SystemAuthService.cs new file mode 100644 index 00000000..bbe90dc4 --- /dev/null +++ b/OpenAuth.Domain/Service/SystemAuthService.cs @@ -0,0 +1,58 @@ +// *********************************************************************** +// Assembly : OpenAuth.Domain +// Author : yubaolee +// Created : 04-21-2016 +// +// Last Modified By : yubaolee +// Last Modified On : 04-21-2016 +// Contact : Microsoft +// File: AuthenService.cs +// *********************************************************************** + +using OpenAuth.Domain.Interface; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.Domain.Service +{ + /// + /// 领域服务 + /// 超级管理员权限 + /// + public class SystemAuthService : AuthoriseService + { + public SystemAuthService(IUnitWork unitWork):base(unitWork) + { + _user = new User { Account = "System", Id = Guid.Empty }; + } + + + + public override IQueryable GetOrgsQuery() + { + return _unitWork.Find(null); + } + + public override IQueryable GetResourcesQuery() + { + return _unitWork.Find(null); + } + + public override IQueryable GetModuleElementsQuery() + { + return _unitWork.Find(null); + } + + public override IQueryable GetModulesQuery() + { + return _unitWork.Find(null); + } + + public override IQueryable GetRolesQuery() + { + //用户角色 + return _unitWork.Find(null); + } + } +} \ No newline at end of file diff --git a/OpenAuth.Mvc/BllScripts/commonApply.js b/OpenAuth.Mvc/BllScripts/commonApply.js index 72622952..6b31ecea 100644 --- a/OpenAuth.Mvc/BllScripts/commonApply.js +++ b/OpenAuth.Mvc/BllScripts/commonApply.js @@ -134,11 +134,11 @@ function del() { if (selected == null) return; $.post('/CommonApplies/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { + if (data.Status) { list.reload(); } else { - $(this).alertmsg('warn', data.message); + $(this).alertmsg('warn', data.Message); } }, "json"); } diff --git a/OpenAuth.Mvc/BllScripts/modulemanager.js b/OpenAuth.Mvc/BllScripts/modulemanager.js index 1d446b8d..afddac4e 100644 --- a/OpenAuth.Mvc/BllScripts/modulemanager.js +++ b/OpenAuth.Mvc/BllScripts/modulemanager.js @@ -1,107 +1,10 @@ -// *********************************************************************** -// Assembly : OpenAuth.Mvc -// Author : yubaolee -// Created : 04-06-2016 -// -// Last Modified By : yubaolee -// Last Modified On : 04-06-2016 -// *********************************************************************** -// -// 版权所有(C) 2015 -// -// 模块管理脚本 -// *********************************************************************** - -//grid列表模块 -function MainGrid() { - var url = '/ModuleManager/Load?orgId='; - var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块 - this.maingrid = $('#maingrid').datagrid({ - showToolbar: false, - filterThead: false, - loadType: 'GET', - target: $(this), - columns: [ - { - name: 'Id', - label: '功能模块流水号', - width: 100 - , hide: true - }, - { - name: 'CascadeId', - label: '节点语义ID', - width: 100 - }, - { - name: 'Name', - label: '功能模块名称', - width: 100 - }, - { - name: 'Url', - label: '主页面URL', - width: 100 - }, - - { - name: 'IsLeaf', - label: '是否叶子节点', - width: 100 - , type: 'select', - align: 'center', - items: [{ 'false': '否' }, { 'true': '是' }], - }, - { - name: 'IsAutoExpand', - label: '是否自动展开', - width: 100 - , type: 'select', - align: 'center', - items: [{ 'false': '否' }, { 'true': '是' }], - }, - { - name: 'Status', - label: '当前状态', - width: 100 - , type: 'select', - align: 'center', - items: [{ '0': '默认' }, { '1': '状态1' }], - }, - { - name: 'ParentName', - label: '父节点名称', - width: 100 - }, - { - name: 'Vector', - label: '矢量图标', - width: 100 - }, - { - name: 'SortNo', - label: '排序号', - width: 100 - }, - ], - dataUrl: url + selectedId, - fullGrid: true, - showLinenumber: true, - showCheckboxcol: true, - paging: true, - filterMult: false, - showTfoot: false, - +$(function () { + $("#ParentName").on("click", function () { + parent.reload(); }); - this.reload = function (id) { - if (id != undefined) selectedId = id; - this.maingrid.datagrid('reload', { dataUrl: url + selectedId }); - }; -}; -MainGrid.prototype = new Grid(); -var list = new MainGrid(); +}); -//左边分类导航树 +//左边导航 var ztree = function () { var url = '/ModuleManager/LoadModuleWithRoot'; var setting = { @@ -118,158 +21,165 @@ var ztree = function () { rootPId: 'null' } }, - callback: { onClick: zTreeOnClick } - }; - $.getJSON(url, function (json) { - $.fn.zTree.init($("#tree"), setting, json).expandAll(true); - }); - function zTreeOnClick(event, treeId, treeNode) { - list.reload(treeNode.Id); - } - - return { - reload: function () { - $.getJSON(url, function (json) { - $.fn.zTree.init($("#tree"), setting, json).expandAll(true); - }); - } - } -}(); - -//编辑时,选择上级弹出的树 -var parentTree = function () { - var nameDom = "#ParentName"; - var idDom = "#ParentId"; - var zTreeObj; - var setting = { - view: { - selectedMulti: false - }, - check: { - enable: true, - chkStyle: "radio", //单选 - radioType: "all" - }, - data: { - key: { - name: 'Name', - title: 'Name' - }, - simpleData: { - enable: true, - idKey: 'Id', - pIdKey: 'ParentId', - rootPId: 'null' - } - }, callback: { - onClick: zTreeOnClick, - onCheck: zTreeCheck + onClick: function (event, treeId, treeNode) { + list.reload(treeNode.Id); + } } }; - - function zTreeCheck(event, treeId, treeNode) { - var nodes = zTreeObj.getCheckedNodes(true); - var ids = nodes.map(function (e) { return e.Id; }).join(","); - var names = nodes.map(function (e) { return e.Name; }).join(","); - - $(nameDom).val(names); - $(idDom).val(ids); - } - function zTreeOnClick(event, treeId, treeNode) { - zTreeObj.checkNode(treeNode, !treeNode.checked, true, true); - event.preventDefault(); - } + var load = function () { + $.getJSON(url, function (json) { + var zTreeObj = $.fn.zTree.init($("#orgtree"), setting, json); + list.reload(); + zTreeObj.expandAll(true); + }); + }; + load(); return { - show: function () { - $.getJSON('/moduleManager/LoadForTree', function (json) { - zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json); - var orgstr = $(idDom).val(); - var name = ''; - if (orgstr != '') { - var nodeIds = orgstr.split(','); - $.each(nodeIds, function () { - var node = zTreeObj.getNodeByParam("Id", this, null); - name += ',' + node.Name; - zTreeObj.checkNode(node, true, true); - }); - $(nameDom).val(name.substr(1)); //显示名称 - } - zTreeObj.expandAll(true); - }); - } - }; + reload: load + } }(); +//grid列表模块 +function MainGrid() { + var url = '/ModuleManager/Load?orgId='; + var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块 + this.maingrid = $('#maingrid') + .jqGrid({ + colModel: [ + { + name: 'Id', + index: 'Id', + hidden: true + }, + + { + index: 'Name', + name: 'Name', + label: '模块名称' + }, + { + index: 'Url', + name: 'Url', + label: '模块地址' + }, + { + index: 'IconName', + name: 'IconName', + label: '图标' + }, + { + index: 'ParentName', + name: 'ParentName', + label: '所属模块' + }, + { + index: 'ParentId', + name: 'ParentId', + hidden: true + }, + + { + index: 'SortNo', + name: 'SortNo', + label: '排序号' + + } + ], + url: url + selectedId, + datatype: "json", + + viewrecords: true, + rowNum: 18, + pager: "#grid-pager", + altRows: true, + height: 'auto', + multiselect: true, + multiboxonly: true, + + loadComplete: function () { + var table = this; + setTimeout(function () { + updatePagerIcons(table); + }, + 0); + } + }).jqGrid('navGrid', "#grid-pager", { + edit: false, add: false, del: false, refresh: false, search: false + }); + + this.reload = function (id) { + if (id != undefined) selectedId = id; + this.maingrid.jqGrid("setGridParam", { url: url + selectedId }) + .trigger("reloadGrid", [{ page: 1 }]); //重载JQGrid + + }; +}; +MainGrid.prototype = new Grid(); +var list = new MainGrid(); +var vm = new Vue({ + el: '#editDlg' +}); + +//上级机构选择框 +var parent = new ParentTree("/moduleManager/LoadForTree", "ParentName", "ParentId"); + //添加(编辑)对话框 var editDlg = function () { var update = false; var show = function () { - BJUI.dialog({ id: 'editDlg', title: '编辑', target: '#editDlg' }); - $("#btnSave").on("click", function () { - editDlg.save(); + layer.open({ + type: 1, + skin: 'layui-layer-rim', //加上边框 + title: "用户管理", //不显示标题 + area: ['450px', '400px'], //宽高 + content: $('#editDlg'), //捕获的元素 + btn: ['保存', '关闭'], + yes: function (index, layero) { + $.post("/moduleManager/Add", vm.$data, function (data) { + layer.msg(data.Message); + if (data.Status) { + list.reload(); + ztree.reload(); + } + }, "json"); + }, + cancel: function (index) { + layer.close(index); + } }); } return { add: function () { //弹出添加 update = false; show(); - $.CurrentDialog.find("form")[0].reset(); //reset方法只能通过dom调用 - $("#Id").val('00000000-0000-0000-0000-000000000000'); - - parentTree.show() + vm.$set('$data', { + Id: '00000000-0000-0000-0000-000000000000', + SortNo: 0 + }); }, update: function (ret) { //弹出编辑框 update = true; show(); - $('#Id').val(ret.Id); - $('#CascadeId').val(ret.CascadeId); - $('#Name').val(ret.Name); - $('#Url').val(ret.Url); - $('#HotKey').val(ret.HotKey); - $('#ParentId').val(ret.ParentId); - $('#IsLeaf').selectpicker('val', ret.IsLeaf?"true":"false"); - $('#IsAutoExpand').selectpicker('val', ret.IsAutoExpand?"true":"false"); - $('#IconName').val(ret.IconName); - $('#Status').val(ret.Status); - $('#ParentName').val(ret.ParentName); - $('#Vector').val(ret.Vector); - $('#SortNo').val(ret.SortNo); - parentTree.show() - }, - save: function () { //编辑-->保存 - $('#editForm').isValid(function (v) { - if (!v) return; //验证没通过 - $("#editForm").bjuiajax('ajaxForm', { - reload: false, - callback: function (json) { - if (json.statusCode != "200") { - $(this).alertmsg('warn', json.message); - return; - } - list.reload(); - ztree.reload(); - } - }); - }); + vm.$set('$data', ret); } }; }(); - //删除 function del() { - var selected = list.getSelectedObj(); + var selected = list.getSelectedProperties("Id"); if (selected == null) return; - $.post('/moduleManager/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { + $.post('/moduleManager/Delete', + { ids: selected }, function (data) { + if (data.Status) { list.reload(); ztree.reload(); } else { - $(this).alertmsg('warn', data.message); + $(this).alertmsg('warn', data.Message); } }, "json"); } @@ -291,6 +201,7 @@ function refresh() { list.reload(); } + //为模块分配按钮 function assignButton() { var selected = list.getSelectedObj(); @@ -304,8 +215,6 @@ function assignButton() { url: '/ModuleElementManager/Index?id=' + selected.Id, title: '为模块分配按钮', width: '800', - height:'600' + height: '600' }); } - -//@@ sourceURL=moduleManager.js \ No newline at end of file diff --git a/OpenAuth.Mvc/BllScripts/orgManager.js b/OpenAuth.Mvc/BllScripts/orgManager.js index 81e06e02..af8bfa26 100644 --- a/OpenAuth.Mvc/BllScripts/orgManager.js +++ b/OpenAuth.Mvc/BllScripts/orgManager.js @@ -118,68 +118,7 @@ var vm = new Vue({ }); //上级机构选择框 -var parent = function () { //ztree搜索框 - var zTreeObj; - var setting = { - view: { selectedMulti: false }, - data: { - key: { - name: 'Name', - title: 'Name' - }, - simpleData: { - enable: true, - idKey: 'Id', - pIdKey: 'ParentId', - rootPId: 'null' - } - }, - callback: { - onClick: onClick - } - }; - var showMenu = function () { - $("#menuContent").css({ left: "10px", top: $("#ParentName").outerHeight() + "px" }).slideDown("fast"); - $("body").bind("mousedown", onBodyDown); - }; - function onClick(e, treeId, treeNode) { - var nodes = zTreeObj.getSelectedNodes(); - - for (var i = 0, l = nodes.length; i < l; i++) { - vm.$set('ParentName', nodes[i].Name); - vm.$set('ParentId', nodes[i].Id); - break; - } - hideMenu(); - } - function onBodyDown(event) { - if (!(event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) { - hideMenu(); - } - } - function hideMenu() { - $("#menuContent").fadeOut("fast"); - $("body").unbind("mousedown", onBodyDown); - } - return { - reload: function () { - var index = layer.load(); - $.getJSON("/OrgManager/LoadOrg", { - page: 1, rows: 10000 - }, function (json) { - layer.close(index); - if (json.length == 0) { - vm.$set('ParentName', ''); - vm.$set('ParentId', ''); - return; - } - zTreeObj = $.fn.zTree.init($("#org"), setting, json); - zTreeObj.expandAll(true); - showMenu(); - }); - } - } -}(); +var parent = new ParentTree("/OrgManager/LoadOrg","ParentName", "ParentId"); //添加(编辑)对话框 var editDlg = function () { @@ -210,9 +149,11 @@ var editDlg = function () { add: function () { //弹出添加 update = false; show(); - vm.$set('$data', null); - vm.$set('Id', '00000000-0000-0000-0000-000000000000'); - vm.$set('SortNo', 0); + vm.$set('$data', + { + Id: '00000000-0000-0000-0000-000000000000', + SortNo: 0 + }); }, update: function (ret) { //弹出编辑框 update = true; diff --git a/OpenAuth.Mvc/BllScripts/parentTree.js b/OpenAuth.Mvc/BllScripts/parentTree.js new file mode 100644 index 00000000..f50c6e20 --- /dev/null +++ b/OpenAuth.Mvc/BllScripts/parentTree.js @@ -0,0 +1,89 @@ +// *********************************************************************** +// Assembly : OpenAuth.Mvc +// Author : yubaolee +// Created : 10-16-2016 +// +// Last Modified By : yubaolee +// Last Modified On : 10-16-2016 +// *********************************************************************** +// +// 版权所有(C) 2015 +// +// 单击文本框弹出的选择列表 +// *********************************************************************** + +function ParentTree(url, name, id) { + var zTreeObj; + var options = { + text: 'Name', + key: 'Id', + parentKey: 'ParentId', + nameDOM: name, //显示的文本框ID,如:"#catetoryName" + idDOM: id //隐藏的文本框,如:"#categoryId" + } + var setting = { + view: { selectedMulti: false }, + data: { + key: { + name: options.text, + title: options.text + }, + simpleData: { + enable: true, + idKey: options.key, + pIdKey: options.parentKey, + rootPId: 'null' + } + }, + callback: { + onClick: onClick + } + }; + var showMenu = function () { + $("#menuContent").css({ left: "10px", top: $("#" + options.nameDOM).outerHeight() + "px" }).slideDown("fast"); + $("body").bind("mousedown", onBodyDown); + }; + + var setCheck = function() { //todo:设置初始选中的值 + //var value = vm.$get(options.idDom); + } + function onClick(e, treeId, treeNode) { + var nodes = zTreeObj.getSelectedNodes(); + + for (var i = 0, l = nodes.length; i < l; i++) { + vm.$set(options.nameDOM, nodes[i].Name); + vm.$set(options.idDOM, nodes[i].Id); + break; + } + hideMenu(); + } + function onBodyDown(event) { + if (!(event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) { + hideMenu(); + } + } + function hideMenu() { + $("#menuContent").fadeOut("fast"); + $("body").unbind("mousedown", onBodyDown); + } + return { + reload: function () { + var index = layer.load(); + $.getJSON(url, + { + page: 1, rows: 10000 + }, + function (json) { + layer.close(index); + if (json.length == 0) { + vm.$set(options.nameDOM, ''); + vm.$set(options.idDOM, ''); + return; + } + zTreeObj = $.fn.zTree.init($("#org"), setting, json); + zTreeObj.expandAll(true); + showMenu(); + }); + } + } +} \ No newline at end of file diff --git a/OpenAuth.Mvc/BllScripts/processDetail.js b/OpenAuth.Mvc/BllScripts/processDetail.js index bb74e7c3..26cfd1d9 100644 --- a/OpenAuth.Mvc/BllScripts/processDetail.js +++ b/OpenAuth.Mvc/BllScripts/processDetail.js @@ -39,11 +39,11 @@ $(function () { .on("click", function () { //执行命令 $.post("/CommonApplies/ExeCmd?id=" +$("#processId").val() +"&cmd=" +$(this).val() , function (data) { - if (data.statusCode == "200") { + if (data.Status) { BJUI.dialog('refresh', 'detailDlg'); } else { - $(this).alertmsg('warn', data.message); + $(this).alertmsg('warn', data.Message); } },'json'); }); diff --git a/OpenAuth.Mvc/BllScripts/resourceManager.js b/OpenAuth.Mvc/BllScripts/resourceManager.js index bab40821..cbb6079c 100644 --- a/OpenAuth.Mvc/BllScripts/resourceManager.js +++ b/OpenAuth.Mvc/BllScripts/resourceManager.js @@ -1,71 +1,10 @@ - -//grid列表模块 -function MainGrid() { - var url = '/ResourceManager/Load?categoryId='; - var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块 - this.maingrid = $('#maingrid').datagrid({ - showToolbar: false, - filterThead: false, - loadType: 'GET', - target: $(this), - columns: [ - { - name: 'Id', - label: '资源表ID', - width: 100 - , hide: true - }, - - { - name: 'Key', - label: 'Key', - width: 100 - }, - { - name: 'Name', - label: '名称', - width: 100 - }, - - { - name: 'Status', - label: '当前状态', - width: 100 - , align: 'center', - items: [{ '0': '默认' }, { '1': '状态1' }], - }, - { - name: 'SortNo', - label: '排序号', - width: 100 - , align: 'center', - items: [{ '0': '默认' }, { '1': '状态1' }], - }, - - { - name: 'Description', - label: '描述', - width: 100 - }, - ], - dataUrl: url + selectedId, - fullGrid: true, - showLinenumber: true, - showCheckboxcol: true, - paging: true, - filterMult: false, - showTfoot: false, - +$(function () { + $("#CategoryName").on("click", function () { + parent.reload(); }); - this.reload = function (id) { - if (id != undefined) selectedId = id; - this.maingrid.datagrid('reload', { dataUrl: url + selectedId }); - }; -}; -MainGrid.prototype = new Grid(); -var list = new MainGrid(); +}); -//左边分类导航树 +//左边导航 var ztree = function () { var url = '/CategoryManager/LoadForTree'; var setting = { @@ -82,151 +21,159 @@ var ztree = function () { rootPId: 'null' } }, - callback: { onClick: zTreeOnClick } - }; - $.getJSON(url, function (json) { - $.fn.zTree.init($("#tree"), setting, json).expandAll(true); - }); - function zTreeOnClick(event, treeId, treeNode) { - list.reload(treeNode.Id); - } - - return { - reload: function () { - $.getJSON(url, function (json) { - $.fn.zTree.init($("#tree"), setting, json).expandAll(true); - }); - } - } -}(); - -//编辑时,选择上级弹出的树 -var parentTree = function () { - var nameDom = "#CategoryName"; - var idDom = "#CategoryId"; - var zTreeObj; - var setting = { - view: { - selectedMulti: false - }, - check: { - enable: true, - chkStyle: "radio", //单选 - radioType: "all" - }, - data: { - key: { - name: 'Name', - title: 'Name' - }, - simpleData: { - enable: true, - idKey: 'Id', - pIdKey: 'ParentId', - rootPId: 'null' - } - }, callback: { - onClick: zTreeOnClick, - onCheck: zTreeCheck + onClick: function (event, treeId, treeNode) { + list.reload(treeNode.Id); + } } }; - - function zTreeCheck(event, treeId, treeNode) { - var nodes = zTreeObj.getCheckedNodes(true); - var ids = nodes.map(function (e) { return e.Id; }).join(","); - var names = nodes.map(function (e) { return e.Name; }).join(","); - - $(nameDom).val(names); - $(idDom).val(ids); - } - function zTreeOnClick(event, treeId, treeNode) { - zTreeObj.checkNode(treeNode, !treeNode.checked, true, true); - event.preventDefault(); - } + var load = function () { + $.getJSON(url, function (json) { + var zTreeObj = $.fn.zTree.init($("#orgtree"), setting, json); + list.reload(); + zTreeObj.expandAll(true); + }); + }; + load(); return { - show: function () { - $.getJSON('/CategoryManager/LoadForTree', function (json) { - zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json); - var orgstr = $(idDom).val(); - var name = ''; - if (orgstr != '') { - var nodeIds = orgstr.split(','); - $.each(nodeIds, function () { - var node = zTreeObj.getNodeByParam("Id", this, null); - name += ',' + node.Name; - zTreeObj.checkNode(node, true, true); - }); - $(nameDom).val(name.substr(1)); //显示名称 - } - zTreeObj.expandAll(true); - }); - } - }; + reload: load + } }(); +//grid列表模块 +function MainGrid() { + var url = '/ResourceManager/Load?categoryId='; + var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块 + this.maingrid = $('#maingrid') + .jqGrid({ + colModel: [ + { + name: 'Id', + index: 'Id', + hidden: true + }, + { + index: 'Key', + name: 'Key', + label: '资源标识' + }, + { + index: 'Name', + name: 'Name', + label: '分类名称' + }, + { + index: 'CategoryName', + name: 'CategoryName', + label: '所属分类' + }, + { + index: 'CategoryId', + name: 'CategoryId', + hidden: true + }, + + { + index: 'SortNo', + name: 'SortNo', + label: '排序号' + + } + ], + url: url + selectedId, + datatype: "json", + + viewrecords: true, + rowNum: 18, + pager: "#grid-pager", + altRows: true, + height: 'auto', + multiselect: true, + multiboxonly: true, + + loadComplete: function () { + var table = this; + setTimeout(function () { + updatePagerIcons(table); + }, + 0); + } + }).jqGrid('navGrid', "#grid-pager", { + edit: false, add: false, del: false, refresh: false, search: false + }); + + this.reload = function (id) { + if (id != undefined) selectedId = id; + this.maingrid.jqGrid("setGridParam", { url: url + selectedId }) + .trigger("reloadGrid", [{ page: 1 }]); //重载JQGrid + + }; +}; +MainGrid.prototype = new Grid(); +var list = new MainGrid(); +var vm = new Vue({ + el: '#editDlg' +}); + +//上级机构选择框 +var parent = new ParentTree("/CategoryManager/LoadForTree", "CategoryName", "CategoryId"); + //添加(编辑)对话框 var editDlg = function () { var update = false; var show = function () { - BJUI.dialog({ id: 'editDlg', title: '编辑对话框', target: '#editDlg' }); - $("#btnSave").on("click", function () { - editDlg.save(); + layer.open({ + type: 1, + skin: 'layui-layer-rim', //加上边框 + title: "用户管理", //不显示标题 + area: ['400px', '300px'], //宽高 + content: $('#editDlg'), //捕获的元素 + btn: ['保存', '关闭'], + yes: function (index, layero) { + $.post("/ResourceManager/Add", vm.$data, function (data) { + layer.msg(data.Message); + if (data.Status) { + list.reload(); + ztree.reload(); + } + }, "json"); + }, + cancel: function (index) { + layer.close(index); + } }); } return { add: function () { //弹出添加 update = false; show(); - $.CurrentDialog.find("form")[0].reset(); //reset方法只能通过dom调用 - $("#Id").val('00000000-0000-0000-0000-000000000000'); - - parentTree.show(); + vm.$set('$data', { + Id: '00000000-0000-0000-0000-000000000000', + SortNo: 0 + }); }, update: function (ret) { //弹出编辑框 update = true; show(); - $('#Id').val(ret.Id); - $('#Key').val(ret.Key); - $('#Name').val(ret.Name); - $('#Status').selectpicker('val', ret.Status); - $('#SortNo').val(ret.SortNo); - $('#CategoryId').val(ret.CategoryId); - $('#Description').val(ret.Description); - parentTree.show(); - }, - save: function () { //编辑-->保存 - $('#editForm').isValid(function (v) { - if (!v) return; //验证没通过 - $("#editForm").bjuiajax('ajaxForm', { - reload: false, - callback: function (json) { - if (json.statusCode != "200") { - $(this).alertmsg('warn', json.message); - return; - } - list.reload(); - ztree.reload(); - } - }); - }); + vm.$set('$data', ret); } }; }(); //删除 function del() { - var selected = list.getSelectedObj(); + var selected = list.getSelectedProperties("Id"); if (selected == null) return; - $.post('/ResourceManager/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { + $.post('/ResourceManager/Delete', + { ids: selected }, function (data) { + if (data.Status) { list.reload(); ztree.reload(); } else { - $(this).alertmsg('warn', data.message); + $(this).alertmsg('warn', data.Message); } }, "json"); } diff --git a/OpenAuth.Mvc/BllScripts/roleManager.js b/OpenAuth.Mvc/BllScripts/roleManager.js index fdf5135d..bbce1fff 100644 --- a/OpenAuth.Mvc/BllScripts/roleManager.js +++ b/OpenAuth.Mvc/BllScripts/roleManager.js @@ -219,7 +219,7 @@ function del() { if (selected == null) return; $.post('/RoleManager/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { + if (data.Status) { list.reload(); orgtree.reload(); } diff --git a/OpenAuth.Mvc/BllScripts/stockManager.js b/OpenAuth.Mvc/BllScripts/stockManager.js index 977d0365..94bb0244 100644 --- a/OpenAuth.Mvc/BllScripts/stockManager.js +++ b/OpenAuth.Mvc/BllScripts/stockManager.js @@ -233,7 +233,7 @@ function del() { if (selected == null) return; $.post('/StockManager/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { + if (data.Status) { list.reload(); ztree.reload(); } diff --git a/OpenAuth.Mvc/BllScripts/usermanager.js b/OpenAuth.Mvc/BllScripts/usermanager.js index 0c849c4a..f523aacc 100644 --- a/OpenAuth.Mvc/BllScripts/usermanager.js +++ b/OpenAuth.Mvc/BllScripts/usermanager.js @@ -1,5 +1,11 @@ -//左边分类导航树 -var maintree = function () { +$(function () { + $("#Organizations").on("click", function () { + parent.reload(); + }); +}); + +//左边导航 +var ztree = function () { var url = '/OrgManager/LoadOrg'; var setting = { view: { selectedMulti: false }, @@ -24,13 +30,7 @@ var maintree = function () { var load = function () { $.getJSON(url, function (json) { var zTreeObj = $.fn.zTree.init($("#orgtree"), setting, json); - var firstId; //tree的第一个ID - if (json.length > 0) { - firstId = json[0].Id; - } else { - firstId = -1; - } - list.reload(firstId); + list.reload(); zTreeObj.expandAll(true); }); }; @@ -44,79 +44,83 @@ var maintree = function () { //grid列表模块 function MainGrid() { var url = '/UserManager/Load?orgId='; - var selectedId ='00000000-0000-0000-0000-000000000000'; //ztree选中的模块 - this.maingrid = $('#maingrid').datagrid({ - showToolbar: false, - filterThead: false, - target: $(this), - loadType: 'GET', - columns: [ - { - name: 'Id', - label: 'Id', - width: 100 - , hide: true - }, - { - name: 'Account', - label: '账号', - width: 100 - }, - { - name: 'Name', - label: '名称', - width: 100 - }, - { - name: 'Sex', - label: '性别', - width: 100 - , align: 'center', - items: [{ '0': '男' }, { '1': '女' }], - }, - { - name: 'Status', - label: '状态', - width: 100 - , align: 'center', - items: [{ '0': '默认' }, { '1': '状态1' }], - }, - { - name: 'Type', - label: '用户类型', - width: 100 - , align: 'center', - items: [{ '0': '默认' }, { '1': '类型' }], - } - - ], - dataUrl: url + selectedId, //todo:这里如果配置data:[]的话,不会自动加载,但在分页的下拉中会有undefined - fullGrid: true, - showLinenumber: true, - showCheckboxcol: true, - paging: true, - filterMult: false, - showTfoot: false, - - }); + var selectedId = '00000000-0000-0000-0000-000000000000'; //ztree选中的模块 + this.maingrid = $('#maingrid') + .jqGrid({ + colModel: [ + { + name: 'Id', + index: 'Id', + hidden: true + }, + { + index: 'Name', + name: 'Name', + label: '姓名' + }, + { + index: 'Account', + name: 'Account', + label: '账号' + }, + { + index: 'Sex', + name: 'Sex', + label: '性别' + + }, + { + index: 'OrganizationIds', + name: 'OrganizationIds', + hidden:true + }, + { + index: 'Organizations', + name: 'Organizations', + label: '所属机构' + + } + ], + url: url + selectedId, + datatype: "json", + + viewrecords: true, + rowNum: 18, + pager: "#grid-pager", + altRows: true, + height: 'auto', + multiselect: true, + multiboxonly: true, + + loadComplete: function () { + var table = this; + setTimeout(function () { + updatePagerIcons(table); + }, + 0); + } + }).jqGrid('navGrid', "#grid-pager", { + edit: false, add: false, del: false, refresh: false, search: false + }); this.reload = function (id) { if (id != undefined) selectedId = id; - this.maingrid.datagrid('reload', { dataUrl: url + selectedId }); + this.maingrid.jqGrid("setGridParam", { url: url + selectedId }) + .trigger("reloadGrid", [{ page: 1 }]); //重载JQGrid + }; }; MainGrid.prototype = new Grid(); var list = new MainGrid(); +var vm = new Vue({ + el: '#editDlg' +}); -//编辑时,选择上级弹出的树 -var parentTree = function () { - var nameDom = "#Organizations"; - var idDom = "#OrganizationIds"; +//上级机构选择框 +var parent = function () { //ztree搜索框 var zTreeObj; var setting = { - view: { - selectedMulti: false - }, + view: { selectedMulti: true }, check: { enable: true, chkStyle: "checkbox", @@ -135,113 +139,127 @@ var parentTree = function () { } }, callback: { - onClick: zTreeOnClick, - onCheck: zTreeCheck + onClick: onClick, + onCheck: onCheck } }; + var showMenu = function () { + $("#menuContent").css({ left: "10px", top: $("#Organizations").outerHeight() + "px" }).slideDown("fast"); + $("body").bind("mousedown", onBodyDown); + }; + function onClick(e, treeId, treeNode) { + var nodes = zTreeObj.getSelectedNodes(); + for (var i = 0, l = nodes.length; i < l; i++) { + vm.$set('Organizations', nodes[i].Name); + vm.$set('OrganizationIds', nodes[i].Id); + break; + } + hideMenu(); + } - function zTreeCheck(event, treeId, treeNode) { + function onCheck(e, treeId, treeNode) { var nodes = zTreeObj.getCheckedNodes(true); + var ids = nodes.map(function (e) { return e.Id; }).join(","); var names = nodes.map(function (e) { return e.Name; }).join(","); - $(nameDom).val(names); - $(idDom).val(ids); + vm.$set('Organizations', names); + vm.$set('OrganizationIds', ids); } - function zTreeOnClick(event, treeId, treeNode) { - zTreeObj.checkNode(treeNode, !treeNode.checked, true, true); - event.preventDefault(); + function onBodyDown(event) { + if (!(event.target.id == "menuContent" || $(event.target).parents("#menuContent").length > 0)) { + hideMenu(); + } + } + function hideMenu() { + $("#menuContent").fadeOut("fast"); + $("body").unbind("mousedown", onBodyDown); } - return { - show: function () { - $.getJSON('/OrgManager/LoadOrg', function (json) { - zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json); - var orgstr = $(idDom).val(); - var name = ''; - if (orgstr != '') { - var nodeIds = orgstr.split(','); - $.each(nodeIds, function () { - var node = zTreeObj.getNodeByParam("Id", this, null); - name += ',' + node.Name; - zTreeObj.checkNode(node, true, true); - }); - $(nameDom).val(name.substr(1)); //显示名称 + reload: function () { + var index = layer.load(); + $.getJSON("/OrgManager/LoadOrg", { + page: 1, rows: 10000 + }, function (json) { + layer.close(index); + if (json.length == 0) { + vm.$set('Organizations', ''); + vm.$set('OrganizationIds', ''); + return; } + zTreeObj = $.fn.zTree.init($("#org"), setting, json); zTreeObj.expandAll(true); + showMenu(); }); } - }; + } }(); //添加(编辑)对话框 var editDlg = function () { var update = false; var show = function () { - BJUI.dialog({ id: 'editDlg', title: '编辑对话框', target: '#editDlg' }); - $("#btnSave").on("click", function () { - editDlg.save(); + layer.open({ + type: 1, + skin: 'layui-layer-rim', //加上边框 + title: "用户管理", //不显示标题 + area: ['400px', '300px'], //宽高 + content: $('#editDlg'), //捕获的元素 + btn: ['保存', '关闭'], + yes: function (index, layero) { + $.post("/UserManager/Add", vm.$data, function (data) { + layer.msg(data.Message); + if (data.Status) { + list.reload(); + ztree.reload(); + } + }, "json"); + }, + cancel: function (index) { + layer.close(index); + } }); } return { add: function () { //弹出添加 update = false; show(); - $.CurrentDialog.find("form")[0].reset(); //reset方法只能通过dom调用 - $("#Id").val('00000000-0000-0000-0000-000000000000'); - parentTree.show(); - + vm.$set('$data', + { + Id:'00000000-0000-0000-0000-000000000000', + Sex:0 + }); }, update: function (ret) { //弹出编辑框 update = true; show(); - $('#Id').val(ret.Id); - $('#Account').val(ret.Account); - $('#Name').val(ret.Name); - $('#Sex').selectpicker('val', ret.Sex); - $('#Status').selectpicker('val', ret.Status); - $('#Type').selectpicker('val', ret.Type); - $("#OrganizationIds").val(ret.OrganizationIds); - parentTree.show(); - }, - save: function () { //编辑-->保存 - $('#editForm').isValid(function (v) { - if (!v) return; //验证没通过 - $("#editForm").bjuiajax('ajaxForm', { - reload: false, - callback: function (json) { - if (json.statusCode != "200") { - $(this).alertmsg('warn', json.message); - return; - } - list.reload(); - maintree.reload(); - } - }); - }); + vm.$set('$data', ret); } }; }(); + + //删除 function del() { - var selected = list.getSelectedObj(); + var selected = list.getSelectedProperties("Id"); if (selected == null) return; - $.post('/UserManager/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { + $.post('/UserManager/Delete', + { ids: selected }, + function (data) { + if (data.Status) { list.reload(); - maintree.reload(); + ztree.reload(); } else { - $(this).alertmsg('warn', data.message); + layer.msg(data.Message); } }, "json"); } - //自定义的编辑按钮 function edit() { var selected = list.getSelectedObj(); @@ -329,6 +347,4 @@ function openAssignUserElement(obj) { key: "UserElement" } }); -} - -//@@ sourceURL=UserManager.js \ No newline at end of file +} \ No newline at end of file diff --git a/OpenAuth.Mvc/BllScripts/workflowSchemaManager.js b/OpenAuth.Mvc/BllScripts/workflowSchemaManager.js index 298eab90..722fd088 100644 --- a/OpenAuth.Mvc/BllScripts/workflowSchemaManager.js +++ b/OpenAuth.Mvc/BllScripts/workflowSchemaManager.js @@ -35,7 +35,7 @@ function del() { if (selected == null) return; $.post('/StockManager/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { + if (data.Status) { list.reload(); ztree.reload(); } @@ -66,7 +66,7 @@ function del() { if (selected == null) return; $.post('/WorkflowSchemas/Del?code=' +selected.Code, function (data) { - if (data.statusCode == "200") { + if (data.Status) { list.reload(); } else { diff --git a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs index 5f6e1f91..993e2796 100644 --- a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs +++ b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs @@ -95,13 +95,14 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(Result); } - public string Delete(string Id) + [HttpPost] + public string Delete(Guid[] ids) { try { - foreach (var obj in Id.Split(',')) + foreach (var obj in ids) { - _app.Delete(Guid.Parse(obj)); + _app.Delete(obj); } } catch (Exception e) diff --git a/OpenAuth.Mvc/Controllers/ResourceManagerController.cs b/OpenAuth.Mvc/Controllers/ResourceManagerController.cs index c64a3032..4f50f624 100644 --- a/OpenAuth.Mvc/Controllers/ResourceManagerController.cs +++ b/OpenAuth.Mvc/Controllers/ResourceManagerController.cs @@ -56,11 +56,12 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(models); } - public string Delete(Guid Id) + [HttpPost] + public string Delete(Guid[] ids) { try { - _app.Delete(Id); + _app.Delete(ids); } catch (Exception e) { diff --git a/OpenAuth.Mvc/Controllers/UserManagerController.cs b/OpenAuth.Mvc/Controllers/UserManagerController.cs index f945176b..a8296ec8 100644 --- a/OpenAuth.Mvc/Controllers/UserManagerController.cs +++ b/OpenAuth.Mvc/Controllers/UserManagerController.cs @@ -50,15 +50,12 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize)); } - public string Delete(Guid Id) + [HttpPost] + public string Delete(Guid[] ids) { try { - _app.Delete(Id); - //foreach (var obj in Id.Split(',')) - //{ - // _app.Delete(int.Parse(obj)); - //} + _app.Delete(ids); } catch (Exception e) { diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index 2aad8e9b..77ee9332 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -182,6 +182,7 @@ + diff --git a/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml b/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml index 8b5b19e3..fecf2158 100644 --- a/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml +++ b/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml @@ -1,108 +1,99 @@ @{ Layout = "~/Views/Shared/_Layout.cshtml"; } - -@{ Html.RenderAction("MenuHeader", "Home");} -
-
-
-
    -
    - -
    -
    -
    -
    + + - -