refactor: response

This commit is contained in:
wangfuduo 2026-07-08 17:26:14 +08:00
parent c7b7e919ed
commit 11c5ab5094
2 changed files with 14 additions and 3 deletions

View File

@ -75,3 +75,10 @@ func (r *Response) Message(message string) *Response {
r.Msg = message
return r
}
func (r *Response) Title(t string) *Response { r.Data.Window.Title = t; return r }
func (r *Response) Closable(b bool) *Response { r.Data.Window.Close = b; return r }
func (r *Response) AddButton(text, url, typ string) *Response {
r.Data.Buttons = append(r.Data.Buttons, &Button{Text: text, Url: url, Type: typ})
return r
}

View File

@ -52,6 +52,10 @@ func NewUser(ctx *gin.Context) *User {
return u
}
func (u *User) resp(code int, msgKey string) *response.Response {
return response.New(u.ctx, code, u.params.Str(msgKey))
}
// 判断注册时间
// 判断免费使用时间
// 判断是否有会员
@ -60,9 +64,9 @@ func NewUser(ctx *gin.Context) *User {
// 判断包是否提示更新
func (u *User) success() *response.Response {
resp := response.New(u.ctx, config.Success, "success")
resp.Window(&response.Window{Title: "", Close: true})
resp.Data.Buttons = make([]*response.Button, 0)
resp := u.resp(config.Success, "success").
Window(&response.Window{Title: "", Close: true}).
AddButton("", "", "")
return resp
}