Use a better method to share common page layout

This commit is contained in:
2025-10-15 16:57:09 +09:00
parent b90001a89c
commit 4821d73b11
2 changed files with 42 additions and 50 deletions

View File

@ -11,8 +11,6 @@
@attribute [Authorize] @attribute [Authorize]
@layout AuthorizedLayout
@implements IDisposable @implements IDisposable
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
@ -21,7 +19,9 @@
<PageTitle>Тестирование экспорта</PageTitle> <PageTitle>Тестирование экспорта</PageTitle>
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);"> <AuthorizedContent Roles="@AppRole.OPERATOR_TYPE">
<Content>
<RadzenSplitter Orientation="Orientation.Vertical" Style="height: 100%; border: 1px solid rgba(0,0,0,.08);">
<RadzenSplitterPane Size="200px"> <RadzenSplitterPane Size="200px">
<div style="height: 100%;overflow: auto;"> <div style="height: 100%;overflow: auto;">
<RadzenCardGroup Responsive="true"> <RadzenCardGroup Responsive="true">
@ -51,7 +51,9 @@
<RadzenSplitterPane Size="auto" Resizable="false"> <RadzenSplitterPane Size="auto" Resizable="false">
<EventConsole @ref=@console /> <EventConsole @ref=@console />
</RadzenSplitterPane> </RadzenSplitterPane>
</RadzenSplitter> </RadzenSplitter>
</Content>
</AuthorizedContent>
@code { @code {
EventConsole console = default!; EventConsole console = default!;
@ -66,16 +68,6 @@
FileMessageCapturer messageCapturer; FileMessageCapturer messageCapturer;
bool catchMessageBody; bool catchMessageBody;
[CascadingParameter]
public AuthorizedLayout Layout { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
Layout.Roles = AppRole.ADMINISTRATOR_TYPE;
}
public void Dispose() public void Dispose()
{ {
if (messageCapturer != null) if (messageCapturer != null)

View File

@ -1,13 +1,9 @@
@inherits LayoutComponentBase @using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Authorization
@layout MainLayout
<AuthorizeView Roles="@Roles"> <AuthorizeView Roles="@Roles">
<Authorized> <Authorized>
<CascadingValue Value="this"> <CascadingValue Value="this">
@Body @Content
</CascadingValue> </CascadingValue>
</Authorized> </Authorized>
<NotAuthorized> <NotAuthorized>
@ -18,5 +14,9 @@
</AuthorizeView> </AuthorizeView>
@code { @code {
public string Roles { get; set; } [Parameter]
public required string Roles { get; set; }
[Parameter]
public required RenderFragment Content { get; set; }
} }