diff --git a/app/hdl/hdl_comm.go b/app/hdl/hdl_comm.go index 995f99e..dbffc73 100644 --- a/app/hdl/hdl_comm.go +++ b/app/hdl/hdl_comm.go @@ -110,8 +110,8 @@ func MenuList(c *gin.Context) { // GetBaseInfo // @Summary 获取系统信息 -// @Tags 公共模块-获取系统信息 -// @Description 获取系统信息 +// @Tags 公共模块 +// @Description 公共模块-获取系统信息 // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Accept json // @Produce json @@ -130,3 +130,34 @@ func GetBaseInfo(c *gin.Context) { }, nil) return } + +// UploadFile +// @Summary 上传文件 +// @Tags 公共模块 +// @Description 公共模块-上传文件 +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Accept multipart/form-data +// @Produce multipart/form-data +// @Param file formData file true "上传的文件" +// @Success 200 {string} "success" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/comm/basicGet [POST] +func UploadFile(c *gin.Context) { + // 单文件上传 + file, err := c.FormFile("file") + if err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err.Error()) + return + } + + dst := "./static/upload/" + file.Filename + if err = c.SaveUploadedFile(file, dst); err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + + e.OutSuc(c, map[string]string{ + "url": c.Request.Host + "/api/comm/upload/" + file.Filename, + }, nil) + return +} diff --git a/app/router/router.go b/app/router/router.go index 917407e..7eff844 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -8,6 +8,7 @@ import ( "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" + "net/http" ) // 初始化路由 @@ -66,12 +67,12 @@ func route(r *gin.RouterGroup) { } r.Use(mw.CheckBody) // body参数转换 r.Use(mw.CheckSign) // 签名校验 - - r.Use(mw.Auth) // 以下接口需要JWT验证 r.GET("/loginInfo", hdl.LoginInfo) rComm(r.Group("/comm")) + r.Use(mw.Auth) // 以下接口需要JWT验证 + r.Use(mw.CheckPermission) // 检测权限 rRole(r.Group("/role")) // 权限管理 rDataCenter(r.Group("/dataCenter")) // 数据中心 @@ -80,6 +81,8 @@ func route(r *gin.RouterGroup) { } func rComm(r *gin.RouterGroup) { + r.StaticFS("/upload", http.Dir("./static/upload")) + r.POST("/uploadFile", hdl.UploadFile) // 上传文件 r.GET("/getBaseInfo", hdl.GetBaseInfo) // 获取系统信息 r.POST("/getMenuList", hdl.MenuList) // 获取菜单栏列表 } diff --git a/docs/docs.go b/docs/docs.go index ce2af95..ee4241c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -27,7 +27,7 @@ const docTemplate = `{ "paths": { "/api/comm/basicGet": { "get": { - "description": "获取系统信息", + "description": "公共模块-获取系统信息", "consumes": [ "application/json" ], @@ -35,7 +35,7 @@ const docTemplate = `{ "application/json" ], "tags": [ - "公共模块-获取系统信息" + "公共模块" ], "summary": "获取系统信息", "parameters": [ @@ -61,6 +61,49 @@ const docTemplate = `{ } } } + }, + "post": { + "description": "公共模块-上传文件", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "multipart/form-data" + ], + "tags": [ + "公共模块" + ], + "summary": "上传文件", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "file", + "description": "上传的文件", + "name": "file", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } } }, "/api/dataCenter/generate/data/detail": { diff --git a/docs/swagger.json b/docs/swagger.json index 223905b..6972363 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -19,7 +19,7 @@ "paths": { "/api/comm/basicGet": { "get": { - "description": "获取系统信息", + "description": "公共模块-获取系统信息", "consumes": [ "application/json" ], @@ -27,7 +27,7 @@ "application/json" ], "tags": [ - "公共模块-获取系统信息" + "公共模块" ], "summary": "获取系统信息", "parameters": [ @@ -53,6 +53,49 @@ } } } + }, + "post": { + "description": "公共模块-上传文件", + "consumes": [ + "multipart/form-data" + ], + "produces": [ + "multipart/form-data" + ], + "tags": [ + "公共模块" + ], + "summary": "上传文件", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "file", + "description": "上传的文件", + "name": "file", + "in": "formData", + "required": true + } + ], + "responses": { + "200": { + "description": "success", + "schema": { + "type": "string" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } } }, "/api/dataCenter/generate/data/detail": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 81956fc..7f71f60 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -497,7 +497,7 @@ paths: get: consumes: - application/json - description: 获取系统信息 + description: 公共模块-获取系统信息 parameters: - description: 验证参数Bearer和token空格拼接 in: header @@ -517,7 +517,36 @@ paths: $ref: '#/definitions/md.Response' summary: 获取系统信息 tags: - - 公共模块-获取系统信息 + - 公共模块 + post: + consumes: + - multipart/form-data + description: 公共模块-上传文件 + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + - description: 上传的文件 + in: formData + name: file + required: true + type: file + produces: + - multipart/form-data + responses: + "200": + description: success + schema: + type: string + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 上传文件 + tags: + - 公共模块 /api/dataCenter/generate/data/detail: post: consumes: diff --git a/static/upload/0.png b/static/upload/0.png new file mode 100644 index 0000000..3210c5b Binary files /dev/null and b/static/upload/0.png differ diff --git a/static/upload/111 - 副本.jpg b/static/upload/111 - 副本.jpg new file mode 100644 index 0000000..36b7910 Binary files /dev/null and b/static/upload/111 - 副本.jpg differ