Skip to content

Commit 0403ec3

Browse files
author
QM303176530
committed
用户头像由上传模式改为 媒体库选择模式
1 parent f8cb44b commit 0403ec3

File tree

13 files changed

+109
-661
lines changed

13 files changed

+109
-661
lines changed

server/GORMV2接口测试文档.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
| /menu/updateBaseMenu | 更新菜单 || SliverHorn |
2222
| /menu/getBaseMenuById | 根据id获取菜单 || SliverHorn |
2323
| /user/changePassword | 修改密码 || SliverHorn |
24-
| /user/uploadHeaderImg | 上传头像 || SliverHorn |
2524
| /user/getUserList | 获取用户列表 || SliverHorn |
2625
| /user/setUserAuthority | 修改用户角色 || SliverHorn |
2726
| /fileUploadAndDownload/upload | 文件上传示例 || SliverHorn |

server/api/v1/sys_user.go

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func tokenNext(c *gin.Context, user model.SysUser) {
9090
NickName: user.NickName,
9191
Username: user.Username,
9292
AuthorityId: user.AuthorityId,
93-
BufferTime: 60*60*24, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
93+
BufferTime: 60 * 60 * 24, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
9494
StandardClaims: jwt.StandardClaims{
9595
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
9696
ExpiresAt: time.Now().Unix() + 60*60*24*7, // 过期时间 7天
@@ -174,50 +174,6 @@ type UserHeaderImg struct {
174174
HeaderImg multipart.File `json:"headerImg"`
175175
}
176176

177-
// @Tags SysUser
178-
// @Summary 用户上传头像
179-
// @Security ApiKeyAuth
180-
// @accept multipart/form-data
181-
// @Produce application/json
182-
// @Param headerImg formData file true "用户上传头像"
183-
// @Param username formData string true "用户上传头像"
184-
// @Success 200 {string} string "{"success":true,"data":{},"msg":"上传成功"}"
185-
// @Router /user/uploadHeaderImg [post]
186-
func UploadHeaderImg(c *gin.Context) {
187-
claims, _ := c.Get("claims")
188-
// 获取头像文件
189-
// 这里我们通过断言获取 claims内的所有内容
190-
waitUse := claims.(*request.CustomClaims)
191-
uuid := waitUse.UUID
192-
_, header, err := c.Request.FormFile("headerImg")
193-
// 便于找到用户 以后从jwt中取
194-
if err != nil {
195-
response.FailWithMessage(fmt.Sprintf("上传文件失败,%v", err), c)
196-
} else {
197-
// 文件上传后拿到文件路径
198-
var uploadErr error
199-
var filePath string
200-
if global.GVA_CONFIG.LocalUpload.Local {
201-
// 本地上传
202-
uploadErr, filePath, _ = utils.UploadAvatarLocal(header)
203-
} else {
204-
// 七牛云上传
205-
uploadErr, filePath, _ = utils.UploadRemote(header)
206-
}
207-
if uploadErr != nil {
208-
response.FailWithMessage(fmt.Sprintf("接收返回值失败,%v", err), c)
209-
} else {
210-
// 修改数据库后得到修改后的user并且返回供前端使用
211-
err, user := service.UploadHeaderImg(uuid, filePath)
212-
if err != nil {
213-
response.FailWithMessage(fmt.Sprintf("修改数据库链接失败,%v", err), c)
214-
} else {
215-
response.OkWithData(resp.SysUserResponse{User: *user}, c)
216-
}
217-
}
218-
}
219-
}
220-
221177
// @Tags SysUser
222178
// @Summary 分页获取用户列表
223179
// @Security ApiKeyAuth
@@ -298,3 +254,24 @@ func DeleteUser(c *gin.Context) {
298254
response.OkWithMessage("删除成功", c)
299255
}
300256
}
257+
258+
// @Tags SysUser
259+
// @Summary 删除用户
260+
// @Security ApiKeyAuth
261+
// @accept application/json
262+
// @Produce application/json
263+
// @Param data body model.SysUser true "删除用户"
264+
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
265+
// @Router /user/setUserInfo [put]
266+
func SetUserInfo(c *gin.Context) {
267+
var user model.SysUser
268+
c.ShouldBindJSON(&user)
269+
err, ReqUser := service.SetUserInfo(user)
270+
if err != nil {
271+
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
272+
} else {
273+
response.OkWithData(gin.H{
274+
"userInfo": ReqUser,
275+
}, c)
276+
}
277+
}

server/db/qmplus.sql

Lines changed: 25 additions & 109 deletions
Large diffs are not rendered by default.

server/db/sqlite/casbin_rule.sql

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
4343
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
4444
'p','8881','/user/changePassword','POST','','','');
4545
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
46-
'p','8881','/user/uploadHeaderImg','POST','','','');
47-
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
4846
'p','8881','/user/getInfoList','POST','','','');
4947
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
5048
'p','8881','/user/getUserList','POST','','','');
@@ -121,8 +119,6 @@ INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
121119
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
122120
'p','9528','/user/changePassword','POST','','','');
123121
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
124-
'p','9528','/user/uploadHeaderImg','POST','','','');
125-
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
126122
'p','9528','/user/getInfoList','POST','','','');
127123
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
128124
'p','9528','/user/getUserList','POST','','','');
@@ -201,8 +197,6 @@ INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
201197
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
202198
'p','888','/user/changePassword','POST','','','');
203199
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
204-
'p','888','/user/uploadHeaderImg','POST','','','');
205-
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
206200
'p','888','/user/getInfoList','POST','','','');
207201
INSERT INTO casbin_rule (p_type,v0,v1,v2,v3,v4,v5) VALUES (
208202
'p','888','/user/getUserList','POST','','','');

server/db/sqlite/sys_apis.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",de
4141
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
4242
23,1569828559000,1569828559000,NULL,NULL,'/user/changePassword','修改密码','user','POST');
4343
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
44-
24,1569828573000,1569828573000,NULL,NULL,'/user/uploadHeaderImg','上传头像','user','POST');
45-
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
4644
25,1569828600000,1569828600000,NULL,NULL,'/user/getInfoList','分页获取用户列表','user','POST');
4745
INSERT INTO sys_apis (id,created_at,updated_at,deleted_at,authority_id,"path",description,api_group,"method") VALUES (
4846
28,1570605317000,1570605427000,NULL,NULL,'/user/getUserList','获取用户列表','user','POST');

0 commit comments

Comments
 (0)