Skip to content

Commit

Permalink
update ui
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Jan 14, 2025
1 parent a57bc68 commit 7fc2a85
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@page "/analysis/appvisit"
@inherits TscComponentBase

<MRow Dense>
<MCol Cols="12" Class="d-flex align-center justify-end">
<MMenu>
<ActivatorContent>
<MButton Plain Small @attributes="@context.Attrs">
@(_interval)分钟刷新一次,上次刷新时间:@_lastRefreshTime.ToString("HH:mm:ss")
@(_interval)分钟刷新一次,上次刷新时间:@_lastRefreshTime.Add(CurrentTimeZone.BaseUtcOffset).ToString("HH:mm:ss")
</MButton>
</ActivatorContent>
<ChildContent>
Expand All @@ -25,53 +26,50 @@
Loading="@_loading"
OnClick="@ReloadAll"/>
</MCol>
<MCol Cols="12"
Sm="6"
Md="3">
@GenAppVisitCard(UvTitle, _uva)
<MCol Cols="12" Lg="12" Xl="3">
<MRow Dense>
<MCol Cols="12" Sm="6" Md="6" Lg="3" Xl="12">
@GenAppVisitCard(UvTitle, _uva)
</MCol>
<MCol Cols="12" Sm="6" Md="6" Lg="3" Xl="12">
@GenAppVisitCard(UvTitle, _uvta)
</MCol>
<MCol Cols="12" Sm="6" Md="6" Lg="3" Xl="12">
@GenAppVisitCard(PvTitle, _pva)
</MCol>
<MCol Cols="12" Sm="6" Md="6" Lg="3" Xl="12">
@GenAliveRate(_aliverate)
</MCol>
</MRow>
</MCol>
<MCol Cols="12"
Sm="6"
Md="3">
@GenAppVisitCard(UvTitle, _uvta)
</MCol>
<MCol Cols="12"
Sm="6"
Md="3">
@GenAppVisitCard(PvTitle, _pva)
</MCol>
<MCol Cols="12"
Sm="6"
Md="3">
@GenAliveRate(_aliverate)
</MCol>
<MCol Cols="12">
<MCol Cols="12" Lg="12" Xl="9">
<MCard Class="pa-4">
<MECharts Option="@_mapOption"
IncludeFunctionsInOption
Height="600">
MinHeight="616">
Height="@("100%")">
</MECharts>
</MCard>
</MCol>
<MCol Cols="12">
<MCol Cols="12" Xl="4">
<MCard Class="pa-4">
<MECharts Option="_uvOption"
Height="260"/>
</MCard>
</MCol>
<MCol Cols="12">
<MCol Cols="12" Xl="4">
<MCard Class="pa-4">
<MECharts Option="_uvtOption"
Height="260"/>
</MCard>
</MCol>
<MCol Cols="12">
<MCol Cols="12" Xl="4">
<MCard Class="pa-4">
<MECharts Option="_pvOption"
Height="260"/>
</MCard>
</MCol>
<MCol Cols="12">
<MCol Cols="12" Xl="4">
<MCard Class="echarts-card"
Title="@Top10UvTitle">
<MCardText>
Expand All @@ -82,7 +80,7 @@
</MCardText>
</MCard>
</MCol>
<MCol Cols="12">
<MCol Cols="12" Xl="4">
<MCard Class="echarts-card"
Title="@Top10UvtTitle">
<MCardText>
Expand All @@ -93,7 +91,7 @@
</MCardText>
</MCard>
</MCol>
<MCol Cols="12">
<MCol Cols="12" Xl="4">
<MCard Class="echarts-card"
Title="@Top10PvTitle">
<MCardText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

Expand Down Expand Up @@ -120,10 +120,10 @@ private void OnIgnoreHomeChanged(bool val)

