mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 完成授权相关功能
This commit is contained in:
parent
ded920c332
commit
0b525a0af4
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
|
@ -114,10 +114,10 @@
|
||||
break;
|
||||
case 'auth':
|
||||
if( dataValue['url'] ){
|
||||
if( dataValue[fieldName] == 0 ){
|
||||
dataListHtml += '<td><input class="auth" type="checkbox" name="'+fieldName+'" ></td>';
|
||||
if( dataValue[fieldName] && dataValue[fieldName] != 0 ){
|
||||
dataListHtml += '<td><input class="auth" checked type="checkbox" url="'+ rule.rule['url'] +'" name="'+fieldName+'" ></td>';
|
||||
}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>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user