From 826f9ebdd9d88b1c4a7d10614828ada0becc27a7 Mon Sep 17 00:00:00 2001 From: cxdbz Date: Tue, 26 Mar 2019 21:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E5=8F=8Aauthrule=E6=95=B0=E6=8D=AE=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/AuthRule.php | 2 + application/admin/controller/Index.php | 1 + application/admin/model/AuthRule.php | 72 +++--- application/index/controller/Index.php | 18 ++ application/index/view/index/index.html | 262 ++-------------------- application/index/view/index/welcome.html | 6 +- database/seeds/Rule.php | 18 +- 7 files changed, 101 insertions(+), 278 deletions(-) diff --git a/application/admin/controller/AuthRule.php b/application/admin/controller/AuthRule.php index deaa66ab..b5213beb 100644 --- a/application/admin/controller/AuthRule.php +++ b/application/admin/controller/AuthRule.php @@ -223,4 +223,6 @@ class AuthRule extends Base // 返回信息 return json($data); } + + } diff --git a/application/admin/controller/Index.php b/application/admin/controller/Index.php index 462cbc2a..7ecda922 100644 --- a/application/admin/controller/Index.php +++ b/application/admin/controller/Index.php @@ -21,6 +21,7 @@ class Index extends Base $list['title'] = '管理员列表'; $list['count'] = $count; + // 模板赋值 $this->assign('list',$list); diff --git a/application/admin/model/AuthRule.php b/application/admin/model/AuthRule.php index dec70105..640a0b89 100644 --- a/application/admin/model/AuthRule.php +++ b/application/admin/model/AuthRule.php @@ -8,45 +8,61 @@ use app\common\model\Base; class AuthRule extends Base { - // 顶级权限列表 - public function getRule($pid = 0) + // 父级菜单数据模型关联 + public function authPid() { - return $this - ->where('pid',$pid) - ->where('status',1) - ->field('id,title') - ->order(['paixu']) - ->select(); + return $this->belongsTo('AuthRule','pid','id'); } - // 是否是菜单获取器 - public function getIsmenuAttr($value) - { - $arr = array('0'=>'否','1'=>'是'); - return $arr[$value]; + // 子菜单数据模型关联 + public function authCid() + { + return $this->hasMany('AuthRule','pid','id'); } - // 父级菜单名获取器 - public function getPidAttr($value) - { - return $this->where('id',$value)->value('title'); - } + // // 顶级权限列表 + // public function getRule($pid = 0) + // { + // return $this + // ->where('pid',$pid) + // ->where('status',1) + // ->field('id,title') + // ->order(['paixu']) + // ->select(); + // } - // 获取二级菜单 - public function getMymenuAttr($value) - { - return $this - ->where('pid',$this->getAttr('id')) - ->where('status&ismenu',1) - ->field('title,url,name') - ->order(['paixu']) - ->select(); - } + // // 是否是菜单获取器 + // public function getIsmenuAttr($value) + // { + // $arr = array('0'=>'否','1'=>'是'); + + // return $arr[$value]; + // } + + + // // 父级菜单名获取器 + // public function getPidAttr($value) + // { + + // return $this->where('id',$value)->value('title'); + // } + + + // // 获取二级菜单 + // public function getMymenuAttr($value) + // { + // return $this + // ->where('pid',$this->getAttr('id')) + // ->where('status&ismenu',1) + // ->field('title,url,name') + // ->order(['paixu']) + // ->select(); + // } diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 3a8ca828..226cab28 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -41,6 +41,23 @@ class Index extends Base // 获取版本号 $list->version = config('app.chengji.version'); + + // 实例化权限数据模型 + $authrule = new \app\admin\model\AuthRule; + + $list['menu'] = $authrule + ->where('pid',0) + ->where('status&ismenu',1) + ->field('id,title,font,name,pid') + ->with([ + 'authCid'=>function($query){ + $query->field('id,title,name,pid,url'); + }, + ]) + ->order(['paixu']) + ->select(); + // dump($list['menu']);halt('aa'); + // 模版赋值 $this->assign('list',$list); @@ -87,4 +104,5 @@ class Index extends Base return $this->fetch(); } + } diff --git a/application/index/view/index/index.html b/application/index/view/index/index.html index c084da48..94aa8792 100644 --- a/application/index/view/index/index.html +++ b/application/index/view/index/index.html @@ -7,14 +7,13 @@ - - + {load href="__STATIC__/xadmin/css/font.css" /} + {load href="__STATIC__/xadmin/css/xadmin.css" /} - - - - + {load href="__STATIC__/xadmin/lib/layui/layui.js" /} + {load href="__STATIC__/xadmin/js/xadmin.js" /} + {load href="__STATIC__/xadmin/js/cookie.js" /}