From 25a15c6ec3f59df30d859eea5d9618a25edb1cab Mon Sep 17 00:00:00 2001 From: hdm Date: Fri, 8 Jul 2022 01:24:56 +0800 Subject: [PATCH] =?UTF-8?q?TP=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=E6=8E=A5?= =?UTF-8?q?=E7=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/base/view/common/errortemplate.html | 50 ++-- app/contract/common.php | 2 +- app/exception/Http.php | 29 ++ app/home/controller/Conf.php | 2 +- app/home/controller/Index.php | 6 - app/home/controller/Login.php | 5 - app/home/view/login/errorshow.html | 27 -- app/provider.php | 7 + config/app.php | 28 +- public/tpl/401.html | 37 +++ public/tpl/403.html | 37 +++ public/tpl/404.html | 37 +++ public/tpl/405.html | 37 +++ public/tpl/406.html | 36 +++ public/tpl/500.html | 37 +++ public/tpl/think_exception.tpl | 373 +++++++++++------------- 16 files changed, 481 insertions(+), 269 deletions(-) create mode 100644 app/exception/Http.php delete mode 100644 app/home/view/login/errorshow.html create mode 100644 app/provider.php create mode 100644 public/tpl/401.html create mode 100644 public/tpl/403.html create mode 100644 public/tpl/404.html create mode 100644 public/tpl/405.html create mode 100644 public/tpl/406.html create mode 100644 public/tpl/500.html diff --git a/app/base/view/common/errortemplate.html b/app/base/view/common/errortemplate.html index 21e6a1d..c8f197b 100644 --- a/app/base/view/common/errortemplate.html +++ b/app/base/view/common/errortemplate.html @@ -1,25 +1,39 @@ + - - - 找不到模板 - + + + + + 找不到模板 + + -
-
404
-
-
-
出错啦!
-
对不起,找不到模板文件...
-
{$file | default=""}模板不存在,请检查对应的目录文件,注意区分大小写!
-
+
+
+
+
4
😔
6
+
+
哎呀!找不到模板文件
+
{$file | default=""}模板不存在,请检查对应的目录文件,注意区分大小写!
+
+ +
+ \ No newline at end of file diff --git a/app/contract/common.php b/app/contract/common.php index 276b76c..80b0cb9 100644 --- a/app/contract/common.php +++ b/app/contract/common.php @@ -37,7 +37,7 @@ function contract_subject() return $subject; } -//读取签约主体 +//写入日志 function to_log($uid,$new,$old) { $log_data = []; diff --git a/app/exception/Http.php b/app/exception/Http.php new file mode 100644 index 0000000..25f4989 --- /dev/null +++ b/app/exception/Http.php @@ -0,0 +1,29 @@ +getError(), 422); + to_assign(1, $e->getError(), [], '', 422); + } + + // 请求异常 + if ($e instanceof HttpException && $request->isAjax()) { + //return response($e->getMessage(), $e->getStatusCode()); + to_assign(1, $e->getMessage(), [], '', $e->getStatusCode()); + } + + // 其他错误交给系统处理 + return parent::render($request, $e); + } +} \ No newline at end of file diff --git a/app/home/controller/Conf.php b/app/home/controller/Conf.php index 3c36dc2..dd76c6c 100644 --- a/app/home/controller/Conf.php +++ b/app/home/controller/Conf.php @@ -116,7 +116,7 @@ class Conf extends BaseController if(isTemplate($template)){ return view($conf['name']); }else{ - return view('Base@common/errortemplate',['file' =>$template]); + return view('../../base/view/common/errortemplate',['file' =>$template]); } } } diff --git a/app/home/controller/Index.php b/app/home/controller/Index.php index 72d9477..fdf5b9f 100644 --- a/app/home/controller/Index.php +++ b/app/home/controller/Index.php @@ -138,10 +138,4 @@ class Index extends BaseController View::assign('TP_VERSION',\think\facade\App::version()); return View(); } - - public function errorShow() - { - echo '错误'; - } - } diff --git a/app/home/controller/Login.php b/app/home/controller/Login.php index 1bc9c1e..8d1b4d5 100644 --- a/app/home/controller/Login.php +++ b/app/home/controller/Login.php @@ -21,11 +21,6 @@ class Login { return View(); } - //错误页面 - public function errorshow() - { - return View(); - } //提交登录 public function login_submit() { diff --git a/app/home/view/login/errorshow.html b/app/home/view/login/errorshow.html deleted file mode 100644 index d1a71a1..0000000 --- a/app/home/view/login/errorshow.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - 404错误 - - - -
-
404
-
-
-
出错啦!
-
对不起,您要访问的页面不见了...
- -
- - \ No newline at end of file diff --git a/app/provider.php b/app/provider.php new file mode 100644 index 0000000..aee9966 --- /dev/null +++ b/app/provider.php @@ -0,0 +1,7 @@ + '\\app\\exception\\Http', +]; diff --git a/config/app.php b/config/app.php index b294366..0333724 100644 --- a/config/app.php +++ b/config/app.php @@ -21,12 +21,17 @@ return [ 'domain_bind' => [], // 禁止URL访问的应用列表(自动多应用模式有效) 'deny_app_list' => [], + + // 默认全局过滤方法 用逗号分隔多个 + 'default_filter' => 'htmlspecialchars', // 异常页面的模板文件 - 'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl', - + 'exception_tmpl' => app()->getRootPath() . '/public/tpl/think_exception.tpl', + // 默认跳转页面对应的模板文件【新增】 + 'dispatch_success_tmpl' => app()->getRootPath() . '/public/tpl/dispatch_jump.tpl', + 'dispatch_error_tmpl' => app()->getRootPath() . '/public/tpl/dispatch_jump.tpl', // 错误显示信息,非调试模式有效 - 'error_message' => '页面错误!请稍后再试~', + 'error_message' => '😔错误~', // 显示错误信息 'show_error_msg' => false, @@ -36,7 +41,18 @@ return [ 'session_admin' => 'gougu_admin', - // 默认跳转页面对应的模板文件【新增】 - 'dispatch_success_tmpl' => app()->getRootPath() . '/public/tpl/dispatch_jump.tpl', - 'dispatch_error_tmpl' => app()->getRootPath() . '/public/tpl/dispatch_jump.tpl', + 'http_exception_template' => [ + // 登录失败 + 401 => public_path() . 'tpl/401.html', + // 禁止访问 + 403 => public_path() . 'tpl/403.html', + // 无法找到文件 + 404 => public_path() . 'tpl/404.html', + // 无权限访问 + 405 => public_path() . 'tpl/405.html', + // 找不到数据 + 406 => public_path() . 'tpl/406.html', + //内部服务器错误 + 500 => public_path() . 'tpl/500.html', + ] ]; diff --git a/public/tpl/401.html b/public/tpl/401.html new file mode 100644 index 0000000..04851ec --- /dev/null +++ b/public/tpl/401.html @@ -0,0 +1,37 @@ + + + + + + + + + 登录失败 + + + + +
+
+
+
4
😔
1
+
+
哎呀!登录失败
+
+ +
+ + + \ No newline at end of file diff --git a/public/tpl/403.html b/public/tpl/403.html new file mode 100644 index 0000000..1be46b1 --- /dev/null +++ b/public/tpl/403.html @@ -0,0 +1,37 @@ + + + + + + + + + 禁止访问 + + + + +
+
+
+
4
😔
3
+
+
哎呀!禁止访问
+
+ +
+ + + \ No newline at end of file diff --git a/public/tpl/404.html b/public/tpl/404.html new file mode 100644 index 0000000..a8c1442 --- /dev/null +++ b/public/tpl/404.html @@ -0,0 +1,37 @@ + + + + + + + + + 找不到页面 + + + + +
+
+
+
4
😔
4
+
+
哎呀!找不到页面
+
+ +
+ + + \ No newline at end of file diff --git a/public/tpl/405.html b/public/tpl/405.html new file mode 100644 index 0000000..1b67188 --- /dev/null +++ b/public/tpl/405.html @@ -0,0 +1,37 @@ + + + + + + + + + 无权限访问 + + + + +
+
+
+
4
😔
5
+
+
哎呀!无权限访问
+
+ +
+ + + \ No newline at end of file diff --git a/public/tpl/406.html b/public/tpl/406.html new file mode 100644 index 0000000..019eea6 --- /dev/null +++ b/public/tpl/406.html @@ -0,0 +1,36 @@ + + + + + + + + + 找不到相关记录 + + + + +
+
+
+
4
😔
6
+
+
哎呀!找不到相关记录
+
+ +
+ + \ No newline at end of file diff --git a/public/tpl/500.html b/public/tpl/500.html new file mode 100644 index 0000000..2bd0a3c --- /dev/null +++ b/public/tpl/500.html @@ -0,0 +1,37 @@ + + + + + + + + + 页面错误 + + + + +
+
+
+
5
😔
0
+
+
哎呀!页面错误
+
+ +
+ + + \ No newline at end of file diff --git a/public/tpl/think_exception.tpl b/public/tpl/think_exception.tpl index 21bbafc..e21a751 100644 --- a/public/tpl/think_exception.tpl +++ b/public/tpl/think_exception.tpl @@ -1,95 +1,107 @@ '.end($names).''; - } +if (!function_exists('parse_class')) { + function parse_class($name) + { + $names = explode('\\', $name); + return ''.end($names).''; } +} - if(!function_exists('parse_file')){ - function parse_file($file, $line) - { - return ''.basename($file)." line {$line}".''; - } +if (!function_exists('parse_file')) { + function parse_file($file, $line) + { + return ''.basename($file)." line {$line}".''; } +} - if(!function_exists('parse_args')){ - function parse_args($args) - { - $result = []; - - foreach ($args as $key => $item) { - switch (true) { - case is_object($item): - $value = sprintf('object(%s)', parse_class(get_class($item))); - break; - case is_array($item): - if(count($item) > 3){ - $value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3))); - } else { - $value = sprintf('[%s]', parse_args($item)); - } - break; - case is_string($item): - if(strlen($item) > 20){ - $value = sprintf( - '\'%s...\'', - htmlentities($item), - htmlentities(substr($item, 0, 20)) - ); - } else { - $value = sprintf("'%s'", htmlentities($item)); - } - break; - case is_int($item): - case is_float($item): - $value = $item; - break; - case is_null($item): - $value = 'null'; - break; - case is_bool($item): - $value = '' . ($item ? 'true' : 'false') . ''; - break; - case is_resource($item): - $value = 'resource'; - break; - default: - $value = htmlentities(str_replace("\n", '', var_export(strval($item), true))); - break; - } - - $result[] = is_int($key) ? $value : "'{$key}' => {$value}"; +if (!function_exists('parse_args')) { + function parse_args($args) + { + $result = []; + foreach ($args as $key => $item) { + switch (true) { + case is_object($item): + $value = sprintf('object(%s)', parse_class(get_class($item))); + break; + case is_array($item): + if (count($item) > 3) { + $value = sprintf('[%s, ...]', parse_args(array_slice($item, 0, 3))); + } else { + $value = sprintf('[%s]', parse_args($item)); + } + break; + case is_string($item): + if (strlen($item) > 20) { + $value = sprintf( + '\'%s...\'', + htmlentities($item), + htmlentities(substr($item, 0, 20)) + ); + } else { + $value = sprintf("'%s'", htmlentities($item)); + } + break; + case is_int($item): + case is_float($item): + $value = $item; + break; + case is_null($item): + $value = 'null'; + break; + case is_bool($item): + $value = '' . ($item ? 'true' : 'false') . ''; + break; + case is_resource($item): + $value = 'resource'; + break; + default: + $value = htmlentities(str_replace("\n", '', var_export(strval($item), true))); + break; } - return implode(', ', $result); + $result[] = is_int($key) ? $value : "'{$key}' => {$value}"; + } + + return implode(', ', $result); + } +} +if (!function_exists('echo_value')) { + function echo_value($val) + { + if (is_array($val) || is_object($val)) { + echo htmlentities(json_encode($val, JSON_PRETTY_PRINT)); + } elseif (is_bool($val)) { + echo $val ? 'true' : 'false'; + } elseif (is_scalar($val)) { + echo htmlentities($val); + } else { + echo 'Resource'; } } +} ?> - <?php echo \think\Lang::get('System Error'); ?> + 错误 - -
- -
- + + $trace) { ?>
-
- +
-

[

+

-

+

- -
- -
-
    $value) { ?>
- + +
+
    $value) { ?>
  1. ">
+
+
-

Call Stack

+

Call Stack

    -
  1. - -
  2. -
  3. + +
  4. + -
  5. + // Show line + if (isset($value['file']) && isset($value['line'])) { + echo sprintf(' in %s', parse_file($value['file'], $value['line'])); + } + ?> +
+
- -

- +

- +

Exception Datas

$value) { ?> - + @@ -379,19 +360,7 @@ $val) { ?> - + @@ -401,53 +370,35 @@ - +

Environment Variables

$value) { ?> -
- -
-
-
empty
-
+
empty
- -
+ + -

-
+
+ $val) { ?> -
-
-
- -
-
+ + + + - + - +
empty
- +