|
1 | 1 | @page "/" |
2 | 2 | @using BlazorAdmin.Servers.Core.Helper |
3 | 3 | @using BlazorAdmin.Servers.Core.States |
4 | | -<MudMarkdown Value="@Value" /> |
| 4 | +@using BlazorAdmin.Servers.Core.Data.Entities.Rbac |
| 5 | +@using BlazorAdmin.Servers.Core.Data.Entities.Log |
| 6 | +@using BlazorAdmin.Servers.Core.Data.Entities.Notification |
| 7 | +@using BlazorAdmin.Servers.Core.Data |
| 8 | +@using Microsoft.EntityFrameworkCore |
| 9 | +@inject BlazorAdminDbContext DbContext |
| 10 | + |
| 11 | +<MudContainer MaxWidth="MaxWidth.Large" Class="mt-4"> |
| 12 | + <MudGrid> |
| 13 | + <MudItem xs="12"> |
| 14 | + <MudText Typo="Typo.h4" Class="mb-4">系统概览</MudText> |
| 15 | + </MudItem> |
| 16 | + |
| 17 | + <MudItem xs="12" sm="6" md="3"> |
| 18 | + <MudPaper Elevation="2" Class="pa-4" Style="height: 150px;"> |
| 19 | + <MudStack> |
| 20 | + <MudIcon Icon="@Icons.Material.Filled.People" Color="Color.Primary" Size="Size.Large" /> |
| 21 | + <MudText Typo="Typo.h5">@_userCount</MudText> |
| 22 | + <MudText>用户总数</MudText> |
| 23 | + </MudStack> |
| 24 | + </MudPaper> |
| 25 | + </MudItem> |
| 26 | + |
| 27 | + <MudItem xs="12" sm="6" md="3"> |
| 28 | + <MudPaper Elevation="2" Class="pa-4" Style="height: 150px;"> |
| 29 | + <MudStack> |
| 30 | + <MudIcon Icon="@Icons.Material.Filled.AccountTree" Color="Color.Secondary" Size="Size.Large" /> |
| 31 | + <MudText Typo="Typo.h5">@_orgCount</MudText> |
| 32 | + <MudText>组织数量</MudText> |
| 33 | + </MudStack> |
| 34 | + </MudPaper> |
| 35 | + </MudItem> |
| 36 | + |
| 37 | + <MudItem xs="12" sm="6" md="3"> |
| 38 | + <MudPaper Elevation="2" Class="pa-4" Style="height: 150px;"> |
| 39 | + <MudStack> |
| 40 | + <MudIcon Icon="@Icons.Material.Filled.Login" Color="Color.Success" Size="Size.Large" /> |
| 41 | + <MudText Typo="Typo.h5">@_todayLoginCount</MudText> |
| 42 | + <MudText>今日登录</MudText> |
| 43 | + </MudStack> |
| 44 | + </MudPaper> |
| 45 | + </MudItem> |
| 46 | + |
| 47 | + <MudItem xs="12" sm="6" md="3"> |
| 48 | + <MudPaper Elevation="2" Class="pa-4" Style="height: 150px;"> |
| 49 | + <MudStack> |
| 50 | + <MudIcon Icon="@Icons.Material.Filled.History" Color="Color.Warning" Size="Size.Large" /> |
| 51 | + <MudText Typo="Typo.h5">@_todayAuditCount</MudText> |
| 52 | + <MudText>今日操作</MudText> |
| 53 | + </MudStack> |
| 54 | + </MudPaper> |
| 55 | + </MudItem> |
| 56 | + |
| 57 | + <MudItem xs="12" md="12"> |
| 58 | + <MudGrid> |
| 59 | + <MudItem xs="6"> |
| 60 | + <MudPaper Elevation="2" Class="pa-4"> |
| 61 | + <MudText Typo="Typo.h6" Class="mb-4">系统通知</MudText> |
| 62 | + <MudList Dense="true" T="string"> |
| 63 | + @foreach (var notification in _notifications) |
| 64 | + { |
| 65 | + <MudListItem> |
| 66 | + <MudText>@notification.Title</MudText> |
| 67 | + <MudText Typo="Typo.caption">@notification.SendTime.ToString("yyyy-MM-dd HH:mm:ss")</MudText> |
| 68 | + </MudListItem> |
| 69 | + } |
| 70 | + </MudList> |
| 71 | + </MudPaper> |
| 72 | + </MudItem> |
| 73 | + |
| 74 | + <MudItem xs="6"> |
| 75 | + <MudPaper Elevation="2" Class="pa-4"> |
| 76 | + <MudText Typo="Typo.h6" Class="mb-4">最近登录</MudText> |
| 77 | + <MudList Dense="true" T="string"> |
| 78 | + @foreach (var log in _recentLogins) |
| 79 | + { |
| 80 | + <MudListItem> |
| 81 | + <div class="d-flex"> |
| 82 | + <MudText>@log.UserName</MudText> |
| 83 | + <MudText Typo="Typo.caption" Class="ml-auto">@log.Time.ToString("yyyy-MM-dd HH:mm:ss")</MudText> |
| 84 | + </div> |
| 85 | + <MudText Typo="Typo.caption">IP: @log.Ip</MudText> |
| 86 | + </MudListItem> |
| 87 | + } |
| 88 | + </MudList> |
| 89 | + </MudPaper> |
| 90 | + </MudItem> |
| 91 | + </MudGrid> |
| 92 | + </MudItem> |
| 93 | + |
| 94 | + <MudItem xs="12" md="12"> |
| 95 | + <MudGrid> |
| 96 | + |
| 97 | + <MudItem xs="12"> |
| 98 | + <MudPaper Elevation="2" Class="pa-4"> |
| 99 | + <MudText Typo="Typo.h6" Class="mb-4">最近操作审计</MudText> |
| 100 | + <MudTable Items="_recentAudits" Dense="true" Hover="true"> |
| 101 | + <HeaderContent> |
| 102 | + <MudTh>操作类型</MudTh> |
| 103 | + <MudTh>实体</MudTh> |
| 104 | + <MudTh>时间</MudTh> |
| 105 | + </HeaderContent> |
| 106 | + <RowTemplate> |
| 107 | + <MudTd> |
| 108 | + @switch (context.Operation) |
| 109 | + { |
| 110 | + case 2: |
| 111 | + <MudChip Color="Color.Error" Size="Size.Small" T="string">删除</MudChip> |
| 112 | + break; |
| 113 | + case 3: |
| 114 | + <MudChip Color="Color.Warning" Size="Size.Small" T="string">修改</MudChip> |
| 115 | + break; |
| 116 | + case 4: |
| 117 | + <MudChip Color="Color.Success" Size="Size.Small" T="string">添加</MudChip> |
| 118 | + break; |
| 119 | + } |
| 120 | + </MudTd> |
| 121 | + <MudTd>@context.EntityName</MudTd> |
| 122 | + <MudTd>@context.OperateTime.ToString("yyyy-MM-dd HH:mm:ss")</MudTd> |
| 123 | + </RowTemplate> |
| 124 | + </MudTable> |
| 125 | + </MudPaper> |
| 126 | + </MudItem> |
| 127 | + </MudGrid> |
| 128 | + </MudItem> |
| 129 | + |
| 130 | + </MudGrid> |
| 131 | +</MudContainer> |
| 132 | + |
| 133 | +@code { |
| 134 | + private int _userCount; |
| 135 | + private int _orgCount; |
| 136 | + private int _todayLoginCount; |
| 137 | + private int _todayAuditCount; |
| 138 | + private List<Organization> _organizations = new(); |
| 139 | + private List<LoginLog> _recentLogins = new(); |
| 140 | + private List<AuditLog> _recentAudits = new(); |
| 141 | + private List<Notification> _notifications = new(); |
| 142 | + |
| 143 | + protected override async Task OnInitializedAsync() |
| 144 | + { |
| 145 | + _userCount = await DbContext.Users.CountAsync(); |
| 146 | + _orgCount = await DbContext.Organizations.CountAsync(); |
| 147 | + _todayLoginCount = await DbContext.LoginLogs |
| 148 | + .Where(x => x.Time.Date == DateTime.Today) |
| 149 | + .CountAsync(); |
| 150 | + _todayAuditCount = await DbContext.AuditLogs |
| 151 | + .Where(x => x.OperateTime.Date == DateTime.Today) |
| 152 | + .CountAsync(); |
| 153 | + |
| 154 | + _recentLogins = await DbContext.LoginLogs |
| 155 | + .OrderByDescending(x => x.Time) |
| 156 | + .Take(5) |
| 157 | + .ToListAsync(); |
| 158 | + |
| 159 | + _recentAudits = await DbContext.AuditLogs |
| 160 | + .OrderByDescending(x => x.OperateTime) |
| 161 | + .Take(10) |
| 162 | + .ToListAsync(); |
| 163 | + |
| 164 | + _notifications = await DbContext.Notifications |
| 165 | + .OrderByDescending(x => x.SendTime) |
| 166 | + .Take(5) |
| 167 | + .ToListAsync(); |
| 168 | + } |
| 169 | +} |
0 commit comments