diff --git a/db/MongoDB/Navigations.js b/db/MongoDB/Navigations.js index d7667129..8d5bac4d 100644 --- a/db/MongoDB/Navigations.js +++ b/db/MongoDB/Navigations.js @@ -279,7 +279,7 @@ "_id": ObjectId("5bd7b8445fa31256f77e4b14"), "ParentId": "0", "Name": "图标页面", - "Order": NumberInt(55), + "Order": NumberInt(50), "Icon": "fa fa-fa", "Url": "~/Admin/IconView", "Category": "0", @@ -287,6 +287,18 @@ "IsResource": NumberInt(1), "Application": "BA" }, + { + "_id": ObjectId("5bd7b8445fa31256f77e4b15"), + "ParentId": "0", + "Name": "侧边栏", + "Order": NumberInt(55), + "Icon": "fa fa-fa", + "Url": "~/Admin/Sidebar", + "Category": "0", + "Target": "_self", + "IsResource": NumberInt(1), + "Application": "BA" + }, { "_id": ObjectId("5bd7b8445fa31256f77e4b95"), "ParentId": "0", diff --git a/db/MySQL/initData.sql b/db/MySQL/initData.sql index 15089570..6e932fc6 100644 --- a/db/MySQL/initData.sql +++ b/db/MySQL/initData.sql @@ -83,6 +83,7 @@ INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResourc INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (@@identity - 2, '删除', 30, 'fa fa-fa', 'del', '0', 2); INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (@@identity - 3, '分配角色', 40, 'fa fa-fa', 'assignRole', '0', 2); INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (0, '图标页面', 50, 'fa fa-fa', '~/Admin/IconView', '0', 1); +INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (0, '侧边栏', 55, 'fa fa-fa', '~/Admin/Sidebar', '0', 1); INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category) VALUES (0, '用户管理', 60, 'fa fa-user', '~/Admin/Users', '0'); INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (@@identity, '新增', 10, 'fa fa-fa', 'add', '0', 2); INSERT INTO Navigations (ParentId, Name, `Order`, Icon, Url, Category, IsResource) VALUES (@@identity - 1, '编辑', 20, 'fa fa-fa', 'edit', '0', 2); diff --git a/db/Postgresql/initData.sql b/db/Postgresql/initData.sql index b8bcd1cc..e11ad9b5 100644 --- a/db/Postgresql/initData.sql +++ b/db/Postgresql/initData.sql @@ -84,6 +84,7 @@ INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (currval('navigations_id_seq') - 3, '删除', 30, 'fa fa-fa', 'del', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (currval('navigations_id_seq') - 4, '分配角色', 40, 'fa fa-fa', 'assignRole', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (0, '图标页面', 50, 'fa fa-fa', '~/Admin/IconView', '0', 1); +INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (0, '侧边栏', 55, 'fa fa-fa', '~/Admin/Sidebar', '0', 1); INSERT INTO Navigations (ParentId, Name, "order", Icon, Url, Category) VALUES (0, '用户管理', 60, 'fa fa-user', '~/Admin/Users', '0'); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (currval('navigations_id_seq') - 1, '新增', 10, 'fa fa-fa', 'add', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (currval('navigations_id_seq') - 2, '编辑', 20, 'fa fa-fa', 'edit', '0', 2); diff --git a/db/SQLite/InitData.sql b/db/SQLite/InitData.sql index bcf15cf1..3d701bde 100644 --- a/db/SQLite/InitData.sql +++ b/db/SQLite/InitData.sql @@ -83,6 +83,7 @@ INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (last_insert_rowid() - 2, '删除', 30, 'fa fa-fa', 'del', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (last_insert_rowid() - 3, '分配角色', 40, 'fa fa-fa', 'assignRole', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (0, '图标页面', 50, 'fa fa-fa', '~/Admin/IconView', '0', 1); +INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (0, '侧边栏', 55, 'fa fa-fa', '~/Admin/Sidebar', '0', 1); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, '用户管理', 60, 'fa fa-user', '~/Admin/Users', '0'); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (last_insert_rowid(), '新增', 10, 'fa fa-fa', 'add', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (last_insert_rowid() - 1, '编辑', 20, 'fa fa-fa', 'edit', '0', 2); diff --git a/db/SqlServer/InitData.sql b/db/SqlServer/InitData.sql index f2d74ab4..0271917d 100644 --- a/db/SqlServer/InitData.sql +++ b/db/SqlServer/InitData.sql @@ -86,6 +86,7 @@ INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (@@Identity - 2, N'删除', 30, 'fa fa-fa', 'del', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (@@Identity - 3, N'分配角色', 40, 'fa fa-fa', 'assignRole', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (0, N'图标页面', 50, 'fa fa-fa', '~/Admin/IconView', '0', 1); +INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (0, N'侧边栏', 55, 'fa fa-fa', '~/Admin/Sidebar', '0', 1); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category]) VALUES (0, N'用户管理', 60, N'fa fa-user', N'~/Admin/Users', N'0') INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (@@Identity, N'新增', 10, 'fa fa-fa', 'add', '0', 2); INSERT INTO [Navigations] ([ParentId], [Name], [Order], [Icon], [Url], [Category], IsResource) VALUES (@@Identity - 1, N'编辑', 20, 'fa fa-fa', 'edit', '0', 2); diff --git a/src/admin/Bootstrap.Admin/BootstrapAdmin.db b/src/admin/Bootstrap.Admin/BootstrapAdmin.db index 4463f044..78ebda81 100644 Binary files a/src/admin/Bootstrap.Admin/BootstrapAdmin.db and b/src/admin/Bootstrap.Admin/BootstrapAdmin.db differ diff --git a/src/admin/Bootstrap.Admin/Controllers/AdminController.cs b/src/admin/Bootstrap.Admin/Controllers/AdminController.cs index 2e690f9e..9bf293f4 100644 --- a/src/admin/Bootstrap.Admin/Controllers/AdminController.cs +++ b/src/admin/Bootstrap.Admin/Controllers/AdminController.cs @@ -92,6 +92,13 @@ namespace Bootstrap.Admin.Controllers [ResponseCache(Duration = 600)] public PartialViewResult IconView() => PartialView("IconView"); + /// + /// 侧边栏局部视图 + /// + /// + /// 菜单维护页面增删菜单时局部刷新时调用 + public PartialViewResult Sidebar() => PartialView("Sidebar", new NavigatorBarModel(this)); + /// /// 网站设置 /// diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Sidebar.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Sidebar.cshtml new file mode 100644 index 00000000..834a2de9 --- /dev/null +++ b/src/admin/Bootstrap.Admin/Views/Admin/Sidebar.cshtml @@ -0,0 +1,5 @@ +@model NavigatorBarModel +@foreach (var menu in Model.Navigations) +{ + @await Html.PartialAsync("SubNavItem", menu) +} diff --git a/src/admin/Bootstrap.Admin/Views/Shared/Navigator.cshtml b/src/admin/Bootstrap.Admin/Views/Shared/Navigator.cshtml index 0aa5f2ad..240b89f7 100644 --- a/src/admin/Bootstrap.Admin/Views/Shared/Navigator.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Shared/Navigator.cshtml @@ -16,10 +16,7 @@ diff --git a/src/admin/Bootstrap.Admin/wwwroot/js/common-scripts.js b/src/admin/Bootstrap.Admin/wwwroot/js/common-scripts.js index 1116e018..de1bc3e9 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/js/common-scripts.js +++ b/src/admin/Bootstrap.Admin/wwwroot/js/common-scripts.js @@ -252,6 +252,7 @@ $(function () { window.Menu = { url: 'api/Menus', iconView: 'Admin/IconView', + sidebar: 'Admin/Sidebar', title: "分配菜单" }; diff --git a/src/admin/Bootstrap.Admin/wwwroot/js/menus.js b/src/admin/Bootstrap.Admin/wwwroot/js/menus.js index 34f713e3..b3465224 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/js/menus.js +++ b/src/admin/Bootstrap.Admin/wwwroot/js/menus.js @@ -15,7 +15,7 @@ $(function () { var $parentMenuID = $('#parentId'); var $parentMenuName = $('#parentName'); var $category = $('#category'); - var $sidebar = $('.sidebar'); + var $sidebar = $('.sidebar .nav-sidebar'); var initNestMenu = function () { $nestMenuInput = $nestMenu.find('div.dd3-content'); @@ -69,15 +69,7 @@ $(function () { callback: function (result) { if (!result.success) return; if ((result.oper === "save") || result.oper === "del") { - if (result.oper === "del") { - var $menu = $sidebar.find('#menus_' + result.Id + ''); - var $menuCount = $menu.parent().parent().parent(); - $menu.remove(); - if ($menuCount.find('li').length === 0) { - $menuCount.find('.fa-angle-left').remove(); - - } - } + refreshSidebar(); $nestMenu.nestMenu(initNestMenu); } } @@ -232,7 +224,7 @@ $(function () { $dialogNew.find('[data-toggle="LgbValidate"] [aria-describedby]').tooltip('hide'); $dialogNew.hide(); $dialogMenu.modal('show'); - } + }; $dialogMenu.on('hidden.bs.modal', function () { var sta = state.pop(); @@ -275,6 +267,19 @@ $(function () { $nestMenu.nestMenu(initNestMenu); + function refreshSidebar() { + $.bc({ + url: Menu.sidebar, + contentType: 'text/html', + dataType: 'html', + callback: function (result) { + if (result) { + $sidebar.html(result); + } + } + }); + }; + var $scroll = null; $.bc({ url: Menu.iconView, diff --git a/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js b/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js index 0a59c3de..a7b55928 100644 --- a/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js +++ b/src/admin/Bootstrap.Admin/wwwroot/lib/longbow/longbow.dataentity.js @@ -167,7 +167,7 @@ url: options.url, data: iDs, method: 'delete', title: options.delTitle, logData: arrselections, callback: function (result) { if (result) $(options.bootstrapTable).bootstrapTable('refresh'); - handlerCallback.call(that, null, element, { oper: 'del', success: result }); + handlerCallback.call(that, null, element, { oper: 'del', success: result, data: iDs }); } }); } @@ -240,7 +240,7 @@ url: op.url, data: iDs, method: 'delete', title: '删除数据', logData: data, callback: function (result) { if (result) $(op.table).bootstrapTable('refresh'); - handlerCallback.call(op.src, null, e, { oper: 'del', success: result, Id: row.Id }); + handlerCallback.call(op.src, null, e, { oper: 'del', success: result, data: data }); } }); } diff --git a/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs b/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs index 6b1eb118..4875fe0d 100644 --- a/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Controllers/SQLServer/AdminTest.cs @@ -18,6 +18,7 @@ namespace Bootstrap.Admin.Controllers.SqlServer [InlineData("Traces", "访问日志")] [InlineData("Logins", "登录日志")] [InlineData("FAIcon", "图标集")] + [InlineData("Sidebar", "后台管理")] [InlineData("IconView", "图标分类")] [InlineData("Settings", "网站设置")] [InlineData("Notifications", "通知管理")]