From b3b71a143fc793b04cc7ac92d01e2f8fee866d09 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 2 Nov 2019 15:42:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(I13MQ4):=20=E8=8F=9C=E5=8D=95=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0=E4=BE=A7=E8=BE=B9=E6=A0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Comment comment #I13MQ4 增加局部视图同步更新侧边栏 #Issue link https://gitee.com/LongbowEnterprise/dashboard/issues?id=I13MQ4 --- db/MongoDB/Navigations.js | 14 ++++++++- db/MySQL/initData.sql | 1 + db/Postgresql/initData.sql | 1 + db/SQLite/InitData.sql | 1 + db/SqlServer/InitData.sql | 1 + src/admin/Bootstrap.Admin/BootstrapAdmin.db | Bin 102400 -> 102400 bytes .../Controllers/AdminController.cs | 7 +++++ .../Views/Admin/Sidebar.cshtml | 5 ++++ .../Views/Shared/Navigator.cshtml | 5 +--- .../wwwroot/js/common-scripts.js | 1 + src/admin/Bootstrap.Admin/wwwroot/js/menus.js | 27 +++++++++++------- .../wwwroot/lib/longbow/longbow.dataentity.js | 4 +-- .../Controllers/SQLServer/AdminTest.cs | 1 + 13 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 src/admin/Bootstrap.Admin/Views/Admin/Sidebar.cshtml 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 4463f04428adc7b121c62e18119ee60e14ed59e3..78ebda81f41a83d3440eef6cdacc8d719c17b09c 100644 GIT binary patch delta 1873 zcmeH{%TH556vjK#-s!#Q>7_BIky6^K7g`E^Kx^fpbuy8?K7-OOVSBCf^F;O?hmC-x*qM483|TKD$0VPiqcRPLdALazoyKpv-8-|v7C;a zBI%d(TAGqhNj`~+%i^@yFV=~h%}eGf^LcZt+0DMN$E=@qutMRN@Ki_$F(KEqWJ1$H zlhgR#c*htw2IyD1Krho)3S^n|5u4$oVGgai+o`V!zb8saBRU2`(6GrsoW$KL+eB+U z9v*0ieJTkNWsS@X93u6Yn+!vp=Ja{FGlreXAk=C^aq8q+(gQUr@eyUs^DJ3TV)!%Z zCwsAQum<*MyN)fgjaaMk+@M0L@#bKRRN>pfT2hJjp(?1*YI=9@ni1?CDuLZ9QHWcs z8Npjaeu!$Me2pv(MPZljQS?*xR0)Y-bIMP`cp+6o%5g4LP0H{`Dh46dxsB*O__204 zAA&mB%DYm@xB~)Np2;hATIt6}!&OkK#W>vD>cNL&9!t0+3k62J;9Gavqa_sUL`zVK zn&8dy@PyqSd^1u3MS3~)Nr}~k_E8TM>O{+QVaKQ!6rHF~#682K#jrEW!<*QllE2q< zX-#a`iPnTl)F#|n9_^Yg>>jHE=elxv>NUMkpc5@J4_C&D!Ljaeo)(a=6D>d`YJfe< z!vmsuI65BnhqrAqh)&}0$u`OQVgAAD{F6`ViD*yU)e|r6iC+rTo;Y**Y@qA(iId0U zeVN(uHo@2h(`cT&YPVTriy3~yPxuC(;TkRz5*v;Hga Mzj|vEK2Ior02V@iD*ylh delta 1784 zcmeH`-Aj{E9LIOg_ME-QZ!d+(+~%{TPurZ+ZO?L>^W8S>MM)tlP%xryqYEMGX3kBW zR2t{PZcI~xs0)daLPF9_(M=FSK|#>PDhMQqf^MScoX5aj^#|nD7e42EzP}gvWtK>0 ziOf0B;w@(nT6{Emuf`n;M&j;>+#)AhYc{CODw)H*6&hqmF3D15s7%klpG6W5r0J7P14_}) znJ^qt-bLiOq`cd@sWd(SJqigUX@_LS&!TSnZafNI+!^pQXFGLdL(s{IB&y_0)(0I5 z2_R|5b0aIGcKR&ah}!74Y$vqxSJ!?^6|yC1+k}LY^!!8zYN0C=T_{0I6G@2kOn)uQ zjM8AP0b&Y~kcVeR>BU?lG;<>Fkh{4U99BJSO66B6*MOpQU%nB^v@73*>tGGPO>7`=@pE(*RL%$~d zP`~T5mlyD>gctDg0=_bjwcx;UFI}8Uz#%nG*(kD!v^3=dNhQ3dNUNv)P^S`QL(Fq> zx*lrFJgkX>3i&&w$eZw}gf}7bCfsEnHl;{|g(TGMO0z3d`oX0VUeQh;7V5#d>#v>X zJ5<8+?L5D_%)^F^+3COm&zXWva!bkEx7FFH;jHX{HzpDV@fM za8bJR@wH(?V|ihjvZSdw6WF`Ny-QS1`aiqG_06j&B@kp;)>xK{Hur4{9`2jJJd1|^ E0MNQuG5`Po 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", "通知管理")]