diff --git a/Source/Store.Management.Api/Shops/ShopApi.cs b/Source/Store.Management.Api/Shops/ShopApi.cs
new file mode 100644
index 0000000..3b8dd42
--- /dev/null
+++ b/Source/Store.Management.Api/Shops/ShopApi.cs
@@ -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)
+{
+ /// 按店铺 ID 获取 Cookie,仅在用户请求时读取。
+ public Task> GetCookiesAsync(string shopId, CancellationToken cancellationToken = default)
+ {
+ ArgumentException.ThrowIfNullOrWhiteSpace(shopId);
+ return transport.GetRequiredAsync>("shop/GetShopCookies", Method.Post,
+ new { ShopIds = new[] { shopId } }, cancellationToken: cancellationToken);
+ }
+
+ /// 管理员分页查询商铺,筛选条件由服务端处理。
+ public Task> SearchAsync(ShopQueryRequest request, CancellationToken cancellationToken = default)
+ {
+ ArgumentNullException.ThrowIfNull(request);
+ return transport.GetRequiredAsync>("shop/GetAllShops", Method.Post,
+ request, cancellationToken: cancellationToken);
+ }
+}
diff --git a/Source/Store.Management.Api/Shops/ShopQueryRequest.cs b/Source/Store.Management.Api/Shops/ShopQueryRequest.cs
new file mode 100644
index 0000000..f728804
--- /dev/null
+++ b/Source/Store.Management.Api/Shops/ShopQueryRequest.cs
@@ -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; }
+}
diff --git a/Source/Store.Management.Api/StoreApiClient.cs b/Source/Store.Management.Api/StoreApiClient.cs
index 0b493b0..58f8dde 100644
--- a/Source/Store.Management.Api/StoreApiClient.cs
+++ b/Source/Store.Management.Api/StoreApiClient.cs
@@ -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; }
/// 可选的外部 HTTP 客户端,由调用方管理其生命周期。
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()
diff --git a/Source/Store.Management.Framework/Controls/DataGridEx/DataGridEx.xaml b/Source/Store.Management.Framework/Controls/DataGridEx/DataGridEx.xaml
index 7830e8a..74f07e7 100644
--- a/Source/Store.Management.Framework/Controls/DataGridEx/DataGridEx.xaml
+++ b/Source/Store.Management.Framework/Controls/DataGridEx/DataGridEx.xaml
@@ -176,7 +176,7 @@
-
+
@@ -203,7 +203,7 @@
-
+
@@ -334,7 +334,7 @@
-
+
@@ -370,65 +370,42 @@
+ BorderBrush="LightGray"
+ BorderThickness="1">
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
+
@@ -1006,7 +983,10 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
Fonts/iconfont.ttf#iconfont
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/Store.Management/Views/ShopManagementView.xaml.cs b/Source/Store.Management/Views/ShopManagementView.xaml.cs
new file mode 100644
index 0000000..b563d06
--- /dev/null
+++ b/Source/Store.Management/Views/ShopManagementView.xaml.cs
@@ -0,0 +1,8 @@
+using System.Windows.Controls;
+
+namespace Store.Management.Views;
+
+public partial class ShopManagementView : UserControl
+{
+ public ShopManagementView() => InitializeComponent();
+}
diff --git a/Source/Store.Management/Views/UserManagementPage.xaml b/Source/Store.Management/Views/UserManagementPage.xaml
index e3a4956..874c2e2 100644
--- a/Source/Store.Management/Views/UserManagementPage.xaml
+++ b/Source/Store.Management/Views/UserManagementPage.xaml
@@ -47,20 +47,12 @@
-
-
+
+
@@ -70,7 +62,6 @@
+ Style="{StaticResource TableSearchPrimaryButtonStyle}" />
diff --git a/Tests/Store.Management.App.SmokeTests/Program.cs b/Tests/Store.Management.App.SmokeTests/Program.cs
index 9952201..663e139 100644
--- a/Tests/Store.Management.App.SmokeTests/Program.cs
+++ b/Tests/Store.Management.App.SmokeTests/Program.cs
@@ -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;
diff --git a/Tests/Store.Management.App.SmokeTests/ShopManagementChecks.cs b/Tests/Store.Management.App.SmokeTests/ShopManagementChecks.cs
new file mode 100644
index 0000000..df59761
--- /dev/null
+++ b/Tests/Store.Management.App.SmokeTests/ShopManagementChecks.cs
@@ -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();
+ 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(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