mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-08-23 13:06:48 +08:00
完成导航动态加载
This commit is contained in:
parent
cd31e8791d
commit
2793d20ef4
@ -4,6 +4,7 @@ using OpenAuth.Domain.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenAuth.App.ViewModel;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
@ -16,18 +17,6 @@ namespace OpenAuth.App
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
public int GetModuleCntInOrg(int orgId)
|
||||
{
|
||||
if (orgId == 0)
|
||||
{
|
||||
return _repository.Find(null).Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _repository.GetModuleCntInOrgs(GetSubOrgIds(orgId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个部门及子部门全部Modules
|
||||
/// </summary>
|
||||
@ -61,7 +50,19 @@ namespace OpenAuth.App
|
||||
return _repository.Find(u => u.ParentId == 0).ToList();
|
||||
}
|
||||
|
||||
|
||||
public List<ModuleView> LoadByParent(int parentId)
|
||||
{
|
||||
var modules = new List<ModuleView>();
|
||||
var roots = _repository.Find(u => u.ParentId == parentId);
|
||||
foreach (var module in roots)
|
||||
{
|
||||
ModuleView mv = module;
|
||||
mv.Childern = LoadByParent(module.Id);
|
||||
modules.Add(mv);
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
|
||||
public Module Find(int id)
|
||||
{
|
||||
@ -141,6 +142,5 @@ namespace OpenAuth.App
|
||||
|
||||
#endregion 私有方法
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -49,6 +49,7 @@
|
||||
<Compile Include="UserManagerApp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="OrgManagerApp.cs" />
|
||||
<Compile Include="ViewModel\ModuleView.cs" />
|
||||
<Compile Include="ViewModel\UserView.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
55
OpenAuth.App/ViewModel/ModuleView.cs
Normal file
55
OpenAuth.App/ViewModel/ModuleView.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
public class ModuleView
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主页面URL
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 父节点流水号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点图标文件名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string IconName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 子节点
|
||||
/// </summary>
|
||||
public List<ModuleView> Childern = new List<ModuleView>();
|
||||
|
||||
public static implicit operator ModuleView(Module module)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<Module, ModuleView>(module);
|
||||
}
|
||||
|
||||
public static implicit operator Module(ModuleView view)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<ModuleView, Module>(view);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,12 +1,25 @@
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
private ModuleManagerApp _app;
|
||||
|
||||
public HomeController()
|
||||
{
|
||||
_app = (ModuleManagerApp)DependencyResolver.Current.GetService(typeof(ModuleManagerApp));
|
||||
}
|
||||
|
||||
public string GetModules(int parentId = 0)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.LoadByParent(parentId));
|
||||
}
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
return View(_app.LoadByParent(0));
|
||||
}
|
||||
|
||||
public ActionResult Main()
|
||||
|
@ -23,28 +23,6 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Add(int id = 0)
|
||||
{
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改模块
|
||||
[HttpPost]
|
||||
public string Add(Module model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载模块下面的所有模块
|
||||
/// </summary>
|
||||
@ -64,16 +42,33 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
Id = 0,
|
||||
ParentId = -1,
|
||||
Name = "全部模块",
|
||||
Name = "根节点",
|
||||
CascadeId = "0"
|
||||
});
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
//获取模块下面模块个数
|
||||
public int GetCount(int orgId)
|
||||
|
||||
public ActionResult Add(int id = 0)
|
||||
{
|
||||
return _app.GetModuleCntInOrg(orgId);
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改模块
|
||||
[HttpPost]
|
||||
public string Add(Module model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
public string Delete(string Id)
|
||||
|
@ -1,4 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
@model List<OpenAuth.App.ViewModel.ModuleView>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
@ -84,76 +85,70 @@
|
||||
},
|
||||
debug: true, // [可选]调试模式 [true|false,默认false]
|
||||
theme: 'sky' // 若有Cookie['bjui_theme'],优先选择Cookie['bjui_theme']。皮肤[五种皮肤:default, orange, purple, blue, red, green]
|
||||
})
|
||||
});
|
||||
|
||||
// main - menu
|
||||
$('#bjui-accordionmenu')
|
||||
.collapse()
|
||||
.on('hidden.bs.collapse', function (e) {
|
||||
$(this).find('> .panel > .panel-heading').each(function () {
|
||||
var $heading = $(this), $a = $heading.find('> h4 > a')
|
||||
|
||||
if ($a.hasClass('collapsed')) $heading.removeClass('active')
|
||||
})
|
||||
var $heading = $(this), $a = $heading.find('> h4 > a');
|
||||
if ($a.hasClass('collapsed')) $heading.removeClass('active');
|
||||
});
|
||||
})
|
||||
.on('shown.bs.collapse', function (e) {
|
||||
$(this).find('> .panel > .panel-heading').each(function () {
|
||||
var $heading = $(this), $a = $heading.find('> h4 > a')
|
||||
|
||||
if (!$a.hasClass('collapsed')) $heading.addClass('active')
|
||||
})
|
||||
})
|
||||
|
||||
var $heading = $(this), $a = $heading.find('> h4 > a');
|
||||
if (!$a.hasClass('collapsed')) $heading.addClass('active');
|
||||
});
|
||||
});
|
||||
$(document).on('click', 'ul.menu-items > li > a', function (e) {
|
||||
var $a = $(this), $li = $a.parent(), options = $a.data('options').toObj()
|
||||
var $a = $(this), $li = $a.parent(), options = $a.data('options').toObj();
|
||||
var onClose = function () {
|
||||
$li.removeClass('active')
|
||||
}
|
||||
$li.removeClass('active');
|
||||
};
|
||||
var onSwitch = function () {
|
||||
$('#bjui-accordionmenu').find('ul.menu-items > li').removeClass('switch')
|
||||
$li.addClass('switch')
|
||||
}
|
||||
|
||||
$li.addClass('active')
|
||||
$('#bjui-accordionmenu').find('ul.menu-items > li').removeClass('switch');
|
||||
$li.addClass('switch');
|
||||
};
|
||||
$li.addClass('active');
|
||||
if (options) {
|
||||
options.url = $a.attr('href')
|
||||
options.onClose = onClose
|
||||
options.onSwitch = onSwitch
|
||||
if (!options.title) options.title = $a.text()
|
||||
|
||||
options.url = $a.attr('href');
|
||||
options.onClose = onClose;
|
||||
options.onSwitch = onSwitch;
|
||||
if (!options.title) options.title = $a.text();
|
||||
if (!options.target)
|
||||
$a.navtab(options)
|
||||
$a.navtab(options);
|
||||
else
|
||||
$a.dialog(options)
|
||||
$a.dialog(options);
|
||||
}
|
||||
|
||||
e.preventDefault()
|
||||
})
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
//时钟
|
||||
var today = new Date(), time = today.getTime()
|
||||
$('#bjui-date').html(today.formatDate('yyyy/MM/dd'))
|
||||
var today = new Date(), time = today.getTime();
|
||||
$('#bjui-date').html(today.formatDate('yyyy/MM/dd'));
|
||||
setInterval(function () {
|
||||
today = new Date(today.setSeconds(today.getSeconds() + 1))
|
||||
$('#bjui-clock').html(today.formatDate('HH:mm:ss'))
|
||||
}, 1000)
|
||||
})
|
||||
today = new Date(today.setSeconds(today.getSeconds() + 1));
|
||||
$('#bjui-clock').html(today.formatDate('HH:mm:ss'));
|
||||
}, 1000);
|
||||
|
||||
});
|
||||
|
||||
//菜单-事件
|
||||
function MainMenuClick(event, treeId, treeNode) {
|
||||
event.preventDefault()
|
||||
|
||||
if (treeNode.isParent) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId)
|
||||
|
||||
zTree.expandNode(treeNode, !treeNode.open, false, true, true)
|
||||
return
|
||||
}
|
||||
event.preventDefault();
|
||||
//if (treeNode.isParent) {
|
||||
// var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
// zTree.expandNode(treeNode, !treeNode.open, false, true, true);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (treeNode.target && treeNode.target == 'dialog')
|
||||
$(event.target).dialog({ id: treeNode.tabid, url: treeNode.url, title: treeNode.name })
|
||||
$(event.target).dialog({ id: treeNode.tabid, url: treeNode.url, title: treeNode.name });
|
||||
else
|
||||
$(event.target).navtab({ id: treeNode.tabid, url: treeNode.url, title: treeNode.name, fresh: treeNode.fresh, external: treeNode.external })
|
||||
$(event.target).navtab({ id: treeNode.tabid, url: treeNode.url, title: treeNode.name, fresh: treeNode.fresh, external: treeNode.external });
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
@ -200,19 +195,30 @@
|
||||
<ul id="bjui-hnav-navbar">
|
||||
<li class="active">
|
||||
<a href="javascript:;" data-toggle="slidebar"><i class="fa fa-check-square-o"></i> 应用管理</a>
|
||||
<div class="items hide" data-noinit="true">
|
||||
<div class="items hide" data-noinit="true" id="navTree">
|
||||
|
||||
<ul id="bjui-doc-tree-base" class="ztree ztree_main" data-toggle="ztree" data-on-click="MainMenuClick"
|
||||
data-expand-all="true" data-faicon="star-o" data-tit="基本设置">
|
||||
<li data-id="99" data-pid="0" data-faicon="folder-open-o" data-faicon-close="folder-o">系统设置</li>
|
||||
<li data-id="100" data-pid="99" data-url="OrgManager/Index" data-tabid="orgManager" data-faicon="caret-right">机构管理</li>
|
||||
<li data-id="101" data-pid="99" data-url="UserManager/Index" data-tabid="userManager" data-faicon="caret-right">用户管理</li>
|
||||
<li data-id="102" data-pid="99" data-url="RoleManager/Index" data-tabid="roleManager" data-faicon="caret-right">角色管理</li>
|
||||
<li data-id="103" data-pid="99" data-url="ModuleManager/Index" data-tabid="moduleManager" data-faicon="caret-right">模块管理</li>
|
||||
data-expand-all="true" data-faicon="star-o" data-tit="控制台">
|
||||
|
||||
@foreach (var module in Model)
|
||||
{
|
||||
<li data-id="@module.Id" data-pid="0" data-faicon="folder-open-o" data-faicon-close="folder-o">@module.Name</li>
|
||||
|
||||
foreach (var child in module.Childern)
|
||||
{
|
||||
<li data-id="@child.Id" data-pid="@child.ParentId"
|
||||
data-faicon="caret-right"
|
||||
data-url="@child.Url" data-tabid="@child.Id">@child.Name</li>
|
||||
}
|
||||
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-cog"></i> 系统设置 <span class="caret"></span></a>
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="fa fa-cog"></i> 系统设置 <span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="#">角色权限</a></li>
|
||||
<li><a href="#">用户列表</a></li>
|
||||
|
@ -45,8 +45,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<label for="IconName" class="control-label x105">节点图标文件名称:</label>
|
||||
<input type="text" name="IconName" id="IconName" value="@Model.IconName"
|
||||
data-rule="required" size="20">
|
||||
<input type="text" name="IconName" id="IconName" value="@Model.IconName" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -62,8 +61,7 @@
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Vector" class="control-label x105">矢量图标:</label>
|
||||
<input type="text" name="Vector" id="Vector" value="@Model.Vector"
|
||||
data-rule="required" size="20">
|
||||
<input type="text" name="Vector" id="Vector" value="@Model.Vector" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -82,6 +82,17 @@ namespace OpenAuth.UnitTest
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestLoad()
|
||||
{
|
||||
var modules = _app.LoadByParent(0);
|
||||
foreach (var module in modules)
|
||||
{
|
||||
|
||||
Console.WriteLine(module.Name);
|
||||
}
|
||||
}
|
||||
|
||||
public Module Add(int parent = 0)
|
||||
{
|
||||
var module = new Module()
|
||||
|
Loading…
Reference in New Issue
Block a user