feat:完善项目
This commit is contained in:
425
app/api/menu.go
Normal file
425
app/api/menu.go
Normal file
@ -0,0 +1,425 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"ArmedPolice/app/controller/menu"
|
||||
"ArmedPolice/app/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Menu struct{}
|
||||
|
||||
type (
|
||||
// menuForm 菜单信息
|
||||
menuForm struct {
|
||||
ParentID uint64 `json:"parent_id" form:"parent_id"`
|
||||
Name string `json:"name" form:"name" binding:"required"`
|
||||
Kind int `json:"kind" form:"kind" binding:"required"`
|
||||
Link string `json:"link" form:"link"`
|
||||
Component string `json:"component" form:"component"`
|
||||
Icon string `json:"icon" form:"icon"`
|
||||
Auth int `json:"auth" form:"auth"`
|
||||
Sort int `json:"sort" form:"sort"`
|
||||
Status int `json:"status" form:"status"`
|
||||
Remark string `json:"remark" form:"remark"`
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* @apiDefine Menu 菜单管理
|
||||
*/
|
||||
|
||||
/**
|
||||
* @api {get} /api/menu/list 菜单列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuList
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) List(c *gin.Context) {
|
||||
data, err := menu.NewInstance()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/add 菜单添加
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuAdd
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} parent_id 父级ID
|
||||
* @apiParam {String} name 菜单名
|
||||
* @apiParam {Number} kind 菜单类型(1:目录,2:菜单)
|
||||
* @apiParam {String} link 访问地址
|
||||
* @apiParam {String} component 页面组件
|
||||
* @apiParam {String} icon 页面icon
|
||||
* @apiParam {Number} auth 菜单权限(0:普通权限,1:超管权限)
|
||||
* @apiParam {Number} sort 排序,从大到小
|
||||
* @apiParam {Number} status 忘了干嘛,没用
|
||||
* @apiParam {String} remark 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Add(c *gin.Context) {
|
||||
form := new(menuForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Data(&menu.InstanceParams{
|
||||
ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/edit 菜单修改
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuEdit
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {Number} parent_id 父级ID
|
||||
* @apiParam {String} name 菜单名
|
||||
* @apiParam {Number} kind 菜单类型(1:目录,2:菜单)
|
||||
* @apiParam {String} link 访问地址
|
||||
* @apiParam {String} component 页面组件
|
||||
* @apiParam {String} icon 页面icon
|
||||
* @apiParam {Number} auth 菜单权限(0:普通权限,1:超管权限)
|
||||
* @apiParam {Number} sort 排序,从大到小
|
||||
* @apiParam {Number} status 禁用状态(1:启用,2:禁用)
|
||||
* @apiParam {String} remark 备注信息
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Edit(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
menuForm
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Data(&menu.InstanceParams{
|
||||
ID: form.ID, ParentID: form.ParentID, Name: form.Name, Kind: form.Kind, Link: form.Link, Component: form.Component,
|
||||
Icon: form.Icon, Auth: form.Auth, Sort: form.Sort, Status: form.Status, Remark: form.Remark,
|
||||
})
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/status 菜单状态
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuStatus
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
* @apiParam {Number} status 状态(1:启动,2:禁用)
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Status(c *gin.Context) {
|
||||
form := &struct {
|
||||
idForm
|
||||
Status int `json:"status" form:"status" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Status(form.ID, form.Status)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/delete 删除菜单
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuDelete
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} id ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Delete(c *gin.Context) {
|
||||
form := new(idForm)
|
||||
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Delete(form.ID)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} /api/menu/user 用户菜单列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuUser
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) User(c *gin.Context) {
|
||||
data, err := menu.NewUser()(getSession()(c).(*service.Session)).List()
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
func (a *Menu) Tenant(c *gin.Context) {
|
||||
form := &struct {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := menu.NewTenant()(getSession()(c).(*service.Session)).List(form.TenantID)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/tenant/bind 租户菜单绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuTenantBind
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} tenant_id 租户ID
|
||||
* @apiParam {Array.Number} menu_ids 菜单ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) TenantBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
TenantID uint64 `json:"tenant_id" form:"tenant_id" binding:"required"`
|
||||
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewTenant()(getSession()(c).(*service.Session)).Bind(form.TenantID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/menu/role 角色菜单列表
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuRole
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiSuccess (200) {Number} code 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg 成功提示
|
||||
* @apiSuccess (200) {Array} data 具体信息
|
||||
* @apiSuccess (200) {Number} data.id 菜单ID
|
||||
* @apiSuccess (200) {Number} data.parent_id 父级ID
|
||||
* @apiSuccess (200) {String} data.name 菜单名称
|
||||
* @apiSuccess (200) {Number} data.kind 类型(1:目录,2:菜单)
|
||||
* @apiSuccess (200) {String} data.link 访问地址
|
||||
* @apiSuccess (200) {String} data.component 组件
|
||||
* @apiSuccess (200) {Array} data.children="[]" 子集
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": [
|
||||
* "id": 1,
|
||||
* "parent_id": 0,
|
||||
* "name": "系统管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [
|
||||
* {
|
||||
* "id": 2,
|
||||
* "parent_id": 1,
|
||||
* "name": "用户管理",
|
||||
* "kind": 1,
|
||||
* "link": "1"
|
||||
* "component": ""
|
||||
* "children": [],
|
||||
* }
|
||||
* ]
|
||||
* ]
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) Role(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
data, err := menu.NewRole()(getSession()(c).(*service.Session)).List(form.RoleID)
|
||||
APIResponse(err, data)(c)
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} /api/role/bind 角色菜单绑定
|
||||
* @apiVersion 1.0.0
|
||||
* @apiName MenuRoleBind
|
||||
* @apiGroup Menu
|
||||
*
|
||||
* @apiHeader {string} x-token token
|
||||
*
|
||||
* @apiParam {Number} role_id 角色ID
|
||||
* @apiParam {Array.Number} menu_ids 菜单ID
|
||||
*
|
||||
* @apiSuccess (200) {Number} code=200 成功响应状态码!
|
||||
* @apiSuccess (200) {String} msg="ok" 成功提示
|
||||
*
|
||||
* @apiSuccessExample {json} Success response:
|
||||
* HTTPS 200 OK
|
||||
* {
|
||||
* "code": 200
|
||||
* "msg": "ok"
|
||||
* "data": null
|
||||
* }
|
||||
*/
|
||||
func (a *Menu) RoleBind(c *gin.Context) {
|
||||
form := &struct {
|
||||
RoleID uint64 `json:"role_id" form:"role_id" binding:"required"`
|
||||
MenuIDs []uint64 `json:"menu_ids" form:"menu_ids" binding:"required"`
|
||||
}{}
|
||||
if err := bind(form)(c); err != nil {
|
||||
APIFailure(err.(error))(c)
|
||||
return
|
||||
}
|
||||
err := menu.NewRole()(getSession()(c).(*service.Session)).Bind(form.RoleID, form.MenuIDs)
|
||||
APIResponse(err)(c)
|
||||
}
|
Reference in New Issue
Block a user