feat: vue-mobile => 完成用户信息修改功能,前后端都添加文件上传功能。

This commit is contained in:
RockYang
2023-06-27 12:11:55 +08:00
parent c3d62bb8d8
commit 3efd5fb77a
20 changed files with 353 additions and 73 deletions

View File

@@ -233,8 +233,38 @@ func (h *UserHandler) Session(c *gin.Context) {
}
type userProfile struct {
Id uint `json:"id"`
Username string `json:"username"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
ChatConfig types.ChatConfig `json:"chat_config"`
Calls int `json:"calls"`
Tokens int `json:"tokens"`
}
func (h *UserHandler) Profile(c *gin.Context) {
user, err := utils.GetLoginUser(c, h.db)
if err != nil {
resp.NotAuth(c)
return
}
h.db.First(&user, user.Id)
var profile userProfile
err = utils.CopyObject(user, &profile)
if err != nil {
logger.Error("对象拷贝失败:", err.Error())
resp.ERROR(c, "获取用户信息失败")
return
}
profile.Id = user.Id
resp.SUCCESS(c, profile)
}
func (h *UserHandler) ProfileUpdate(c *gin.Context) {
var data vo.User
var data userProfile
if err := c.ShouldBindJSON(&data); err != nil {
resp.ERROR(c, types.InvalidArgs)
return
@@ -272,26 +302,6 @@ func (h *UserHandler) ProfileUpdate(c *gin.Context) {
resp.SUCCESS(c)
}
func (h *UserHandler) Profile(c *gin.Context) {
user, err := utils.GetLoginUser(c, h.db)
if err != nil {
resp.NotAuth(c)
return
}
h.db.First(&user, user.Id)
var userVo vo.User
err = utils.CopyObject(user, &userVo)
if err != nil {
logger.Error("对象拷贝失败:", err.Error())
resp.ERROR(c, "获取用户信息失败")
return
}
userVo.Id = user.Id
resp.SUCCESS(c, userVo)
}
// Password 更新密码
func (h *UserHandler) Password(c *gin.Context) {
var data struct {