Skip to content

Commit d6fc086

Browse files
authored
修复综合搜索结果为空的问题 (#962)
1 parent 9f4514d commit d6fc086

File tree

5 files changed

+80
-64
lines changed

5 files changed

+80
-64
lines changed

src/Desktop/BiliCopilot.UI/Controls/Components/VideoCardControl/VideoCardControl.xaml

+49-36
Original file line numberDiff line numberDiff line change
@@ -504,46 +504,59 @@
504504
Grid.Row="1"
505505
HorizontalAlignment="Left"
506506
Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.Title}" />
507-
<StackPanel
508-
Grid.Row="2"
509-
Orientation="Horizontal"
510-
Spacing="12">
511-
<StackPanel
512-
VerticalAlignment="Center"
513-
Orientation="Horizontal"
514-
Spacing="4"
515-
ToolTipService.ToolTip="{ext:Locale Name=PlayCount}">
516-
<ic:SymbolIcon
507+
<Grid Grid.Row="2">
508+
<Grid.ColumnDefinitions>
509+
<ColumnDefinition />
510+
<ColumnDefinition Width="Auto" />
511+
</Grid.ColumnDefinitions>
512+
<StackPanel Orientation="Horizontal" Spacing="12">
513+
<StackPanel
517514
VerticalAlignment="Center"
518-
FontSize="10"
519-
Foreground="{ThemeResource AccentTextFillColorTertiaryBrush}"
520-
Symbol="PlayCircle" />
521-
<TextBlock
515+
Orientation="Horizontal"
516+
Spacing="4"
517+
ToolTipService.ToolTip="{ext:Locale Name=PlayCount}">
518+
<ic:SymbolIcon
519+
VerticalAlignment="Center"
520+
FontSize="10"
521+
Foreground="{ThemeResource AccentTextFillColorTertiaryBrush}"
522+
Symbol="PlayCircle" />
523+
<TextBlock
524+
VerticalAlignment="Center"
525+
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
526+
Style="{StaticResource CaptionTextBlockStyle}"
527+
Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlayCount, Converter={StaticResource CountConverter}}"
528+
TextLineBounds="Tight" />
529+
</StackPanel>
530+
<StackPanel
522531
VerticalAlignment="Center"
523-
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
524-
Style="{StaticResource CaptionTextBlockStyle}"
525-
Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PlayCount, Converter={StaticResource CountConverter}}"
526-
TextLineBounds="Tight" />
532+
Orientation="Horizontal"
533+
Spacing="4"
534+
ToolTipService.ToolTip="{ext:Locale Name=DanmakuCount}"
535+
Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.DanmakuCount, Converter={StaticResource ObjectToVisibilityConverter}}">
536+
<ic:SymbolIcon
537+
VerticalAlignment="Center"
538+
FontSize="10"
539+
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
540+
Symbol="TextBulletList" />
541+
<TextBlock
542+
VerticalAlignment="Center"
543+
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
544+
Style="{StaticResource CaptionTextBlockStyle}"
545+
Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.DanmakuCount, Converter={StaticResource CountConverter}}"
546+
TextLineBounds="Tight" />
547+
</StackPanel>
527548
</StackPanel>
528-
<StackPanel
549+
<TextBlock
550+
Grid.Column="1"
551+
HorizontalAlignment="Right"
529552
VerticalAlignment="Center"
530-
Orientation="Horizontal"
531-
Spacing="4"
532-
ToolTipService.ToolTip="{ext:Locale Name=DanmakuCount}"
533-
Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.DanmakuCount, Converter={StaticResource ObjectToVisibilityConverter}}">
534-
<ic:SymbolIcon
535-
VerticalAlignment="Center"
536-
FontSize="10"
537-
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
538-
Symbol="TextBulletList" />
539-
<TextBlock
540-
VerticalAlignment="Center"
541-
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
542-
Style="{StaticResource CaptionTextBlockStyle}"
543-
Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.DanmakuCount, Converter={StaticResource CountConverter}}"
544-
TextLineBounds="Tight" />
545-
</StackPanel>
546-
</StackPanel>
553+
Foreground="{ThemeResource TextFillColorTertiaryBrush}"
554+
Style="{StaticResource CaptionTextBlockStyle}"
555+
Text="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PublishRelativeTime}"
556+
TextTrimming="CharacterEllipsis"
557+
TextWrapping="NoWrap"
558+
Visibility="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=ViewModel.PublishRelativeTime, Converter={StaticResource ObjectToVisibilityConverter}}" />
559+
</Grid>
547560
</Grid>
548561
</Grid>
549562
</base:CardControl>

