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:
@@ -180,3 +180,71 @@ func (h *MerchantHandler) AdminUpdateMerchantAccount(c *gin.Context) {
|
||||
}
|
||||
response.OK(c, account)
|
||||
}
|
||||
|
||||
// ListPlatformMerchantMembers GET /api/platform/merchants/:id/members
|
||||
func (h *MerchantHandler) ListPlatformMerchantMembers(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if id == 0 {
|
||||
response.BadRequest(c, "商户 ID 无效")
|
||||
return
|
||||
}
|
||||
members, err := h.merchantSvc.ListMembers(uint(id))
|
||||
if err != nil {
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, members)
|
||||
}
|
||||
|
||||
// UpdatePlatformMerchantMember PATCH /api/platform/merchants/:id/members/:mid
|
||||
func (h *MerchantHandler) UpdatePlatformMerchantMember(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
mid, _ := strconv.ParseUint(c.Param("mid"), 10, 64)
|
||||
if id == 0 || mid == 0 {
|
||||
response.BadRequest(c, "参数无效")
|
||||
return
|
||||
}
|
||||
var req updateMemberReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
response.BadRequest(c, "参数错误:角色必填")
|
||||
return
|
||||
}
|
||||
member, err := h.merchantSvc.UpdateMember(uint(id), uint(mid), service.UpdateMemberInput{
|
||||
Role: req.Role, Status: req.Status, IsDefault: req.IsDefault,
|
||||
}, middleware.GetUserID(c))
|
||||
if err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, member)
|
||||
}
|
||||
|
||||
// DeletePlatformMerchantMember DELETE /api/platform/merchants/:id/members/:mid
|
||||
func (h *MerchantHandler) DeletePlatformMerchantMember(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
mid, _ := strconv.ParseUint(c.Param("mid"), 10, 64)
|
||||
if id == 0 || mid == 0 {
|
||||
response.BadRequest(c, "参数无效")
|
||||
return
|
||||
}
|
||||
if err := h.merchantSvc.RemoveMember(uint(id), uint(mid), middleware.GetUserID(c)); err != nil {
|
||||
response.BadRequest(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, nil)
|
||||
}
|
||||
|
||||
// ListPlatformMerchantRoles GET /api/platform/merchants/:id/roles
|
||||
func (h *MerchantHandler) ListPlatformMerchantRoles(c *gin.Context) {
|
||||
id, _ := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if id == 0 {
|
||||
response.BadRequest(c, "商户 ID 无效")
|
||||
return
|
||||
}
|
||||
roles, err := h.merchantSvc.ListRoles(uint(id))
|
||||
if err != nil {
|
||||
response.ServerError(c, err.Error())
|
||||
return
|
||||
}
|
||||
response.OK(c, roles)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user