fix: add user failed in admin user list page

This commit is contained in:
RockYang 2024-01-07 10:49:36 +08:00
parent dc6719cf54
commit b677d3fac7
2 changed files with 7 additions and 4 deletions

View File

@ -8,6 +8,8 @@ import (
"chatplus/store/vo" "chatplus/store/vo"
"chatplus/utils" "chatplus/utils"
"chatplus/utils/resp" "chatplus/utils/resp"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -63,7 +65,7 @@ func (h *UserHandler) Save(c *gin.Context) {
var data struct { var data struct {
Id uint `json:"id"` Id uint `json:"id"`
Password string `json:"password"` Password string `json:"password"`
Mobile string `json:"mobile"` Username string `json:"username"`
Calls int `json:"calls"` Calls int `json:"calls"`
ImgCalls int `json:"img_calls"` ImgCalls int `json:"img_calls"`
ChatRoles []string `json:"chat_roles"` ChatRoles []string `json:"chat_roles"`
@ -83,7 +85,7 @@ func (h *UserHandler) Save(c *gin.Context) {
user.Id = data.Id user.Id = data.Id
// 此处需要用 map 更新,用结构体无法更新 0 值 // 此处需要用 map 更新,用结构体无法更新 0 值
res = h.db.Model(&user).Updates(map[string]interface{}{ res = h.db.Model(&user).Updates(map[string]interface{}{
"mobile": data.Mobile, "username": data.Username,
"calls": data.Calls, "calls": data.Calls,
"img_calls": data.ImgCalls, "img_calls": data.ImgCalls,
"status": data.Status, "status": data.Status,
@ -95,7 +97,8 @@ func (h *UserHandler) Save(c *gin.Context) {
} else { } else {
salt := utils.RandString(8) salt := utils.RandString(8)
u := model.User{ u := model.User{
Username: data.Mobile, Username: data.Username,
Nickname: fmt.Sprintf("极客学长@%d", utils.RandomNumber(6)),
Password: utils.GenPassword(data.Password, salt), Password: utils.GenPassword(data.Password, salt),
Avatar: "/images/avatar/user.png", Avatar: "/images/avatar/user.png",
Salt: salt, Salt: salt,

View File

@ -70,7 +70,7 @@
> >
<el-form :model="user" label-width="100px" ref="userEditFormRef" :rules="rules"> <el-form :model="user" label-width="100px" ref="userEditFormRef" :rules="rules">
<el-form-item label="手机号:" prop="username"> <el-form-item label="手机号:" prop="username">
<el-input v-model="user.mobile" autocomplete="off"/> <el-input v-model="user.username" autocomplete="off"/>
</el-form-item> </el-form-item>
<el-form-item v-if="add" label="密码:" prop="password"> <el-form-item v-if="add" label="密码:" prop="password">
<el-input v-model="user.password" autocomplete="off"/> <el-input v-model="user.password" autocomplete="off"/>