feat: 添加前台应用功能,未完成
This commit is contained in:
parent
7e66b50b79
commit
e7b8a9ef51
|
@ -152,6 +152,68 @@ public class AppInfo
|
|||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public int IPCacheExpired { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
public Dictionary<string, string>? FrontApp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Display(Name = "应用ID")]
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string? AppID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Display(Name = "应用名称")]
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string? AppName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Display(Name = "应用首页")]
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string? Home { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Display(Name = "网站标题")]
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string? WebTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Display(Name = "网站页脚")]
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string? WebFooter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Display(Name = "网站图标")]
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string? WebIcon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Display(Name = "Favicon")]
|
||||
[Required(ErrorMessage = "{0}不可为空")]
|
||||
public string? Favicon { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -314,13 +314,15 @@ class DictService : IDict
|
|||
|
||||
public bool SaveAutoLockScreen(bool value) => SaveDict(new Dict { Category = "网站设置", Name = "自动锁屏", Code = value ? "1" : "0" });
|
||||
|
||||
public string? GetAutoLockScreenInterval()
|
||||
public int GetAutoLockScreenInterval()
|
||||
{
|
||||
var dicts = GetAll();
|
||||
return dicts.FirstOrDefault(s => s.Category == "网站设置" && s.Name == "自动锁屏时长" && s.Define == EnumDictDefine.System)?.Code;
|
||||
var value = dicts.FirstOrDefault(s => s.Category == "网站设置" && s.Name == "自动锁屏时长" && s.Define == EnumDictDefine.System)?.Code ?? "0";
|
||||
_ = int.TryParse(value, out var ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool SaveAutoLockScreenInterval(string value) => SaveDict(new Dict { Category = "网站设置", Name = "自动锁屏时长", Code = value });
|
||||
public bool SaveAutoLockScreenInterval(int value) => SaveDict(new Dict { Category = "网站设置", Name = "自动锁屏时长", Code = value.ToString() });
|
||||
|
||||
public Dictionary<string, string> GetIps()
|
||||
{
|
||||
|
@ -396,4 +398,22 @@ class DictService : IDict
|
|||
}
|
||||
|
||||
public bool SaveIPCacheExpired(int value) => SaveDict(new Dict { Category = "网站设置", Name = "IP请求缓存时长", Code = value.ToString() });
|
||||
|
||||
public Dictionary<string, string> GetFrontApp()
|
||||
{
|
||||
var dicts = GetAll();
|
||||
return dicts.Where(s => s.Category == "应用程序" && s.Code != "BA").ToDictionary(s => s.Name, s => s.Code);
|
||||
}
|
||||
|
||||
public string GetFrontUrl(string name)
|
||||
{
|
||||
var dicts = GetAll();
|
||||
return dicts.Where(s => s.Category == "应用首页" && s.Name == name).FirstOrDefault()?.Code ?? "";
|
||||
}
|
||||
|
||||
public string? GetAppNameByAppName(string name)
|
||||
{
|
||||
var dicts = GetAll();
|
||||
return dicts.Where(s => s.Category == "应用程序" && s.Code == name).FirstOrDefault()?.Name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,13 +257,13 @@ public interface IDict
|
|||
/// 获得自动锁屏间隔时间
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string? GetAutoLockScreenInterval();
|
||||
int GetAutoLockScreenInterval();
|
||||
|
||||
/// <summary>
|
||||
/// 保存自动锁屏间隔时间
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool SaveAutoLockScreenInterval(string value);
|
||||
bool SaveAutoLockScreenInterval(int value);
|
||||
|
||||
/// <summary>
|
||||
/// 获得地理位置服务
|
||||
|
@ -354,4 +354,22 @@ public interface IDict
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
bool SaveIPCacheExpired(int value);
|
||||
|
||||
/// <summary>
|
||||
/// 获得前台应用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Dictionary<string, string>? GetFrontApp();
|
||||
|
||||
/// <summary>
|
||||
/// 获得前台应用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string GetFrontUrl(string name);
|
||||
|
||||
/// <summary>
|
||||
/// 获得前台应用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string? GetAppNameByAppName(string name);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
@using BootstrapAdmin.Web.Core;
|
||||
@using BootstrapAdmin.Web.Validators;
|
||||
|
||||
<ValidateForm OnValidSubmit="CreateFrontApp" Model="Value">
|
||||
<div class="row g-3 form-inline">
|
||||
<div class="col-6 col-sm-6">
|
||||
<BootstrapInput @bind-Value="Value.AppID" placeholder="不可为空,50字以内" Readonly="Value.AppID!=null" ValidateRules="@Validators"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-6 col-sm-6">
|
||||
<BootstrapInput @bind-Value="Value.AppName" placeholder="不可为空,50字以内" Readonly="Value.AppName!=null"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12">
|
||||
<BootstrapInput @bind-Value="Value.Home" placeholder="不可为空,50字以内"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12">
|
||||
<BootstrapInput @bind-Value="Value.WebTitle" placeholder="不可为空,50字以内"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12">
|
||||
<BootstrapInput @bind-Value="Value.WebFooter" placeholder="不可为空,50字以内"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12">
|
||||
<BootstrapInput @bind-Value="Value.WebIcon" placeholder="不可为空,2000字以内"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12">
|
||||
<BootstrapInput @bind-Value="Value.Favicon" placeholder="不可为空,2000字以内"></BootstrapInput>
|
||||
</div>
|
||||
<div class="col-12 col-sm-12 text-end">
|
||||
<Button ButtonType="ButtonType.Submit" Text="保存" Icon="fa fa-save"></Button>
|
||||
</div>
|
||||
</div>
|
||||
</ValidateForm>
|
||||
|
||||
@code{
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
[Parameter]
|
||||
public AppInfo? Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public EventCallback<AppInfo>? ValueChanged { get; set; }
|
||||
|
||||
[NotNull]
|
||||
[Inject]
|
||||
private IDict? DictService { get; set; }
|
||||
|
||||
private List<IValidator> Validators = new List<IValidator>();
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
if (Value?.AppID == null)
|
||||
{
|
||||
Validators.Add(new AppIdValidator(DictService));
|
||||
}
|
||||
}
|
||||
|
||||
private Task CreateFrontApp(EditContext context)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
|
@ -47,11 +47,29 @@
|
|||
</ValidateForm>
|
||||
</AdminCard>
|
||||
|
||||
<AdminCard HeaderText="前台应用设置" AuthorizeKey="SaveFrontApp">
|
||||
<div class="row g-3 form-inline">
|
||||
@foreach (var item in AppInfo.FrontApp)
|
||||
{
|
||||
var value = DictService.GetFrontUrl(item.Value);
|
||||
<div class="col-12 col-sm-6">
|
||||
<BootstrapInputGroup>
|
||||
<BootstrapInput Value="value" DisplayText="@item.Key" ShowLabel="true"></BootstrapInput>
|
||||
<Button Icon="fa fa-trash-o" Color="Color.Danger" Text="删除" OnClickWithoutRender="@OnDeleteFrontApp" />
|
||||
<Button Icon="fa fa-edit" Text="编辑" OnClickWithoutRender="@OnSaveFrontApp" />
|
||||
</BootstrapInputGroup>
|
||||
</div>
|
||||
}
|
||||
<div class="col-12 col-sm-6 text-end">
|
||||
<Button ButtonType="ButtonType.Button" Icon="fa fa-plus" Text="新增" OnClickWithoutRender="@OnSaveFrontApp" />
|
||||
</div>
|
||||
</div>
|
||||
</AdminCard>
|
||||
|
||||
<AdminCard HeaderText="网站样式设置" AuthorizeKey="SaveTheme">
|
||||
<AdminAlert Color="Color.Info">
|
||||
<span>注意:本设置将覆盖 <b><TabLink Url="/Admin/Profiles" Text="个人中心" Icon="fa fa-fa">个人中心</TabLink></b> 中设置的网站样式覆盖本设置</span>
|
||||
</AdminAlert>
|
||||
|
||||
<ValidateForm OnValidSubmit="OnSaveTheme" Model="AppInfo">
|
||||
<div class="row g-3 form-inline">
|
||||
<div class="col-12 col-sm-6">
|
||||
|
@ -133,7 +151,7 @@
|
|||
</AdminCard>
|
||||
|
||||
<AdminCard HeaderText="地址位置信息" AuthorizeKey="SaveLogCache">
|
||||
<ValidateForm OnValidSubmit="OnSaveLogCache" Model="AppInfo">
|
||||
<ValidateForm OnValidSubmit="SaveAdressInfo" Model="AppInfo">
|
||||
<div class="row g-3 form-inline">
|
||||
<div class="col-6 col-sm-6">
|
||||
<Dropdown Items="@IPs" @bind-Value="AppInfo.Ip" ShowLabel="false"></Dropdown>
|
||||
|
@ -146,7 +164,7 @@
|
|||
</AdminCard>
|
||||
|
||||
<AdminCard HeaderText="日志缓存设置" AuthorizeKey="SaveAdressInfo">
|
||||
<ValidateForm OnValidSubmit="SaveAdressInfo" Model="AppInfo">
|
||||
<ValidateForm OnValidSubmit="OnSaveLogCache" Model="AppInfo">
|
||||
<div class="row g-3 form-inline">
|
||||
<div class="col-6 col-sm-6">
|
||||
<BootstrapInputNumber @bind-Value="AppInfo.ExceptionExpired"></BootstrapInputNumber>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Components;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
|
@ -36,6 +37,10 @@ public partial class Settings
|
|||
[NotNull]
|
||||
private ToastService? ToastService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private DialogService? DialogService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -61,13 +66,14 @@ public partial class Settings
|
|||
MobileLogin = DictService.GetAppMobileLogin(),
|
||||
OAuthLogin = DictService.GetAppOAuthLogin(),
|
||||
AutoLock = DictService.GetAutoLockScreen(),
|
||||
Interval = Convert.ToInt32(DictService.GetAutoLockScreenInterval()),
|
||||
Interval = DictService.GetAutoLockScreenInterval(),
|
||||
ExceptionExpired = DictService.GetExceptionExpired(),
|
||||
OperateExpired = DictService.GetOperateExpired(),
|
||||
LoginExpired = DictService.GetLoginExpired(),
|
||||
AccessExpired = DictService.GetAccessExpired(),
|
||||
CookieExpired = DictService.GetCookieExpiresPeriod(),
|
||||
IPCacheExpired = DictService.GetIPCacheExpired(),
|
||||
FrontApp = DictService.GetFrontApp()
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -137,14 +143,14 @@ public partial class Settings
|
|||
private async Task OnSaveSaveAppLogin(EditContext context)
|
||||
{
|
||||
var ret = DictService.SaveAppMobileLogin(AppInfo.MobileLogin);
|
||||
DictService.SaveAppOAuthLogin(AppInfo.TitleSetting);
|
||||
DictService.SaveAppOAuthLogin(AppInfo.OAuthLogin);
|
||||
await ShowToast(ret, "网站登录");
|
||||
}
|
||||
|
||||
private async Task OnSaveAppLockScreen(EditContext context)
|
||||
{
|
||||
var ret = DictService.SaveAutoLockScreen(AppInfo.AutoLock);
|
||||
DictService.SaveAutoLockScreenInterval(AppInfo.Interval.ToString());
|
||||
DictService.SaveAutoLockScreenInterval(AppInfo.Interval);
|
||||
await ShowToast(ret, "自动锁屏");
|
||||
}
|
||||
|
||||
|
@ -165,4 +171,33 @@ public partial class Settings
|
|||
|
||||
await ShowToast(ret, "日志缓存");
|
||||
}
|
||||
|
||||
private async Task OnSaveFrontApp()
|
||||
{
|
||||
|
||||
DialogOption option = new DialogOption
|
||||
{
|
||||
Title = "添加前台应用",
|
||||
BodyTemplate = BootstrapDynamicComponent.CreateComponent<FrontAppDialog>(new Dictionary<string, object?>
|
||||
{
|
||||
[nameof(FrontAppDialog.Value)] = AppInfo
|
||||
}).Render(),
|
||||
ShowFooter = false,
|
||||
};
|
||||
await DialogService.Show(option);
|
||||
}
|
||||
|
||||
private async Task OnDeleteFrontApp()
|
||||
{
|
||||
DialogOption option = new DialogOption
|
||||
{
|
||||
Title = "添加前台应用",
|
||||
BodyTemplate = BootstrapDynamicComponent.CreateComponent<FrontAppDialog>(new Dictionary<string, object?>
|
||||
{
|
||||
[nameof(FrontAppDialog.Value)] = AppInfo
|
||||
}).Render(),
|
||||
ShowFooter = false,
|
||||
};
|
||||
await DialogService.Show(option);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
using BootstrapAdmin.Web.Core;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BootstrapAdmin.Web.Validators;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class AppIdValidator : IValidator
|
||||
{
|
||||
private IDict DictService { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="dictService"></param>
|
||||
public AppIdValidator(IDict dictService) => DictService = dictService;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="propertyValue"></param>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="results"></param>
|
||||
public void Validate(object? propertyValue, ValidationContext context, List<ValidationResult> results)
|
||||
{
|
||||
var AppName = DictService.GetAppNameByAppName(propertyValue?.ToString()!);
|
||||
if (!string.IsNullOrEmpty(AppName))
|
||||
{
|
||||
ErrorMessage = $"{context.DisplayName}已存在";
|
||||
}
|
||||
else
|
||||
{
|
||||
ErrorMessage = null;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(ErrorMessage))
|
||||
{
|
||||
results.Add(new ValidationResult(ErrorMessage, new string[] { context.MemberName! }));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue