@page "/admin/dashboard"
@using AsetcoMarket.Components.Admin.Shared
@using AsetcoMarket.Features.Dashboard
@using MudBlazor
@inherits AdminPageBase
@inject IMediator Mediator
<MudGrid Justify="Justify.SpaceBetween" Class="mb-3">
<MudItem xs="6" Class="text-end">
<MudText Typo="Typo.h5">داشبورد مدیریتی</MudText>
</MudItem>
<MudItem xs="6">
<MudBreadcrumbs Items="_items"></MudBreadcrumbs>
</MudItem>
</MudGrid>
@if (_statistics == null)
{
<div class="d-flex justify-center mt-10">
<MudProgressCircular Indeterminate="true" Size="Size.Large" Color="Color.Primary" />
</div>
}
else
{
<!-- ۱: کارتهای اولیه -->
<MudGrid Class="mt-4" Spacing="4">
@foreach (var card in _mainCards)
{
<MudItem xs="12" sm="3">
<MudPaper Class="pa-6 rounded-lg hover-lift animate__animated animate__fadeInUp" Elevation="8" Style="@card.Background">
<div class="d-flex align-center">
<MudIcon Icon="@card.Icon" Size="Size.Large" Class="ml-3" Style="color: white;" />
<div>
<MudText Typo="Typo.subtitle2" Style="color:white;opacity:0.85;">@card.Title</MudText>
<MudText Typo="Typo.h6" Style="color:white;font-weight:700;">@card.Value</MudText>
</div>
</div>
<MudText Typo="Typo.caption" Class="mt-2" Style="color:white;opacity:0.75;">
<MudIcon Icon="@Icons.Material.Filled.TrendingUp" Size="Size.Small" /> @card.Growth
</MudText>
</MudPaper>
</MudItem>
}
</MudGrid>
<!-- ۲: نمودار و نوتیفیکیشن -->
<MudGrid Class="mt-8" Spacing="4">
<MudItem xs="12" md="8">
<MudPaper Class="pa-6 rounded-lg animate__animated animate__fadeInUp" Elevation="8">
<MudText Typo="Typo.h6" Class="mb-4">فروش ماهانه</MudText>
<MudChart ChartType="ChartType.Line"
Width="100%" Height="300px"
ChartSeries="@_salesSeries"
XAxisLabels="@_months" />
</MudPaper>
</MudItem>
<MudItem xs="12" md="4">
<MudPaper Class="pa-6 rounded-lg animate__animated animate__fadeInRight" Elevation="8" Style="max-height:320px;overflow-y:auto;">
<MudText Typo="Typo.h6" Class="mb-3">نوتیفیکیشن فروشندگان</MudText>
<MudList Dense="true">
@foreach (var n in _notifications)
{
<MudListItem Class="py-2">
<MudAvatar Icon="@Icons.Material.Filled.Person" Size="Size.Small" Class="ml-2" Color="Color.Primary" />
<div>
<MudText Typo="Typo.body2">@n.Message</MudText>
<MudText Typo="Typo.caption" Color="Color.TextSecondary">@n.Date.ToString("yyyy/MM/dd HH:mm")</MudText>
</div>
</MudListItem>
}
</MudList>
</MudPaper>
</MudItem>
</MudGrid>
<!-- ۳: سه کارت جدید -->
<MudGrid Class="mt-8" Spacing="4">
@foreach (var card in _extraCards)
{
<MudItem xs="12" sm="4">
<MudPaper Class="pa-6 rounded-lg hover-lift animate__animated animate__fadeInUp" Elevation="8" Style="@card.Background">
<div class="d-flex align-center">
<MudIcon Icon="@card.Icon" Size="Size.Large" Class="ml-3" Style="color:white;" />
<div>
<MudText Typo="Typo.subtitle2" Style="color:white;opacity:0.85;">@card.Title</MudText>
<MudText Typo="Typo.h6" Style="color:white;font-weight:700;">@card.Value</MudText>
</div>
</div>
@if (!string.IsNullOrEmpty(card.Info))
{
<MudText Typo="Typo.caption" Class="mt-2" Style="color:white;opacity:0.75;">
<MudIcon Icon="@Icons.Material.Filled.Info" Size="Size.Small" /> @card.Info
</MudText>
}
</MudPaper>
</MudItem>
}
</MudGrid>
<!-- ۴: جدول پرفروشترین محصولات -->
<MudGrid Class="mt-8" Spacing="4">
<MudItem xs="12">
<MudPaper Class="pa-6 rounded-lg animate__animated animate__fadeInUp" Elevation="8">
<MudText Typo="Typo.h6" Class="mb-4">محصولات پرفروش</MudText>
<MudTable Items="@_topProducts" Dense="true" Hover="true" Striped="true" Bordered="true">
<HeaderContent>
<MudTh>نام محصول</MudTh>
<MudTh>دستهبندی</MudTh>
<MudTh>فروش</MudTh>
<MudTh>درآمد</MudTh>
<MudTh>امتیاز</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.Name</MudTd>
<MudTd>@context.Category</MudTd>
<MudTd>@context.SalesCount</MudTd>
<MudTd>@context.Revenue.ToString("N0") تومان</MudTd>
<MudTd><MudRating ReadOnly="true" SelectedValue="@context.Rating" Size="Size.Small" /></MudTd>
</RowTemplate>
</MudTable>
</MudPaper>
</MudItem>
</MudGrid>
}
<style>
/* Animate.css را در index.html اضافه کنید یا اینجا نسخه خلاصه */
.animate__animated { animation-duration: .6s; }
.animate__fadeInUp { animation-name: fadeInUp; }
.animate__fadeInRight { animation-name: fadeInRight; }
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeInRight {
from { opacity: 0; transform: translateX(20px); }
to { opacity: 1; transform: translateX(0); }
}
.hover-lift {
transition: transform .3s ease, box-shadow .3s ease;
}
.hover-lift:hover {
transform: translateY(-5px);
box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
</style>
@code {
private List<BreadcrumbItem> _items = new()
{
new("پنل مدیریت", href: "/admin/dashboard", icon: Icons.Material.Filled.Home)
};
// مدل آماری اصلی
private AdminDashboardStatisticsModel _statistics;
// کارتهای اولیه
private List<CardModel> _mainCards;
// دادههای نمودار
private ChartSeries[] _salesSeries;
private string[] _months = { "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند" };
// نوتیفیکیشنها
private List<NotificationModel> _notifications;
// سه کارت اضافی
private List<CardModel> _extraCards;
// محصولات پرفروش
private List<TopProductModel> _topProducts;
protected override async Task OnInitializedAsync()
{
// ۱. بارگذاری آمار اصلی
_statistics = await Mediator.Send(new GetAdminDashboardStatisticsQuery());
// ۲. آمادهسازی کارتها
_mainCards = new()
{
new("#4facfe 0%, #00f2fe 100%", Icons.Material.Filled.ShoppingBasket, "تعداد محصولات", $"{_statistics.TotalProducts:N0}", "۱۲+ مورد جدید"),
new("#a18cd1 0%, #fbc2eb 100%", Icons.Material.Filled.AttachMoney, "فروش کل", $"{_statistics.TotalSales:N0} تومان", "۱۵% رشد"),
new("#ff9a9e 0%, #fad0c4 100%", Icons.Material.Filled.Payment, "کارمزد سایت", $"{_statistics.TotalCommission:N0} تومان", $"{(_statistics.TotalSales>0?(_statistics.TotalCommission/_statistics.TotalSales*100).ToString("F1"):"0")}%"),
new("#84fab0 0%, #8fd3f4 100%", Icons.Material.Filled.Groups, "تعداد فروشندگان", $"{_statistics.TotalSellers:N0}", "۳ نفر جدید")
};
// ۳. دادههای نمودار (نمونه یا از یک کوئری دیگر)
_salesSeries = new[]
{
new ChartSeries { Name="فروش", Data = new double[]{ 12, 15, 18, 22, 24, 28, 26, 30, 33, 37, 42, 48 } }
};
// ۴. نوتیفیکیشنها (نمونه)
_notifications = new()
{
new("فروشنده 'علی حسینی' ثبتنام کرد", DateTime.Now.AddMinutes(-30)),
new("فروشنده 'سارا محمدی' ثبتنام کرد", DateTime.Now.AddHours(-1)),
new("فروشنده 'رضا احمدی' ثبتنام کرد", DateTime.Now.AddDays(-1))
};
// ۵. سه کارت اضافی
_extraCards = new()
{
new("#f6d365 0%, #fda085 100%", Icons.Material.Filled.ShoppingCart, "تعداد سفارشات", $"{_statistics.TotalOrders:N0}", "۱۰% رشد"),
new("#d4fc79 0%, #96e6a1 100%", Icons.Material.Filled.Money, "میانگین سبد خرید", $"{_statistics.AverageCartValue:N0} تومان", "۸% رشد"),
new("#89f7fe 0%, #66a6ff 100%", Icons.Material.Filled.TrendingUp, "نرخ تبدیل", $"{_statistics.ConversionRate:F1}%", "")
};
// ۶. محصولات پرفروش (نمونه)
_topProducts = new()
{
new("گوشی سامسونگ A52","الکترونیک",150,75_000_000,4),
new("لپتاپ لنوو IdeaPad","الکترونیک",120,96_000_000,5),
new("کفش نایک Air Zoom","پوشاک",90,45_000_000,3),
new("عطر دیور Sauvage","آرایشی",80,64_000_000,4)
};
}
// مدل کارت
record CardModel(string Background, string Icon, string Title, string Value, string Growth, string Info = "");
// مدل نوتیف
record NotificationModel(string Message, DateTime Date);
// مدل محصول
record TopProductModel(string Name, string Category, int SalesCount, decimal Revenue, int Rating);
}