feat: 增加返回首页菜单逻辑
This commit is contained in:
parent
11984e20e7
commit
19a2123cee
|
@ -159,14 +159,12 @@ class DictService : IDict
|
|||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <returns></returns>
|
||||
public string? GetHomeUrlByAppId(string? appId)
|
||||
public string? GetHomeUrlByAppId(string? appId = null)
|
||||
{
|
||||
string? url = null;
|
||||
if (!string.IsNullOrEmpty(appId))
|
||||
{
|
||||
var dicts = GetAll();
|
||||
url = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name.Equals(appId, StringComparison.OrdinalIgnoreCase) && d.Define == EnumDictDefine.System)?.Code;
|
||||
}
|
||||
var dicts = GetAll();
|
||||
appId ??= "BA";
|
||||
url = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name.Equals(appId, StringComparison.OrdinalIgnoreCase) && d.Define == EnumDictDefine.System)?.Code;
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,13 @@ class UserService : IUser
|
|||
return FreeSql.Ado.Query<string>($"select d.Code from Dicts d inner join RoleApp ra on d.Code = ra.AppId inner join (select r.Id from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @UserName union select r.Id from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join Groups g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @UserName) r on ra.RoleId = r.ID union select Code from Dicts where Category = @Category and exists(select r.ID from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @UserName and r.RoleName = @RoleName union select r.ID from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join Groups g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @UserName and r.RoleName = @RoleName)", new { UserName = userName, Category = "应用程序", RoleName = "Administrators" }).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户名获得指定的前台 AppId
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public string? GetAppIdByUserName(string userName) => FreeSql.Select<User>().Where(s => s.UserName == userName).ToOne(s => s.App);
|
||||
|
||||
public string? GetDisplayName(string? userName)
|
||||
{
|
||||
return FreeSql.Select<User>().Where(s => s.UserName == userName).ToOne(s => s.DisplayName);
|
||||
|
|
|
@ -186,14 +186,12 @@ class DictService : BaseDatabase, IDict
|
|||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <returns></returns>
|
||||
public string? GetHomeUrlByAppId(string? appId)
|
||||
public string? GetHomeUrlByAppId(string? appId = null)
|
||||
{
|
||||
string? url = null;
|
||||
if (!string.IsNullOrEmpty(appId))
|
||||
{
|
||||
var dicts = GetAll();
|
||||
url = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name.Equals(appId, StringComparison.OrdinalIgnoreCase) && d.Define == EnumDictDefine.System)?.Code;
|
||||
}
|
||||
appId ??= "BA";
|
||||
var dicts = GetAll();
|
||||
url = dicts.FirstOrDefault(d => d.Category == "应用首页" && d.Name.Equals(appId, StringComparison.OrdinalIgnoreCase) && d.Define == EnumDictDefine.System)?.Code;
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,13 @@ class UserService : BaseDatabase, IUser
|
|||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<string> GetApps(string userName) => Database.Fetch<string>($"select d.Code from Dicts d inner join RoleApp ra on d.Code = ra.AppId inner join (select r.Id from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 union select r.Id from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0) r on ra.RoleId = r.ID union select Code from Dicts where Category = @1 and exists(select r.ID from Roles r inner join UserRole ur on r.ID = ur.RoleID inner join Users u on ur.UserID = u.ID where u.UserName = @0 and r.RoleName = @2 union select r.ID from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join {Database.Provider.EscapeSqlIdentifier("Groups")} g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID where u.UserName = @0 and r.RoleName = @2)", userName, "应用程序", "Administrators");
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户名获得指定的前台 AppId
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
public string? GetAppIdByUserName(string userName) => Database.FirstOrDefault<User>("Where UserName = @0", userName)?.App;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -148,5 +148,5 @@ public interface IDict
|
|||
/// </summary>
|
||||
/// <param name="appId"></param>
|
||||
/// <returns></returns>
|
||||
string? GetHomeUrlByAppId(string? appId);
|
||||
string? GetHomeUrlByAppId(string? appId = null);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,13 @@ public interface IUser
|
|||
/// <returns></returns>
|
||||
List<string> GetApps(string userName);
|
||||
|
||||
/// <summary>
|
||||
/// 通过用户名获得指定的前台 AppId
|
||||
/// </summary>
|
||||
/// <param name="userName"></param>
|
||||
/// <returns></returns>
|
||||
string? GetAppIdByUserName(string userName);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace BootstrapAdmin.Web.Pages.Home;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 返回前台页面
|
||||
/// </summary>
|
||||
[Route("/")]
|
||||
[Route("/Index")]
|
||||
[Route("/Home/Index")]
|
||||
[Authorize]
|
||||
public class Index : ComponentBase
|
||||
|
@ -13,6 +17,34 @@ public class Index : ComponentBase
|
|||
[NotNull]
|
||||
private NavigationManager? Navigation { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private BootstrapAppContext? Context { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IDict? DictsService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IUser? UsersService { get; set; }
|
||||
|
||||
[NotNull]
|
||||
private string? Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
var appId = UsersService.GetAppIdByUserName(Context.UserName);
|
||||
Url = DictsService.GetHomeUrlByAppId(appId) ?? "Admin/Index";
|
||||
|
||||
#if !DEBUG
|
||||
Navigation.NavigateTo(Url, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -20,15 +52,7 @@ public class Index : ComponentBase
|
|||
/// <param name="firstRender"></param>
|
||||
protected override void OnAfterRender(bool firstRender)
|
||||
{
|
||||
Navigation.NavigateTo($"/Admin/Index", true);
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Navigation.NavigateTo($"/Admin/Index");
|
||||
Navigation.NavigateTo(Url, true);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -3,29 +3,29 @@
|
|||
namespace BootstrapAdmin.Web.Services
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// AppContext 实体类
|
||||
/// </summary>
|
||||
public class BootstrapAppContext
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得/设置 当前网站 AppId
|
||||
/// </summary>
|
||||
public string AppId { get; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得/设置 当前登录账号
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
public string? UserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 获得/设置 当前用户显示名称
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
public string? DisplayName { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
public BootstrapAppContext(IConfiguration configuration)
|
||||
|
|
|
@ -20,11 +20,11 @@ namespace BootstrapAdmin.Web.Shared
|
|||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IDict? DictsService { get; set; }
|
||||
private AuthenticationStateProvider? AuthenticationStateProvider { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private AuthenticationStateProvider? AuthenticationStateProvider { get; set; }
|
||||
private IDict? DictsService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
|
|
Loading…
Reference in New Issue