From 712455ebe22a7896a50d7f6f122ba9d972d673f9 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 27 Feb 2020 15:45:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BD=91=E7=AB=99=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=89=8D=E5=8F=B0=E7=AB=99=E7=82=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/SettingsController.cs | 23 +++++- .../Bootstrap.Admin/Models/SettingsModel.cs | 16 +++- .../Views/Admin/Settings.cshtml | 73 ++++++++++++++++++- .../Bootstrap.Admin/wwwroot/css/site.css | 4 + .../Bootstrap.Admin/wwwroot/css/theme.css | 2 +- .../Bootstrap.Admin/wwwroot/js/settings.js | 65 ++++++++++++++++- .../Bootstrap.DataAccess/Helper/DictHelper.cs | 56 ++++++++++++++ 7 files changed, 231 insertions(+), 8 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Controllers/Api/SettingsController.cs b/src/admin/Bootstrap.Admin/Controllers/Api/SettingsController.cs index 5a110720..63444be5 100644 --- a/src/admin/Bootstrap.Admin/Controllers/Api/SettingsController.cs +++ b/src/admin/Bootstrap.Admin/Controllers/Api/SettingsController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.Admin.Controllers.Api { @@ -29,13 +30,31 @@ namespace Bootstrap.Admin.Controllers.Api /// 保存网站是否为演示系统时调用 /// /// - [HttpPut("{id}")] - public bool Put(string id, [FromBody]BootstrapDict dict) => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name); + [HttpPost("{id}")] + public bool Post(string id, [FromBody]BootstrapDict dict) => id switch + { + "Demo" => DictHelper.UpdateSystemModel(dict.Code == "1", dict.Name), + "AppPath" => DictHelper.SaveAppSettings(dict), + _ => false + }; /// /// 获取网站缓存站点集合 /// [HttpGet] public IEnumerable Get() => CacheManager.CorsSites; + + /// + /// 删除指定键值的前台应用配置信息 + /// + /// + /// + /// + [HttpDelete("{id}")] + public bool Delete(string id, [FromBody]BootstrapDict dict) => id switch + { + "AppPath" => DictHelper.DeleteApp(dict), + _ => false + }; } } diff --git a/src/admin/Bootstrap.Admin/Models/SettingsModel.cs b/src/admin/Bootstrap.Admin/Models/SettingsModel.cs index b5b9fc03..c9e189f5 100644 --- a/src/admin/Bootstrap.Admin/Models/SettingsModel.cs +++ b/src/admin/Bootstrap.Admin/Models/SettingsModel.cs @@ -1,7 +1,9 @@ using Bootstrap.DataAccess; using Bootstrap.Security; using Microsoft.AspNetCore.Mvc; +using System; using System.Collections.Generic; +using System.Linq; namespace Bootstrap.Admin.Models { @@ -29,6 +31,13 @@ namespace Bootstrap.Admin.Models IPCachePeriod = DictHelper.RetrieveLocaleIPSvrCachePeriod(); EnableDemo = DictHelper.RetrieveSystemModel(); AdminPathBase = DictHelper.RetrievePathBase(); + + var dicts = DictHelper.RetrieveDicts(); + Apps = DictHelper.RetrieveApps().Where(d => !d.Key.Equals("BA", StringComparison.OrdinalIgnoreCase)).Select(k => + { + var url = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name == k.Key && d.Define == 0)?.Code ?? "未设置"; + return (k.Key, k.Value, url); + }); } /// @@ -94,6 +103,11 @@ namespace Bootstrap.Admin.Models /// /// 获得/设置 后台管理网站地址 /// - public string AdminPathBase { get; set; } = ""; + public string AdminPathBase { get; set; } + + /// + /// 获得/设置 系统应用程序集合 + /// + public IEnumerable<(string Key, string Name, string Url)> Apps { get; set; } } } diff --git a/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml b/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml index 8b416505..8ae6f52c 100644 --- a/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml +++ b/src/admin/Bootstrap.Admin/Views/Admin/Settings.cshtml @@ -25,6 +25,47 @@ } +@section modal { + +}
网站名称设置
@@ -58,7 +99,7 @@
-
后台管理地址设置
+
/// public static string RetrievePathBase() => DbContextManager.Create()?.RetrievePathBase() ?? ""; + + /// + /// 保存前台应用配置信息 + /// + /// + /// + public static bool SaveAppSettings(BootstrapDict dict) + { + // dict define == 1 时为新建前台应用 + bool ret; + if (dict.Define == 0) + { + // Update + ret = SaveSettings(new BootstrapDict[] { + new BootstrapDict() + { + Category = "应用首页", + Name = dict.Name, + Code = dict.Code, + Define = 0 + } + }); + } + else + { + ret = Save(new BootstrapDict() + { + Category = "应用程序", + Name = dict.Category, + Code = dict.Name, + Define = 0 + }); + if (ret) ret = Save(new BootstrapDict() + { + Category = "应用首页", + Name = dict.Name, + Code = dict.Code, + Define = 0 + }); + } + return ret; + } + + /// + /// 删除指定前台应用 + /// + /// + /// + public static bool DeleteApp(BootstrapDict dict) + { + var ids = new List(); + ids.AddRange(RetrieveDicts().Where(d => d.Category == "应用程序" && d.Name == dict.Name && d.Code == dict.Code).Select(d => d.Id ?? "")); + ids.AddRange(RetrieveDicts().Where(d => d.Category == "应用首页" && d.Name == dict.Code).Select(d => d.Id ?? "")); + + return Delete(ids); + } } }