src/Desktop/BiliCopilot.UI/ViewModels/Components/VideoSearchSectionDetailViewModel/VideoSearchSectionDetailViewModel.Properties.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public sealed partial class VideoSearchSectionDetailViewModel
1919
private readonly ILogger<VideoSearchSectionDetailViewModel> _logger;
2020

2121
private bool _canRequest;
22-
private string _offset;
22+
private int? _currentPage;
2323
private string _keyword;
2424
private bool _isPreventLoadMore;
2525

src/Desktop/BiliCopilot.UI/ViewModels/Components/VideoSearchSectionDetailViewModel/VideoSearchSectionDetailViewModel.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public VideoSearchSectionDetailViewModel(
2626
{
2727
_service = service;
2828
_logger = this.Get<ILogger<VideoSearchSectionDetailViewModel>>();
29-
Sorts = Enum.GetValues<ComprehensiveSearchSortType>().ToList();
29+
Sorts = [.. Enum.GetValues<ComprehensiveSearchSortType>()];
3030
}
3131

3232
/// <inheritdoc/>
3333
public void Initialize(string keyword, SearchPartition partition)
3434
{
3535
Clear();
36-
Sort = ComprehensiveSearchSortType.Play;
36+
Sort = ComprehensiveSearchSortType.Default;
3737
_keyword = keyword;
3838
}
3939

@@ -47,10 +47,10 @@ public void Clear()
4747
this.Get<DispatcherQueue>().TryEnqueue(DispatcherQueuePriority.Low, Items.Clear);
4848
}
4949

