增加商铺列表
This commit is contained in:
1 parent
d5232c581c
commit
440510aa8c
19 files changed
+734
-77
No files matched your search
@@ -0,0 +1,25 @@
|
||||
using RestSharp;
|
||||
using Store.Management.Api.Models;
|
||||
using Store.Management.Api.Transport;
|
||||
using Store.Management.Models;
|
||||
|
||||
namespace Store.Management.Api.Shops;
|
||||
|
||||
public sealed class ShopApi(ApiTransport transport)
|
||||
{
|
||||
/// <summary>按店铺 ID 获取 Cookie,仅在用户请求时读取。</summary>
|
||||
public Task<IReadOnlyList<ShopCookieInfo>> GetCookiesAsync(string shopId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(shopId);
|
||||
return transport.GetRequiredAsync<IReadOnlyList<ShopCookieInfo>>("shop/GetShopCookies", Method.Post,
|
||||
new { ShopIds = new[] { shopId } }, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>管理员分页查询商铺,筛选条件由服务端处理。</summary>
|
||||
public Task<PageResult<ShopInfo>> SearchAsync(ShopQueryRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
return transport.GetRequiredAsync<PageResult<ShopInfo>>("shop/GetAllShops", Method.Post,
|
||||
request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Store.Management.Api.Models;
|
||||
|
||||
namespace Store.Management.Api.Shops;
|
||||
|
||||
public sealed class ShopQueryRequest : PageRequest
|
||||
{
|
||||
public string? SearchUserName { get; init; }
|
||||
public string? SearchId { get; init; }
|
||||
public string? SearchName { get; init; }
|
||||
public string? SearchNotes { get; init; }
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public sealed class StoreApiClient : IDisposable
|
||||
public ApiTransport Transport { get; }
|
||||
public AuthApi Auth { get; }
|
||||
public UserApi Users { get; }
|
||||
public Shops.ShopApi Shops { get; }
|
||||
|
||||
/// <param name="httpClient">可选的外部 HTTP 客户端,由调用方管理其生命周期。</param>
|
||||
public StoreApiClient(ApiClientOptions options, HttpClient? httpClient = null)
|
||||
@@ -22,6 +23,7 @@ public sealed class StoreApiClient : IDisposable
|
||||
Transport = new ApiTransport(options, Session, httpClient);
|
||||
Auth = new AuthApi(Transport, Session);
|
||||
Users = new UserApi(Transport);
|
||||
Shops = new Shops.ShopApi(Transport);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
@@ -176,7 +176,7 @@
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="Foreground" Value="{Binding SelectedRowForeground, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridEx}}}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
@@ -203,7 +203,7 @@
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}" Value="True">
|
||||
<Setter Property="Foreground" Value="White" />
|
||||
<Setter Property="Foreground" Value="{Binding SelectedRowForeground, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridEx}}}" />
|
||||
</DataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
@@ -334,7 +334,7 @@
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="fousIcon" Property="Opacity" Value="1" />
|
||||
<!-- 整行变色 -->
|
||||
<Setter TargetName="border" Property="Background" Value="#4BB2FF" />
|
||||
<Setter TargetName="border" Property="Background" Value="{Binding SelectedRowBackground, RelativeSource={RelativeSource AncestorType={x:Type local:DataGridEx}}}" />
|
||||
</Trigger>
|
||||
<Trigger Property="DetailsVisibility" Value="Visible">
|
||||
<Setter TargetName="DetailsPresenter" Property="Margin" Value="0,0,1,0" />
|
||||
@@ -370,65 +370,42 @@
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ContextMenu">
|
||||
<Border
|
||||
Padding="0"
|
||||
Background="White"
|
||||
BorderBrush="#DDE0E5"
|
||||
BorderThickness="1"
|
||||
CornerRadius="6">
|
||||
BorderBrush="LightGray"
|
||||
BorderThickness="1">
|
||||
<StackPanel KeyboardNavigation.DirectionalNavigation="Cycle">
|
||||
<StackPanel Margin="14,12,14,8">
|
||||
<TextBlock
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
Text="显示的列" />
|
||||
<TextBlock
|
||||
Margin="0,4,0,0"
|
||||
Foreground="#858A94"
|
||||
Text="勾选后立即生效" />
|
||||
</StackPanel>
|
||||
|
||||
<Border
|
||||
Padding="10,0"
|
||||
Background="#eeeeee"
|
||||
BorderBrush="{StaticResource BorderBrush}"
|
||||
BorderThickness="0,0,0,1">
|
||||
<Grid>
|
||||
<TextBlock
|
||||
VerticalAlignment="Center"
|
||||
FontSize="14"
|
||||
FontWeight="SemiBold"
|
||||
Text="显示的列" />
|
||||
<Button
|
||||
Width="64"
|
||||
Height="28"
|
||||
HorizontalAlignment="Right"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
Command="{x:Static ApplicationCommands.Close}"
|
||||
Content="完成"
|
||||
Style="{x:Null}" />
|
||||
</Grid>
|
||||
|
||||
</Border>
|
||||
|
||||
<ScrollViewer
|
||||
MaxHeight="340"
|
||||
Margin="6,0,6,8"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
VerticalScrollBarVisibility="Auto">
|
||||
<ItemsPresenter KeyboardNavigation.DirectionalNavigation="Cycle" />
|
||||
</ScrollViewer>
|
||||
<Border
|
||||
Padding="12,9"
|
||||
Background="#FAFAFB"
|
||||
BorderBrush="#ECEEF1"
|
||||
BorderThickness="0,1,0,0">
|
||||
<Button
|
||||
x:Name="PART_DoneButton"
|
||||
Width="64"
|
||||
Height="28"
|
||||
HorizontalAlignment="Right"
|
||||
Background="#98638F"
|
||||
BorderThickness="0"
|
||||
Command="{x:Static ApplicationCommands.Close}"
|
||||
Content="完成"
|
||||
Foreground="White">
|
||||
<Button.Template>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<Border
|
||||
x:Name="ButtonBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
CornerRadius="4">
|
||||
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="ButtonBorder" Property="Opacity" Value="0.85" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocused" Value="True">
|
||||
<Setter TargetName="ButtonBorder" Property="BorderBrush" Value="#343A40" />
|
||||
<Setter TargetName="ButtonBorder" Property="BorderThickness" Value="1" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Button.Template>
|
||||
</Button>
|
||||
</Border>
|
||||
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
@@ -1006,7 +983,10 @@
|
||||
<Setter Property="HorizontalContentAlignment" Value="Right" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="DataGridExBaseStyle" BasedOn="{StaticResource DataGridExDefaultDataGridStyle}" TargetType="local:DataGridEx">
|
||||
<Style
|
||||
x:Key="DataGridExBaseStyle"
|
||||
BasedOn="{StaticResource DataGridExDefaultDataGridStyle}"
|
||||
TargetType="local:DataGridEx">
|
||||
<Setter Property="EnableRowVirtualization" Value="True" />
|
||||
<Setter Property="EnableColumnVirtualization" Value="True" />
|
||||
<Setter Property="VirtualizingPanel.IsVirtualizing" Value="True" />
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using Riok.Mapperly.Abstractions;
|
||||
using Store.Management.Framework.ViewModels;
|
||||
using Store.Management.Models;
|
||||
|
||||
namespace Store.Management.Framework.Mappers;
|
||||
|
||||
[Mapper]
|
||||
public static partial class ShopMapper
|
||||
{
|
||||
public static partial IReadOnlyList<ShopItemViewModel> ToItemViewModels(IReadOnlyList<ShopInfo> shops);
|
||||
}
|
||||
@@ -13,6 +13,58 @@
|
||||
<ResourceDictionary Source="/Store.Management.Framework;component/Controls/DataGridEx/DataGridEx.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style
|
||||
x:Key="IconButtonStyle"
|
||||
BasedOn="{StaticResource ButtonCustom}"
|
||||
TargetType="Button">
|
||||
<Setter Property="Width" Value="32" />
|
||||
<Setter Property="Height" Value="28" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
</Style>
|
||||
|
||||
|
||||
<!-- 表格搜索区:统一尺寸,窄窗口允许换行。 -->
|
||||
<Style x:Key="TableSearchTextBoxStyle" BasedOn="{StaticResource TextBoxExtend}" TargetType="TextBox">
|
||||
<Setter Property="Width" Value="180" />
|
||||
<Setter Property="Height" Value="32" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Center" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TableSearchComboBoxStyle" BasedOn="{StaticResource {x:Type ComboBox}}" TargetType="ComboBox">
|
||||
<Setter Property="Width" Value="180" />
|
||||
<Setter Property="Height" Value="32" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TableSearchButtonStyle" BasedOn="{StaticResource {x:Type Button}}" TargetType="Button">
|
||||
<Setter Property="Width" Value="80" />
|
||||
<Setter Property="Height" Value="32" />
|
||||
<Setter Property="Padding" Value="8,0" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TableSearchPrimaryButtonStyle" BasedOn="{StaticResource ButtonPrimary}" TargetType="Button">
|
||||
<Setter Property="Width" Value="80" />
|
||||
<Setter Property="Height" Value="32" />
|
||||
<Setter Property="Padding" Value="8,0" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TableSearchBarStyle" TargetType="wpf:SpacingStackPanel">
|
||||
<Style.Resources>
|
||||
<Style BasedOn="{StaticResource TableSearchTextBoxStyle}" TargetType="TextBox" />
|
||||
<Style BasedOn="{StaticResource TableSearchComboBoxStyle}" TargetType="ComboBox" />
|
||||
<Style BasedOn="{StaticResource TableSearchButtonStyle}" TargetType="Button" />
|
||||
</Style.Resources>
|
||||
<Setter Property="MinHeight" Value="44" />
|
||||
<Setter Property="Margin" Value="10,0" />
|
||||
<Setter Property="Orientation" Value="Horizontal" />
|
||||
<Setter Property="ChildWrapping" Value="True" />
|
||||
<Setter Property="HorizontalSpacing" Value="8" />
|
||||
<Setter Property="VerticalSpacing" Value="8" />
|
||||
<Setter Property="ItemVerticalAlignment" Value="Center" />
|
||||
</Style>
|
||||
|
||||
<FontFamily x:Key="IconPack">Fonts/iconfont.ttf#iconfont</FontFamily>
|
||||
|
||||
<Style BasedOn="{StaticResource DataGridExBaseStyle}" TargetType="{x:Type f:DataGridEx}">
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using MAX.Core.DependencyInjection;
|
||||
using Store.Management.Api;
|
||||
using Store.Management.Api.Models;
|
||||
using Store.Management.Api.Shops;
|
||||
using Store.Management.Models;
|
||||
|
||||
namespace Store.Management.Framework.Services;
|
||||
|
||||
public interface IShopService
|
||||
{
|
||||
Task<IReadOnlyList<ShopCookieInfo>> GetCookiesAsync(string shopId, CancellationToken cancellationToken = default);
|
||||
Task<PageResult<ShopInfo>> SearchAsync(ShopQueryRequest request, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
internal sealed class ShopService(StoreApiClient client) : IShopService, ISingletonDependency
|
||||
{
|
||||
public Task<IReadOnlyList<ShopCookieInfo>> GetCookiesAsync(string shopId, CancellationToken cancellationToken = default)
|
||||
=> client.Shops.GetCookiesAsync(shopId, cancellationToken);
|
||||
|
||||
public Task<PageResult<ShopInfo>> SearchAsync(ShopQueryRequest request, CancellationToken cancellationToken = default)
|
||||
=> client.Shops.SearchAsync(request, cancellationToken);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Store.Management.Framework.ViewModels;
|
||||
|
||||
public sealed class ShopItemViewModel
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public string? UserName { get; init; }
|
||||
public string? ShopId { get; init; }
|
||||
public string? ShopAccount { get; init; }
|
||||
public string? LoginStatus { get; init; }
|
||||
public bool IsLoggedOut => LoginStatus?.Contains("未登录", StringComparison.Ordinal) == true;
|
||||
public string? CompanyName { get; init; }
|
||||
public string? Notes { get; init; }
|
||||
public string? GroupName { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Store.Management.Models;
|
||||
|
||||
public sealed class ShopCookieInfo
|
||||
{
|
||||
public required string ShopId { get; init; }
|
||||
public required string Cookies { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Store.Management.Models;
|
||||
|
||||
/// <summary>商铺列表所需的服务端字段。</summary>
|
||||
public sealed class ShopInfo
|
||||
{
|
||||
public int Id { get; init; }
|
||||
public string? UserName { get; init; }
|
||||
public string? ShopId { get; init; }
|
||||
public string? ShopAccount { get; init; }
|
||||
public string? LoginStatus { get; init; }
|
||||
public string? CompanyName { get; init; }
|
||||
public string? Notes { get; init; }
|
||||
public string? GroupName { get; init; }
|
||||
}
|
||||
@@ -87,6 +87,7 @@ public partial class App : FrameworkApplication
|
||||
|
||||
|
||||
containerRegistry.RegisterForNavigation<UserManagementPage, UserManagementPageViewModel>(nameof(UserManagementPage));
|
||||
containerRegistry.RegisterForNavigation<ShopManagementView, ShopManagementViewModel>(nameof(ShopManagementView));
|
||||
containerRegistry.RegisterForNavigation<DataGridTestView, DataGridTestViewModel>(nameof(DataGridTestView));
|
||||
|
||||
|
||||
|
||||
@@ -24,15 +24,16 @@ namespace Store.Management.ViewModels
|
||||
Code = "1",
|
||||
Title = "角色管理",
|
||||
Icon = IconNameEnum.Person,
|
||||
Url = nameof(DataGridTestView)
|
||||
Url = nameof(UserManagementPage)
|
||||
});
|
||||
NavItems.Add(new NavItemViewModel
|
||||
{
|
||||
Code = "1",
|
||||
Title = "商铺管理",
|
||||
Icon = IconNameEnum.BuildingShop,
|
||||
Url = nameof(ShopManagementView),
|
||||
IsSelected = true,
|
||||
Url = nameof(UserManagementPage)
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
using Prism.Commands;
|
||||
using Store.Management.Api.Models;
|
||||
using Store.Management.Api.Shops;
|
||||
using Store.Management.Api.Transport;
|
||||
using Store.Management.Framework.Controls;
|
||||
using Store.Management.Framework.Mappers;
|
||||
using Store.Management.Framework.Services;
|
||||
using Store.Management.Framework.ViewModels;
|
||||
using Store.Management.Models;
|
||||
|
||||
namespace Store.Management.ViewModels;
|
||||
|
||||
public sealed class ShopManagementViewModel(IShopService shopService, IStatusBarService statusBar) : ViewModelBase
|
||||
{
|
||||
public const int SearchTextLimit = 250;
|
||||
private string account = string.Empty;
|
||||
private string shopId = string.Empty;
|
||||
private string shopName = string.Empty;
|
||||
private string notes = string.Empty;
|
||||
private int page = 1;
|
||||
private int pageSize = 50;
|
||||
private int total;
|
||||
private IReadOnlyList<ShopItemViewModel> shops = [];
|
||||
private ShopQueryRequest appliedQuery = new();
|
||||
|
||||
public string Account { get => account; set => SetProperty(ref account, value); }
|
||||
public string ShopId { get => shopId; set => SetProperty(ref shopId, value); }
|
||||
public string ShopName { get => shopName; set => SetProperty(ref shopName, value); }
|
||||
public string Notes { get => notes; set => SetProperty(ref notes, value); }
|
||||
public int Page { get => page; private set => SetProperty(ref page, value); }
|
||||
public int Total { get => total; private set => SetProperty(ref total, value); }
|
||||
public IReadOnlyList<ShopItemViewModel> Shops { get => shops; private set => SetProperty(ref shops, value); }
|
||||
public LoadingStatus LoadingStatus { get; } = new();
|
||||
|
||||
public AsyncDelegateCommand SearchCommand => field ??= new(SearchAsync);
|
||||
private Task SearchAsync() => LoadAsync(new ShopQueryRequest
|
||||
{
|
||||
SearchUserName = Account.Trim(), SearchId = ShopId.Trim(),
|
||||
SearchName = ShopName.Trim(), SearchNotes = Notes.Trim(), PageSize = pageSize
|
||||
});
|
||||
|
||||
public AsyncDelegateCommand ResetCommand => field ??= new(ResetAsync);
|
||||
private Task ResetAsync()
|
||||
{
|
||||
Account = ShopId = ShopName = Notes = string.Empty;
|
||||
return SearchAsync();
|
||||
}
|
||||
|
||||
public AsyncDelegateCommand<DataGridPageRequest> PageCommand => field ??= new(request => LoadAsync(new ShopQueryRequest
|
||||
{
|
||||
SearchUserName = appliedQuery.SearchUserName, SearchId = appliedQuery.SearchId,
|
||||
SearchName = appliedQuery.SearchName, SearchNotes = appliedQuery.SearchNotes,
|
||||
Page = request.PageIndex, PageSize = request.PageSize
|
||||
}));
|
||||
|
||||
public AsyncDelegateCommand<ShopItemViewModel> CopyCookieCommand => field ??= new(CopyCookieAsync,
|
||||
shop => !string.IsNullOrWhiteSpace(shop?.ShopId));
|
||||
private async Task CopyCookieAsync(ShopItemViewModel shop)
|
||||
{
|
||||
try
|
||||
{
|
||||
IReadOnlyList<ShopCookieInfo> cookies = await shopService.GetCookiesAsync(shop.ShopId!);
|
||||
string? cookie = cookies.FirstOrDefault(item => item.ShopId == shop.ShopId)?.Cookies;
|
||||
if (string.IsNullOrWhiteSpace(cookie))
|
||||
{
|
||||
statusBar.Report("该店铺没有可复制的 Cookie。", StatusLevel.Warning);
|
||||
return;
|
||||
}
|
||||
System.Windows.Clipboard.SetText(cookie);
|
||||
statusBar.Report("Cookie 已复制。", StatusLevel.Success);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
statusBar.Report(ex.Message, StatusLevel.Error);
|
||||
}
|
||||
catch (System.Runtime.InteropServices.COMException)
|
||||
{
|
||||
statusBar.Report("剪贴板暂时不可用,请重试。", StatusLevel.Error);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoadedOnce() => _ = SearchAsync();
|
||||
|
||||
private async Task LoadAsync(ShopQueryRequest request)
|
||||
{
|
||||
if (LoadingStatus.IsLoading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
LoadingStatus.Initialize("正在查询商铺…");
|
||||
try
|
||||
{
|
||||
PageResult<ShopInfo> result = await shopService.SearchAsync(request);
|
||||
int lastPage = (int)Math.Clamp((result.Total - 1) / request.PageSize + 1, 1, request.Page);
|
||||
if (request.Page > lastPage)
|
||||
{
|
||||
request.Page = lastPage;
|
||||
result = await shopService.SearchAsync(request);
|
||||
}
|
||||
appliedQuery = request;
|
||||
pageSize = request.PageSize;
|
||||
Shops = ShopMapper.ToItemViewModels(result.Items);
|
||||
Total = (int)Math.Min(result.Total, int.MaxValue);
|
||||
Page = request.Page;
|
||||
LoadingStatus.Done();
|
||||
statusBar.Report($"商铺查询完成,共 {Total} 条。", StatusLevel.Success, 100);
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
Shops = [];
|
||||
Total = 0;
|
||||
Page = 1;
|
||||
LoadingStatus.Error(ex.Message);
|
||||
statusBar.Report(ex.Message, StatusLevel.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:f="Store.Management.Framework"
|
||||
xmlns:wpf="MAX.WPF"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:Store.Management.ViewModels"
|
||||
d:Background="White"
|
||||
@@ -69,14 +70,13 @@
|
||||
Style="{StaticResource DemoButton}" />
|
||||
</WrapPanel>
|
||||
<!-- 两种搜索:当前页实时过滤、全部样例模拟后台查询。 -->
|
||||
<WrapPanel Margin="0,10,0,0">
|
||||
<StackPanel Margin="0,0,24,6" Orientation="Horizontal">
|
||||
<wpf:SpacingStackPanel Style="{StaticResource TableSearchBarStyle}">
|
||||
<StackPanel Margin="0,0,16,0" Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"
|
||||
Text="当前页实时搜索" />
|
||||
<TextBox
|
||||
Width="220"
|
||||
MaxLength="{x:Static vm:DataGridTestViewModel.SearchTextLimit}"
|
||||
Text="{Binding LocalKeyword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ToolTip="输入即过滤当前页;清空恢复本页数据,不改变分页总数" />
|
||||
@@ -85,23 +85,21 @@
|
||||
VerticalAlignment="Center"
|
||||
Text="{Binding LocalSearchSummary, Mode=OneWay}" />
|
||||
</StackPanel>
|
||||
<StackPanel Margin="0,0,0,6" Orientation="Horizontal">
|
||||
<StackPanel Margin="0" Orientation="Horizontal">
|
||||
<TextBlock
|
||||
Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"
|
||||
Text="后台搜索(模拟)" />
|
||||
<TextBox
|
||||
Width="220"
|
||||
MaxLength="{x:Static vm:DataGridTestViewModel.SearchTextLimit}"
|
||||
Text="{Binding BackendKeyword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
ToolTip="按名称、ID、分组、子账号、手机号、状态或备注搜索全部样例" />
|
||||
<Button
|
||||
Margin="8,0,0,0"
|
||||
Padding="14,3"
|
||||
Command="{Binding SearchCommand, Mode=OneWay}"
|
||||
Content="搜索" />
|
||||
</StackPanel>
|
||||
</WrapPanel>
|
||||
</wpf:SpacingStackPanel>
|
||||
</StackPanel>
|
||||
<!-- ItemsSource 是当前页;后台分页时只需替换加载命令。 -->
|
||||
<f:DataGridEx
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
<UserControl
|
||||
x:Class="Store.Management.Views.ShopManagementView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:f="Store.Management.Framework"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vm="clr-namespace:Store.Management.ViewModels"
|
||||
xmlns:wpf="MAX.WPF"
|
||||
Margin="5"
|
||||
d:DataContext="{d:DesignInstance Type=vm:ShopManagementViewModel}"
|
||||
d:DesignHeight="650"
|
||||
d:DesignWidth="1200"
|
||||
Background="{DynamicResource RegionBrush}"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<wpf:BindingProxy x:Key="PageViewModel" Data="{Binding Mode=OneWay}" />
|
||||
</UserControl.Resources>
|
||||
<DockPanel>
|
||||
<!-- 搜索条件 -->
|
||||
<wpf:SpacingStackPanel DockPanel.Dock="Top" VerticalSpacing="10">
|
||||
<wpf:SpacingStackPanel>
|
||||
<wpf:SpacingStackPanel.Style>
|
||||
<Style BasedOn="{StaticResource TableSearchBarStyle}" TargetType="wpf:SpacingStackPanel">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding LoadingStatus.IsLoading, Mode=OneWay}" Value="True">
|
||||
<Setter Property="IsEnabled" Value="False" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</wpf:SpacingStackPanel.Style>
|
||||
<wpf:TitleContent
|
||||
Title="账户"
|
||||
Placement="Left"
|
||||
TitleVerticalAlignment="Center">
|
||||
<TextBox
|
||||
d:Text="运营账户"
|
||||
MaxLength="{x:Static vm:ShopManagementViewModel.SearchTextLimit}"
|
||||
Text="{Binding Account, UpdateSourceTrigger=PropertyChanged}">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Enter" Command="{Binding SearchCommand, Mode=OneWay}" />
|
||||
</TextBox.InputBindings>
|
||||
</TextBox>
|
||||
</wpf:TitleContent>
|
||||
<wpf:TitleContent
|
||||
Title="店铺 ID"
|
||||
Placement="Left"
|
||||
TitleVerticalAlignment="Center">
|
||||
<TextBox
|
||||
d:Text="wx123456"
|
||||
MaxLength="{x:Static vm:ShopManagementViewModel.SearchTextLimit}"
|
||||
Text="{Binding ShopId, UpdateSourceTrigger=PropertyChanged}">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Enter" Command="{Binding SearchCommand, Mode=OneWay}" />
|
||||
</TextBox.InputBindings>
|
||||
</TextBox>
|
||||
</wpf:TitleContent>
|
||||
<wpf:TitleContent
|
||||
Title="店铺名"
|
||||
Placement="Left"
|
||||
TitleVerticalAlignment="Center">
|
||||
<TextBox
|
||||
d:Text="生活百货旗舰店"
|
||||
MaxLength="{x:Static vm:ShopManagementViewModel.SearchTextLimit}"
|
||||
Text="{Binding ShopName, UpdateSourceTrigger=PropertyChanged}">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Enter" Command="{Binding SearchCommand, Mode=OneWay}" />
|
||||
</TextBox.InputBindings>
|
||||
</TextBox>
|
||||
</wpf:TitleContent>
|
||||
<wpf:TitleContent
|
||||
Title="备注"
|
||||
Placement="Left"
|
||||
TitleVerticalAlignment="Center">
|
||||
<TextBox
|
||||
d:Text="重点运营"
|
||||
MaxLength="{x:Static vm:ShopManagementViewModel.SearchTextLimit}"
|
||||
Text="{Binding Notes, UpdateSourceTrigger=PropertyChanged}">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Enter" Command="{Binding SearchCommand, Mode=OneWay}" />
|
||||
</TextBox.InputBindings>
|
||||
</TextBox>
|
||||
</wpf:TitleContent>
|
||||
<Button
|
||||
Command="{Binding SearchCommand, Mode=OneWay}"
|
||||
Content="查询"
|
||||
Style="{StaticResource TableSearchPrimaryButtonStyle}" />
|
||||
<Button Command="{Binding ResetCommand, Mode=OneWay}" Content="重置" />
|
||||
</wpf:SpacingStackPanel>
|
||||
</wpf:SpacingStackPanel>
|
||||
<TextBlock
|
||||
Margin="10,5"
|
||||
d:Text="查询失败,请重试。"
|
||||
DockPanel.Dock="Bottom"
|
||||
Foreground="{DynamicResource DangerBrush}"
|
||||
Text="{Binding LoadingStatus.ErrorMessage, Mode=OneWay}"
|
||||
TextWrapping="Wrap" />
|
||||
<!-- 商铺列表与服务端分页 -->
|
||||
<f:DataGridEx
|
||||
d:ItemsSource="{d:SampleData ItemCount=5}"
|
||||
AutoGenerateColumns="False"
|
||||
BorderThickness="1"
|
||||
CanUserSortColumns="False"
|
||||
IsLoading="{Binding LoadingStatus.IsLoading, Mode=OneWay}"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding Shops, Mode=OneWay}"
|
||||
LoadingText="{Binding LoadingStatus.Message, Mode=OneWay}"
|
||||
NoDataTips="暂无符合条件的商铺"
|
||||
PageChangedCommand="{Binding PageCommand, Mode=OneWay}"
|
||||
PageSize="50"
|
||||
ShowCheckBox="False"
|
||||
ShowPagination="True"
|
||||
ShowRowNumber="True"
|
||||
TotalItemCount="{Binding Total, Mode=OneWay}"
|
||||
PageIndex="{Binding Page, Mode=OneWay}">
|
||||
<f:DataGridEx.RowStyle>
|
||||
<Style BasedOn="{StaticResource DataGridExDefaultRowStyle}" TargetType="DataGridRow">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsLoggedOut, Mode=OneWay}" Value="True">
|
||||
<Setter Property="Background" Value="{DynamicResource DangerBrush}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource RegionBrush}" />
|
||||
</DataTrigger>
|
||||
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</f:DataGridEx.RowStyle>
|
||||
<f:DataGridEx.Columns>
|
||||
<DataGridTextColumn
|
||||
Width="*"
|
||||
MinWidth="120"
|
||||
Binding="{Binding UserName, Mode=OneWay}"
|
||||
Header="账户" />
|
||||
<DataGridTextColumn
|
||||
Width="*"
|
||||
MinWidth="140"
|
||||
Binding="{Binding ShopId, Mode=OneWay}"
|
||||
Header="店铺 ID" />
|
||||
<DataGridTextColumn
|
||||
Width="*"
|
||||
MinWidth="160"
|
||||
Binding="{Binding ShopAccount, Mode=OneWay}"
|
||||
Header="店铺名" />
|
||||
<DataGridTextColumn
|
||||
Width="120"
|
||||
Binding="{Binding LoginStatus, Mode=OneWay}"
|
||||
Header="登录状态" />
|
||||
<DataGridTextColumn
|
||||
Width="*"
|
||||
MinWidth="160"
|
||||
Binding="{Binding Notes, Mode=OneWay}"
|
||||
Header="备注" />
|
||||
<DataGridTextColumn
|
||||
Width="*"
|
||||
MinWidth="120"
|
||||
Binding="{Binding GroupName, Mode=OneWay}"
|
||||
Header="分组名" />
|
||||
<DataGridTemplateColumn
|
||||
Width="132"
|
||||
CanUserSort="False"
|
||||
Header="功能">
|
||||
<DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
d:Text="功能"
|
||||
Text="{Binding Mode=OneWay}"
|
||||
TextAlignment="Center" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.HeaderTemplate>
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<wpf:SpacingStackPanel
|
||||
VerticalAlignment="Center"
|
||||
Cursor="Hand"
|
||||
HorizontalSpacing="6"
|
||||
Orientation="Horizontal">
|
||||
<Button
|
||||
AutomationProperties.Name="复制 Cookie"
|
||||
Command="{Binding Data.CopyCookieCommand, Source={StaticResource PageViewModel}, Mode=OneWay}"
|
||||
CommandParameter="{Binding Mode=OneWay}"
|
||||
Style="{StaticResource IconButtonStyle}"
|
||||
ToolTip="复制 Cookie">
|
||||
<f:IconText FontSize="16" Icon="Copy" />
|
||||
</Button>
|
||||
<Button
|
||||
AutomationProperties.Name="购买API"
|
||||
IsEnabled="False"
|
||||
Style="{StaticResource IconButtonStyle}"
|
||||
ToolTip="购买API(功能待接入)"
|
||||
ToolTipService.ShowOnDisabled="True">
|
||||
<f:IconText FontSize="16" Icon="Cart" />
|
||||
</Button>
|
||||
<Button
|
||||
AutomationProperties.Name="进入店铺"
|
||||
IsEnabled="False"
|
||||
Style="{StaticResource IconButtonStyle}"
|
||||
ToolTip="进入店铺(功能待接入)"
|
||||
ToolTipService.ShowOnDisabled="True">
|
||||
<f:IconText FontSize="16" Icon="BuildingShop" />
|
||||
</Button>
|
||||
</wpf:SpacingStackPanel>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
</f:DataGridEx.Columns>
|
||||
</f:DataGridEx>
|
||||
</DockPanel>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Store.Management.Views;
|
||||
|
||||
public partial class ShopManagementView : UserControl
|
||||
{
|
||||
public ShopManagementView() => InitializeComponent();
|
||||
}
|
||||
@@ -47,20 +47,12 @@
|
||||
<DockPanel IsEnabled="{Binding CanInteract}">
|
||||
|
||||
<!-- 查询及用户操作 -->
|
||||
<Border
|
||||
Padding="10,5"
|
||||
VerticalAlignment="Center"
|
||||
DockPanel.Dock="Top">
|
||||
<wpf:SpacingStackPanel
|
||||
Height="44"
|
||||
HorizontalSpacing="8"
|
||||
Orientation="Horizontal">
|
||||
<Border VerticalAlignment="Center" DockPanel.Dock="Top">
|
||||
<wpf:SpacingStackPanel Style="{StaticResource TableSearchBarStyle}">
|
||||
<wpf:TitleContent Title="关键词" Style="{StaticResource VerticalAlignment}">
|
||||
<TextBox
|
||||
Width="175"
|
||||
hc:InfoElement.Placeholder="用户名,昵称,公司"
|
||||
MaxLength="{x:Static vm:UserManagementPageViewModel.KeywordLimit}"
|
||||
Style="{StaticResource TextBoxExtend}"
|
||||
Text="{Binding Keyword, UpdateSourceTrigger=PropertyChanged}">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Enter" Command="{Binding SearchCommand}" />
|
||||
@@ -70,7 +62,6 @@
|
||||
<wpf:TitleContent Title="用户组" Style="{StaticResource VerticalAlignment}">
|
||||
<ComboBox
|
||||
x:Name="GroupFilter"
|
||||
Width="120"
|
||||
d:ItemsSource="{d:SampleData ItemCount=8}"
|
||||
DisplayMemberPath="Display"
|
||||
ItemsSource="{wpf:EnumBindingMarkup EnumType={x:Type users:UserGroup},
|
||||
@@ -83,7 +74,7 @@
|
||||
<Button
|
||||
Command="{Binding SearchCommand}"
|
||||
Content="查询"
|
||||
Style="{StaticResource ButtonPrimary}" />
|
||||
Style="{StaticResource TableSearchPrimaryButtonStyle}" />
|
||||
<Button Command="{Binding CreateCommand}" Content="创建用户" />
|
||||
<Button Command="{Binding EditCommand}" Content="编辑" />
|
||||
<Button Command="{Binding DeleteCommand}" Content="删除" />
|
||||
|
||||
@@ -22,6 +22,10 @@ class Program
|
||||
[STAThread]
|
||||
static int Main(string[] args)
|
||||
{
|
||||
if (args.Contains("--shops"))
|
||||
{
|
||||
return ShopManagementChecks.Run();
|
||||
}
|
||||
var handler = new LoginHandler();
|
||||
using var httpClient = new HttpClient(handler);
|
||||
using var client = new StoreApiClient(new ApiClientOptions { BaseUrl = new Uri("http://localhost:14312/api/") }, httpClient);
|
||||
@@ -79,7 +83,17 @@ class Program
|
||||
grid.UpdateLayout();
|
||||
Check(ReferenceEquals(grid.SelectedRowBackground, app.FindResource("SelectedBackgroundBrush")), "主题选中背景");
|
||||
Check(ReferenceEquals(grid.SelectedRowForeground, app.FindResource("SelectedForegroundBrush")), "主题选中文字");
|
||||
Console.WriteLine("PASS: DataGridEx theme retains template, data rows and selection colors.");
|
||||
grid.SelectedRowBackground = System.Windows.Media.Brushes.LightGreen;
|
||||
grid.SelectedRowForeground = System.Windows.Media.Brushes.DarkGreen;
|
||||
foreach (string rowStyle in new[] { "DataGridExRowStyle", "DataGridExDefaultRowStyle" })
|
||||
{
|
||||
grid.RowStyle = (Style)grid.FindResource(rowStyle);
|
||||
grid.UpdateLayout();
|
||||
var row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(0);
|
||||
var border = (Border)row.Template.FindName("border", row);
|
||||
Check(ReferenceEquals(border.Background, grid.SelectedRowBackground), $"{rowStyle} 应使用外部选中背景");
|
||||
}
|
||||
Console.WriteLine("PASS: DataGridEx template, data rows, theme colors and custom selection background.");
|
||||
}
|
||||
finally { window.Close(); app.Shutdown(); }
|
||||
return 0;
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
using Autofac;
|
||||
using Store.Management;
|
||||
using Store.Management.Api;
|
||||
using Store.Management.Api.Shops;
|
||||
using Store.Management.Framework.Controls;
|
||||
using Store.Management.Framework.Services;
|
||||
using Store.Management.ViewModels;
|
||||
using Store.Management.Views;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
|
||||
internal static class ShopManagementChecks
|
||||
{
|
||||
public static int Run()
|
||||
{
|
||||
using ShopHandler handler = new();
|
||||
using HttpClient http = new(handler);
|
||||
using StoreApiClient client = new(new ApiClientOptions { BaseUrl = new Uri("https://test.invalid/api/v1/") }, http);
|
||||
client.Auth.LoginAsync(new Store.Management.Api.Authentication.LoginRequest { UserName = "tester", Password = "password" }).GetAwaiter().GetResult();
|
||||
Prism.Autofac.AutofacContainerExtension extension = new();
|
||||
extension.RegisterInstance(typeof(StoreApiClient), client);
|
||||
extension.FinalizeExtension();
|
||||
using IContainer container = extension.Instance;
|
||||
IShopService service = container.Resolve<IShopService>();
|
||||
ShopManagementViewModel vm = new(service, new TestStatusBar())
|
||||
{
|
||||
Account = " account ", ShopId = " shop-1 ", ShopName = " shop name ", Notes = " note "
|
||||
};
|
||||
vm.SearchCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(handler.Path == "/api/v1/shop/GetAllShops" && handler.Authorization == "Bearer shop-test-token", "route and authentication");
|
||||
Check(handler.Query!.SearchUserName == "account" && handler.Query.SearchId == "shop-1" &&
|
||||
handler.Query.SearchName == "shop name" && handler.Query.SearchNotes == "note", "trimmed search fields");
|
||||
Check(vm.Total == 101 && vm.Shops.Single().ShopAccount == "sample shop" && vm.Shops[0].GroupName == "group" && vm.Shops[0].LoginStatus == "状态:未登录" && vm.Shops[0].IsLoggedOut, "mapping and total");
|
||||
vm.Account = "not submitted";
|
||||
vm.PageCommand.Execute(new DataGridPageRequest(2, 50)).GetAwaiter().GetResult();
|
||||
Check(handler.Query!.SearchUserName == "account" && vm.Page == 2, "paging preserves submitted filters");
|
||||
vm.SearchCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(vm.Page == 1 && handler.Query!.SearchUserName == "not submitted", "search resets page");
|
||||
vm.ResetCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(vm.Account == "" && vm.ShopId == "" && vm.ShopName == "" && vm.Notes == "" && handler.Query!.SearchNotes == "", "reset");
|
||||
handler.Total = 1;
|
||||
vm.PageCommand.Execute(new DataGridPageRequest(3, 50)).GetAwaiter().GetResult();
|
||||
Check(vm.Page == 1 && handler.Query!.Page == 1, "shrinking results return to valid page");
|
||||
handler.Fail = true;
|
||||
vm.SearchCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(vm.Shops.Count == 0 && vm.Total == 0 && !vm.LoadingStatus.IsLoading && vm.LoadingStatus.ErrorMessage == "query failed", "failure clears stale rows and loading");
|
||||
handler.Fail = false;
|
||||
vm.SearchCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(vm.Shops.Count == 1 && vm.LoadingStatus.ErrorMessage == "", "retry recovers");
|
||||
handler.Total = 0;
|
||||
vm.SearchCommand.Execute().GetAwaiter().GetResult();
|
||||
Check(vm.Total == 0 && vm.Shops.Count == 0, "empty result");
|
||||
int count = handler.Count;
|
||||
try
|
||||
{
|
||||
client.Shops.SearchAsync(new ShopQueryRequest { Page = 0 }).GetAwaiter().GetResult();
|
||||
throw new Exception("Missing page validation");
|
||||
}
|
||||
catch (System.ComponentModel.DataAnnotations.ValidationException)
|
||||
{
|
||||
Check(handler.Count == count, "invalid page never sent");
|
||||
}
|
||||
|
||||
Check(!new Store.Management.Framework.ViewModels.ShopItemViewModel { LoginStatus = "已登录" }.IsLoggedOut &&
|
||||
!new Store.Management.Framework.ViewModels.ShopItemViewModel().IsLoggedOut, "normal and null login status");
|
||||
var cookies = service.GetCookiesAsync("shop-1").GetAwaiter().GetResult();
|
||||
Check(cookies.Single().Cookies == "test-cookie" && cookies[0].ShopId == "shop-1", "cookie response");
|
||||
Check(!vm.CopyCookieCommand.CanExecute(new Store.Management.Framework.ViewModels.ShopItemViewModel()), "missing shop ID disables copy");
|
||||
handler.Total = 1;
|
||||
vm.SearchCommand.Execute().GetAwaiter().GetResult();
|
||||
App app = new();
|
||||
app.InitializeComponent();
|
||||
app.ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
||||
ShopManagementView view = new() { DataContext = vm };
|
||||
Window window = new() { Content = view, Width = 1000, Height = 650, ShowInTaskbar = false };
|
||||
try
|
||||
{
|
||||
window.Show();
|
||||
app.Dispatcher.Invoke(() => { }, DispatcherPriority.ApplicationIdle);
|
||||
view.UpdateLayout();
|
||||
Check(view.IsLoaded && view.ActualWidth > 0, "page resources and layout");
|
||||
TextBox[] searchInputs = Descendants<TextBox>(view).Where(input => input.GetBindingExpression(TextBox.TextProperty)?.ParentBinding.Path.Path is "Account" or "ShopId" or "ShopName" or "Notes").ToArray();
|
||||
Check(searchInputs.Length == 4 && searchInputs.All(input => input.Width == 180 && input.Height == 32 && input.ReadLocalValue(FrameworkElement.StyleProperty) == DependencyProperty.UnsetValue), "search inputs inherit scoped styles");
|
||||
Button searchButton = Descendants<Button>(view).Single(button => Equals(button.Content, "查询"));
|
||||
Check(searchButton.Width == 80 && searchButton.Height == 32 && searchButton.ReadLocalValue(FrameworkElement.StyleProperty) == DependencyProperty.UnsetValue, "search button inherits scoped style");
|
||||
DataGridEx grid = Descendants<DataGridEx>(view).Single();
|
||||
DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(0);
|
||||
Check(ReferenceEquals(row.Background, app.FindResource("DangerBrush")), "logged-out row color");
|
||||
row.IsSelected = true;
|
||||
view.UpdateLayout();
|
||||
Check(ReferenceEquals(row.Foreground, app.FindResource("SelectedForegroundBrush")), "selected warning row contrast");
|
||||
DataGridTemplateColumn actions = grid.Columns.OfType<DataGridTemplateColumn>().Single();
|
||||
FrameworkElement content = actions.GetCellContent(row);
|
||||
Button[] buttons = Descendants<Button>(content).ToArray();
|
||||
Check(buttons.Length == 3 && ReferenceEquals(buttons[0].Command, vm.CopyCookieCommand) &&
|
||||
ReferenceEquals(buttons[0].CommandParameter, vm.Shops[0]) && !buttons[1].IsEnabled && !buttons[2].IsEnabled,
|
||||
"row commands and pending action buttons");
|
||||
}
|
||||
finally
|
||||
{
|
||||
window.Close();
|
||||
app.Shutdown();
|
||||
}
|
||||
Console.WriteLine("PASS: shop API, DI, filters, paging, reset, errors, retry, empty results and WPF page load.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static IEnumerable<T> Descendants<T>(DependencyObject parent) where T : DependencyObject
|
||||
{
|
||||
for (int index = 0; index < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); index++)
|
||||
{
|
||||
DependencyObject child = System.Windows.Media.VisualTreeHelper.GetChild(parent, index);
|
||||
if (child is T match)
|
||||
{
|
||||
yield return match;
|
||||
}
|
||||
foreach (T descendant in Descendants<T>(child))
|
||||
{
|
||||
yield return descendant;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Check(bool condition, string message)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class TestStatusBar : IStatusBarService
|
||||
{
|
||||
public StatusBarMessage Current { get; private set; } = new("", StatusLevel.Info, null);
|
||||
public void Report(string text, StatusLevel level = StatusLevel.Info, int? progress = null)
|
||||
=> Current = new(text, level, progress);
|
||||
}
|
||||
|
||||
private sealed class ShopHandler : HttpMessageHandler
|
||||
{
|
||||
public string? Path { get; private set; }
|
||||
public string? Authorization { get; private set; }
|
||||
public ShopQueryRequest? Query { get; private set; }
|
||||
public bool Fail { get; set; }
|
||||
public int Total { get; set; } = 101;
|
||||
public int Count { get; private set; }
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
if (request.RequestUri!.AbsolutePath.EndsWith("/Auth/Login"))
|
||||
{
|
||||
return new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent("""{"code":200,"data":{"token":"shop-test-token"}}""", Encoding.UTF8, "application/json")
|
||||
};
|
||||
}
|
||||
Count++;
|
||||
Check(request.Method == HttpMethod.Post, "POST required");
|
||||
Path = request.RequestUri!.AbsolutePath;
|
||||
Authorization = request.Headers.Authorization?.ToString();
|
||||
if (Path.EndsWith("/shop/GetShopCookies"))
|
||||
{
|
||||
using JsonDocument body = JsonDocument.Parse(await request.Content!.ReadAsStringAsync(cancellationToken));
|
||||
Check(body.RootElement.GetProperty("shopIds").GetArrayLength() == 1 &&
|
||||
body.RootElement.GetProperty("shopIds")[0].GetString() == "shop-1", "cookie request shop ID");
|
||||
return new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent("""{"code":200,"data":[{"shopId":"shop-1","cookies":"test-cookie"}]}""", Encoding.UTF8, "application/json")
|
||||
};
|
||||
}
|
||||
Query = JsonSerializer.Deserialize<ShopQueryRequest>(await request.Content!.ReadAsStringAsync(cancellationToken), new JsonSerializerOptions(JsonSerializerDefaults.Web));
|
||||
string items = Total == 0 ? "[]" : """[{"id":1,"userName":"account","shopId":"shop-1","shopAccount":"sample shop","loginStatus":"状态:未登录","notes":null,"groupName":"group"}]""";
|
||||
string json = Fail ? """{"code":400,"msg":"query failed"}""" : $$$"""{"code":200,"data":{"total":{{{Total}}},"items":{{{items}}}}}""";
|
||||
return new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(json, Encoding.UTF8, "application/json") };
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user