feat: 网站设置功能更新

This commit is contained in:
Argo-Lenovo 2022-01-01 15:40:13 +08:00
parent 0e0f016cd9
commit 1086b7d6a1
5 changed files with 101 additions and 19 deletions

View File

@ -82,11 +82,11 @@ INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '后台地址', 'http://localhost:50852', 0);
-- 系统登录首页设置
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统首页', '高仿码云', 'Login-Gitee', 1);
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统首页', '蓝色清新', 'Login-Blue', 1);
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统首页', '系统默认', 'Login', 1);
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统首页', '科技动感', 'Login-Tec', 1);
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统首页', 'Admin-LTE', 'Login-LTE', 1);
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统首页', '2-高仿码云', 'Login-Gitee', 1);
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统首页', '3-蓝色清新', 'Login-Blue', 1);
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('系统首页', '1-系统默认', 'Login', 1);
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统首页', '科技动感', '4-Login-Tec', 1);
INSERT INTO Dicts (Category, Name, Code, Define) VALUES ('系统首页', 'Admin-LTE', '5-Login-LTE', 1);
INSERT INTO [Dicts] ([Category], [Name], [Code], [Define]) VALUES ('网站设置', '登录界面', 'Login', 1);

View File

@ -9,6 +9,7 @@ public class AppInfo
/// </summary>
[Display(Name = "系统名称")]
[Required(ErrorMessage = "{0}不可为空")]
[NotNull]
public string? Title { get; set; }
/// <summary>
@ -16,23 +17,27 @@ public class AppInfo
/// </summary>
[Display(Name = "网站页脚")]
[Required(ErrorMessage = "{0}不可为空")]
[NotNull]
public string? Footer { get; set; }
/// <summary>
///
/// </summary>
[Display(Name = "登录地址")]
[NotNull]
public string? Login { get; set; }
/// <summary>
///
/// </summary>
[Display(Name = "后台地址")]
[NotNull]
public string? AuthUrl { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public string? Theme { get; set; }
/// <summary>

View File

@ -36,6 +36,12 @@ class DictService : BaseDatabase, IDict
return dicts.Where(d => d.Category == "系统首页").Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).ToDictionary(i => i.Key, i => i.Value);
}
public string GetCurrentLogin()
{
var dicts = GetAll();
return dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "登录界面" && d.Define == EnumDictDefine.System)?.Code ?? "Login";
}
public Dictionary<string, string> GetThemes()
{
var dicts = GetAll();
@ -134,4 +140,16 @@ class DictService : BaseDatabase, IDict
_ = int.TryParse(code, out var ret);
return ret;
}
private bool SaveDict(Dict dict) => Database.Update<Dict>("set Code = @Code where Category = @Category and Name = @Name", dict) == 1;
public bool SaveLogin(string login) => SaveDict(new Dict { Category = "网站设置", Name = "登录界面", Code = login });
public bool SaveTheme(string theme) => SaveDict(new Dict { Category = "网站设置", Name = "使用样式", Code = theme });
public bool SaveWebTitle(string title) => SaveDict(new Dict { Category = "网站设置", Name = "网站标题", Code = title });
public bool SaveWebFooter(string footer) => SaveDict(new Dict { Category = "网站设置", Name = "网站页脚", Code = footer });
public bool SaveCookieExpiresPeriod(int expiresPeriod) => SaveDict(new Dict { Category = "网站设置", Name = "Cookie保留时长", Code = expiresPeriod.ToString() });
}

View File

@ -26,12 +26,27 @@ namespace BootstrapAdmin.Web.Core
/// <returns></returns>
Dictionary<string, string> GetLogins();
/// <summary>
/// 获得 当前配置登录页
/// </summary>
/// <returns></returns>
string GetCurrentLogin();
bool SaveLogin(string login);
/// <summary>
/// 获得 配置所有的主题集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetThemes();
/// <summary>
///
/// </summary>
/// <param name="theme"></param>
/// <returns></returns>
bool SaveTheme(string theme);
/// <summary>
/// 获取当前系统配置是否为演示模式
/// </summary>
@ -64,16 +79,37 @@ namespace BootstrapAdmin.Web.Core
/// <returns></returns>
string GetWebTitle();
/// <summary>
///
/// </summary>
/// <param name="title"></param>
/// <returns></returns>
bool SaveWebTitle(string title);
/// <summary>
/// 获取站点 Footer 配置信息
/// </summary>
/// <returns></returns>
string GetWebFooter();
/// <summary>
///
/// </summary>
/// <param name="footer"></param>
/// <returns></returns>
bool SaveWebFooter(string footer);
/// <summary>
/// 获得 Cookie 登录持久化时长
/// </summary>
/// <returns></returns>
int GetCookieExpiresPeriod();
/// <summary>
///
/// </summary>
/// <param name="expiresPeriod"></param>
/// <returns></returns>
bool SaveCookieExpiresPeriod(int expiresPeriod);
}
}

View File

@ -26,6 +26,10 @@ namespace BootstrapAdmin.Web.Pages.Admin
[NotNull]
private IUser? UserService { get; set; }
[Inject]
[NotNull]
private ToastService? ToastService { get; set; }
/// <summary>
///
/// </summary>
@ -41,44 +45,63 @@ namespace BootstrapAdmin.Web.Pages.Admin
IsDemo = IsDemo,
AuthCode = "123789",
Title = DictService.GetWebTitle(),
Footer = DictService.GetWebFooter()
Footer = DictService.GetWebFooter(),
Login = DictService.GetCurrentLogin()
};
}
private Task OnSaveTitle(EditContext context)
private async Task ShowToast(bool result, string title)
{
return Task.CompletedTask;
if (result)
{
await ToastService.Success(title, $"保存{title}成功");
}
else
{
await ToastService.Error(title, $"保存{title}失败");
}
}
private Task OnSaveFooter(EditContext context)
private async Task OnSaveTitle(EditContext context)
{
return Task.CompletedTask;
var ret = DictService.SaveWebTitle(AppInfo.Title);
await ShowToast(ret, "网站标题");
}
private Task OnSaveLogin(EditContext context)
private async Task OnSaveFooter(EditContext context)
{
return Task.CompletedTask;
var ret = DictService.SaveWebTitle(AppInfo.Title);
await ShowToast(ret, "网站页脚");
}
private Task OnSaveAuthUrl(EditContext context)
private async Task OnSaveLogin(EditContext context)
{
return Task.CompletedTask;
var ret = DictService.SaveLogin(AppInfo.Login);
await ShowToast(ret, "登录界面");
}
private Task OnSaveTheme(EditContext context)
private async Task OnSaveAuthUrl(EditContext context)
{
return Task.CompletedTask;
var ret = DictService.SaveLogin(AppInfo.Login);
await ShowToast(ret, "授权后台地址");
}
private Task OnSaveDemo(EditContext context)
private async Task OnSaveTheme(EditContext context)
{
var ret = DictService.SaveLogin(AppInfo.Login);
await ShowToast(ret, "网站主题");
}
private async Task OnSaveDemo(EditContext context)
{
var ret = false;
if (DictService.AuthenticateDemo(AppInfo.AuthCode))
{
IsDemo = AppInfo.IsDemo;
DictService.SaveDemo(IsDemo);
ret = DictService.SaveDemo(IsDemo);
}
StateHasChanged();
return Task.CompletedTask;
await ShowToast(ret, "演示系统");
}
}
}