50-
internal void SetFirstPageData(IReadOnlyList<VideoInformation> videos, string initialOffset)
50+
internal void SetFirstPageData(IReadOnlyList<VideoInformation> videos, int? initialOffset)
5151
{
5252
_canRequest = true;
53-
_offset = initialOffset;
53+
_currentPage = initialOffset;
5454
this.Get<DispatcherQueue>().TryEnqueue(DispatcherQueuePriority.Low, () =>
5555
{
5656
Items.Clear();
@@ -81,17 +81,17 @@ internal void SetFirstPageData(IReadOnlyList<VideoInformation> videos, string in
8181
[RelayCommand]
8282
private async Task LoadItemsAsync()
8383
{
84-
if (!_canRequest || IsEmpty || _isPreventLoadMore || IsLoading)
84+
if (!_canRequest || IsEmpty || _isPreventLoadMore || IsLoading || _currentPage == null)
8585
{
8686
return;
8787
}
8888

8989
try
9090
{
9191
IsLoading = true;
92-
var (videos, _, nextOffset) = await _service.GetComprehensiveSearchResultAsync(_keyword, _offset, Sort);
93-
_offset = nextOffset;
94-
_canRequest = !string.IsNullOrEmpty(_offset);
92+
var (videos, nextOffset) = await _service.GetComprehensiveSearchResultAsync(_keyword, _currentPage, Sort);
93+
_currentPage = nextOffset;
94+
_canRequest = _currentPage != null;
9595
foreach (var item in videos)
9696
{
9797
if (Items.Any(p => p.Data.Equals(item)))
@@ -122,6 +122,7 @@ private async Task RefreshAsync()
122122
this.Get<DispatcherQueue>().TryEnqueue(DispatcherQueuePriority.Low, async () =>
123123
{
124124
var keyword = _keyword;
125+
_currentPage = 1;
125126
Clear();
126127
_keyword = keyword;
127128
_canRequest = true;

src/Desktop/BiliCopilot.UI/ViewModels/View/SearchPageViewModel/SearchPageViewModel.cs

+20-18
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,16 @@ private async Task SearchAsync(string keyword)
8383
try
8484
{
8585
IsSearching = true;
86-
var (videos, partitions, nextVideoOffset) = await _service.GetComprehensiveSearchResultAsync(keyword, sort: Richasy.BiliKernel.Models.ComprehensiveSearchSortType.Play);
87-
var sections = new List<ISearchSectionDetailViewModel>()
86+
var (videos, nextVideoOffset) = await _service.GetComprehensiveSearchResultAsync(keyword);
87+
var sections = new List<ISearchSectionDetailViewModel>
8888
{
8989
CreateVideoSection(videos, nextVideoOffset),
90+
CreateSection(SearchSectionType.Anime),
91+
CreateSection(SearchSectionType.Cinema),
92+
CreateSection(SearchSectionType.Live),
93+
CreateSection(SearchSectionType.User),
94+
CreateSection(SearchSectionType.Article),
9095
};
91-
if (partitions is not null)
92-
{
93-
foreach (var section in partitions)
94-
{
95-
var sec = CreateSection(section);
96-
if (sec is not null)
97-
{
98-
sections.Add(sec);
99-
}
100-
}
101-
}
102-
10396
Sections = [.. sections];
10497
SelectSection(Sections.FirstOrDefault());
10598
SectionInitialized?.Invoke(this, EventArgs.Empty);
@@ -129,17 +122,16 @@ private void SelectSection(ISearchSectionDetailViewModel section)
129122
section.TryFirstLoadCommand.Execute(default);
130123
}
131124

132-
private VideoSearchSectionDetailViewModel CreateVideoSection(IReadOnlyList<VideoInformation> videos, string offset)
125+
private VideoSearchSectionDetailViewModel CreateVideoSection(IReadOnlyList<VideoInformation> videos, int? page)
133126
{
134127
var newSection = new VideoSearchSectionDetailViewModel(_service);
135128
newSection.Initialize(Keyword, new SearchPartition(0, ResourceToolkit.GetLocalizedString(StringNames.Video)));
136-
newSection.SetFirstPageData(videos, offset);
129+
newSection.SetFirstPageData(videos, page);
137130
return newSection;
138131
}
139132

140-
private ISearchSectionDetailViewModel CreateSection(SearchPartition partition)
133+
private ISearchSectionDetailViewModel CreateSection(SearchSectionType type)
141134
{
142-
var type = (SearchSectionType)partition.Id;
143135
var sectionDetail = type switch
144136
{
145137
SearchSectionType.Anime or SearchSectionType.Cinema => (ISearchSectionDetailViewModel)new PgcSearchSectionDetailViewModel(_service),
@@ -149,6 +141,16 @@ private ISearchSectionDetailViewModel CreateSection(SearchPartition partition)
149141
_ => default
150142
};
151143

144+
var partition = type switch
145+
{
146+
SearchSectionType.Anime => new SearchPartition(7, ResourceToolkit.GetLocalizedString(StringNames.Anime)),
147+
SearchSectionType.Cinema => new SearchPartition(8, ResourceToolkit.GetLocalizedString(StringNames.Cinema)),
148+
SearchSectionType.Live => new SearchPartition(4, ResourceToolkit.GetLocalizedString(StringNames.Live)),
149+
SearchSectionType.User => new SearchPartition(2, ResourceToolkit.GetLocalizedString(StringNames.User)),
150+
SearchSectionType.Article => new SearchPartition(6, ResourceToolkit.GetLocalizedString(StringNames.Article)),
151+
_ => default
152+
};
153+
152154
sectionDetail?.Initialize(Keyword, partition);
153155
return sectionDetail;
154156
}

0 commit comments

Comments
 (0)