refactor: App 接口移除重复 GetAll 方法统一使用 Dict 接口服务

This commit is contained in:
Argo-Tianyi 2021-12-25 12:32:58 +08:00
parent eadf199649
commit 90e06fedc2
6 changed files with 40 additions and 27 deletions

View File

@ -5,7 +5,7 @@ namespace BootstrapAdmin.DataAccess.EFCore.Services
{
class DictsService : IDict
{
public List<SelectedItem> GetApps()
public Dictionary<string, string> GetApps()
{
throw new NotImplementedException();
}
@ -19,5 +19,10 @@ namespace BootstrapAdmin.DataAccess.EFCore.Services
{
throw new NotImplementedException();
}
public bool IsDemo()
{
throw new NotImplementedException();
}
}
}

View File

@ -1,22 +1,15 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Core;
using BootstrapBlazor.Components;
using BootstrapAdmin.Web.Core;
using PetaPoco;
namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
class AppService : BaseDatabase, IApp
{
private List<SelectedItem> Apps { get; set; }
public AppService(IDatabase db, IDict dict)
public AppService(IDatabase db)
{
Database = db;
Apps = dict.GetApps();
}
public List<SelectedItem> GetAll() => Apps;
public List<string> GetAppsByRoleId(string? roleId) => Database.Fetch<string>("select AppID from RoleApp where RoleID = @0", roleId);
public bool SaveAppsByRoleId(string? roleId, IEnumerable<string> appIds)

View File

@ -23,10 +23,10 @@ class DictService : BaseDatabase, IDict
private List<Dict> GetAll() => Database.Fetch<Dict>();
public List<SelectedItem> GetApps()
public Dictionary<string, string> GetApps()
{
var dicts = GetAll();
return dicts.Where(d => d.Category == "应用程序").Select(d => new SelectedItem(d.Code, d.Name)).ToList();
return dicts.Where(d => d.Category == "应用程序").Select(d => new SelectedItem(d.Code, d.Name)).ToDictionary(i => i.Value, i => i.Text);
}
/// <summary>
@ -62,4 +62,15 @@ class DictService : BaseDatabase, IDict
}
return title;
}
/// <summary>
/// 获得 应用是否为演示模式
/// </summary>
/// <returns></returns>
public bool IsDemo()
{
var dicts = GetAll();
var code = dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "演示系统" && d.Define == EnumDictDefine.System)?.Code ?? "0";
return code == "1";
}
}

View File

@ -1,18 +1,10 @@
using BootstrapBlazor.Components;
namespace BootstrapAdmin.Web.Core;
namespace BootstrapAdmin.Web.Core;
/// <summary>
///
/// </summary>
public interface IApp
{
/// <summary>
/// 获得所有用户
/// </summary>
/// <returns></returns>
List<SelectedItem> GetAll();
/// <summary>
///
/// </summary>

View File

@ -1,13 +1,21 @@
using BootstrapBlazor.Components;
namespace BootstrapAdmin.Web.Core
namespace BootstrapAdmin.Web.Core
{
/// <summary>
/// Dict 字典表接口
/// </summary>
public interface IDict
{
List<SelectedItem> GetApps();
/// <summary>
/// 获得 配置所有的 App 集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetApps();
/// <summary>
/// 获取当前系统配置是否为演示模式
/// </summary>
/// <returns></returns>
bool IsDemo();
/// <summary>
/// 获取 站点 Title 配置信息

View File

@ -27,6 +27,10 @@ public partial class Roles
[NotNull]
private IApp? AppService { get; set; }
[Inject]
[NotNull]
private IDict? DictService { get; set; }
[Inject]
[NotNull]
private INavigation? NavigationService { get; set; }
@ -73,10 +77,10 @@ public partial class Roles
private async Task OnAssignmentApps(Role role)
{
var apps = AppService.GetAll();
var apps = DictService.GetApps();
var values = AppService.GetAppsByRoleId(role.Id);
await DialogService.ShowAssignmentDialog($"分配应用 - 当前角色: {role.RoleName}", apps, values, () =>
await DialogService.ShowAssignmentDialog($"分配应用 - 当前角色: {role.RoleName}", apps.ToSelectedItemList(), values, () =>
{
var ret = AppService.SaveAppsByRoleId(role.Id, values);
return Task.FromResult(ret);