From 6c58b9bcba739f9d11a3a248ef4f7afa3005de47 Mon Sep 17 00:00:00 2001 From: cxdbz Date: Sun, 21 Oct 2018 21:58:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E6=9D=83=E9=99=90=E7=9A=84?= =?UTF-8?q?=E5=A2=9E=E5=88=A0=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/AuthRule.php | 255 +++++++++++++++--- application/admin/model/AuthRule.php | 33 ++- application/admin/validate/Rule.php | 28 ++ application/admin/view/auth_group/create.html | 100 +++++++ application/admin/view/auth_group/edit.html | 100 +++++++ application/admin/view/auth_group/index.html | 134 +++++++++ application/admin/view/auth_group/read.html | 51 ++++ application/admin/view/auth_rule/create.html | 101 +++++++ application/admin/view/auth_rule/edit.html | 101 +++++++ application/admin/view/auth_rule/index.html | 130 +++++++++ application/admin/view/index/create.html | 4 +- application/index/view/index/index.html | 4 +- application/login/controller/Index.php | 9 +- .../migrations/20181010075553_auth_rule.php | 3 +- route/admin.php | 6 +- 15 files changed, 1002 insertions(+), 57 deletions(-) create mode 100644 application/admin/validate/Rule.php create mode 100644 application/admin/view/auth_group/create.html create mode 100644 application/admin/view/auth_group/edit.html create mode 100644 application/admin/view/auth_group/index.html create mode 100644 application/admin/view/auth_group/read.html create mode 100644 application/admin/view/auth_rule/create.html create mode 100644 application/admin/view/auth_rule/edit.html create mode 100644 application/admin/view/auth_rule/index.html diff --git a/application/admin/controller/AuthRule.php b/application/admin/controller/AuthRule.php index a3a2cfa1..a3f00ceb 100644 --- a/application/admin/controller/AuthRule.php +++ b/application/admin/controller/AuthRule.php @@ -4,72 +4,199 @@ namespace app\admin\controller; // 引用控制器基类 use app\common\controller\Base; +// 引用权限数据模型类 +use app\admin\model\AuthRule as authrulemod; class AuthRule extends Base { - /** - * 显示资源列表 - * - * @return \think\Response - */ + // 显示权限列表 public function index() { - // + // 实例化权限数据模型类 + $authrulemod = new authrulemod(); + + // 设置数据总数 + $list['count'] = $authrulemod->count(); + // 设置页面标题 + $list['title'] = '权限列表'; + + + // 模板赋值 + $this->assign('list', $list); + + // 渲染模板 + return $this->fetch(); } - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ + + // 获取权限信息列表 + public function ajaxData() + { + // 实例化权限数据模型类 + $authrulemod = new authrulemod(); + + // 获取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 = $authrulemod->count(); + //查询数据 + $data = $authrulemod + ->field('id,title,name,condition,paixu,ismenu,font,status,pid') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) + ->all(); + + + // 如果需要查询 + if($search){ + $data = $authrulemod + ->field('id,title,name,condition,paixu,ismenu,font,status,pid') + ->order([$order_field=>$order]) + ->limit($limit_start,$limit_length) + ->where('title','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() { - // + // 实例化权限数据模型类 + $authrulemod = new authrulemod(); + + // 实例化验证模型 + $validate = new \app\admin\validate\Rule; + + + // 获取表单数据 + $list = request()->only(['title','name','pid','condition','paixue','ismenu','font','beizhu'],'post'); + + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + // 保存数据 + $data = $authrulemod->save($list); + + $msg = array(); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'添加成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ + // public function read($id) { // } - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ + + + + // 修改权限信息 public function edit($id) { - // + //实例化权限数据模型 + $authrulemod = new authrulemod(); + + // 获取权限信息 + $list = $authrulemod + ->field('id,title,name,condition,pid,paixu,ismenu,font') + ->get($id); + + + $this->assign('list',$list); + + return $this->fetch(); } - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) + + + + + // 更新权限信息 + public function update($id) { - // + // 实例化权限数据模型类 + $authrulemod = new authrulemod(); + // 实例化验证模型 + $validate = new \app\admin\validate\Rule; + + // 获取表单数据 + $list = request()->put(); + + // 验证表单数据 + $result = $validate->check($list); + $msg = $validate->getError(); + + // 如果验证不通过则停止保存 + if(!$result){ + return json(['msg'=>$msg,'val'=>0]);; + } + + + $data = $authrulemod->save($list,['id'=>$id]); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'更新成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } /** @@ -80,6 +207,48 @@ class AuthRule extends Base */ public function delete($id) { - // + //实例化权限数据模型类 + $authrulemod = new authrulemod(); + + if($id == 'm') + { + $id = request()->delete('ids/a');// 获取delete请求方式传送过来的数据并转换成数据 + } + + $data = $authrulemod->destroy($id); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'删除成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); + } + + + + // 设置权限状态 + public function setStatus() + { + // 实例化权限数据模型类 + $authrulemod = new authrulemod(); + + // 获取id变量 + $id = request()->post('id'); + $value = request()->post('value'); + + // 获取权限信息 + $list = $authrulemod->get($id); + + // 修改状态值 + $list->status = $value; + + // 更新数据 + $data = $list->save(); + + // 根据更新结果设置返回提示信息 + $data ? $data=['msg'=>'状态设置成功','val'=>1] : $data=['msg'=>'数据处理错误','val'=>0]; + + // 返回信息 + return json($data); } } diff --git a/application/admin/model/AuthRule.php b/application/admin/model/AuthRule.php index 3520fa46..4d5aa8d7 100644 --- a/application/admin/model/AuthRule.php +++ b/application/admin/model/AuthRule.php @@ -7,5 +7,36 @@ use app\common\model\Base; class AuthRule extends Base { - // + // 状态获取器 + public function getStatusAttr($value) + { + $status =array('1'=>'已启用','0'=>'已停用'); + return $status[$value]; + } + + // 顶级权限列表 + public function topRule() + { + return $this + ->where('pid',0) + ->field('id,title') + ->select(); + } + + + // 是否是菜单获取器 + public function getIsmenuAttr($value) + { + $arr = array('0'=>'否','1'=>'是'); + + return $arr[$value]; + } + + + // 父级菜单名获取器 + public function getPidAttr($value) + { + + return $this->where('id',$value)->value('title'); + } } diff --git a/application/admin/validate/Rule.php b/application/admin/validate/Rule.php new file mode 100644 index 00000000..95d96ede --- /dev/null +++ b/application/admin/validate/Rule.php @@ -0,0 +1,28 @@ + ['规则1','规则2'...] + * + * @var array + */ + protected $rule = [ + 'title|规则名' => 'require|chs|length:2,6', + 'name|规则' => ['require','length:1,80','uset'=>'/^[a-z\/]*$/'], + 'paixu|排序' => 'number|max:999', + ]; + + /** + * 定义错误信息 + * 格式:'字段名.规则名' => '错误信息' + * + * @var array + */ + protected $message = []; +} diff --git a/application/admin/view/auth_group/create.html b/application/admin/view/auth_group/create.html new file mode 100644 index 00000000..d826f386 --- /dev/null +++ b/application/admin/view/auth_group/create.html @@ -0,0 +1,100 @@ +{extend name="common@create" /} +{block name="formaa"} +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +

