237 lines
6.3 KiB
Go
237 lines
6.3 KiB
Go
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/v1/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/v1/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)).Form(&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/v1/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 {
|
||
IDStringForm
|
||
menuForm
|
||
}{}
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Form(&menu.InstanceParams{
|
||
ID: form.Convert(), 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/v1/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 {
|
||
IDStringForm
|
||
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.Convert(), form.Status)
|
||
APIResponse(err)(c)
|
||
}
|
||
|
||
/**
|
||
* @api {post} /api/v1/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(IDStringForm)
|
||
|
||
if err := bind(form)(c); err != nil {
|
||
APIFailure(err.(error))(c)
|
||
return
|
||
}
|
||
err := menu.NewInstance()(getSession()(c).(*service.Session)).Delete(form.Convert())
|
||
APIResponse(err)(c)
|
||
}
|