You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
256 lines
12 KiB
256 lines
12 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
/**
|
|
* Created by 安徽云掌.
|
|
* User: 云掌.帮德
|
|
* Date: 2020/3/8 22:30
|
|
* Desc: 获取权限菜单
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
|
|
use auth\PermissAuth;
|
|
use think\App;
|
|
|
|
/**
|
|
* Menu类添加、修改等公共请求参数
|
|
* @OA\Schema (
|
|
* schema = "MenuField",
|
|
* required={"id","name","model_name"},
|
|
* @OA\Property(property="name",type="string",minLength=1,maxLength=30,mock={"mock":"@cname"},default="栏目菜单",description="权限菜单名称"),
|
|
* @OA\Property(property="parent_id",type="integer",format="int15",minLength=1,maxLength=100,default="0",description="父级ID"),
|
|
* @OA\Property(property="model_name",type="string",minLength=2,maxLength=20,mock={"mock":"@word"},default="/api/menu/index ",description="模块名/控制器/方法"),
|
|
* @OA\Property(property="path",type="string",default="/system/menu",description="权限菜单前端路由"),
|
|
* @OA\Property(property="component",type="string",default="/system/menu",description="对应前台的模板的路由地址"),
|
|
* @OA\Property(property="authority",type="string",default="sys:menu:add",description="按钮权限标识"),
|
|
* @OA\Property(property="icon",type="string",default="",description="菜单图标"),
|
|
* @OA\Property(property="color",type="string",default="",description="icon颜色"),
|
|
* @OA\Property(property="target",type="string",default="",description="是否新窗口 _target"),
|
|
* @OA\Property(property="iframe",type="integer",format="int15",default="0",description="是否为 iframe模式 0:不是 1:是"),
|
|
* @OA\Property(property="hide",type="integer",format="int15",minLength=1,maxLength=1,default="0",description="是否显示 0:显示 1:隐藏"),
|
|
* @OA\Property(property="sort",type="integer",format="int15",minLength=1,maxLength=100,default="0",description="排序"),
|
|
* @OA\Property(property="menu_type",type="integer",format="int15",minLength=1,maxLength=1,default="0",description="菜单类型 0:菜单 1:按钮"),
|
|
* @OA\Property(property="open_type",type="integer",format="int15",minLength=1,maxLength=1,default="0",description="打开方式 0:组件 1:内链 2:外链"),
|
|
* @OA\Property(property="is_dev",type="integer",format="int15",minLength=1,maxLength=1,default="0",description="1:开发者模式(即tp调试模式开启)"),
|
|
* @OA\Property(property="status",type="integer",format="int15",minLength=1,maxLength=1,default="1",description="状态:为1正常,为0禁用"),
|
|
* @OA\Property(property="condition",type="string",minLength=1,maxLength=100,default=" ",description="规则表达式,为空表示存在就验证,不为空表示按照条件验证"),
|
|
* @OA\Property(property="remarks",type="string",minLength=1,maxLength=200,default=" ",description="备注"),
|
|
* @OA\Property(property="child_list",type="string",minLength=1,maxLength=200,default=" ",description="100100 子集菜单集合"),
|
|
* ),
|
|
*/
|
|
class Menu extends Common
|
|
{
|
|
public $model = null;
|
|
|
|
public function __construct(App $app)
|
|
{
|
|
parent::__construct($app);
|
|
$this->model = new \app\api\model\Menu();
|
|
}
|
|
/**
|
|
* @OA\Get (
|
|
* path="menu/index",tags={"权限菜单"},summary="获取菜单列表",description="根据相关参数获取菜单列表",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\Parameter(name="path",in="query",description="前端权限路由",@OA\Schema (type="string")),
|
|
* @OA\Parameter(name="name",in="query",description="权限菜单名称",@OA\Schema (type="string")),
|
|
* @OA\Parameter (name="page",in="query",description="当前页码",@OA\Schema (type="integer",format="int15")),
|
|
* @OA\Parameter (name="limit",in="query",description="分页数量",@OA\Schema (type="integer",format="int15")),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="返回权限菜单菜单数据信息",
|
|
* @OA\JsonContent(ref="#/components/schemas/MenuMsgExport"),
|
|
* ),
|
|
* )
|
|
*/
|
|
public function index()
|
|
{
|
|
//接受参数
|
|
$_get = $this->request->param();
|
|
|
|
//指定搜索参数
|
|
$this->model->search_arr = ['path', 'name'];
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Menu::class)->scene('lists')->check($_get);
|
|
|
|
$_data = $this->model->index();
|
|
|
|
//数据处理 前台处理
|
|
// $_data['data'] = get_tree($_data['data'], 0, 'children');
|
|
|
|
//返回数据
|
|
return send_http_status($_data);
|
|
}
|
|
|
|
|
|
/**
|
|
* @OA\Post (path="menu/add",tags={"权限菜单"},summary="添加权限菜单数据",description="添加后台权限菜单数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema(ref="#/components/schemas/MenuField"),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="添加成功",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录总数"),
|
|
* @OA\Property(property="data", type="integer",format="int32",description="添加成功的的数据ID"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name] 在 [sys_time] 创建了权限菜单:[name]
|
|
*/
|
|
public function add()
|
|
{
|
|
//接收参数
|
|
$_post = $this->request->post();
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Menu::class)->check($_post);
|
|
//处理并返回参数
|
|
$insertId = $this->model->parentAdd($_post);
|
|
return send_http_status($insertId, $insertId ? 201 : 202);
|
|
}
|
|
|
|
|
|
/**
|
|
* @OA\Get (
|
|
* path="menu/read/id/{id}",tags={"权限菜单"},summary="获取菜单详情",description="根据ID查询菜单信息",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\Parameter(name="id",in="path",required=true,description="ID",@OA\Schema (type="integer",format="int32")),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="返回权限菜单菜单数据信息",
|
|
* @OA\JsonContent(ref="#/components/schemas/MenuMsgExport"),
|
|
* ),
|
|
* )
|
|
*/
|
|
public function read($id = '')
|
|
{
|
|
//验证参数
|
|
validate(\app\api\validate\Menu::class)->scene('read')->check(['id' => $id]);
|
|
|
|
//返回数据
|
|
return send_http_status($this->model->parentRead($id));
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (path="menu/edit/id/{id}",tags={"权限菜单"},summary="修改菜单数据",description="修改权限菜单数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema(ref="#/components/schemas/MenuField"),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="修改数据状态",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
|
|
* @OA\Property(property="data", type="string",description="不返回"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name]在[sys_time] 修改了权限菜单[name]的数据
|
|
*/
|
|
public function edit($id = 0)
|
|
{
|
|
//接收参数
|
|
$_post = $this->request->post();
|
|
$_post['id'] = $id; //安全赋值,以免客户端没传id,修改需要id字段
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Menu::class)->scene('update')->check($_post);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', $this->model->parentEdit($_post, $id) ? 203 : 204);
|
|
}
|
|
|
|
|
|
/**
|
|
* @OA\Post (
|
|
* path="menu/delete",tags={"权限菜单"},summary="删除菜单数据",description="根据ID删除菜单数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema (
|
|
* required={"id"},
|
|
* @OA\Property(property="id",type="string",description="数据ID或数据ID集合 id=1或 id=1,2,8"),
|
|
* ),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="删除数据状态",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
|
|
* @OA\Property(property="data", type="string",description="不返回"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name] 在 [sys_time] 删除了权限菜单:[name]
|
|
*/
|
|
public function delete()
|
|
{
|
|
//接收参数
|
|
$ids = $this->request->param('id');
|
|
|
|
//验证参数
|
|
validate(['ids|id' => 'require|length:1,100'])->check(['ids' => $ids]);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', $this->model->parentDel($ids) ? 205 : 206);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (
|
|
* path="menu/status",tags={"权限菜单"},summary="更新菜单状态",description="根据ID及status更新菜单状态",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema (
|
|
* required={"id","status"},
|
|
* @OA\Property(property="id",type="string",description="数据ID或数据ID集合 id=1或 id=1,2,8"),
|
|
* @OA\Property(property="status",type="integer",format="int15",description="数据状态 0禁用 1启用"),
|
|
* ),
|
|
* ),
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="删除数据状态",
|
|
* @OA\JsonContent(type="object",
|
|
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
|
|
* @OA\Property(property="msg", type="string",description="提示信息"),
|
|
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
|
|
* @OA\Property(property="data", type="string",description="不返回"),
|
|
* ),
|
|
* ),
|
|
* )
|
|
* @Log [sys_name] 在 [sys_time] [dictionary_status]了权限菜单:[name]
|
|
*/
|
|
public function status()
|
|
{
|
|
//接收参数
|
|
$ids = $this->request->param('id');
|
|
$status = $this->request->param('status');
|
|
|
|
//验证参数
|
|
$_rules = [
|
|
'ids|id' => 'require|length:1,100',
|
|
'status|状态值' => 'require|number|length:1',
|
|
];
|
|
validate($_rules)->check(['ids' => $ids, 'status' => $status]);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', $this->model->parentStatus($ids, $status) !== false ? 207 : 208);
|
|
}
|
|
}
|
|
|