0/80

+
+
+
+
+ +
+
+
+{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/admin/view/auth_group/edit.html b/application/admin/view/auth_group/edit.html new file mode 100644 index 00000000..c89bb80c --- /dev/null +++ b/application/admin/view/auth_group/edit.html @@ -0,0 +1,100 @@ +{extend name="common@create" /} +{block name="formaa"} +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +

0/80

+
+
+
+
+ +
+
+
+{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/admin/view/auth_group/index.html b/application/admin/view/auth_group/index.html new file mode 100644 index 00000000..666588fb --- /dev/null +++ b/application/admin/view/auth_group/index.html @@ -0,0 +1,134 @@ +{extend name="common@list" /} +{block name="topnav"} + +{/block} +{block name="bouttons"} +
+ + + + + 批量删除 + + + + + 添加管理员 + + + + 共有数据:{$list.count} 条 + +
+{/block} +{block name="tables"} + + + + + + + + + + + + + + + + + +
姓名性别出生日期帐号手机号码登录次数创建时间状态操作
+ + +{/block} +{block name="myjs"} + +{/block} \ No newline at end of file diff --git a/application/admin/view/auth_group/read.html b/application/admin/view/auth_group/read.html new file mode 100644 index 00000000..d0912f70 --- /dev/null +++ b/application/admin/view/auth_group/read.html @@ -0,0 +1,51 @@ +{extend name="common@admininfo" /} +{block name="topdiv"} +
+ +
+
+ {$list.xingming} + 帐号:{$list.username} +
+
这家伙很懒,什么也没有留下
+
+
+{/block} +{block name="mytable"} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
性别:{$list.sex}
出生日期:{$list.shengri}
手机:{$list.phone}
注册时间:{$list.create_time}
登录次数:{$list.denglucishu}
最后登录时间:{$list.lasttime}
最后登录IP:{$list.lastip}
备注:{$list.beizhu}
+{/block} \ No newline at end of file diff --git a/application/admin/view/auth_rule/create.html b/application/admin/view/auth_rule/create.html new file mode 100644 index 00000000..3dc69e14 --- /dev/null +++ b/application/admin/view/auth_rule/create.html @@ -0,0 +1,101 @@ +{extend name="common@create" /} +{block name="formaa"} +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {php} $authrulemod = model('AuthRule'); $pid = $authrulemod->topRule();{/php} + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/admin/view/auth_rule/edit.html b/application/admin/view/auth_rule/edit.html new file mode 100644 index 00000000..ff26d844 --- /dev/null +++ b/application/admin/view/auth_rule/edit.html @@ -0,0 +1,101 @@ +{extend name="common@create" /} +{block name="formaa"} +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ {php} $authrulemod = model('AuthRule'); $pid = $authrulemod->topRule();{/php} + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+ +
+
+
+
+ +
+
+
+{/block} +{block name="yanzheng"} + +{/block} \ No newline at end of file diff --git a/application/admin/view/auth_rule/index.html b/application/admin/view/auth_rule/index.html new file mode 100644 index 00000000..29027744 --- /dev/null +++ b/application/admin/view/auth_rule/index.html @@ -0,0 +1,130 @@ +{extend name="common@list" /} +{block name="topnav"} + +{/block} +{block name="bouttons"} +
+ + + + + 批量删除 + + + + + 添加权限 + + + + 共有数据:{$list.count} 条 + +
+{/block} +{block name="tables"} + + + + + + + + + + + + + + + + + +
名称规则表达式父级规则排序是否是菜单 菜单字体状态操作
+ + +{/block} +{block name="myjs"} + +{/block} \ No newline at end of file diff --git a/application/admin/view/index/create.html b/application/admin/view/index/create.html index d826f386..6a8e6124 100644 --- a/application/admin/view/index/create.html +++ b/application/admin/view/index/create.html @@ -4,13 +4,13 @@
- +
- +
diff --git a/application/index/view/index/index.html b/application/index/view/index/index.html index ff9abd86..3ca2cab8 100644 --- a/application/index/view/index/index.html +++ b/application/index/view/index/index.html @@ -131,8 +131,8 @@
管理员管理
diff --git a/application/login/controller/Index.php b/application/login/controller/Index.php index 824fcb33..bbd2f196 100644 --- a/application/login/controller/Index.php +++ b/application/login/controller/Index.php @@ -40,10 +40,6 @@ class Index extends Controller $this->error($msg); } - // - // $password = $admin->password($data['username']); - // $check = $md5->check($data['password'],$password); - // 验证用户名和密码 $check = $this->check($data['username'],$data['password']); @@ -88,10 +84,11 @@ class Index extends Controller $md5 = new APR1_MD5(); // 获取服务器密码 - $serpw = $admin->password($username); + $serpw = $admin->password('admin'); + $serpw == null ? $serpw ='$apr1$tzQxnliW$f' : $serpw ; #serpw为随意字符 //验证密码 $check = $md5->check($password,$serpw); - + if($check) { // Session存值 diff --git a/database/migrations/20181010075553_auth_rule.php b/database/migrations/20181010075553_auth_rule.php index cb29c6e1..91da9735 100644 --- a/database/migrations/20181010075553_auth_rule.php +++ b/database/migrations/20181010075553_auth_rule.php @@ -40,7 +40,8 @@ class AuthRule extends Migrator ->addColumn('condition','string',['limit'=>100,'default'=>'','null'=>true,'comment'=>'规则表达式']) ->addColumn('paixu','integer',['limit'=>11,'default'=>999,'null'=>false,'comment'=>'排序']) ->addColumn('ismenu','boolean',['limit'=>1,'default'=>false,'null'=>false,'comment'=>'是否是菜单']) - ->addColumn('pid','integer',['limit'=>3,'default'=>1,'null'=>true,'comment'=>'父ID']) + ->addColumn('font','string',['limit'=>40,'default'=>'','null'=>true,'comment'=>'菜单字体']) + ->addColumn('pid','integer',['limit'=>3,'default'=>0,'null'=>true,'comment'=>'父ID']) ->addColumn('delete_time','integer',['limit'=>11,'null'=>true,'comment'=>'删除时间']) ->addIndex(array('name'), array('unique' => true)) ->create(); diff --git a/route/admin.php b/route/admin.php index dfec147a..c7106bfc 100644 --- a/route/admin.php +++ b/route/admin.php @@ -10,5 +10,7 @@ // +---------------------------------------------------------------------- //系统设置路由 -Route::resource('admin','admin/index'); -Route::get('resetpassword/:id','admin/index/resetpassword'); +Route::resource('admin','admin/Index'); +Route::resource('authgroup','admin/AuthGroup'); +Route::resource('authrule','admin/AuthRule'); +Route::get('resetpassword/:id','admin/Index/resetpassword');