diff --git a/Bootstrap.Admin/Models/NavigatorBarModel.cs b/Bootstrap.Admin/Models/NavigatorBarModel.cs index c83f8d5a..0f925d72 100644 --- a/Bootstrap.Admin/Models/NavigatorBarModel.cs +++ b/Bootstrap.Admin/Models/NavigatorBarModel.cs @@ -10,6 +10,7 @@ namespace Bootstrap.Admin.Models public NavigatorBarModel(string url) { Navigations = MenuHelper.RetrieveNavigationsByUserName(UserName).Where(m => m.IsResource == 0); + Applications = DictHelper.RetrieveApps(); ActiveMenu(null, Navigations.ToList(), url); HomeUrl = "~/Admin/Index"; } @@ -27,5 +28,9 @@ namespace Bootstrap.Admin.Models /// /// public IEnumerable Navigations { get; set; } + /// + /// + /// + public IEnumerable> Applications { get; set; } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Scripts/Menus.js b/Bootstrap.Admin/Scripts/Menus.js index da2c12a5..aaa1d40d 100644 --- a/Bootstrap.Admin/Scripts/Menus.js +++ b/Bootstrap.Admin/Scripts/Menus.js @@ -34,7 +34,8 @@ Url: "url", Category: "category", Target: "target", - IsResource: "isRes" + IsResource: "isRes", + ApplicationCode: "app" } }), click: { diff --git a/Bootstrap.Admin/Views/Admin/Menus.cshtml b/Bootstrap.Admin/Views/Admin/Menus.cshtml index 0a0eed4d..595073d1 100644 --- a/Bootstrap.Admin/Views/Admin/Menus.cshtml +++ b/Bootstrap.Admin/Views/Admin/Menus.cshtml @@ -160,6 +160,21 @@ +
+ + +
diff --git a/Bootstrap.DataAccess/DictHelper.cs b/Bootstrap.DataAccess/DictHelper.cs index 32195810..972195dd 100644 --- a/Bootstrap.DataAccess/DictHelper.cs +++ b/Bootstrap.DataAccess/DictHelper.cs @@ -215,5 +215,14 @@ namespace Bootstrap.DataAccess var settings = RetrieveDicts(); return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "~/Home/Index" }).Code; } + /// + /// + /// + /// + public static IEnumerable> RetrieveApps() + { + var settings = RetrieveDicts(); + return settings.Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair(d.Code, d.Name)).OrderBy(d => d.Key); + } } } diff --git a/Bootstrap.DataAccess/Menu.cs b/Bootstrap.DataAccess/Menu.cs index 9471e2e6..b39f32ff 100644 --- a/Bootstrap.DataAccess/Menu.cs +++ b/Bootstrap.DataAccess/Menu.cs @@ -56,6 +56,10 @@ namespace Bootstrap.DataAccess /// public int IsResource { get; set; } /// + /// 获得/设置 所属应用程序 + /// + public string ApplicationCode { get; set; } + /// /// /// public IEnumerable Menus { get; set; } diff --git a/Bootstrap.DataAccess/MenuHelper.cs b/Bootstrap.DataAccess/MenuHelper.cs index 530fdd05..22914f0b 100644 --- a/Bootstrap.DataAccess/MenuHelper.cs +++ b/Bootstrap.DataAccess/MenuHelper.cs @@ -49,8 +49,9 @@ namespace Bootstrap.DataAccess Category = (string)reader[6], Target = (string)reader[7], IsResource = (bool)reader[8] ? 1 : 0, - CategoryName = (string)reader[9], - ParentName = LgbConvert.ReadValue(reader[10], string.Empty) + ApplicationCode = reader.IsDBNull(9) ? string.Empty : (string)reader[9], + CategoryName = (string)reader[10], + ParentName = LgbConvert.ReadValue(reader[11], string.Empty) }); } } @@ -141,8 +142,8 @@ namespace Bootstrap.DataAccess if (p.Icon != null && p.Icon.Length > 50) p.Icon.Substring(0, 50); if (p.Url != null && p.Url.Length > 50) p.Url.Substring(0, 50); string sql = p.ID == 0 ? - "Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource)" : - "Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource where ID = @ID"; + "Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" : + "Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID"; try { using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql)) @@ -156,6 +157,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", p.Category, ParameterDirection.Input)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Target", p.Target, ParameterDirection.Input)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@IsResource", p.IsResource, ParameterDirection.Input)); + cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode, ParameterDirection.Input)); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } CacheCleanUtility.ClearCache(menuIds: p.ID == 0 ? string.Empty : p.ID.ToString()); diff --git a/DatabaseScripts/InitData.sql b/DatabaseScripts/InitData.sql index e8ec0d4c..d02d33a4 100644 --- a/DatabaseScripts/InitData.sql +++ b/DatabaseScripts/InitData.sql @@ -9,6 +9,7 @@ SET IDENTITY_INSERT [dbo].[Users] OFF DELETE From Dicts INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'菜单', N'系统菜单', N'0', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'菜单', N'外部菜单', N'1', 0) +INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'应用程序', N'未设置', N'0', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站设置', N'网站标题', N'后台管理系统', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站设置', N'网站页脚', N'2016 © 通用后台管理系统', 0) INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'系统通知', N'用户注册', N'0', 0) diff --git a/DatabaseScripts/Install.sql b/DatabaseScripts/Install.sql index 8b9c12b6..0429a6d9 100644 --- a/DatabaseScripts/Install.sql +++ b/DatabaseScripts/Install.sql @@ -175,6 +175,7 @@ CREATE TABLE [dbo].[Navigations]( [Category] [nvarchar](50) NOT NULL, [Target] [varchar](10) NOT NULL, [IsResource] [bit] NOT NULL, + [Application] [nvarchar](200) NOT NULL, CONSTRAINT [PK_Navigations] PRIMARY KEY CLUSTERED ( [ID] ASC @@ -320,6 +321,9 @@ GO ALTER TABLE [dbo].[Navigations] ADD CONSTRAINT [DF_Navigations_IsResource] DEFAULT ((0)) FOR [IsResource] GO +ALTER TABLE [dbo].[Navigations] ADD CONSTRAINT [DF_Navigations_Application] DEFAULT ((0)) FOR [Application] +GO + /****** Object: Table [dbo].[Messages] Script Date: 11/14/2016 13:59:21 ******/ SET ANSI_NULLS ON GO diff --git a/DatabaseScripts/Procedures.sql b/DatabaseScripts/Procedures.sql index b5c5e14c..c4895926 100644 --- a/DatabaseScripts/Procedures.sql +++ b/DatabaseScripts/Procedures.sql @@ -126,11 +126,11 @@ BEGIN SET XACT_ABORT ON; -- Insert statements for procedure here if @userName = '' or @userName is null - select n.*, d.Name as CategoryName, ln.Name as ParentName + select n.ID, n.ParentId, n.Name, n.[Order], n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.[Application], d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = N'菜单' and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID else - select n.*, d.Name as CategoryName, ln.Name as ParentName + select n.ID, n.ParentId, n.Name, n.[Order], n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.[Application], d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = N'菜单' and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (