mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 权限细节的完善
This commit is contained in:
parent
61f67118af
commit
ded920c332
@ -456,5 +456,110 @@ class Auth extends Base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载权限因子
|
||||
*/
|
||||
public function access(){
|
||||
$authList = cache('AuthRule');
|
||||
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'
|
||||
]
|
||||
],
|
||||
'post' => [
|
||||
'module' => 'auth',
|
||||
'rule' => [
|
||||
'value' => ''
|
||||
]
|
||||
],
|
||||
'get' => [
|
||||
'module' => 'auth',
|
||||
'rule' => [
|
||||
'value' => ''
|
||||
]
|
||||
],
|
||||
'put' => [
|
||||
'module' => 'auth',
|
||||
'rule' => [
|
||||
'value' => ''
|
||||
]
|
||||
],
|
||||
'delete' => [
|
||||
'module' => 'auth',
|
||||
'rule' => [
|
||||
'value' => ''
|
||||
]
|
||||
]
|
||||
],
|
||||
'data' => $authList
|
||||
];
|
||||
$this->result($table, ReturnCode::GET_TEMPLATE_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新权限因子缓存
|
||||
* @param array $menu
|
||||
* @return array
|
||||
*/
|
||||
public function refreshAuth( $menu = [] ){
|
||||
if( empty($menu) ){
|
||||
$menuObj = \app\admin\model\Menu::all(function($query){
|
||||
$query->order('sort', 'asc');
|
||||
});
|
||||
foreach ($menuObj as $value){
|
||||
$menuArr = $value->toArray();
|
||||
if( $menuArr['url'] ){
|
||||
$menuArr['token'] = url($menuArr['url']);
|
||||
}else{
|
||||
$menuArr['token'] = '';
|
||||
}
|
||||
$menu[] = $menuArr;
|
||||
}
|
||||
$menu = formatTree(listToTree($menu));
|
||||
}
|
||||
cache('AuthRule', $menu);
|
||||
return $menu;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -15,14 +15,22 @@ class Menu extends Base {
|
||||
$query->order('sort', 'asc');
|
||||
});
|
||||
foreach ($dataObj as $value){
|
||||
$data[] = $value->toArray();
|
||||
$dataArr = $value->toArray();
|
||||
if( $dataArr['url'] ){
|
||||
$dataArr['token'] = url($dataArr['url']);
|
||||
}else{
|
||||
$dataArr['token'] = '';
|
||||
}
|
||||
$data[] = $dataArr;
|
||||
}
|
||||
$data = formatTree(listToTree($data));
|
||||
(new Auth())->refreshAuth($data);
|
||||
foreach( $data as &$value ){
|
||||
$value['name'] = $value['showName'];
|
||||
unset($value['showName']);
|
||||
unset($value['namePrefix']);
|
||||
unset($value['lv']);
|
||||
unset($value['token']);
|
||||
$value['post'] = intval(boolval($value['auth'] & \Permission::AUTH_POST));
|
||||
$value['get'] = intval(boolval($value['auth'] & \Permission::AUTH_GET));
|
||||
$value['put'] = intval(boolval($value['auth'] & \Permission::AUTH_PUT));
|
||||
|
@ -16,7 +16,7 @@ class Menu extends Model {
|
||||
'type' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'hide' => 'integer',
|
||||
'auth' => 'integer',
|
||||
'auth' => 'integer',
|
||||
'level' => 'integer',
|
||||
];
|
||||
|
||||
|
@ -277,4 +277,16 @@
|
||||
$.refresh(url, urlData);
|
||||
});
|
||||
|
||||
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());
|
||||
})
|
||||
|
||||
})(jQuery);
|
||||
|
@ -112,6 +112,14 @@
|
||||
dataListHtml += '<td style="color:red;">' + dataValue[fieldName] + '</td>';
|
||||
}
|
||||
break;
|
||||
case 'auth':
|
||||
if( dataValue['url'] ){
|
||||
if( dataValue[fieldName] == 0 ){
|
||||
dataListHtml += '<td><input class="auth" type="checkbox" name="'+fieldName+'" ></td>';
|
||||
}else{
|
||||
dataListHtml += '<td><input class="auth" checked type="checkbox" name="'+fieldName+'" ></td>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
dataListHtml += '<td>' + dataValue[fieldName] + '</td>';
|
||||
|
Loading…
x
Reference in New Issue
Block a user