feat: 增加地理位置设置

This commit is contained in:
zhangpeihang 2022-01-14 11:41:55 +08:00
parent cdeee4b3b2
commit 5bdb883947
5 changed files with 60 additions and 1 deletions

View File

@ -104,6 +104,11 @@ public class AppInfo
[Display(Name = "时长间隔(秒)")]
public int Interval { get; set; }
/// <summary>
///
/// </summary>
public string? Ip { get; set; }
/// <summary>
///
/// </summary>

View File

@ -321,4 +321,18 @@ class DictService : IDict
}
public bool SaveAutoLockScreenInterval(string value) => SaveDict(new Dict { Category = "网站设置", Name = "自动锁屏时长", Code = value });
public Dictionary<string, string> GetIps()
{
var dicts = GetAll();
return dicts.Where(d => d.Category == "地理位置服务").Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(i => i.Value).ToDictionary(i => i.Key, i => i.Value);
}
public string? GetCurrentIp()
{
var dicts = GetAll();
return dicts.FirstOrDefault(s => s.Category == "网站设置" && s.Name == "IP地理位置接口" && s.Define == EnumDictDefine.System)?.Code;
}
public bool SaveCurrentIp(string value) => SaveDict(new Dict { Category = "网站设置", Name = "IP地理位置接口", Code = value });
}

View File

@ -264,4 +264,22 @@ public interface IDict
/// </summary>
/// <returns></returns>
bool SaveAutoLockScreenInterval(string value);
/// <summary>
/// 获得地理位置服务
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetIps();
/// <summary>
/// 获得当前地理位置服务
/// </summary>
/// <returns></returns>
string? GetCurrentIp();
/// <summary>
/// 设置当前地理位置服务
/// </summary>
/// <returns></returns>
bool SaveCurrentIp(string value);
}

View File

@ -132,6 +132,18 @@
</ValidateForm>
</AdminCard>
<AdminCard HeaderText="地址位置信息" AuthorizeKey="SaveAdressInfo">
<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>
</div>
<div class="col-6 col-sm-6 text-end">
<Button ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="保存" />
</div>
</div>
</ValidateForm>
</AdminCard>
<AdminCard HeaderText="系统演示设置" AuthorizeKey="SaveDemo">
<AdminAlert Text="开启本功能后系统运行在演示模式下部分功能禁止操作" Color="Color.Info" />

View File

@ -21,6 +21,9 @@ public partial class Settings
[NotNull]
private List<SelectedItem>? Themes { get; set; }
[NotNull]
private List<SelectedItem>? IPs { get; set; }
[Inject]
[NotNull]
private IDict? DictService { get; set; }
@ -43,6 +46,7 @@ public partial class Settings
IsDemo = DictService.IsDemo();
Logins = DictService.GetLogins().ToSelectedItemList();
Themes = DictService.GetThemes().ToSelectedItemList();
IPs = DictService.GetIps().ToSelectedItemList();
AppInfo = new()
{
IsDemo = IsDemo,
@ -57,7 +61,7 @@ public partial class Settings
MobileLogin = DictService.GetAppMobileLogin(),
OAuthLogin = DictService.GetAppOAuthLogin(),
AutoLock = DictService.GetAutoLockScreen(),
Interval = Convert.ToInt32(DictService.GetAutoLockScreenInterval())
Interval = Convert.ToInt32(DictService.GetAutoLockScreenInterval()),
};
}
@ -137,4 +141,10 @@ public partial class Settings
DictService.SaveAutoLockScreenInterval(AppInfo.Interval.ToString());
await ShowToast(ret, "自动锁屏");
}
private async Task SaveAdressInfo(EditContext context)
{
var ret = DictService.SaveCurrentIp(AppInfo.Ip!);
await ShowToast(ret, "地理位置");
}
}