added 完成授权相关功能

This commit is contained in:
zhaoxiang 2016-11-14 19:14:22 +08:00
parent ded920c332
commit 0b525a0af4
3 changed files with 135 additions and 78 deletions

View File

@ -464,76 +464,116 @@ class Auth extends Base {
if( !$authList ){ if( !$authList ){
$authList = $this->refreshAuth(); $authList = $this->refreshAuth();
} }
$table = [ if( $this->request->isPut() ){
'tempType' => 'table', $gid = session('authGid');
'header' => [ if( !$gid ){
[ $this->error('组ID丢失');
'field' => 'showName', }
'info' => '权限名称' $url = $this->request->put('urlName');
], $getAuth = $this->request->put('get');
[ $putAuth = $this->request->put('put');
'field' => 'url', $deleteAuth = $this->request->put('delete');
'info' => 'URL标识' $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] );
'field' => 'token', if( $authDetail ){
'info' => '真实URL' $authDetail->auth = $auth;
], $authDetail->save();
[ }else{
'field' => 'get', $newAuthDetail = new AuthRule();
'info' => 'Get' $newAuthDetail->url = $url;
], $newAuthDetail->group_id = $gid;
[ $newAuthDetail->auth = $auth;
'field' => 'put', $newAuthDetail->save();
'info' => 'Put' }
], $this->success('更新成功!', url('Auth/access'), '', 1);
[ }else{
'field' => 'post', $gid = $this->request->get('id')?$this->request->get('id'):session('authGid');
'info' => 'Post' if( !$gid ){
], $this->result('', ReturnCode::GET_TEMPLATE_ERROR, '组ID丢失');
[ }else{
'field' => 'delete', session('authGid', $gid);
'info' => 'Delete' }
] $authRuleArr = AuthRule::where(['group_id' => $gid])->select();
], if( $authRuleArr ){
'typeRule' => [ $authRule = [];
'access' => [ foreach ( $authRuleArr as $value ){
'module' => 'a', $authRule[$value->url] = $value->auth;
'rule' => [ }
'info' => '访问授权', foreach ( $authList as &$authValue ){
'href' => url('Auth/access'), $authRuleValue = isset($authRule[$authValue['url']])?$authRule[$authValue['url']]:0;
'param'=> [$this->primaryKey], $authValue['get'] = \Permission::AUTH_GET & $authRuleValue;
'class' => 'refresh' $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' => [ 'typeRule' => [
'module' => 'auth', 'post' => [
'rule' => [ 'module' => 'auth',
'value' => '' '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' => [ 'data' => $authList
'module' => 'auth', ];
'rule' => [ $this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS);
'value' => '' }
]
],
'put' => [
'module' => 'auth',
'rule' => [
'value' => ''
]
],
'delete' => [
'module' => 'auth',
'rule' => [
'value' => ''
]
]
],
'data' => $authList
];
$this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS);
} }
/** /**

View File

@ -278,15 +278,32 @@
}); });
bodyDom.on('click', '.auth', function () { bodyDom.on('click', '.auth', function () {
var tdDom = $(this).parent().parent().children();
var reg = new RegExp("(^|&)id=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var urlName = tdDom.eq(2).html();
var r = window.location.search.substr(1).match(reg); //匹配目标参数 var url = $(this).attr('url');
if (r != null) { var message;
var id = unescape(r[2]); $.ajax({
} type: "PUT",
console.log(id); 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'))}
console.log($(this).parent().parent().children().eq(2).html()); }).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); })(jQuery);

View File

@ -114,10 +114,10 @@
break; break;
case 'auth': case 'auth':
if( dataValue['url'] ){ if( dataValue['url'] ){
if( dataValue[fieldName] == 0 ){ if( dataValue[fieldName] && dataValue[fieldName] != 0 ){
dataListHtml += '<td><input class="auth" type="checkbox" name="'+fieldName+'" ></td>'; dataListHtml += '<td><input class="auth" checked type="checkbox" url="'+ rule.rule['url'] +'" name="'+fieldName+'" ></td>';
}else{ }else{
dataListHtml += '<td><input class="auth" checked type="checkbox" name="'+fieldName+'" ></td>'; dataListHtml += '<td><input class="auth" type="checkbox" url="'+ rule.rule['url'] +'" name="'+fieldName+'" ></td>';
} }
} }
} }