diff --git a/.gitignore b/.gitignore index d465120..0c60eea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.idea /.vscode /vendor +/database *.log .env \ No newline at end of file diff --git a/README.md b/README.md index 8f6fc9b..f983b67 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,14 @@ ### install - curl -sS http://install.phpcomposer.com/installer | php -- composer config -g repo.packagist composer https://packagist.laravel-china.org +- composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ - composer update -- php think install:project +- php think catch:install ### Use - 配置虚拟域名 OR 在根目录下执行 php think run - yourUrl/login -- 默认用户名 admin 密码 admin +- 默认用户名 admin@gmail.com 密码 admin ### Problem > SQLSTATE[42000]: Syntax error or access violation: 1067 Invalid default value for 'updated_at' @@ -38,4 +38,10 @@ remove 'NO_ZERO_IN_DATE,NO_ZERO_DATE' - 欢迎进入 Q 群,可以及时反馈一些问题。 - ![输入图片说明](https://images.gitee.com/uploads/images/2018/1219/110300_0257b6c0_810218.jpeg "微信图片_20181219105915.jpg") -仅供学习 \ No newline at end of file +仅供学习 + +## 体验地址 + +[体验地址](http://catch.njphper.com/login) +- 账号: test@catch.com +- 密码: 123456 \ No newline at end of file diff --git a/app/ExceptionHandle.php b/app/ExceptionHandle.php index e826589..82e554e 100644 --- a/app/ExceptionHandle.php +++ b/app/ExceptionHandle.php @@ -2,6 +2,10 @@ namespace app; use catcher\CatchResponse; +use catcher\exceptions\CatchException; +use catcher\exceptions\FailedException; +use catcher\exceptions\LoginFailedException; +use catcher\exceptions\PermissionForbiddenException; use think\db\exception\DataNotFoundException; use think\db\exception\ModelNotFoundException; use think\exception\Handle; @@ -45,17 +49,17 @@ class ExceptionHandle extends Handle * Render an exception into an HTTP response. * * @access public - * @param \think\Request $request + * @param \think\Request $request * @param Throwable $e * @return Response + * @throws \Exception */ public function render($request, Throwable $e): Response { - // 添加自定义异常处理机制 - if ($request->isAjax()) { - return CatchResponse::fail($e->getMessage(), $e->getCode()); - } + // if ($e instanceof CatchException){ + return CatchResponse::fail($e->getMessage(), $e->getCode()); + // } // 其他错误交给系统处理 - return parent::render($request, $e); + //return parent::render($request, $e); } } diff --git a/app/Request.php b/app/Request.php index df3670d..097ac2d 100644 --- a/app/Request.php +++ b/app/Request.php @@ -3,7 +3,12 @@ namespace app; // 应用请求对象类 +use catchAdmin\user\Auth; + class Request extends \think\Request { - + public function user() + { + return Auth::user(); + } } diff --git a/app/event.php b/app/event.php index 37cbcb8..9983454 100644 --- a/app/event.php +++ b/app/event.php @@ -1,8 +1,8 @@ [ - ], + 'bind' => [], 'listen' => [ 'AppInit' => [], @@ -10,9 +10,7 @@ return [ 'HttpEnd' => [], 'LogLevel' => [], 'LogWrite' => [], - 'RouteLoaded' => [ - catcher\event\LoadModuleRoutes::class, - ], + 'RouteLoaded' => [], ], 'subscribe' => [ diff --git a/catchAdmin/CatchAdminService.php b/catchAdmin/CatchAdminService.php index cb46296..064dd2d 100644 --- a/catchAdmin/CatchAdminService.php +++ b/catchAdmin/CatchAdminService.php @@ -1,10 +1,21 @@ registerCommands(); + $this->registerValidates(); + $this->registerMiddleWares(); + $this->registerEvents(); + $this->registerListeners(); + } + + /** + * + * @time 2019年12月13日 + * @return void + */ + protected function registerCommands(): void { $this->commands([ InstallCommand::class, ModuleCacheCommand::class, MigrateRunCommand::class, ModelGeneratorCommand::class, + SeedRunCommand::class, + BackupCommand::class, + CompressPackageCommand::class, + CreateModuleCommand::class, ]); - - $this->registerValidates(); } - /** * * @time 2019年12月07日 @@ -44,6 +70,51 @@ class CatchAdminService extends Service $validate->extend($vali->type(), [$vali, 'verify'], $vali->message()); } }); + } + /** + * + * @time 2019年12月12日 + * @return void + */ + protected function registerMiddleWares(): void + { + $this->app->middleware->import([ + 'catch_check_permission' => PermissionsMiddleware::class, + ], 'route'); + } + + /** + * + * @time 2019年12月12日 + * @return void + */ + protected function registerEvents(): void + { + $this->app->event->bind([ + 'loginLog' => LoginLogEvent::class, + 'operateLog' => OperateLogEvent::class, + ]); + } + + /** + * 注册监听者 + * + * @time 2019年12月12日 + * @return void + */ + protected function registerListeners(): void + { + $this->app->event->listenEvents([ + 'loginLog' => [ + LoginLogListener::class, + ], + 'operateLog' => [ + OperateLogListener::class, + ], + 'RouteLoaded' => [ + LoadModuleRoutes::class + ] + ]); } } \ No newline at end of file diff --git a/catchAdmin/helper.php b/catchAdmin/helper.php new file mode 100644 index 0000000..51f1295 --- /dev/null +++ b/catchAdmin/helper.php @@ -0,0 +1,23 @@ +%s', + $event, $name); +} + +function deleteButton($name = '删除', $event = 'del') +{ + return sprintf( + '%s', + $event, $name); +} + +function addButton($name = '新增', $event = 'add') +{ + return sprintf( + '%s', + $event, $name); +} + diff --git a/catchAdmin/index/controller/Index.php b/catchAdmin/index/controller/Index.php index cd6e2d8..36636e7 100644 --- a/catchAdmin/index/controller/Index.php +++ b/catchAdmin/index/controller/Index.php @@ -1,13 +1,59 @@ getPermissionsBy(); + + $menus = Permissions::whereIn('id', $permissionIds) + ->where('type', Permissions::MENU_TYPE) + ->field(['id', 'parent_id', 'permission_name', 'route']) + ->select()->toArray(); + + return $this->fetch([ + 'menus' => Tree::done($menus), + 'username' => Auth::user()->username, + ]); + } + + /** + * + * @time 2019年12月11日 + * @throws \Exception + * @return string + */ + public function theme(): string { return $this->fetch(); } + + /** + * + * @time 2019年12月12日 + * @throws \Exception + * @return string + */ + public function dashboard(): string + { + $mysqlVersion = Db::query('select version() as version'); + return $this->fetch([ + 'mysql_version' => $mysqlVersion['0']['version'], + ]); + } } \ No newline at end of file diff --git a/catchAdmin/index/route.php b/catchAdmin/index/route.php index ebbd5d7..3f0cdef 100644 --- a/catchAdmin/index/route.php +++ b/catchAdmin/index/route.php @@ -1,3 +1,5 @@ get('/', '\catchAdmin\index\controller\index/index'); +$router->get('/', '\catchAdmin\index\controller\Index@index'); +$router->get('theme', '\catchAdmin\index\controller\Index@theme'); +$router->get('dashboard', '\catchAdmin\index\controller\Index@dashboard'); diff --git a/catchAdmin/index/view/dashboard.html b/catchAdmin/index/view/dashboard.html new file mode 100644 index 0000000..ccabf4a --- /dev/null +++ b/catchAdmin/index/view/dashboard.html @@ -0,0 +1,221 @@ + + + + + + + CatchAdmin 后台开发框架 + + + + + + + + + +
+
+ +
+
+ + +
+
+
+
+
+ 访问量 +
+
+

99,666

+

总计访问量88万

+
+
+
+
+
+
+ 下载 +
+
+

33,555

+

新下载10%

+
+
+
+
+
+
+ Start +
+
+

99,666

+

总Start数88万

+
+
+
+
+
+
+ 活跃用户 +
+
+

66,666

+

最近一个月15%

+
+
+
+
+ +
+
+
+
更新日志
+
+
    +
  • + +
    +

    + V1.0 + catchAdmin 后台框架发布  + 2019-12-15 +

    +
      +
    • 基于 Thinkphp6 & layui 开发
    • +
    • 完整的权限管理
    • +
    • 模块化开发方式
    • +
    • ...
    • +
    +
    +
  • +
  • + +
    +
    + CatchAdmin 开发中... 更早 +
    +
    +
  • +
+
+
+
+
+
+
后台框架
+
+ + + + + + + + + + + + + + + + + + + + + + + + + {if condition="function_exists('opcache_get_configuration')"} + + {else/} + + {/if} + + + + + + + + + + + + + + + + + + +
PHP 版本{$Think.PHP_VERSION}
MYSQL 版本{$mysql_version}
WEB 服务器{$_SERVER['SERVER_SOFTWARE']}
操作系统{$Think.PHP_OS}
opcache (建议开启){:opcache_get_configuration()['directives']['opcache.enable'] ? '开启' : '关闭' }未开启
最大执行时间{:get_cfg_var("max_execution_time")} s
上传限制大小(M){:get_cfg_var ("upload_max_filesize")}
当前时间{:date("Y-m-d H:i:s")}
核心框架Thinkphp v6
+
+
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/catchAdmin/index/view/error.html b/catchAdmin/index/view/error.html new file mode 100644 index 0000000..2992249 --- /dev/null +++ b/catchAdmin/index/view/error.html @@ -0,0 +1,38 @@ + + + + + + + 403 + + + + + + + + +
+ +
+

403

+
{$msg}
+
+ {if ($code == 10006)} + 返回登录 + {else/} + + {/if} +
+
+
+ + + + + + \ No newline at end of file diff --git a/catchAdmin/index/view/index.html b/catchAdmin/index/view/index.html index 0d59d0d..d5da168 100644 --- a/catchAdmin/index/view/index.html +++ b/catchAdmin/index/view/index.html @@ -30,33 +30,33 @@