From 781c5f891db1470b9c55a83262be6914a8a28d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9D=BE=E6=A0=91?= Date: Wed, 10 Apr 2019 16:54:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Index.php | 87 +++++---------- application/admin/model/Admin.php | 99 +++++++++++------- application/admin/model/AuthRule.php | 2 +- application/admin/view/index/create.html | 72 +++++++++++-- application/admin/view/index/edit.html | 128 ----------------------- application/admin/view/index/index.html | 46 +++++--- 6 files changed, 186 insertions(+), 248 deletions(-) delete mode 100644 application/admin/view/index/edit.html diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index 7ecda922..1b26aa3b 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -14,13 +14,8 @@ class Index extends Base // 管理员列表 public function index() { - - $count = AD::where('id','>',2)->count(); - // 设置要给模板赋值的信息 - $list['title'] = '管理员列表'; - $list['count'] = $count; - + $list['webtitle'] = '管理员列表'; // 模板赋值 $this->assign('list',$list); @@ -33,67 +28,33 @@ class Index extends Base // 获取数据管理员数据 public function ajaxData() { + // 获取参数 + $src = $this->request + ->only([ + 'page'=>'1' + ,'limit'=>'10' + ,'field'=>'id' + ,'order'=>'asc' + ,'searchval'=>'' + ],'POST'); + // 实例化 + $ad = new AD; - // 获取DT的传值 - $getdt = request()->param(); - - //得到排序的方式 - $order = $getdt['order'][0]['dir']; - //得到排序字段的下标 - $order_column = $getdt['order'][0]['column']; - //根据排序字段的下标得到排序字段 - $order_field = $getdt['columns'][$order_column]['name']; - if($order_field=='') - { - $order_field = $getdt['columns'][$order_column]['data']; - } - //得到limit参数 - $limit_start = $getdt['start']; - $limit_length = $getdt['length']; - //得到搜索的关键词 - $search = $getdt['search']['value']; - - - - //查询数据 - $data = AD::field('id,school,xingming,sex,username,phone,shengri,denglucishu,status,create_time') - ->where('id','>','2') - ->with(['adSchool'=>function($query){ - $query->field('id,jiancheng'); - }]) - ->order([$order_field=>$order]) - ->limit($limit_start,$limit_length) - ->select(); - // 获取记录集总数 + // 查询要显示的数据 + $data = $ad->search($src); + // 获取符合条件记录总数 $cnt = $data->count(); - - - // 如果需要查询 - if($search){ - $data = AD::field('id,school,xingming,sex,username,phone,shengri,denglucishu,status,create_time') - ->where('id','>','1') - ->with(['adSchool'=>function($query){ - $query->field('jiancheng'); - }]) - ->order([$order_field=>$order]) - ->limit($limit_start,$limit_length) - ->where('username|xingming','like','%'.$search.'%') - ->select(); - } - - $datacnt = $data->count(); - - // 追加角色名 - $data = $data->append(['groupnames']); - - - - + // 获取当前页数据 + $limit_start = $src['page'] * $src['limit'] - $src['limit']; + $limit_length = $src['limit']-1; + $data = $data->slice($limit_start,$limit_length); + + // 重组返回内容 $data = [ - 'draw'=> $getdt["draw"] , // ajax请求次数,作为标识符 - 'recordsTotal'=>$datacnt, // 获取到的结果数(每页显示数量) - 'recordsFiltered'=>$cnt, // 符合条件的总数据量 + 'code'=> 0 , // ajax请求次数,作为标识符 + 'msg'=>"", // 获取到的结果数(每页显示数量) + 'count'=>$cnt, // 符合条件的总数据量 'data'=>$data, //获取到的数据结果 ]; diff --git a/application/admin/model/Admin.php b/application/admin/model/Admin.php index b1847bb9..b43d28e5 100644 --- a/application/admin/model/Admin.php +++ b/application/admin/model/Admin.php @@ -7,6 +7,31 @@ use app\common\model\Base; class Admin extends Base { + // 查询所有角色 + public function search($src) + { + // 整理变量 + $searchval = $src['searchval']; + + // 查询数据 + $data = $this + ->order([$src['field'] =>$src['order']]) + ->when(strlen($searchval)>0,function($query) use($searchval){ + $query->where('xingming','like','%'.$searchval.'%'); + }) + ->with([ + 'adSchool'=>function($query){ + $query->field('id,jiancheng'); + } + // ,'authGroup'=>function($query){ + + // } + ]) + ->select(); + return $data; + } + + // 用户角色获取器 public function userGroup() { @@ -52,58 +77,58 @@ class Admin extends Base } - // 最后登录获取器 + // 最后登录时间取器 public function getLasttimeAttr($value) { return date('Y年m月d日 h:i:s',$value); } - // 权限关联 - public function authgroup() + // 角色关联 + public function authGroup() { return $this->hasMany('AuthGroupAccess','uid','id')->field('id,uid,group_id'); } - // 获取角色id表 - public function getGroupidsAttr() - { - // 获取当前当前管理员信息 - $admin = $this->get($this->getAttr('id')); - // 获取角色id - $list = $admin->authgroup()->column('group_id'); + // // 获取角色id表 + // public function getGroupidsAttr() + // { + // // 获取当前当前管理员信息 + // $admin = $this->get($this->getAttr('id')); + // // 获取角色id + // $list = $admin->authgroup()->column('group_id'); - $str = ''; - // 将角色id转换成数组 - foreach ($list as $key => $value) { - $key == 0 ? $str =$value : $str = $str.','.$value; - } + // $str = ''; + // // 将角色id转换成数组 + // foreach ($list as $key => $value) { + // $key == 0 ? $str =$value : $str = $str.','.$value; + // } - // 返回值 - return $str; - } + // // 返回值 + // return $str; + // } - // 获取角色名称 - public function getGroupnamesAttr() - { - // 获取角色id - $group = $this->get($this->getAttr('id'))->append(['groupids']); + // // 获取角色名称 + // public function getGroupnamesAttr() + // { + // // 获取角色id + // $group = $this->get($this->getAttr('id'))->append(['groupids']); - $str = ''; - // 查询角色名称 - $grouplist= db('AuthGroup')->where('id','in',$group->groupids)->column('title'); - // 重组角色名 - foreach ($grouplist as $key => $value) { - if($key == 0){ - $str = $value; - }else{ - $str = $str.'、'.$value; - } - } - // 返回角色名 - return $str; - } + // $str = ''; + // // 查询角色名称 + // $grouplist= db('AuthGroup')->where('id','in',$group->groupids)->column('title'); + // // 重组角色名 + // foreach ($grouplist as $key => $value) { + // if($key == 0){ + // $str = $value; + // }else{ + // $str = $str.'、'.$value; + // } + // } + // // 返回角色名 + // return $str; + // } // 单位关联模型 public function adSchool() diff --git a/application/admin/model/AuthRule.php b/application/admin/model/AuthRule.php index f004ae00..005505a9 100644 --- a/application/admin/model/AuthRule.php +++ b/application/admin/model/AuthRule.php @@ -32,7 +32,7 @@ class AuthRule extends Base $data = $this ->order([$src['field'] =>$src['order']]) ->when(strlen($searchval)>0,function($query) use($searchval){ - $query->where('title','like','%'.$searchval.'%'); + $query->where('title|name','like','%'.$searchval.'%'); }) ->with(['authPid'=>function($query){ $query->field('id,title'); diff --git a/application/admin/view/index/create.html b/application/admin/view/index/create.html index e5e6714e..c309e56f 100644 --- a/application/admin/view/index/create.html +++ b/application/admin/view/index/create.html @@ -4,7 +4,7 @@
- + +
+ +
+
+
+ +
+ +
+
+
+
- {php} $category = getCategory(0);{/php} - {volist name="category" id="vo"}
+
+ +
+ {php} $category = getCategory(102);{/php} + +
+
+
+ +
+ {php} $category = getCategory(103);{/php} + +
+
+ autocomplete="off" class="layui-input" value="999" placeholder="数字1-999">
diff --git a/application/admin/view/index/edit.html b/application/admin/view/index/edit.html deleted file mode 100644 index 79ed2cf3..00000000 --- a/application/admin/view/index/edit.html +++ /dev/null @@ -1,128 +0,0 @@ -{extend name="common@create" /} -{block name="formaa"} - -
- -
- -
-
-
- -
- -
-
-
- -
- - {php} $school = schlist('校级','区级');{/php} - - -
-
-
- - {php} - $group = db('auth_group')->where('status',true)->field('id,title')->all(); - {/php} -
-
{foreach $group as $key=>$vo } - {/foreach} -
-
-
-
- -
-
- - -
-
- - -
-
- - -
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -

