diff --git a/application/admin/controller/Auth.php b/application/admin/controller/Auth.php index db834ac..69ce97c 100644 --- a/application/admin/controller/Auth.php +++ b/application/admin/controller/Auth.php @@ -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; + } + } \ No newline at end of file diff --git a/application/admin/controller/Menu.php b/application/admin/controller/Menu.php index 467fb57..2b8c01f 100644 --- a/application/admin/controller/Menu.php +++ b/application/admin/controller/Menu.php @@ -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)); diff --git a/application/admin/model/Menu.php b/application/admin/model/Menu.php index ed9569f..40a9f1e 100644 --- a/application/admin/model/Menu.php +++ b/application/admin/model/Menu.php @@ -16,7 +16,7 @@ class Menu extends Model { 'type' => 'integer', 'sort' => 'integer', 'hide' => 'integer', - 'auth' => 'integer', + 'auth' => 'integer', 'level' => 'integer', ]; diff --git a/public/admin/static/js/template.js b/public/admin/static/js/template.js index dc8a6d7..bf01b85 100644 --- a/public/admin/static/js/template.js +++ b/public/admin/static/js/template.js @@ -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); diff --git a/public/admin/static/js/template/table.js b/public/admin/static/js/template/table.js index cb6cc8e..80dd29e 100644 --- a/public/admin/static/js/template/table.js +++ b/public/admin/static/js/template/table.js @@ -112,6 +112,14 @@ dataListHtml += '' + dataValue[fieldName] + ''; } break; + case 'auth': + if( dataValue['url'] ){ + if( dataValue[fieldName] == 0 ){ + dataListHtml += ''; + }else{ + dataListHtml += ''; + } + } } }else{ dataListHtml += '' + dataValue[fieldName] + '';