private async Task RefreshMapDataAsync()
{
var response = await _graphClient.SendQueryAsync<Data<AreaVisitItem>>(GetMapDataQuery());
var response = await _graphClient.SendQueryAsync<CubeData<AreaVisitItem>>(GetMapDataQuery());
var data = response.Data.Items.Select(x => new
{
name = ADCodeName[x.AreaVisit.ADCode],
name = TerminalAnalysisData.ADCodeName[x.AreaVisit.ADCode],
value = x.AreaVisit.Pv,
uv = x.AreaVisit.Uv,
uvt = x.AreaVisit.Uvt
Expand All @@ -135,7 +135,7 @@ private async Task RefreshMapDataAsync()

private async Task RefreshAppVisitHourAsync()
{
var response = await _graphClient.SendQueryAsync<Data<AppVisitHourItem>>(GetAppVisitHourQuery());
var response = await _graphClient.SendQueryAsync<CubeData<AppVisitHourItem>>(GetAppVisitHourQuery());

var x = response.Data.Items.Select(u => u.AppVisitHour.TimeKey).ToArray();
var tuv = response.Data.Items.Select(u => u.AppVisitHour.Tuv).ToArray();
Expand Down Expand Up @@ -164,7 +164,7 @@ private async Task RefreshAppVisitPageAsync2()

private async Task<object> RefreshAppVisitPageAsync(AppVisitType type)
{
var response = await _graphClient.SendQueryAsync<Data<AppVisitPageItem>>(GetAppVisitPageQuery(type));
var response = await _graphClient.SendQueryAsync<CubeData<AppVisitPageItem>>(GetAppVisitPageQuery(type));
var data = response.Data.Items.Select(x => new
{
x.AppVisitPage.Path,
Expand All @@ -191,7 +191,7 @@ private async Task RefreshAppVisitDataAsync()
private async Task<AppVisit> GetAppVisitAsync(AppVisitType type)
{
var query = GetAppVisitQuery(type);
var response = await _graphClient.SendQueryAsync<Data<AppVisitItem>>(query);
var response = await _graphClient.SendQueryAsync<CubeData<AppVisitItem>>(query);
return response.Data.Items.First().AppVisit;
}

Expand Down Expand Up @@ -500,6 +500,21 @@ private static int RoundUpToNearest(int value)
return (first + 1) * (int)Math.Pow(10, length - 1);
}

protected override ValueTask DisposeAsyncCore()
{
_graphClient.Dispose();

if (_timer != null)
{
_timer.Stop();
_timer.Elapsed -= TimerOnElapsed;
_timer.Dispose();
_timer = null;
}

return base.DisposeAsyncCore();
}

private enum AppVisitType
{
/// <summary>
Expand All @@ -523,8 +538,6 @@ private enum AppVisitType
Aliverate
}

private record Data<T>([property: JsonPropertyName("cube")] List<T> Items) where T : class;

private record AppVisitItem(
[property: JsonPropertyName("appinitvisit")]
AppVisit AppVisit);
Expand Down Expand Up @@ -559,56 +572,5 @@ private record AppVisitPageItem(
AppVisitPage AppVisitPage);

private record AppVisitPage(string Path, int Count, double Rate);

private static IReadOnlyDictionary<string, string> ADCodeName = new Dictionary<string, string>()
{
{ "110000", "北京" },
{ "120000", "天津" },
{ "130000", "河北" },
{ "140000", "山西" },
{ "150000", "内蒙古" },
{ "210000", "辽宁" },
{ "220000", "吉林" },
{ "230000", "黑龙江" },
{ "310000", "上海" },
{ "320000", "江苏" },
{ "330000", "浙江" },
{ "340000", "安徽" },
{ "350000", "福建" },
{ "360000", "江西" },
{ "370000", "山东" },
{ "410000", "河南" },
{ "420000", "湖北" },
{ "430000", "湖南" },
{ "440000", "广东" },
{ "450000", "广西" },
{ "460000", "海南" },
{ "500000", "重庆" },
{ "510000", "四川" },
{ "520000", "贵州" },
{ "530000", "云南" },
{ "540000", "西藏" },
{ "610000", "陕西" },
{ "620000", "甘肃" },
{ "630000", "青海" },
{ "640000", "宁夏" },
{ "650000", "新疆" },
{ "710000", "台湾" },
{ "810000", "香港" },
{ "820000", "澳门" }
};

public void Dispose()
{
_graphClient.Dispose();

if (_timer != null)
{
_timer.Stop();
_timer.Elapsed -= TimerOnElapsed;
_timer.Dispose();
_timer = null;
}
}
}
}
7 changes: 7 additions & 0 deletions src/Web/Masa.Tsc.Web.Admin.Rcl/Pages/Analysis/CubeData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Tsc.Web.Admin.Rcl.Pages.Analysis
{
internal record CubeData<T>([property: JsonPropertyName("cube")] List<T> Items) where T : class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,55 @@
@if (_platforms.Count > 0)
{
<MCol Cols="12" Md="6">
<MECharts Class="white rounded pa-4" Option="@_platformOption" Height="500"/>
<MCard Title="平台" Class="echarts-card">
<MCardText>
<MECharts Option="@_platformOption" Height="500"/>
</MCardText>
</MCard>
</MCol>
}

@if (_brands.Count > 0)
{
<MCol Cols="12" Md="6">
<MECharts Class="white rounded pa-4" Option="@_brandOption" Height="500"/>
<MCard Title="品牌" Class="echarts-card">
<MCardText>
<MECharts Option="@_brandOption" Height="500"/>
</MCardText>
</MCard>
</MCol>
}

@if (_appVersions.Count > 0)
{
<MCol Cols="12" Md="4">
<MECharts Class="white rounded pa-4 pb-0" Option="@_appVersionOption" Height="1000"/>
<MCard Title="APP 版本" Class="echarts-card">
<MCardText>
<MECharts Option="@_appVersionOption" Height="1000"/>
</MCardText>
</MCard>
</MCol>
}

@if (_devices.Count > 0)
{
<MCol Cols="12" Md="4">
<MECharts Class="white rounded pa-4 pb-0" Option="@_deviceOption" Height="1000"/>
<MCard Title="系统版本" Class="echarts-card">
<MCardText>
<MECharts Option="@_deviceOption" Height="1000"/>
</MCardText>
</MCard>
</MCol>
}

@if (_models.Count > 0)
{
<MCol Cols="12" Md="4">
<MECharts Class="white rounded pa-4 pb-0" Option="@_modelOption" Height="1000"/>
<MCard Title="机型" Class="echarts-card">
<MCardText>
<MECharts Option="@_modelOption" Height="1000"/>
</MCardText>
</MCard>
</MCol>
}
</MRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ private async Task RefreshBrandECharts()
await InvokeAsync(StateHasChanged);
}

private async Task<List<DataItem>> QueryAsync(string type)
private async Task<List<DeviceVisitItem>> QueryAsync(string type)
{
try
{
var query = GetQuery(type);
var result = await _graphClient.SendQueryAsync<Data>(query);
var result = await _graphClient.SendQueryAsync<CubeData<DeviceVisitItem>>(query);
return result.Data.Items;
}
catch (Exception e)
Expand Down Expand Up @@ -208,10 +208,6 @@ private static object GetPieOption(string name, IEnumerable<object> data)
{
return new
{
title = new
{
text = name,
},
tooltip = new
{
trigger = "item",
Expand Down Expand Up @@ -261,10 +257,6 @@ private static object GetBarOption(string name, IEnumerable<string> keys, IEnume
{
return new
{
title = new
{
text = name
},
tooltip = new
{
trigger = "axis",
Expand Down Expand Up @@ -352,9 +344,7 @@ private GraphQLHttpRequest GetQuery(string type)
""");
}

private record Data([property: JsonPropertyName("cube")] List<DataItem> Items);

private record DataItem(
private record DeviceVisitItem(
[property: JsonPropertyName("devicevisit")]
DeviceVisit DeviceVisit);

Expand Down
Loading

0 comments on commit 7fc2a85

Please sign in to comment.