-
Notifications
You must be signed in to change notification settings - Fork 10
/
UserPlayedGameListView.razor
136 lines (121 loc) · 4.45 KB
/
UserPlayedGameListView.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@inject IHttpService _httpService
@inject ToastService? ToastService
@inject IServiceProvider Provider
@inject NavigationManager NavigationManager
@inject DialogService DialogService
@inject IDataCacheService _dataCacheService
@inject IEventService _eventService
<div>
<CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaTitleContainer Title="@(IsAnniversary?"我的游戏库":"游玩记录")" Icon="@((IsAnniversary?IconType.GameRecord: IconType.Steam).ToIconString())" Class="mb-4" Outline>
<ButtonContent>
@if (IsCurrentUser)
{
@if (string.IsNullOrWhiteSpace(SteamId))
{
<MButton Text Block Color="primary" OnClick="OnEditSteam">
<MIcon Left>mdi-steam </MIcon>
绑定Steam账号
</MButton>
}
else
{
<CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaButton TextStyle Text="刷新" Icon="mdi-refresh" IsAsync OnClick="OnRefresh" />
}
}
</ButtonContent>
</CnGalWebSite.Shared.MasaComponent.Shared.Components.MasaTitleContainer>
@if (isReady)
{
<CnGalWebSite.Shared.Component.PlayedGames.SteamUserInforCard GameRecords="GameRecords" SteamUserInfors="SteamUserInfors" IsAnniversary="IsAnniversary" TotalCount="TotalCount" UserInfoModel="UserInfoModel"/>
@if (GameRecords.Count == 0)
{
<div class="mb-3">
<NotFoundTip IsNeedLayput="true" />
</div>
}
else
{
<CnGalWebSite.Shared.Component.PlayedGames.ListGameRecordCard Model="GameRecords.Where(s=>s.IsInSteam||IsAnniversary==false)" IsCurrentUser="IsCurrentUser" IsAnniversary="IsAnniversary" />
}
}
else
{
<div style="height:300px">
<CnGalWebSite.Shared.AppComponent.Normal.Loading.LoadingTip Height="100%" />
</div>
}
</div>
<CnGalWebSite.Shared.Component.PlayedGames.EditUserSteamInforTip @ref="editUserSteamInforTip" OnChanged="OnChanged" />
@code {
[Parameter]
public string SteamId { get; set; }
[Parameter]
public string UserId { get; set; }
[Parameter]
public bool IsAnniversary { get; set; }
[Parameter]
public int TotalCount { get; set; }
[Parameter]
public PersonalSpaceViewModel UserInfoModel { get; set; }
[CascadingParameter]
public ErrorHandler ErrorHandler { get; set; }
public List<GameRecordViewModel> GameRecords = new List<GameRecordViewModel>();
public List<SteamUserInforModel> SteamUserInfors = new List<SteamUserInforModel>();
CnGalWebSite.Shared.Component.PlayedGames.EditUserSteamInforTip editUserSteamInforTip;
[Parameter]
public bool IsCurrentUser { get; set; }
bool isReady = false;
protected override async Task OnInitializedAsync()
{
await Refresh();
}
public async Task Refresh()
{
try
{
GameRecords = await _dataCacheService.UserGameRecordDataCatche.GetCache(UserId);
SteamUserInfors = await _dataCacheService.UserSteamInforDataCatche.GetCache(UserId);
isReady = true;
}
catch (Exception ex)
{
ErrorHandler.ProcessError(ex, "获取用户游玩记录列表失败");
}
}
public void OnEditSteam()
{
//await _eventService.OpenNewPage("https://oauth2.cngal.org/External/Challenge?scheme=Steam");
if (editUserSteamInforTip != null)
{
editUserSteamInforTip.Refresh(true);
}
}
public async Task OnChanged(string steamId)
{
SteamId = steamId;
await OnRefresh();
}
public async Task OnRefresh()
{
try
{
var model = await _httpService.GetAsync<Result>("api/playedgame/RefreshPlayedGameSteamInfor");
if (model.Successful)
{
_dataCacheService.UserGameRecordDataCatche.Clean(UserId);
_dataCacheService.UserSteamInforDataCatche.Clean(UserId);
await Refresh();
await ToastService.Success("刷新成功", "刷新成功");
StateHasChanged();
}
else
{
await ToastService.Error("刷新失败", "刷新失败");
}
}
catch (Exception ex)
{
ErrorHandler.ProcessError(ex, "刷新用户Steam信息失败");
}
}
}