mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
修改界面,重构授权代码
This commit is contained in:
parent
43c44d30af
commit
36d77b17f6
@ -11,29 +11,29 @@ namespace OpenAuth.App
|
||||
/// </summary>
|
||||
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<ModuleView>(),
|
||||
Resources = _service.Resources,
|
||||
Roles = _service.Roles
|
||||
User = service.User,
|
||||
Orgs = service.Orgs,
|
||||
Modules = service.Modules.MapToList<ModuleView>(),
|
||||
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);
|
||||
|
@ -11,7 +11,12 @@ namespace OpenAuth.Domain.Interface
|
||||
IEnumerable<Category> LoadInOrgs(params Guid[] orgId);
|
||||
int GetCategoryCntInOrgs(params Guid[] orgIds);
|
||||
IEnumerable<Category> LoadInOrgs(int pageindex, int pagesize, params Guid[] orgIds);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取子分类ID
|
||||
/// </summary>
|
||||
Guid[] GetSubIds(Guid orgId);
|
||||
|
||||
void Delete(Guid id);
|
||||
|
||||
}
|
||||
|
@ -67,6 +67,8 @@
|
||||
<Compile Include="Relevance.cs" />
|
||||
<Compile Include="Resource.cs" />
|
||||
<Compile Include="Role.cs" />
|
||||
<Compile Include="Service\AuthoriseFactory.cs" />
|
||||
<Compile Include="Service\SystemAuthService.cs" />
|
||||
<Compile Include="Service\AuthoriseService.cs" />
|
||||
<Compile Include="Service\ModuleEleManService.cs" />
|
||||
<Compile Include="Service\ModuleManService.cs" />
|
||||
|
31
OpenAuth.Domain/Service/AuthoriseFactory.cs
Normal file
31
OpenAuth.Domain/Service/AuthoriseFactory.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using OpenAuth.Domain.Interface;
|
||||
|
||||
namespace OpenAuth.Domain.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 权限分配工厂,根据是否是开发者账号创建
|
||||
/// </summary>
|
||||
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<User>(u =>u.Account == loginuser)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -22,14 +22,10 @@ namespace OpenAuth.Domain.Service
|
||||
/// </summary>
|
||||
public class AuthoriseService
|
||||
{
|
||||
private IUnitWork _unitWork;
|
||||
protected IUnitWork _unitWork;
|
||||
protected User _user;
|
||||
|
||||
private User _user;
|
||||
private List<Module> _modules; //用户可访问的模块
|
||||
private List<ModuleElement> _moduleElements; //用户可访问的菜单
|
||||
private List<Resource> _resources; //用户可访问的资源
|
||||
private List<Org> _orgs; //用户可访问的机构
|
||||
private List<Role> _roles; //用户角色
|
||||
private List<Guid> _userRoleIds; //用户角色GUID
|
||||
|
||||
public AuthoriseService(IUnitWork unitWork)
|
||||
{
|
||||
@ -38,32 +34,37 @@ namespace OpenAuth.Domain.Service
|
||||
|
||||
public List<Module> Modules
|
||||
{
|
||||
get { return _modules; }
|
||||
get { return GetModulesQuery().ToList(); }
|
||||
}
|
||||
|
||||
public List<Role> Roles
|
||||
{
|
||||
get { return _roles;}
|
||||
get { return GetRolesQuery().ToList(); }
|
||||
}
|
||||
|
||||
public List<ModuleElement> ModuleElements
|
||||
{
|
||||
get { return _moduleElements; }
|
||||
get { return GetModuleElementsQuery().ToList(); }
|
||||
}
|
||||
|
||||
public List<Resource> Resources
|
||||
{
|
||||
get { return _resources; }
|
||||
get { return GetResourcesQuery().ToList(); }
|
||||
}
|
||||
|
||||
public List<Org> Orgs
|
||||
{
|
||||
get { return _orgs; }
|
||||
get { return GetOrgsQuery().ToList(); }
|
||||
}
|
||||
|
||||
public User User
|
||||
{
|
||||
get { return _user; }
|
||||
set
|
||||
{
|
||||
_user = value;
|
||||
_userRoleIds = _unitWork.Find<Relevance>(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);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载用户可访问的所有机构/资源/菜单
|
||||
/// <para>李玉宝于2016-07-19 10:32:19</para>
|
||||
/// 用户可访问的机构
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
public void LoadAuthControls(string name)
|
||||
/// <returns>IQueryable<Org>.</returns>
|
||||
public virtual IQueryable<Org> GetOrgsQuery()
|
||||
{
|
||||
if (name == "System")
|
||||
{
|
||||
_user = new User{Account = "System", Id = Guid.Empty};
|
||||
LoadForSystem();
|
||||
}
|
||||
else
|
||||
{
|
||||
_user = _unitWork.FindSingle<User>(u => u.Account == name);
|
||||
if (_user != null)
|
||||
{
|
||||
LoadForUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载用户权限
|
||||
/// <para>李玉宝于2016-07-19 10:20:16</para>
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
private void LoadForUser()
|
||||
{
|
||||
//用户角色
|
||||
var userRoleIds =
|
||||
_unitWork.Find<Relevance>(u => u.FirstId == _user.Id && u.Key == "UserRole").Select(u => u.SecondId).ToList();
|
||||
|
||||
_roles = _unitWork.Find<Role>(u => userRoleIds.Contains(u.Id)).ToList();
|
||||
//用户角色与自己分配到的模块ID
|
||||
var moduleIds = _unitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserModule") ||
|
||||
(u.Key == "RoleModule" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
//得出最终用户拥有的模块
|
||||
_modules = _unitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo).ToList();
|
||||
|
||||
//用户角色与自己分配到的菜单ID
|
||||
var elementIds = _unitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserElement") ||
|
||||
(u.Key == "RoleElement" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
//模块菜单权限
|
||||
_moduleElements = _unitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id)).ToList();
|
||||
|
||||
//用户角色与自己分配到的资源ID
|
||||
var resourceIds = _unitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserResource") ||
|
||||
(u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
_resources = _unitWork.Find<Resource>(u => resourceIds.Contains(u.Id)).ToList();
|
||||
|
||||
//用户角色与自己分配到的机构ID
|
||||
var orgids = _unitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserOrg") ||
|
||||
(u.Key == "RoleOrg" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
_orgs = _unitWork.Find<Org>(u => orgids.Contains(u.Id)).ToList();
|
||||
(u.Key == "RoleOrg" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return _unitWork.Find<Org>(u => orgids.Contains(u.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载系统管理员权限
|
||||
/// <para>李玉宝于2016-07-19 10:19:31</para>
|
||||
/// 获取用户可访问的资源
|
||||
/// </summary>
|
||||
private void LoadForSystem()
|
||||
/// <returns>IQueryable<Resource>.</returns>
|
||||
public virtual IQueryable<Resource> GetResourcesQuery()
|
||||
{
|
||||
_modules = _unitWork.Find<Module>(null).ToList();
|
||||
_moduleElements = _unitWork.Find<ModuleElement>(null).ToList();
|
||||
_roles = _unitWork.Find<Role>(null).ToList();
|
||||
_resources = _unitWork.Find<Resource>(null).OrderBy(u => u.SortNo).ToList();
|
||||
_orgs = _unitWork.Find<Org>(null).OrderBy(u => u.SortNo).ToList();
|
||||
var resourceIds = _unitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserResource") ||
|
||||
(u.Key == "RoleResource" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return _unitWork.Find<Resource>(u => resourceIds.Contains(u.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模块菜单权限
|
||||
/// </summary>
|
||||
public virtual IQueryable<ModuleElement> GetModuleElementsQuery()
|
||||
{
|
||||
var elementIds = _unitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserElement") ||
|
||||
(u.Key == "RoleElement" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return _unitWork.Find<ModuleElement>(u => elementIds.Contains(u.Id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 得出最终用户拥有的模块
|
||||
/// </summary>
|
||||
public virtual IQueryable<Module> GetModulesQuery()
|
||||
{
|
||||
var moduleIds = _unitWork.Find<Relevance>(
|
||||
u =>
|
||||
(u.FirstId == _user.Id && u.Key == "UserModule") ||
|
||||
(u.Key == "RoleModule" && _userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId);
|
||||
return _unitWork.Find<Module>(u => moduleIds.Contains(u.Id)).OrderBy(u => u.SortNo);
|
||||
}
|
||||
|
||||
//用户角色
|
||||
public virtual IQueryable<Role> GetRolesQuery()
|
||||
{
|
||||
return _unitWork.Find<Role>(u => _userRoleIds.Contains(u.Id));
|
||||
}
|
||||
}
|
||||
}
|
@ -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<ModuleElement> 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<ModuleElement>();
|
||||
}
|
||||
|
||||
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<dynamic> LoadWithAccess(string username, string accessType, Guid firstId, Guid moduleId)
|
||||
{
|
||||
var listVms = new List<dynamic>();
|
||||
_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<Relevance>(u =>u.Key == accessType
|
||||
&& u.FirstId == firstId && u.SecondId == element.Id);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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<Module>(),
|
||||
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)
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
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<dynamic>();
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前节点的所有下级节点
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
@ -96,7 +112,7 @@ namespace OpenAuth.Domain.Service
|
||||
|
||||
public void Delete(Guid[] ids)
|
||||
{
|
||||
_repository.Delete(u =>ids.Contains(u.Id));
|
||||
_repository.Delete(u => ids.Contains(u.Id));
|
||||
}
|
||||
|
||||
public void AddOrUpdate(Resource resource)
|
||||
@ -124,14 +140,14 @@ namespace OpenAuth.Domain.Service
|
||||
public List<dynamic> LoadWithAccess(string username, string accessType, Guid firstId, Guid cId)
|
||||
{
|
||||
var listVms = new List<dynamic>();
|
||||
_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)
|
||||
{
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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<Func<Stock, bool>> exp = u => u.OrgId != null &&orgs.Contains(u.OrgId.Value) && (u.Viewable == "" || keys.Contains(u.Viewable));
|
||||
var stocks = _repository.Find(pageindex, pagesize, "", exp);
|
||||
|
58
OpenAuth.Domain/Service/SystemAuthService.cs
Normal file
58
OpenAuth.Domain/Service/SystemAuthService.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 领域服务
|
||||
/// <para>超级管理员权限</para>
|
||||
/// </summary>
|
||||
public class SystemAuthService : AuthoriseService
|
||||
{
|
||||
public SystemAuthService(IUnitWork unitWork):base(unitWork)
|
||||
{
|
||||
_user = new User { Account = "System", Id = Guid.Empty };
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override IQueryable<Org> GetOrgsQuery()
|
||||
{
|
||||
return _unitWork.Find<Org>(null);
|
||||
}
|
||||
|
||||
public override IQueryable<Resource> GetResourcesQuery()
|
||||
{
|
||||
return _unitWork.Find<Resource>(null);
|
||||
}
|
||||
|
||||
public override IQueryable<ModuleElement> GetModuleElementsQuery()
|
||||
{
|
||||
return _unitWork.Find<ModuleElement>(null);
|
||||
}
|
||||
|
||||
public override IQueryable<Module> GetModulesQuery()
|
||||
{
|
||||
return _unitWork.Find<Module>(null);
|
||||
}
|
||||
|
||||
public override IQueryable<Role> GetRolesQuery()
|
||||
{
|
||||
//用户角色
|
||||
return _unitWork.Find<Role>(null);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,107 +1,10 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.Mvc
|
||||
// Author : yubaolee
|
||||
// Created : 04-06-2016
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 04-06-2016
|
||||
// ***********************************************************************
|
||||
// <copyright file="modulemanager.js" company="www.cnblogs.com/yubaolee">
|
||||
// 版权所有(C) 2015
|
||||
// </copyright>
|
||||
// <summary>模块管理脚本</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
//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,152 +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 = "#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) {
|
||||
$.post('/moduleManager/Delete',
|
||||
{ ids: selected }, function (data) {
|
||||
if (data.Status) {
|
||||
list.reload();
|
||||
ztree.reload();
|
||||
@ -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
|
@ -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 () {
|
||||
|
89
OpenAuth.Mvc/BllScripts/parentTree.js
Normal file
89
OpenAuth.Mvc/BllScripts/parentTree.js
Normal file
@ -0,0 +1,89 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.Mvc
|
||||
// Author : yubaolee
|
||||
// Created : 10-16-2016
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 10-16-2016
|
||||
// ***********************************************************************
|
||||
// <copyright file="parentTree.js" company="www.cnblogs.com/yubaolee">
|
||||
// 版权所有(C) 2015
|
||||
// </copyright>
|
||||
// <summary>单击文本框弹出的选择列表</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
$(function () {
|
||||
$("#ParentName").on("click", function () {
|
||||
$("#CategoryName").on("click", function () {
|
||||
parent.reload();
|
||||
});
|
||||
});
|
||||
@ -117,68 +117,7 @@ var vm = new Vue({
|
||||
});
|
||||
|
||||
//上级机构选择框
|
||||
var parent = function (name,id) { //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: $("#"+name).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(name, nodes[i].Name);
|
||||
vm.$set(id, 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("/CategoryManager/LoadForTree", {
|
||||
page: 1, rows: 10000
|
||||
}, function (json) {
|
||||
layer.close(index);
|
||||
if (json.length == 0) {
|
||||
vm.$set(name, '');
|
||||
vm.$set(id, '');
|
||||
return;
|
||||
}
|
||||
zTreeObj = $.fn.zTree.init($("#org"), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
showMenu();
|
||||
});
|
||||
}
|
||||
}
|
||||
}("CategoryName","CategoryId");
|
||||
var parent = new ParentTree("/CategoryManager/LoadForTree", "CategoryName", "CategoryId");
|
||||
|
||||
//添加(编辑)对话框
|
||||
var editDlg = function () {
|
||||
@ -192,7 +131,7 @@ var editDlg = function () {
|
||||
content: $('#editDlg'), //捕获的元素
|
||||
btn: ['保存', '关闭'],
|
||||
yes: function (index, layero) {
|
||||
$.post("/CategoryManager/Add", vm.$data, function (data) {
|
||||
$.post("/ResourceManager/Add", vm.$data, function (data) {
|
||||
layer.msg(data.Message);
|
||||
if (data.Status) {
|
||||
list.reload();
|
||||
|
@ -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)
|
||||
|
@ -182,6 +182,7 @@
|
||||
<Content Include="BllScripts\assignModuleElement.js" />
|
||||
<Content Include="BllScripts\categoryManager.js" />
|
||||
<Content Include="BllScripts\jqEvent.js" />
|
||||
<Content Include="BllScripts\parentTree.js" />
|
||||
<Content Include="BllScripts\processDetail.js" />
|
||||
<Content Include="BllScripts\grid.js" />
|
||||
<Content Include="BllScripts\moduleElementMan.js" />
|
||||
|
@ -1,108 +1,99 @@
|
||||
@{
|
||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
@{ Html.RenderAction("MenuHeader", "Home");}
|
||||
<div class="bjui-pageContent tableContent" style="position: relative">
|
||||
<div class="clearfix">
|
||||
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
|
||||
<ul id="tree" class="ztree"></ul>
|
||||
</div>
|
||||
|
||||
<div id="detail" style="margin-left: 225px;">
|
||||
<table id="maingrid" class="table table-bordered"></table>
|
||||
</div>
|
||||
</div>
|
||||
<!-- #section:basics/content.breadcrumbs -->
|
||||
<div class="breadcrumbs" id="breadcrumbs">
|
||||
<ul class="breadcrumb">
|
||||
<li>
|
||||
<i class="ace-icon fa fa-home home-icon"></i>
|
||||
<a href="#">资源管理</a>
|
||||
</li>
|
||||
<li class="active">列表</li>
|
||||
</ul><!-- /.breadcrumb -->
|
||||
</div>
|
||||
|
||||
<!--编辑对话框-->
|
||||
<div class="bjui-dialog hidden bjui-dialog-container" id="editDlg" data-noinit="true">
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/ModuleManager/Add" class="pageForm" data-toggle="validate" data-reload="false" id="editForm">
|
||||
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<input type="text" id="Id" name="Id" value="" class="hidden" />
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label x120">功能模块名称:</label>
|
||||
<input type="text" id="Name" name="Name" value="" data-rule="required"/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Url" class="control-label x120">主页面URL:</label>
|
||||
<input type="text" id="Url" name="url" value=""/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="ParentName" class="control-label x120">所属模块(空时为根):</label>
|
||||
<input id="ParentId" name="ParentId" style="display: none" />
|
||||
<input type="text" name="ParentName" id="ParentName"
|
||||
data-toggle="selectztree" data-tree="#j_select_tree1">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="HotKey" class="control-label x120">热键:</label>
|
||||
<input type="text" id="HotKey" name="HotKey" value="" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="IsLeaf" class="control-label x120">是否叶子节点:</label>
|
||||
<select name="IsLeaf" id="IsLeaf" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="true">是</option>
|
||||
<option value="false">否</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="IsAutoExpand" class="control-label x120">是否自动展开:</label>
|
||||
<select name="IsAutoExpand" id="IsAutoExpand" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="true">是</option>
|
||||
<option value="false">否</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="IconName" class="control-label x120">节点图标文件名称:</label>
|
||||
<input type="text" id="IconName" name="IconName" value="" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Status" class="control-label x120">当前状态:</label>
|
||||
<input type="text" id="Status" name="Status" value="" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Vector" class="control-label x120">矢量图标:</label>
|
||||
<input type="text" id="Vector" name="Vector" value="" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="SortNo" class="control-label x120">排序号:</label>
|
||||
<input type="text" id="SortNo" name="SortNo" value="" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<!-- /section:basics/content.breadcrumbs -->
|
||||
<div class="page-content">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="col-md-3">
|
||||
<div class="widget-box widget-color-blue">
|
||||
<div class="widget-header">
|
||||
</div>
|
||||
<div class="widget-body">
|
||||
<div class="widget-main">
|
||||
<ul id="orgtree" class="ztree" style="width: 100%"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-9">
|
||||
<div class="widget-box widget-color-blue">
|
||||
<div class="widget-header">
|
||||
@Html.Action("MenuHeader", "Home")
|
||||
</div>
|
||||
<div class="widget-body gridwidth">
|
||||
<div class="widget-main">
|
||||
<div class="row">
|
||||
<div class="col-md-12 ">
|
||||
<table id="maingrid"></table>
|
||||
<div id="grid-pager"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bjui-pageFooter">
|
||||
<ul>
|
||||
<li><button type="button" class="btn btn-close">关闭</button></li>
|
||||
<li><button type="button" class="btn btn-primary" id="btnSave">保存</button></li>
|
||||
</ul>
|
||||
</div><!-- /.page-content -->
|
||||
<!--编辑对话框-->
|
||||
<div id="editDlg" style="display: none">
|
||||
<div class="col-xs-12">
|
||||
<form class="form-horizontal" id="editForm">
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 功能模块名称 </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="Name" check-type="required" v-model="Name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 主页面URL </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="Url" check-type="required" v-model="Url" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 图标 </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="IconName" check-type="required" v-model="IconName" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 排序号 </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="SortNo" check-type="required" v-model="SortNo" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 上级模块</label>
|
||||
<div class="col-sm-9">
|
||||
<input id="ParentName" type="text" v-model="ParentName" />
|
||||
<input id="ParentId" type="hidden" v-model="ParentId" />
|
||||
<div id="menuContent" class="menuContent" style="display: none;">
|
||||
<ul id="org" class="ztree"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="~/BllScripts/grid.js"></script>
|
||||
<script src="~/BllScripts/ModuleManager.js"></script>
|
||||
<script src="~/BllScripts/parentTree.js"></script>
|
||||
<script src="~/BllScripts/ModuleManager.js"></script>
|
||||
<script src="~/BllScripts/jqEvent.js"></script>
|
@ -81,5 +81,6 @@
|
||||
</div>
|
||||
<!--组织修改对话框-->
|
||||
<script src="~/BllScripts/grid.js"></script>
|
||||
<script src="~/BllScripts/parentTree.js"></script>
|
||||
<script src="~/BllScripts/OrgManager.js"></script>
|
||||
<script src="~/BllScripts/jqEvent.js"></script>
|
@ -90,6 +90,7 @@
|
||||
</div>
|
||||
|
||||
<script src="~/BllScripts/grid.js"></script>
|
||||
<script src="~/BllScripts/parentTree.js"></script>
|
||||
<script src="~/BllScripts/ResourceManager.js"></script>
|
||||
<script src="~/BllScripts/jqEvent.js"></script>
|
||||
|
||||
|
@ -36,5 +36,19 @@ namespace OpenAuth.Repository
|
||||
{
|
||||
Delete(u =>u.Id == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前节点的所有下级节点
|
||||
/// </summary>
|
||||
public Guid[] GetSubIds(Guid orgId)
|
||||
{
|
||||
if (orgId == Guid.Empty)
|
||||
{
|
||||
return Find(null).Select(u => u.Id).ToArray();
|
||||
}
|
||||
var org = FindSingle(u => u.Id == orgId);
|
||||
var ids = Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,10 +14,10 @@ namespace OpenAuth.UnitTest
|
||||
[TestMethod]
|
||||
public void TestMethod1()
|
||||
{
|
||||
AuthoriseService _service = new AuthoriseService(new UnitWork() );
|
||||
_service.LoadAuthControls("System");
|
||||
AuthoriseFactory factory = new AuthoriseFactory(new UnitWork() );
|
||||
var service= factory.Create("System");
|
||||
|
||||
var orgs = _service.Orgs;
|
||||
var orgs = service.Orgs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user