Skip to content

Commit

Permalink
🐛 fix(AppVisit): optimize the map and top10 charts
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Jan 15, 2025
1 parent 1b6f86f commit e5063a2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@
private RenderFragment GenPageFilter() => __builder =>
{
<div class="d-flex align-center justify-end pr-4">
<MCheckbox Value="ignoreLogin"
<MCheckbox Value="_ignoreLogin"
ValueChanged="OnIgnoreLoginChanged"
TValue="bool"
Label="忽视登录页"
HideDetails="@true"
Class="mt-0 mr-2"
Dense/>
<MCheckbox Value="ignoreHome"
<MCheckbox Value="_ignoreHome"
ValueChanged="OnIgnoreHomeChanged"
TValue="bool"
Label="忽视首页"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
using GraphQL.Client.Serializer.SystemTextJson;
using Timer = System.Timers.Timer;


namespace Masa.Tsc.Web.Admin.Rcl.Pages.Analysis
{
public partial class AppVisitAnalysis : TscComponentBase
{
[Inject] private IHttpClientFactory HttpClientFactory { get; set; } = null!;

[Inject] private MasaBlazor MasaBlazor { get; set; } = null!;

private const string UvTitle = "访问人数";
private const string UvtTitle = "打开次数";
private const string PvTitle = "访问页面数";
Expand All @@ -22,6 +23,12 @@ public partial class AppVisitAnalysis : TscComponentBase
private const string Top10PvTitle = PvTitle + " Top10";

private static readonly CultureInfo ZhCN = new("zh-CN");

private static readonly object AxisLabelWithMinWidth = new
{
overflow = "break",
width = 150
};

private GraphQLHttpClient _graphClient = null!;
private AppVisit? _uva;
Expand All @@ -42,8 +49,10 @@ public partial class AppVisitAnalysis : TscComponentBase
private DateTime _lastRefreshTime = DateTime.UtcNow;
private Timer? _timer;

private bool ignoreLogin;
private bool ignoreHome;
private bool _ignoreLogin;
private bool _ignoreHome;

private object _axisLabelForPage = new { };

protected override void OnInitialized()
{
Expand All @@ -53,12 +62,33 @@ protected override void OnInitialized()
_graphClient = new GraphQLHttpClient("http://10.130.0.33:4000/cubejs-api/graphql",
new SystemTextJsonSerializer(),
httpClient: httpClient);

MasaBlazor.BreakpointChanged += MasaBlazorOnBreakpointChanged;
}

private void MasaBlazorOnBreakpointChanged(object? sender, BreakpointChangedEventArgs e)
{
if (e.Breakpoint is Breakpoints.Xl or Breakpoints.Md)
{
_axisLabelForPage = AxisLabelWithMinWidth;
InvokeAsync(RefreshAppVisitPageAsync);
}
else if (e.Breakpoint == Breakpoints.Lg)
{
_axisLabelForPage = new { };
InvokeAsync(RefreshAppVisitPageAsync);
}
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
if (MasaBlazor.Breakpoint.Name != Breakpoints.Lg)
{
_axisLabelForPage = AxisLabelWithMinWidth;
}

await ReloadAll();

_timer = new Timer(TimeSpan.FromMinutes(_interval.ToInt32()));
Expand Down Expand Up @@ -87,7 +117,7 @@ private async Task ReloadAll()

_ = RefreshMapDataAsync();
_ = RefreshAppVisitHourAsync();
_ = RefreshAppVisitPageAsync2();
_ = RefreshAppVisitPageAsync();
}

private void OnIntervalChanged(StringNumber val)
Expand All @@ -111,14 +141,14 @@ private void OnIntervalChanged(StringNumber val)

private void OnIgnoreLoginChanged(bool val)
{
ignoreLogin = val;
_ = RefreshAppVisitPageAsync2();
_ignoreLogin = val;
_ = RefreshAppVisitPageAsync();
}

private void OnIgnoreHomeChanged(bool val)
{
ignoreHome = val;
_ = RefreshAppVisitPageAsync2();
_ignoreHome = val;
_ = RefreshAppVisitPageAsync();
}

private async Task RefreshMapDataAsync()
Expand Down Expand Up @@ -171,7 +201,7 @@ private async Task RefreshAppVisitHourAsync()

yuvt.Add(item.AppVisitHour.Yuvt);
suvt.Add(item.AppVisitHour.Suvt);

if (item.AppVisitHour.TimeNum <= currentHour)
{
tpv.Add(item.AppVisitHour.Tpv);
Expand All @@ -188,15 +218,15 @@ private async Task RefreshAppVisitHourAsync()
StateHasChanged();
}

private async Task RefreshAppVisitPageAsync2()
private async Task RefreshAppVisitPageAsync()
{
_uvPageOption = await RefreshAppVisitPageAsync(AppVisitType.Uv);
_uvtPageOption = await RefreshAppVisitPageAsync(AppVisitType.Uvt);
_pvPageOption = await RefreshAppVisitPageAsync(AppVisitType.Pv);
_uvPageOption = await RefreshSharedAppVisitPageAsync(AppVisitType.Uv);
_uvtPageOption = await RefreshSharedAppVisitPageAsync(AppVisitType.Uvt);
_pvPageOption = await RefreshSharedAppVisitPageAsync(AppVisitType.Pv);
StateHasChanged();
}

private async Task<object> RefreshAppVisitPageAsync(AppVisitType type)
private async Task<object> RefreshSharedAppVisitPageAsync(AppVisitType type)
{
var response = await _graphClient.SendQueryAsync<CubeData<AppVisitPageItem>>(GetAppVisitPageQuery(type));
var data = response.Data.Items.Select(x => new
Expand Down Expand Up @@ -264,7 +294,6 @@ private void UpdateMapOption(object data, int max)
{
type = "map",
map = "china",
roam = true,
data
}
};
Expand Down Expand Up @@ -295,13 +324,6 @@ private static object GetSharedHourOption(string title, List<string> x, List<int
bottom = "3%",
containLabel = true
},
toolbox = new
{
feature = new
{
saveAsImage = new { }
}
},
xAxis = new
{
type = "category",
Expand Down Expand Up @@ -339,7 +361,7 @@ private static object GetSharedHourOption(string title, List<string> x, List<int
};
}

private static object GetSharedAppVisitPageOption(string[] keys, object[] data, int max)
private object GetSharedAppVisitPageOption(string[] keys, object[] data, int max)
{
return new
{
Expand Down Expand Up @@ -373,11 +395,7 @@ private static object GetSharedAppVisitPageOption(string[] keys, object[] data,
{
type = "category",
data = keys,
axisLabel = new
{
overflow = "break",
width = 250
}
axisLabel = _axisLabelForPage
},
series = new[]
{
Expand Down Expand Up @@ -497,12 +515,12 @@ private GraphQLHttpRequest GetAppVisitPageQuery(AppVisitType type)
var filter = string.Empty;
List<string> _urls = [];

if (ignoreLogin)
if (_ignoreLogin)
{
_urls.Add("/home/index/{IsLogin:bool}");
}

if (ignoreHome)
if (_ignoreHome)
{
_urls.Add("/");
}
Expand Down

0 comments on commit e5063a2

Please sign in to comment.