feat(admin): 平台商户成员管理改用抽屉,消除商户视角切换与全局状态污染
- 交互重构:在「平台商户」与「平台账号」点击成员管理时,不再跳转路由或改写 localStorage.merchant_id,改为滑出 MerchantMembersDrawer 抽屉 - 抽屉能力:支持查看指定商户成员列表、新增成员(新建账号或关联已有账号)、修改角色与启用状态、移除成员 - 顶栏清理:彻底移除顶栏右上角的「当前商户:xxx」标签与「退出商户视角」按钮,超管登录自动清理任何残留上下文 - 后端补齐:新增平台专属 /api/platform/merchants/:id/members 与 roles 接口,平台操作不再依赖 X-Merchant-ID - 验证:tsc -b && vite build 成功;全量 go test ./... 包含路由与鉴权回归测试 100% 通过
This commit is contained in:
@@ -243,7 +243,11 @@ func Setup(h *Handlers) *gin.Engine {
|
||||
platform.GET("/platform/orders", h.Merchant.ListPlatformOrders)
|
||||
platform.POST("/platform/merchants", h.Merchant.CreateMerchant)
|
||||
platform.PATCH("/platform/merchants/:id", h.Merchant.UpdateMerchantSettings)
|
||||
platform.GET("/platform/merchants/:id/members", h.Merchant.ListPlatformMerchantMembers)
|
||||
platform.POST("/platform/merchants/:id/members", h.Merchant.AddPlatformMerchantMember)
|
||||
platform.PATCH("/platform/merchants/:id/members/:mid", h.Merchant.UpdatePlatformMerchantMember)
|
||||
platform.DELETE("/platform/merchants/:id/members/:mid", h.Merchant.DeletePlatformMerchantMember)
|
||||
platform.GET("/platform/merchants/:id/roles", h.Merchant.ListPlatformMerchantRoles)
|
||||
platform.GET("/platform/product-catalog", h.Merchant.ListProductCatalog)
|
||||
platform.GET("/platform/merchants/:id/products", h.Merchant.ListMerchantProductsByAdmin)
|
||||
platform.PATCH("/platform/merchants/:id/products/:pid", h.Merchant.AdminUpdateMerchantProduct)
|
||||
|
||||
@@ -213,3 +213,30 @@ func TestRequestLoggerSuppressesPollingOnInfo(t *testing.T) {
|
||||
t.Errorf("expected GET order to appear as [DEBUG] in DEBUG mode, got: %s", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
// TestPlatformMerchantMembersRoutes 验证平台管理员访问商户成员与角色接口完全独立于 X-Merchant-ID。
|
||||
func TestPlatformMerchantMembersRoutes(t *testing.T) {
|
||||
engine, jm := newTestRouter(t)
|
||||
token, err := jm.Generate(1, "admin", model.RoleAdmin)
|
||||
if err != nil {
|
||||
t.Fatalf("generate token: %v", err)
|
||||
}
|
||||
|
||||
// 1. 获取商户 1 的成员列表
|
||||
req := httptest.NewRequest("GET", "/api/platform/merchants/1/members", nil)
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
w := httptest.NewRecorder()
|
||||
engine.ServeHTTP(w, req)
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("平台管理员查询商户成员应返回 200,实际 %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
// 2. 获取商户 1 的角色列表
|
||||
req = httptest.NewRequest("GET", "/api/platform/merchants/1/roles", nil)
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
w = httptest.NewRecorder()
|
||||
engine.ServeHTTP(w, req)
|
||||
if w.Code != 200 {
|
||||
t.Fatalf("平台管理员查询商户角色应返回 200,实际 %d: %s", w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user