diff --git a/application/admin/controller/AuthGroup.php b/application/admin/controller/AuthGroup.php index 04f5bbaa..80751161 100644 --- a/application/admin/controller/AuthGroup.php +++ b/application/admin/controller/AuthGroup.php @@ -4,38 +4,141 @@ namespace app\admin\controller; // 引用控制器基类 use app\common\controller\Base; +// 引用角色数据模型类 +use app\admin\model\AuthGroup as agmod; class AuthGroup extends Base { - /** - * 显示资源列表 - * - * @return \think\Response - */ + // 角色列表 public function index() { - // + // 实例化角色数据模型类 + $agmod = new agmod(); + + // 设置数据总数 + $list['count'] = $agmod->count(); + // 设置页面标题 + $list['title'] = '角色列表'; + + + // 模板赋值 + $this->assign('list', $list); + + // 渲染模板 + return $this->fetch(); } - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ + + + // 获取角色列表 + public function ajaxData() + { + // 实例化角色数据模型类 + $agmod = new agmod(); + + // 获取DT的传值 + $getdt = request()->param(); + + //得到排序的方式 + $order = $getdt['order'][0]['dir']; + //得到排序字段的下标 + $order_column = $getdt['order'][0]['column']; + //根据排序字段的下标得到排序字段 + $order_field = $getdt['columns'][$order_column]['data']; + //得到limit参数 + $limit_start = $getdt['start']; + $limit_length = $getdt['length']; + //得到搜索的关键词 + $search = $getdt['search']['value']; + + + // 获取记录集总数 + $cnt = $agmod->count(); + //查询数据 + $data = $agmod + ->field('id,title,miaoshu,status') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) + ->all(); + + + // 如果需要查询 + if($search){ + $data = $agmod + ->field('id,title,miaoshu,status') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) + ->where('title|miaoshu','like','%'.$search.'%') + ->all(); + } + + $datacnt = $data->count(); + + + + + $data = [ + 'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符 + 'recordsTotal'=>$datacnt, // 获取到的结果数(每页显示数量) + 'recordsFiltered'=>$cnt, // 符合条件的总数据量 + 'data'=>$data, //获取到的数据结果 + ]; + + return json($data); + } + + + + // 创建角色 public function create() { - // + // 设置页面标题 + $list['title'] = '添加权限'; + + // 模板赋值 + $this->assign('list',$list); + + // 渲染 + return $this->fetch(); } - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) + + + // 保存角色信息 + public function save() { - // + // 实例化权限数据模型类 + $agmod = new agmod(); + + // 实例化验证模型 + $validate = new \app\admin\validate\RuleGroup; + + + // 获取表单数据 + $list = request()->only(['title','rules','miaoshu'],'post'); + $list['rules'] = implode(",",$list['rules']); + + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + // 保存数据 + $data = $agmod->save($list); + + $msg = array(); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** diff --git a/application/admin/controller/AuthRule.php b/application/admin/controller/AuthRule.php index a3f00ceb..6c02464c 100644 --- a/application/admin/controller/AuthRule.php +++ b/application/admin/controller/AuthRule.php @@ -67,7 +67,7 @@ class AuthRule extends Base ->field('id,title,name,condition,paixu,ismenu,font,status,pid') ->order([$order_field=>$order]) ->limit($limit_start,$limit_length) - ->where('title','like','%'.$search.'%') + ->where('title|name|pid','like','%'.$search.'%') ->all(); } diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index e3546480..b63bafb2 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -44,12 +44,6 @@ class Admin extends Base return $sex[$value]; } - // 状态获取器 - public function getStatusAttr($value) - { - $status =array('1'=>'已启用','0'=>'已停用'); - return $status[$value]; - } } diff --git a/application/admin/model/AuthGroup.php b/application/admin/model/AuthGroup.php index 8fabc409..b19b3c14 100644 --- a/application/admin/model/AuthGroup.php +++ b/application/admin/model/AuthGroup.php @@ -7,5 +7,5 @@ use app\common\model\Base; class AuthGroup extends Base { - // + // 状态获取器 } diff --git a/application/admin/model/AuthRule.php b/application/admin/model/AuthRule.php index 4d5aa8d7..e1dc57a2 100644 --- a/application/admin/model/AuthRule.php +++ b/application/admin/model/AuthRule.php @@ -7,19 +7,14 @@ use app\common\model\Base; class AuthRule extends Base { - // 状态获取器 - public function getStatusAttr($value) - { - $status =array('1'=>'已启用','0'=>'已停用'); - return $status[$value]; - } // 顶级权限列表 - public function topRule() + public function getRule($pid = 0) { return $this - ->where('pid',0) + ->where('pid',$pid) ->field('id,title') + ->order(['paixu']) ->select(); } @@ -39,4 +34,6 @@ class AuthRule extends Base return $this->where('id',$value)->value('title'); } + + } diff --git a/application/admin/validate/RuleGroup.php b/application/admin/validate/RuleGroup.php new file mode 100644 index 00000000..3cad141f --- /dev/null +++ b/application/admin/validate/RuleGroup.php @@ -0,0 +1,24 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = []; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = []; +} diff --git a/application/admin/view/auth_group/create.html b/application/admin/view/auth_group/create.html index d826f386..da7fb936 100644 --- a/application/admin/view/auth_group/create.html +++ b/application/admin/view/auth_group/create.html @@ -1,52 +1,63 @@ {extend name="common@create" /} {block name="formaa"} -