mirror of https://github.com/abpframework/abp.git
9 changed files with 226 additions and 64 deletions
@ -1,37 +1,42 @@ |
|||||
using System; |
using System; |
||||
using Microsoft.AspNetCore.Components; |
using Microsoft.AspNetCore.Components; |
||||
using Microsoft.AspNetCore.Components.Routing; |
using Microsoft.AspNetCore.Components.Routing; |
||||
using Volo.Abp.UI.Navigation; |
using Volo.Abp.AspNetCore.Components.Web.Theming.Layout; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic; |
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic; |
||||
|
|
||||
public partial class FirstLevelNavMenuItem : IDisposable |
public partial class FirstLevelNavMenuItem : IDisposable |
||||
{ |
{ |
||||
[Inject] private NavigationManager NavigationManager { get; set; } |
[Inject] |
||||
|
private NavigationManager NavigationManager { get; set; } |
||||
|
|
||||
|
[Inject] |
||||
|
protected PageLayout PageLayout { get; set; } |
||||
|
|
||||
[Parameter] |
[Parameter] |
||||
public ApplicationMenuItem MenuItem { get; set; } |
public MenuViewModel Menu { get; set; } |
||||
|
|
||||
public bool IsSubMenuOpen { get; set; } |
[Parameter] |
||||
|
public MenuItemViewModel MenuItem { get; set; } |
||||
|
|
||||
protected override void OnInitialized() |
protected override void OnInitialized() |
||||
{ |
{ |
||||
NavigationManager.LocationChanged += OnLocationChanged; |
NavigationManager.LocationChanged += OnLocationChanged; |
||||
} |
} |
||||
|
|
||||
private void ToggleSubMenu() |
protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e) |
||||
{ |
{ |
||||
IsSubMenuOpen = !IsSubMenuOpen; |
Menu.CloseAll(); |
||||
|
Menu.InvokeStateChanged(); |
||||
} |
} |
||||
|
|
||||
public void Dispose() |
protected virtual void ToggleMenu() |
||||
{ |
{ |
||||
NavigationManager.LocationChanged -= OnLocationChanged; |
Menu.ToggleOpen(MenuItem); |
||||
} |
} |
||||
|
|
||||
private void OnLocationChanged(object sender, LocationChangedEventArgs e) |
public virtual void Dispose() |
||||
{ |
{ |
||||
IsSubMenuOpen = false; |
NavigationManager.LocationChanged -= OnLocationChanged; |
||||
InvokeAsync(StateHasChanged); |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,46 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.UI.Navigation; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic; |
||||
|
|
||||
|
public class MainMenuProvider : IScopedDependency |
||||
|
{ |
||||
|
private readonly IMenuManager _menuManager; |
||||
|
|
||||
|
public MainMenuProvider(IMenuManager menuManager) |
||||
|
{ |
||||
|
_menuManager = menuManager; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<MenuViewModel> GetMenuAsync() |
||||
|
{ |
||||
|
var menu = await _menuManager.GetMainMenuAsync(); |
||||
|
var result = new MenuViewModel |
||||
|
{ |
||||
|
Menu = menu, |
||||
|
Items = menu.Items.Select(CreateMenuItemViewModel).ToList() |
||||
|
}; |
||||
|
result.SetParents(); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private MenuItemViewModel CreateMenuItemViewModel(ApplicationMenuItem applicationMenuItem) |
||||
|
{ |
||||
|
var viewModel = new MenuItemViewModel |
||||
|
{ |
||||
|
MenuItem = applicationMenuItem, |
||||
|
}; |
||||
|
|
||||
|
viewModel.Items = new List<MenuItemViewModel>(); |
||||
|
|
||||
|
foreach (var item in applicationMenuItem.Items) |
||||
|
{ |
||||
|
viewModel.Items.Add(CreateMenuItemViewModel(item)); |
||||
|
} |
||||
|
|
||||
|
return viewModel; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.UI.Navigation; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic; |
||||
|
|
||||
|
public class MenuItemViewModel |
||||
|
{ |
||||
|
public ApplicationMenuItem MenuItem { get; set; } |
||||
|
|
||||
|
public IList<MenuItemViewModel> Items { get; set; } |
||||
|
|
||||
|
public bool IsOpen { get; set; } |
||||
|
|
||||
|
[CanBeNull] |
||||
|
public MenuItemViewModel Parent { get; set; } |
||||
|
|
||||
|
public void Open() |
||||
|
{ |
||||
|
Parent?.Open(); |
||||
|
IsOpen = true; |
||||
|
} |
||||
|
|
||||
|
public void Close() |
||||
|
{ |
||||
|
foreach (var childItem in Items) |
||||
|
{ |
||||
|
childItem.Close(); |
||||
|
} |
||||
|
|
||||
|
IsOpen = false; |
||||
|
} |
||||
|
|
||||
|
public void SetParents([CanBeNull] MenuItemViewModel parent) |
||||
|
{ |
||||
|
Parent = parent; |
||||
|
|
||||
|
foreach (var childItem in Items) |
||||
|
{ |
||||
|
childItem.SetParents(this); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Volo.Abp.UI.Navigation; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic; |
||||
|
|
||||
|
public class MenuViewModel |
||||
|
{ |
||||
|
public ApplicationMenu Menu { get; set; } |
||||
|
|
||||
|
public List<MenuItemViewModel> Items { get; set; } |
||||
|
|
||||
|
public EventHandler StateChanged; |
||||
|
|
||||
|
public void SetParents() |
||||
|
{ |
||||
|
foreach (var item in Items) |
||||
|
{ |
||||
|
item.SetParents(null); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void ToggleOpen(MenuItemViewModel menuItem) |
||||
|
{ |
||||
|
if (menuItem.IsOpen) |
||||
|
{ |
||||
|
menuItem.Close(); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
CloseAll(); |
||||
|
menuItem.Open(); |
||||
|
} |
||||
|
|
||||
|
StateChanged.InvokeSafely(this); |
||||
|
} |
||||
|
|
||||
|
public void CloseAll() |
||||
|
{ |
||||
|
foreach (var item in Items) |
||||
|
{ |
||||
|
item.Close(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public void InvokeStateChanged() |
||||
|
{ |
||||
|
StateChanged.InvokeSafely(this); |
||||
|
} |
||||
|
} |
||||
@ -1,37 +1,42 @@ |
|||||
using System; |
using System; |
||||
using Microsoft.AspNetCore.Components; |
using Microsoft.AspNetCore.Components; |
||||
using Microsoft.AspNetCore.Components.Routing; |
using Microsoft.AspNetCore.Components.Routing; |
||||
using Volo.Abp.UI.Navigation; |
using Volo.Abp.AspNetCore.Components.Web.Theming.Layout; |
||||
|
|
||||
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic; |
namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic; |
||||
|
|
||||
public partial class SecondLevelNavMenuItem : IDisposable |
public partial class SecondLevelNavMenuItem : IDisposable |
||||
{ |
{ |
||||
[Inject] private NavigationManager NavigationManager { get; set; } |
[Inject] |
||||
|
private NavigationManager NavigationManager { get; set; } |
||||
|
|
||||
|
[Inject] |
||||
|
protected PageLayout PageLayout { get; set; } |
||||
|
|
||||
[Parameter] |
[Parameter] |
||||
public ApplicationMenuItem MenuItem { get; set; } |
public MenuViewModel Menu { get; set; } |
||||
|
|
||||
public bool IsSubMenuOpen { get; set; } |
[Parameter] |
||||
|
public MenuItemViewModel MenuItem { get; set; } |
||||
|
|
||||
protected override void OnInitialized() |
protected override void OnInitialized() |
||||
{ |
{ |
||||
NavigationManager.LocationChanged += OnLocationChanged; |
NavigationManager.LocationChanged += OnLocationChanged; |
||||
} |
} |
||||
|
|
||||
private void ToggleSubMenu() |
protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e) |
||||
{ |
{ |
||||
IsSubMenuOpen = !IsSubMenuOpen; |
Menu.CloseAll(); |
||||
|
Menu.InvokeStateChanged(); |
||||
} |
} |
||||
|
|
||||
public void Dispose() |
protected virtual void ToggleMenu() |
||||
{ |
{ |
||||
NavigationManager.LocationChanged -= OnLocationChanged; |
Menu.ToggleOpen(MenuItem); |
||||
} |
} |
||||
|
|
||||
private void OnLocationChanged(object sender, LocationChangedEventArgs e) |
public virtual void Dispose() |
||||
{ |
{ |
||||
IsSubMenuOpen = false; |
NavigationManager.LocationChanged -= OnLocationChanged; |
||||
InvokeAsync(StateHasChanged); |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue