mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
1、优化路由效率:由于检测机制问题,动态注册的性能比路由配置要高一些,尤其是多种请求类型混合定义的时候。路由分组功能允许把相同前缀的路由定义合并分组,这样可以提高路由匹配的效率,不必每次都去遍历完整的路由规则。
2、配置代码更加明了!
This commit is contained in:
parent
33a2672121
commit
25c0a1d94b
@ -1,240 +1,270 @@
|
||||
<?php
|
||||
use think\Route;
|
||||
|
||||
$afterBehavior = [
|
||||
'\app\admin\behavior\ApiAuth',
|
||||
'\app\admin\behavior\ApiPermission',
|
||||
'\app\admin\behavior\AdminLog'
|
||||
];
|
||||
|
||||
return [
|
||||
'[admin]' => [
|
||||
'Login/index' => [
|
||||
'admin/Login/index',
|
||||
['method' => 'post']
|
||||
],
|
||||
'Index/upload' => [
|
||||
'admin/Index/upload',
|
||||
['method' => 'post', 'after_behavior' => ['\app\admin\behavior\ApiAuth', '\app\admin\behavior\AdminLog']]
|
||||
],
|
||||
'Login/logout' => [
|
||||
'admin/Login/logout',
|
||||
['method' => 'get', 'after_behavior' => ['\app\admin\behavior\ApiAuth', '\app\admin\behavior\AdminLog']]
|
||||
],
|
||||
'Menu/index' => [
|
||||
'admin/Menu/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Menu/changeStatus' => [
|
||||
'admin/Menu/changeStatus',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Menu/add' => [
|
||||
'admin/Menu/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Menu/edit' => [
|
||||
'admin/Menu/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Menu/del' => [
|
||||
'admin/Menu/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'User/index' => [
|
||||
'admin/User/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'User/getUsers' => [
|
||||
'admin/User/getUsers',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'User/changeStatus' => [
|
||||
'admin/User/changeStatus',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'User/add' => [
|
||||
'admin/User/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'User/own' => [
|
||||
'admin/User/own',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'User/edit' => [
|
||||
'admin/User/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'User/del' => [
|
||||
'admin/User/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/index' => [
|
||||
'admin/Auth/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/changeStatus' => [
|
||||
'admin/Auth/changeStatus',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/delMember' => [
|
||||
'admin/Auth/delMember',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/add' => [
|
||||
'admin/Auth/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/edit' => [
|
||||
'admin/Auth/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/del' => [
|
||||
'admin/Auth/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/getGroups' => [
|
||||
'admin/Auth/getGroups',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Auth/getRuleList' => [
|
||||
'admin/Auth/getRuleList',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'App/index' => [
|
||||
'admin/App/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'App/changeStatus' => [
|
||||
'admin/App/changeStatus',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'App/getAppInfo' => [
|
||||
'admin/App/getAppInfo',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'App/add' => [
|
||||
'admin/App/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'App/edit' => [
|
||||
'admin/App/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'App/del' => [
|
||||
'admin/App/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceList/index' => [
|
||||
'admin/InterfaceList/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceList/refresh' => [
|
||||
'admin/InterfaceList/refresh',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceList/changeStatus' => [
|
||||
'admin/InterfaceList/changeStatus',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceList/getHash' => [
|
||||
'admin/InterfaceList/getHash',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceList/add' => [
|
||||
'admin/InterfaceList/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceList/edit' => [
|
||||
'admin/InterfaceList/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceList/del' => [
|
||||
'admin/InterfaceList/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Fields/index' => [
|
||||
'admin/Fields/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Fields/request' => [
|
||||
'admin/Fields/request',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Fields/response' => [
|
||||
'admin/Fields/response',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Fields/add' => [
|
||||
'admin/Fields/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Fields/upload' => [
|
||||
'admin/Fields/upload',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Fields/edit' => [
|
||||
'admin/Fields/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Fields/del' => [
|
||||
'admin/Fields/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceGroup/index' => [
|
||||
'admin/InterfaceGroup/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceGroup/add' => [
|
||||
'admin/InterfaceGroup/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceGroup/edit' => [
|
||||
'admin/InterfaceGroup/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceGroup/del' => [
|
||||
'admin/InterfaceGroup/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceGroup/getAll' => [
|
||||
'admin/InterfaceGroup/getAll',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'InterfaceGroup/changeStatus' => [
|
||||
'admin/InterfaceGroup/changeStatus',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'AppGroup/index' => [
|
||||
'admin/AppGroup/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'AppGroup/add' => [
|
||||
'admin/AppGroup/add',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'AppGroup/edit' => [
|
||||
'admin/AppGroup/edit',
|
||||
['method' => 'post', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'AppGroup/del' => [
|
||||
'admin/AppGroup/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'AppGroup/getAll' => [
|
||||
'admin/AppGroup/getAll',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'AppGroup/changeStatus' => [
|
||||
'admin/AppGroup/changeStatus',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Log/index' => [
|
||||
'admin/Log/index',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'Log/del' => [
|
||||
'admin/Log/del',
|
||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||
],
|
||||
'__miss__' => ['admin/Miss/index'],
|
||||
|
||||
//一些带有特殊参数的路由写到这里
|
||||
Route::rule([
|
||||
'admin/Login/index' => [
|
||||
'admin/Login/index',
|
||||
['method'=>'post']
|
||||
],
|
||||
];
|
||||
'admin/Index/upload' => [
|
||||
'admin/Index/upload',
|
||||
[
|
||||
'method' => 'post', 'after_behavior' => ['\app\admin\behavior\ApiAuth', '\app\admin\behavior\AdminLog']
|
||||
]
|
||||
],
|
||||
'admin/Login/logout' => [
|
||||
'admin/Login/logout',
|
||||
[
|
||||
'method' => 'get', 'after_behavior' => ['\app\admin\behavior\ApiAuth', '\app\admin\behavior\AdminLog']
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
//大部分控制器的路由都以分组的形式写到这里
|
||||
Route::group('admin',function(){
|
||||
Route::group('Menu',[
|
||||
'index'=> [
|
||||
'admin/Menu/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'changeStatus' =>[
|
||||
'admin/Menu/changeStatus',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/Menu/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/Menu/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/Menu/del',
|
||||
['method' => 'get']
|
||||
]
|
||||
]);
|
||||
Route::group('User',[
|
||||
'index'=> [
|
||||
'admin/User/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'getUsers' =>[
|
||||
'admin/User/getUsers',
|
||||
['method' => 'get']
|
||||
],
|
||||
'changeStatus' =>[
|
||||
'admin/User/changeStatus',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/User/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'own' =>[
|
||||
'admin/User/own',
|
||||
['method' => 'post']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/User/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/User/del',
|
||||
['method' => 'get']
|
||||
],
|
||||
]);
|
||||
Route::group('Auth',[
|
||||
'index'=> [
|
||||
'admin/Auth/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'changeStatus' =>[
|
||||
'admin/Auth/changeStatus',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/Auth/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'delMember' =>[
|
||||
'admin/Auth/delMember',
|
||||
['method' => 'get']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/Auth/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/Auth/del',
|
||||
['method' => 'get']
|
||||
],
|
||||
'getGroups' =>[
|
||||
'admin/Auth/getGroups',
|
||||
['method' => 'get']
|
||||
],
|
||||
'getRuleList' =>[
|
||||
'admin/Auth/getRuleList',
|
||||
['method' => 'get']
|
||||
]
|
||||
]);
|
||||
Route::group('App',[
|
||||
'index'=> [
|
||||
'admin/App/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'changeStatus' =>[
|
||||
'admin/App/changeStatus',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/App/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'getAppInfo' =>[
|
||||
'admin/App/getAppInfo',
|
||||
['method' => 'get']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/App/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/App/del',
|
||||
['method' => 'get']
|
||||
]
|
||||
]);
|
||||
Route::group('InterfaceList',[
|
||||
'index'=> [
|
||||
'admin/InterfaceList/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'changeStatus' =>[
|
||||
'admin/InterfaceList/changeStatus',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/InterfaceList/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'refresh' =>[
|
||||
'admin/InterfaceList/refresh',
|
||||
['method' => 'get']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/InterfaceList/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/InterfaceList/del',
|
||||
['method' => 'get']
|
||||
],
|
||||
'getHash' =>[
|
||||
'admin/InterfaceList/getHash',
|
||||
['method' => 'get']
|
||||
]
|
||||
]);
|
||||
Route::group('Fields',[
|
||||
'index'=> [
|
||||
'admin/Fields/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'request' =>[
|
||||
'admin/Fields/request',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/Fields/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'response' =>[
|
||||
'admin/Fields/response',
|
||||
['method' => 'get']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/Fields/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/Fields/del',
|
||||
['method' => 'get']
|
||||
],
|
||||
'upload' =>[
|
||||
'admin/Fields/upload',
|
||||
['method' => 'post']
|
||||
]
|
||||
]);
|
||||
Route::group('InterfaceGroup',[
|
||||
'index'=> [
|
||||
'admin/InterfaceGroup/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'getAll' =>[
|
||||
'admin/InterfaceGroup/getAll',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/InterfaceGroup/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'changeStatus' =>[
|
||||
'admin/InterfaceGroup/changeStatus',
|
||||
['method' => 'get']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/InterfaceGroup/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/InterfaceGroup/del',
|
||||
['method' => 'get']
|
||||
]
|
||||
]);
|
||||
Route::group('AppGroup',[
|
||||
'index'=> [
|
||||
'admin/AppGroup/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'getAll' =>[
|
||||
'admin/AppGroup/getAll',
|
||||
['method' => 'get']
|
||||
],
|
||||
'add' =>[
|
||||
'admin/AppGroup/add',
|
||||
['method' => 'post']
|
||||
],
|
||||
'changeStatus' =>[
|
||||
'admin/AppGroup/changeStatus',
|
||||
['method' => 'get']
|
||||
],
|
||||
'edit' =>[
|
||||
'admin/AppGroup/edit',
|
||||
['method' => 'post']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/AppGroup/del',
|
||||
['method' => 'get']
|
||||
]
|
||||
]);
|
||||
Route::group('Log',[
|
||||
'index'=> [
|
||||
'admin/Log/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'del' =>[
|
||||
'admin/Log/del',
|
||||
['method' => 'get']
|
||||
]
|
||||
]);
|
||||
Route::miss('admin/Miss/index');
|
||||
},['after_behavior' => $afterBehavior]
|
||||
);
|
Loading…
x
Reference in New Issue
Block a user