0/80

-
-
-
-
- -
-
- -{/block} -{block name="yanzheng"} - -{/block} \ No newline at end of file diff --git a/application/admin/view/index/index.html b/application/admin/view/index/index.html index c61ca4e5..859d2f1b 100644 --- a/application/admin/view/index/index.html +++ b/application/admin/view/index/index.html @@ -6,8 +6,8 @@ {block name="nav"} 管理员管理 - 角色管理 - 角色列表 + 用户管理 + 管理员列表 {/block} {block name="search"} @@ -21,6 +21,15 @@ autocomplete="off" class="layui-input">
+
+ +
+ {php} $category = getCategory(101);{/php} + {volist name="category" id="vo"} + + {/volist} +
+
{/block} {block name="table"} @@ -69,8 +78,24 @@ layui.use(['table','laypage','form','cjgl'], function(){ defaultToolbar:'', cols: [[ //表头 {type:'checkbox', fixed: 'left'}, - {field: 'title', title: '名称',sort: true, minWidth:240}, - {field: "miaoshu",title: '描述',sort: true}, + {field: 'xingming', title: '姓名',sort: true, minWidth:80}, + {field: 'sex', title: '性别',sort: true}, + {field: "shengri",title: '生日',sort: true}, + {field: 'username', title: '帐号',sort: true} , + {field: 'school', title: '所在单位',sort: true ,templet:function(d){ + if(d.ad_school){ + return d.ad_school.jiancheng; + } + }}, + {title: '用户组',templet:function(d){ + if(d.ad_school){ + return d.ad_school.jiancheng; + } + }}, + {field: 'phone', title: '联系电话', sort: true}, + {field: 'denglucishu', title: '登录次数', sort: true}, + {field: 'lasttime', title: '最后登录时间', sort: true}, + {field: 'lastip', title: '最后登录地址', sort: true}, {field: 'status', title: '状态',templet:'#status', sort: true}, {field: 'id', title: '操作',toolbar: '#barDemo',minWidth:140} ]], @@ -90,15 +115,12 @@ layui.use(['table','laypage','form','cjgl'], function(){ // 重载表格 tableIns.reload({ where: wheredata - ,page:{ - curr: 1 //重新从第 1 页开始 - } ,done:function(){ for(x in formval) { delete this.where[x]; } - } + } ,page:{ curr:1 } @@ -111,10 +133,10 @@ layui.use(['table','laypage','form','cjgl'], function(){ switch(obj.event){ case 'dels': var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值 - cjgl.delAll(checkStatus,'/admin','mytable'); + cjgl.delAll(checkStatus,'/school','mytable'); break; case 'add': - cjgl.add('添加角色','/admin/create','450','300'); + cjgl.add('添加单位','/school/create','650','500'); break; }; }); @@ -131,10 +153,10 @@ layui.use(['table','laypage','form','cjgl'], function(){ layer.msg('查看' + data.id); break; case 'del':// 删除 - cjgl.del(obj,"/admin"); + cjgl.del(obj,"/school"); break; case 'edit':// 编辑 - cjgl.add('编辑角色','/admin/'+obj.data.id+'/edit','650','500'); + cjgl.add('编辑单位','/school/'+obj.data.id+'/edit','650','500'); break; case 'status':// 状态 cjgl.status(obj,"{:url('setstatus')}");