网站首页 网站源码
website
站点相关全部源代码,隐藏了一些关于服务器的信息
@page "/"
@attribute [Authorize]
@inject IJSRuntime JsRuntime
@inject ICommunityService CommunityService
<MudText Typo="Typo.h5" Color="Color.Primary" Class="mb-4">首页</MudText>
<MudGrid>
    <MudItem xs="12" sm="6" md="3">
        <MudPaper Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
            <MudIcon Icon="@Icons.Material.Filled.Article" Color="Color.Primary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
            <div>
                <MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">总文章数</MudText>
                @if (_isLoading)
                {
                    <MudSkeleton Width="100%" />
                }
                else
                {
                    <MudText Typo="Typo.h5">@_summary?.ArticleTotalCount.ToString("N0")</MudText>
                }
            </div>
        </MudPaper>
    </MudItem>
    <MudItem xs="12" sm="6" md="3">
        <MudPaper Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
            <MudIcon Icon="@Icons.Material.Filled.LocalFireDepartment" Color="Color.Secondary" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
            <div>
                <MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">今日访问次数</MudText>
                @if (_isLoading)
                {
                    <MudSkeleton Width="100%" />
                }
                else
                {
                    <MudText Typo="Typo.h5">@_summary?.TodayAccessNumber.Sum(x => x.Count).ToString("N0")</MudText>
                }
            </div>
        </MudPaper>
    </MudItem>
    <MudItem xs="12" sm="6" md="3">
        <MudPaper Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
            <MudIcon Icon="@Icons.Material.Filled.FiberNew" Color="Color.Success" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
            <div>
                <MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">今日抓取文章</MudText>
                @if (_isLoading)
                {
                    <MudSkeleton Width="100%" />
                }
                else
                {
                    <MudText Typo="Typo.h5">@_summary?.TodayArticleCount.ToString("N0")</MudText>
                }
            </div>
        </MudPaper>
    </MudItem>
    <MudItem xs="12" sm="6" md="3">
        <MudPaper Class="d-flex flex-row pt-6 pb-4" Style="height:100px;">
            <MudIcon Icon="@Icons.Material.Filled.AddComment" Color="Color.Warning" Class="mx-4" Style="width:54px; height:54px;"></MudIcon>
            <div>
                <MudText Typo="Typo.subtitle1" Class="mud-text-secondary mb-n1">近7天访问次数</MudText>
                @if (_isLoading)
                {
                    <MudSkeleton Width="100%" />
                }
                else
                {
                    <MudText Typo="Typo.h5">@_summary?.WeekAccessNumber.Sum(x => x.Count).ToString("N0")</MudText>
                }
            </div>
        </MudPaper>
    </MudItem>
    <MudItem xs="12" sm="8">
        <MudCard Style="height: 500px">
            @if (_isLoading)
            {
                <MudSkeleton Width="100%" Height="100%" />
            }
            else
            {
                <MudCardHeader>
                    <CardHeaderContent>
                        <MudText Typo="Typo.h6">最新日志</MudText>
                    </CardHeaderContent>
                    <CardHeaderActions>
                        <MudIconButton Icon="fas fa-info-circle" Color="Color.Default" />
                    </CardHeaderActions>
                </MudCardHeader>
                <MudCardContent Style="height: 85%">
                    <pre style="height:100%" class="line-numbers language-log"><code>@_summary?.LatestLogs</code></pre>
                </MudCardContent>
            }
        </MudCard>
    </MudItem>
    <MudItem xs="12" sm="4">
        @if (_isLoading)
        {
            <MudSkeleton Width="100%" Height="500px" />
        }
        else
        {
            <MudCarousel Style="height:500px;" ShowArrows="true" ShowBullets="true" AutoCycle="true" TData="object">
                @foreach (var item in _summary?.Banner ?? [])
                {
                    <MudCarouselItem Transition="Transition.Slide">
                        <div class="d-flex" style="height: 100%">
                            <img src="@item.AccessUrl" alt="@item.Description" />
                            <div class="banner-information">
                                @if (!string.IsNullOrEmpty(item.Description))
                                {
                                    <span>@item.Description</span>
                                }
                            </div>
                        </div>
                    </MudCarouselItem>
                }
            </MudCarousel>
        }
    </MudItem>
    <MudItem xs="12" sm="12" md="6">
        @if (_isLoading)
        {
            <MudSkeleton Width="100%" Height="400px" />
        }
        else
        {
            <MudCard Style="height:100%;">
                <MudCardHeader>
                    <CardHeaderContent>
                        <MudText Typo="Typo.h6">
                            <MudLink Href="/article">最新文章</MudLink>
                        </MudText>
                    </CardHeaderContent>
                </MudCardHeader>
                <MudCardContent Class="px-0">
                    <MudSimpleTable Elevation="0" Hover="true">
                        <thead>
                            <tr>
                                <th>标题</th>
                                <th>作者</th>
                                <th>图片数量</th>
                                <th>发布时间</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in _summary?.LatestArticles ?? [])
                            {
                                <tr>
                                    <td>
                                        <MudLink Href="@($"{Program.WebHost}/article/read/{item.Id}.html")" Target="_blank">@item.Title</MudLink>
                                    </td>
                                    <td>
                                        @item.Author.Name
                                    </td>
                                    <td>
                                        @item.ImagesAddress.Count
                                    </td>
                                    <td>
                                        @item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </MudSimpleTable>
                </MudCardContent>
            </MudCard>
        }
    </MudItem>
    <MudItem xs="12" sm="12" md="6">
        @if (_isLoading)
        {
            <MudSkeleton Width="100%" Height="400px" />
        }
        else
        {
            <MudChart ChartType="ChartType.Line" ChartSeries="@_series" @bind-SelectedIndex="_index" XAxisLabels="@_xAxisLabels" Width="100%" Height="400px"></MudChart>
        }
    </MudItem>
</MudGrid>

@code {
    #nullable enable
    
    private bool _isLoading;

    private int _index = -1;

    private SummaryInformation? _summary = null;

    private readonly List<ChartSeries> _series = new();

    private string[] _xAxisLabels = [];

    protected override async Task OnInitializedAsync()
    {
        _isLoading = true;

        try
        {
            _summary = await CommunityService.GetSummaryAsync();
        
            _series.Add(new ChartSeries
            {
                Name = "近7天访问",
                Data = _summary?.WeekAccessNumber.Select(x => (double)x.Count).ToArray()
            });
            _xAxisLabels = _summary?.WeekAccessNumber.Select(x => x.Date).ToArray() ?? [];
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            _summary = null;
        }


        _isLoading = false;
        await base.OnInitializedAsync();
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (!firstRender)
            await JsRuntime.InvokeVoidAsync("Prism.highlightAll");
        await base.OnAfterRenderAsync(firstRender);
    }

    [Obsolete]
    private async Task LightCode()
    {
        await JsRuntime.InvokeVoidAsync("Prism.highlightAll");
    }

}
loading