From 0b525a0af4b884063c32c17c72c30184caaba810 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Mon, 14 Nov 2016 19:14:22 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E5=AE=8C=E6=88=90=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Auth.php | 172 ++++++++++++++--------- public/admin/static/js/template.js | 35 +++-- public/admin/static/js/template/table.js | 6 +- 3 files changed, 135 insertions(+), 78 deletions(-) diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index 69ce97c..d15066b 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -464,76 +464,116 @@ class Auth extends Base { if( !$authList ){ $authList = $this->refreshAuth(); } - $table = [ - 'tempType' => 'table', - 'header' => [ - [ - 'field' => 'showName', - 'info' => '权限名称' - ], - [ - 'field' => 'url', - 'info' => 'URL标识' - ], - [ - 'field' => 'token', - 'info' => '真实URL' - ], - [ - 'field' => 'get', - 'info' => 'Get' - ], - [ - 'field' => 'put', - 'info' => 'Put' - ], - [ - 'field' => 'post', - 'info' => 'Post' - ], - [ - 'field' => 'delete', - 'info' => 'Delete' - ] - ], - 'typeRule' => [ - 'access' => [ - 'module' => 'a', - 'rule' => [ - 'info' => '访问授权', - 'href' => url('Auth/access'), - 'param'=> [$this->primaryKey], - 'class' => 'refresh' + if( $this->request->isPut() ){ + $gid = session('authGid'); + if( !$gid ){ + $this->error('组ID丢失!'); + } + $url = $this->request->put('urlName'); + $getAuth = $this->request->put('get'); + $putAuth = $this->request->put('put'); + $deleteAuth = $this->request->put('delete'); + $postAuth = $this->request->put('post'); + $auth = \Permission::AUTH_GET * $getAuth + \Permission::AUTH_DELETE * $deleteAuth + \Permission::AUTH_POST * $postAuth + \Permission::AUTH_PUT * $putAuth; + $authDetail = AuthRule::get( ['group_id' => $gid, 'url' => $url] ); + if( $authDetail ){ + $authDetail->auth = $auth; + $authDetail->save(); + }else{ + $newAuthDetail = new AuthRule(); + $newAuthDetail->url = $url; + $newAuthDetail->group_id = $gid; + $newAuthDetail->auth = $auth; + $newAuthDetail->save(); + } + $this->success('更新成功!', url('Auth/access'), '', 1); + }else{ + $gid = $this->request->get('id')?$this->request->get('id'):session('authGid'); + if( !$gid ){ + $this->result('', ReturnCode::GET_TEMPLATE_ERROR, '组ID丢失!'); + }else{ + session('authGid', $gid); + } + $authRuleArr = AuthRule::where(['group_id' => $gid])->select(); + if( $authRuleArr ){ + $authRule = []; + foreach ( $authRuleArr as $value ){ + $authRule[$value->url] = $value->auth; + } + foreach ( $authList as &$authValue ){ + $authRuleValue = isset($authRule[$authValue['url']])?$authRule[$authValue['url']]:0; + $authValue['get'] = \Permission::AUTH_GET & $authRuleValue; + $authValue['post'] = \Permission::AUTH_POST & $authRuleValue; + $authValue['put'] = \Permission::AUTH_PUT & $authRuleValue; + $authValue['delete'] = \Permission::AUTH_DELETE & $authRuleValue; + } + } + $table = [ + 'tempType' => 'table', + 'header' => [ + [ + 'field' => 'showName', + 'info' => '权限名称' + ], + [ + 'field' => 'url', + 'info' => 'URL标识' + ], + [ + 'field' => 'token', + 'info' => '真实URL' + ], + [ + 'field' => 'get', + 'info' => 'Get' + ], + [ + 'field' => 'put', + 'info' => 'Put' + ], + [ + 'field' => 'post', + 'info' => 'Post' + ], + [ + 'field' => 'delete', + 'info' => 'Delete' ] ], - 'post' => [ - 'module' => 'auth', - 'rule' => [ - 'value' => '' + 'typeRule' => [ + 'post' => [ + 'module' => 'auth', + 'rule' => [ + 'value' => '', + 'url' => url('Auth/access') + ] + ], + 'get' => [ + 'module' => 'auth', + 'rule' => [ + 'value' => '', + 'url' => url('Auth/access') + ] + ], + 'put' => [ + 'module' => 'auth', + 'rule' => [ + 'value' => '', + 'url' => url('Auth/access') + ] + ], + 'delete' => [ + 'module' => 'auth', + 'rule' => [ + 'value' => '', + 'url' => url('Auth/access') + ] ] ], - 'get' => [ - 'module' => 'auth', - 'rule' => [ - 'value' => '' - ] - ], - 'put' => [ - 'module' => 'auth', - 'rule' => [ - 'value' => '' - ] - ], - 'delete' => [ - 'module' => 'auth', - 'rule' => [ - 'value' => '' - ] - ] - ], - 'data' => $authList - ]; - $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); + 'data' => $authList + ]; + $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS); + } } /** diff --git a/public/admin/static/js/template.js b/public/admin/static/js/template.js index bf01b85..02464db 100644 --- a/public/admin/static/js/template.js +++ b/public/admin/static/js/template.js @@ -278,15 +278,32 @@ }); bodyDom.on('click', '.auth', function () { - - var reg = new RegExp("(^|&)id=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 - var r = window.location.search.substr(1).match(reg); //匹配目标参数 - if (r != null) { - var id = unescape(r[2]); - } - console.log(id); - - console.log($(this).parent().parent().children().eq(2).html()); + var tdDom = $(this).parent().parent().children(); + var urlName = tdDom.eq(2).html(); + var url = $(this).attr('url'); + var message; + $.ajax({ + type: "PUT", + url: url, + data: {urlName:urlName, get:Number(tdDom.find('[name=get]').is(':checked')), post:Number(tdDom.find('[name=post]').is(':checked')), put:Number(tdDom.find('[name=put]').is(':checked')), delete:Number(tdDom.find('[name=delete]').is(':checked'))} + }).done(function( data ) { + var wait = 1000*data.wait; + if (data.code == 1) { + if (data.url) { + message = data.msg + ' 页面即将自动跳转...'; + } else { + message = data.msg; + } + $.alertMsg(message); + setTimeout(function() { + if (data.url) { + $.refresh(data.url); + } + }, wait); + } else { + $.alertMsg(data.msg); + } + }); }) })(jQuery); diff --git a/public/admin/static/js/template/table.js b/public/admin/static/js/template/table.js index 80dd29e..7cac68b 100644 --- a/public/admin/static/js/template/table.js +++ b/public/admin/static/js/template/table.js @@ -114,10 +114,10 @@ break; case 'auth': if( dataValue['url'] ){ - if( dataValue[fieldName] == 0 ){ - dataListHtml += '