2025-04-01 16:23:28 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\adminapi\controller;
|
|
|
|
|
|
|
|
|
|
use app\adminapi\model\AuthRule;
|
|
|
|
|
use app\common\controller\AdminApi;
|
|
|
|
|
use think\Cookie;
|
|
|
|
|
use think\Hook;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* api权限菜单管理
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class Rule extends AdminApi
|
|
|
|
|
{
|
|
|
|
|
protected $model = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化操作
|
|
|
|
|
* @access protected
|
|
|
|
|
*/
|
|
|
|
|
public function _initialize()
|
|
|
|
|
{
|
|
|
|
|
$this->model = new AuthRule;
|
|
|
|
|
parent::_initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 所有权限列表
|
|
|
|
|
*
|
|
|
|
|
* @ApiMethod (GET)
|
|
|
|
|
* @ApiParams (name="is_tree", type="string", required=true, description="是否是树形结构")
|
|
|
|
|
*/
|
2025-04-18 17:22:09 +08:00
|
|
|
|
public function index()
|
2025-04-01 16:23:28 +08:00
|
|
|
|
{
|
|
|
|
|
$admin_id = $this->auth->id;
|
|
|
|
|
$is_tree = $this->request->get('is_tree');
|
|
|
|
|
|
|
|
|
|
$menulist = $this->model->getMenulist($admin_id,[],$is_tree,true);
|
|
|
|
|
|
|
|
|
|
$this->success('查询成功', $menulist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 添加权限节点(接口或菜单)
|
|
|
|
|
*
|
|
|
|
|
* @ApiMethod (POST)
|
|
|
|
|
* @ApiParams (name="pid", type="int", required=true, description="父ID")
|
|
|
|
|
* @ApiParams (name="ismenu", type="int", required=true, description="是否为菜单 0接口 1菜单")
|
|
|
|
|
* @ApiParams (name="name", type="string", required=true, description="节点URL(节点URL和外链选填其一)")
|
|
|
|
|
* @ApiParams (name="url", type="string", required=true, description="外链(节点URL和外链选填其一)")
|
|
|
|
|
* @ApiParams (name="rule_name", type="string", required=true, description="权限标识(菜单才需要)")
|
|
|
|
|
* @ApiParams (name="title", type="string", required=true, description="节点中文名")
|
|
|
|
|
* @ApiParams (name="icon", type="string", required=true, description="图标(菜单才需要)")
|
|
|
|
|
* @ApiParams (name="weigh", type="int", required=true, description="权重")
|
|
|
|
|
* @ApiParams (name="menutype", type="string", required=true, description="菜单类型:'addtabs','blank','dialog','ajax'")
|
|
|
|
|
* @ApiParams (name="extend", type="string", required=true, description="额外扩展属性(比如加类名做特特殊回调逻辑)")
|
|
|
|
|
* @ApiParams (name="status", type="string", required=true, description="状态(normal=正常,hidden=隐藏)")
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function add()
|
|
|
|
|
{
|
|
|
|
|
$admin_id = $this->auth->id;
|
|
|
|
|
$params = $this->request->post();
|
|
|
|
|
|
2025-04-18 17:22:09 +08:00
|
|
|
|
try{
|
|
|
|
|
$menulist = $this->model->add($params,true);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->success('查询成功', $menulist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 编辑权限节点(接口或菜单)
|
|
|
|
|
*
|
|
|
|
|
* @ApiMethod (POST)
|
|
|
|
|
* @ApiParams (name="pid", type="int", required=true, description="父ID")
|
|
|
|
|
* @ApiParams (name="ismenu", type="int", required=true, description="是否为菜单 0接口 1菜单")
|
|
|
|
|
* @ApiParams (name="name", type="string", required=true, description="节点URL(节点URL和外链选填其一)")
|
|
|
|
|
* @ApiParams (name="url", type="string", required=true, description="外链(节点URL和外链选填其一)")
|
|
|
|
|
* @ApiParams (name="rule_name", type="string", required=true, description="权限标识(菜单才需要)")
|
|
|
|
|
* @ApiParams (name="title", type="string", required=true, description="节点中文名")
|
|
|
|
|
* @ApiParams (name="icon", type="string", required=true, description="图标(菜单才需要)")
|
|
|
|
|
* @ApiParams (name="weigh", type="int", required=true, description="权重")
|
|
|
|
|
* @ApiParams (name="menutype", type="string", required=true, description="菜单类型:'addtabs','blank','dialog','ajax'")
|
|
|
|
|
* @ApiParams (name="extend", type="string", required=true, description="额外扩展属性(比如加类名做特特殊回调逻辑)")
|
|
|
|
|
* @ApiParams (name="status", type="string", required=true, description="状态(normal=正常,hidden=隐藏)")
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id=null)
|
|
|
|
|
{
|
|
|
|
|
$admin_id = $this->auth->id;
|
|
|
|
|
$params = $this->request->post();
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$menulist = $this->model->edit($id,$params,true);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-01 16:23:28 +08:00
|
|
|
|
|
|
|
|
|
$this->success('查询成功', $menulist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-18 17:22:09 +08:00
|
|
|
|
/**
|
|
|
|
|
* 查看详情
|
|
|
|
|
*
|
|
|
|
|
* @ApiMethod (GET)
|
|
|
|
|
* @ApiParams (name="id", type="string", required=true, description="规则详情ID")
|
|
|
|
|
*/
|
|
|
|
|
public function detail()
|
|
|
|
|
{
|
|
|
|
|
$admin_id = $this->auth->id;
|
|
|
|
|
$id = $this->request->get('id/d');
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$menulist = $this->model->detail($id,$show_field=[],$except_field=[]);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->success('查询成功', $menulist);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除规则
|
|
|
|
|
*
|
|
|
|
|
* @ApiMethod (GET)
|
|
|
|
|
* @ApiParams (name="ids", type="string", required=true, description="规则详情ID,多值逗号分割")
|
|
|
|
|
*/
|
|
|
|
|
public function del()
|
|
|
|
|
{
|
|
|
|
|
$admin_id = $this->auth->id;
|
|
|
|
|
$ids = $this->request->get('ids/s');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
$menulist = $this->model->del($ids,true);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$this->error($e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->success('执行成功', ["count"=>$menulist]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-04-01 16:23:28 +08:00
|
|
|
|
}
|