mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-05 17:42:49 +08:00
1143 lines
41 KiB
Smarty
1143 lines
41 KiB
Smarty
<?php
|
|
/** @var array $traces */
|
|
if (!function_exists('parse_padding')) {
|
|
function parse_padding($source)
|
|
{
|
|
$length = strlen(strval(count($source['source']) + $source['first']));
|
|
return 40 + ($length - 1) * 8;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('parse_class')) {
|
|
function parse_class($name)
|
|
{
|
|
$names = explode('\\', $name);
|
|
return '<abbr title="'.$name.'">'.end($names).'</abbr>';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('parse_file')) {
|
|
function parse_file($file, $line)
|
|
{
|
|
return '<a class="toggle" title="'."{$file} line {$line}".'">'.basename($file)." line {$line}".'</a>';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('parse_args')) {
|
|
function parse_args($args)
|
|
{
|
|
$result = [];
|
|
foreach ($args as $key => $item) {
|
|
switch (true) {
|
|
case is_object($item):
|
|
$value = sprintf('<em>object</em>(%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(
|
|
'\'<a class="toggle" title="%s">%s...</a>\'',
|
|
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 = '<em>null</em>';
|
|
break;
|
|
case is_bool($item):
|
|
$value = '<em>' . ($item ? 'true' : 'false') . '</em>';
|
|
break;
|
|
case is_resource($item):
|
|
$value = '<em>resource</em>';
|
|
break;
|
|
default:
|
|
$value = htmlentities(str_replace("\n", '', var_export(strval($item), true)));
|
|
break;
|
|
}
|
|
|
|
$result[] = is_int($key) ? $value : sprintf('\'%s\' => %s', htmlentities($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';
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>系统发生错误</title>
|
|
<meta name="robots" content="noindex,nofollow" />
|
|
<style>
|
|
/* Base */
|
|
body {
|
|
color: #333;
|
|
font: 16px Verdana, "Helvetica Neue", helvetica, Arial, 'Microsoft YaHei', sans-serif;
|
|
margin: 0;
|
|
padding: 0 20px 20px;
|
|
}
|
|
h1{
|
|
margin: 10px 0 0;
|
|
font-size: 28px;
|
|
font-weight: 500;
|
|
line-height: 32px;
|
|
}
|
|
h2{
|
|
color: #4288ce;
|
|
font-weight: 400;
|
|
padding: 6px 0;
|
|
margin: 6px 0 0;
|
|
font-size: 18px;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
h3{
|
|
margin: 12px;
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
}
|
|
abbr{
|
|
cursor: help;
|
|
text-decoration: underline;
|
|
text-decoration-style: dotted;
|
|
}
|
|
a{
|
|
color: #868686;
|
|
cursor: pointer;
|
|
}
|
|
a:hover{
|
|
text-decoration: underline;
|
|
}
|
|
.line-error{
|
|
background: #f8cbcb;
|
|
}
|
|
.echo table {
|
|
width: 100%;
|
|
}
|
|
.echo pre {
|
|
padding: 16px;
|
|
overflow: auto;
|
|
font-size: 85%;
|
|
line-height: 1.45;
|
|
background-color: #f7f7f7;
|
|
border: 0;
|
|
border-radius: 3px;
|
|
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
|
}
|
|
.echo pre > pre {
|
|
padding: 0;
|
|
margin: 0;
|
|
}
|
|
/* Exception Info */
|
|
.exception {
|
|
margin-top: 20px;
|
|
}
|
|
.exception .message{
|
|
padding: 12px;
|
|
border: 1px solid #ddd;
|
|
border-bottom: 0 none;
|
|
line-height: 18px;
|
|
font-size:16px;
|
|
border-top-left-radius: 4px;
|
|
border-top-right-radius: 4px;
|
|
font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑",serif;
|
|
}
|
|
.exception .code{
|
|
float: left;
|
|
text-align: center;
|
|
color: #fff;
|
|
margin-right: 12px;
|
|
padding: 16px;
|
|
border-radius: 4px;
|
|
background: #999;
|
|
}
|
|
.exception .source-code{
|
|
padding: 6px;
|
|
border: 1px solid #ddd;
|
|
|
|
background: #f9f9f9;
|
|
overflow-x: auto;
|
|
|
|
}
|
|
.exception .source-code pre{
|
|
margin: 0;
|
|
}
|
|
.exception .source-code pre ol{
|
|
margin: 0;
|
|
color: #4288ce;
|
|
display: inline-block;
|
|
min-width: 100%;
|
|
box-sizing: border-box;
|
|
font-size:14px;
|
|
font-family: "Century Gothic",Consolas,"Liberation Mono",Courier,Verdana,serif;
|
|
padding-left: <?php echo (isset($source) && !empty($source)) ? parse_padding($source) : 40; ?>px;
|
|
}
|
|
.exception .source-code pre li{
|
|
border-left: 1px solid #ddd;
|
|
height: 18px;
|
|
line-height: 18px;
|
|
}
|
|
.exception .source-code pre code{
|
|
color: #333;
|
|
height: 100%;
|
|
display: inline-block;
|
|
border-left: 1px solid #fff;
|
|
font-size:14px;
|
|
font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑",serif;
|
|
}
|
|
.exception .trace{
|
|
padding: 6px;
|
|
border: 1px solid #ddd;
|
|
border-top: 0 none;
|
|
line-height: 16px;
|
|
font-size:14px;
|
|
font-family: Consolas,"Liberation Mono",Courier,Verdana,"微软雅黑",serif;
|
|
}
|
|
.exception .trace h2:hover {
|
|
text-decoration: underline;
|
|
cursor: pointer;
|
|
}
|
|
.exception .trace ol{
|
|
margin: 12px;
|
|
}
|
|
.exception .trace ol li{
|
|
padding: 2px 4px;
|
|
}
|
|
.exception div:last-child{
|
|
border-bottom-left-radius: 4px;
|
|
border-bottom-right-radius: 4px;
|
|
}
|
|
|
|
/* Exception Variables */
|
|
.exception-var table{
|
|
width: 100%;
|
|
margin: 12px 0;
|
|
box-sizing: border-box;
|
|
table-layout:fixed;
|
|
word-wrap:break-word;
|
|
}
|
|
.exception-var table caption{
|
|
text-align: left;
|
|
font-size: 16px;
|
|
font-weight: bold;
|
|
padding: 6px 0;
|
|
}
|
|
.exception-var table caption small{
|
|
font-weight: 300;
|
|
display: inline-block;
|
|
margin-left: 10px;
|
|
color: #ccc;
|
|
}
|
|
.exception-var table tbody{
|
|
font-size: 13px;
|
|
font-family: Consolas, "Liberation Mono", Courier, "微软雅黑",serif;
|
|
}
|
|
.exception-var table td{
|
|
padding: 0 6px;
|
|
vertical-align: top;
|
|
word-break: break-all;
|
|
}
|
|
.exception-var table td:first-child{
|
|
width: 28%;
|
|
font-weight: bold;
|
|
white-space: nowrap;
|
|
}
|
|
.exception-var table td pre{
|
|
margin: 0;
|
|
}
|
|
|
|
/* Copyright Info */
|
|
.copyright{
|
|
margin-top: 24px;
|
|
padding: 12px 0;
|
|
border-top: 1px solid #eee;
|
|
}
|
|
|
|
/* SPAN elements with the classes below are added by prettyprint. */
|
|
pre.prettyprint .pln { color: #000 } /* plain text */
|
|
pre.prettyprint .str { color: #080 } /* string content */
|
|
pre.prettyprint .kwd { color: #008 } /* a keyword */
|
|
pre.prettyprint .com { color: #800 } /* a comment */
|
|
pre.prettyprint .typ { color: #606 } /* a type name */
|
|
pre.prettyprint .lit { color: #066 } /* a literal value */
|
|
/* punctuation, lisp open bracket, lisp close bracket */
|
|
pre.prettyprint .pun, pre.prettyprint .opn, pre.prettyprint .clo { color: #660 }
|
|
pre.prettyprint .tag { color: #008 } /* a markup tag name */
|
|
pre.prettyprint .atn { color: #606 } /* a markup attribute name */
|
|
pre.prettyprint .atv { color: #080 } /* a markup attribute value */
|
|
pre.prettyprint .dec, pre.prettyprint .var { color: #606 } /* a declaration; a variable name */
|
|
pre.prettyprint .fun { color: red } /* a function name */
|
|
|
|
/* AI Copy Toolbar */
|
|
#debug-toolbar {
|
|
position: fixed;
|
|
top: 10px;
|
|
right: 10px;
|
|
z-index: 99999;
|
|
background: rgba(255, 255, 255, 0.95);
|
|
padding: 8px 12px;
|
|
border-radius: 4px;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
|
|
font-size: 12px;
|
|
max-width: 90vw;
|
|
overflow-x: auto;
|
|
white-space: nowrap;
|
|
}
|
|
#debug-toolbar .toolbar-group {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
margin-right: 10px;
|
|
padding-right: 10px;
|
|
border-right: 1px solid #ddd;
|
|
}
|
|
#debug-toolbar .toolbar-group:last-child {
|
|
border-right: none;
|
|
margin-right: 0;
|
|
padding-right: 0;
|
|
}
|
|
#char-count {
|
|
font-size: 12px;
|
|
color: #888;
|
|
min-width: 40px;
|
|
text-align: center;
|
|
font-family: Consolas, monospace;
|
|
}
|
|
#debug-toolbar .toolbar-group label {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 2px;
|
|
cursor: pointer;
|
|
padding: 2px 4px;
|
|
border-radius: 3px;
|
|
transition: background 0.15s;
|
|
font-size: 12px;
|
|
color: #555;
|
|
}
|
|
#debug-toolbar .toolbar-group label:hover {
|
|
background: #f0f0f0;
|
|
}
|
|
#debug-toolbar .toolbar-group label.disabled {
|
|
color: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
#debug-toolbar .toolbar-group input[type="checkbox"] {
|
|
margin: 0;
|
|
cursor: pointer;
|
|
}
|
|
#debug-toolbar .toolbar-group label.disabled input[type="checkbox"] {
|
|
cursor: not-allowed;
|
|
}
|
|
#debug-toolbar button {
|
|
padding: 4px 10px;
|
|
cursor: pointer;
|
|
border: 1px solid #ccc;
|
|
background: #fff;
|
|
border-radius: 3px;
|
|
font-size: 12px;
|
|
transition: all 0.2s;
|
|
}
|
|
#debug-toolbar button:hover {
|
|
background: #f0f0f0;
|
|
border-color: #bbb;
|
|
}
|
|
#debug-toolbar button.active {
|
|
background: #4288ce;
|
|
color: white;
|
|
border-color: #4288ce;
|
|
}
|
|
#debug-toolbar button.copied {
|
|
background: #52c41a;
|
|
color: white;
|
|
border-color: #52c41a;
|
|
}
|
|
#markdown-preview {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
right: 0;
|
|
width: 45%;
|
|
height: 100%;
|
|
background: #fff;
|
|
border-left: 1px solid #ddd;
|
|
box-shadow: -4px 0 16px rgba(0,0,0,0.12);
|
|
z-index: 99998;
|
|
box-sizing: border-box;
|
|
overflow: hidden;
|
|
}
|
|
#markdown-preview .preview-header {
|
|
padding: 12px 20px;
|
|
background: #f8f9fa;
|
|
border-bottom: 1px solid #e8e8e8;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
font-size: 14px;
|
|
font-weight: bold;
|
|
color: #333;
|
|
}
|
|
#markdown-preview .preview-header .close-btn {
|
|
cursor: pointer;
|
|
font-size: 20px;
|
|
color: #999;
|
|
background: none;
|
|
border: none;
|
|
padding: 0 4px;
|
|
line-height: 1;
|
|
}
|
|
#markdown-preview .preview-header .close-btn:hover {
|
|
color: #333;
|
|
}
|
|
#markdown-preview pre {
|
|
white-space: pre-wrap;
|
|
word-break: break-word;
|
|
font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
|
|
font-size: 13px;
|
|
background: #fff;
|
|
padding: 20px;
|
|
margin: 0;
|
|
border: none;
|
|
border-radius: 0;
|
|
color: #333;
|
|
height: calc(100% - 49px);
|
|
overflow: auto;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
/* Mobile toggle button - hidden on desktop */
|
|
#debug-toolbar-toggle {
|
|
display: none;
|
|
}
|
|
|
|
/* Mobile responsive */
|
|
@media (max-width: 768px) {
|
|
html, body {
|
|
overflow-x: hidden;
|
|
max-width: 100vw;
|
|
}
|
|
.exception {
|
|
max-width: 100%;
|
|
overflow: hidden;
|
|
}
|
|
.exception .source-code {
|
|
overflow-x: auto;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
.exception .source-code pre {
|
|
min-width: 0;
|
|
}
|
|
.exception .source-code pre ol {
|
|
min-width: 0;
|
|
}
|
|
.exception-var table {
|
|
table-layout: fixed;
|
|
word-break: break-all;
|
|
}
|
|
.exception-var table td pre {
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
}
|
|
.echo pre {
|
|
white-space: pre-wrap;
|
|
word-break: break-all;
|
|
}
|
|
h1 {
|
|
font-size: 20px;
|
|
line-height: 24px;
|
|
}
|
|
#debug-toolbar-toggle {
|
|
display: block;
|
|
position: fixed;
|
|
top: 10px;
|
|
right: 10px;
|
|
z-index: 99999;
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
background: rgba(255, 255, 255, 0.95);
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
|
|
border: 1px solid #ddd;
|
|
cursor: pointer;
|
|
font-size: 20px;
|
|
line-height: 40px;
|
|
text-align: center;
|
|
color: #555;
|
|
}
|
|
#debug-toolbar-toggle:active {
|
|
background: #f0f0f0;
|
|
}
|
|
#debug-toolbar {
|
|
display: none;
|
|
top: auto;
|
|
bottom: 0;
|
|
right: 0;
|
|
left: 0;
|
|
max-width: 100vw;
|
|
border-radius: 0;
|
|
padding: 12px 16px;
|
|
box-shadow: 0 -2px 10px rgba(0,0,0,0.15);
|
|
white-space: normal;
|
|
overflow-x: visible;
|
|
}
|
|
#debug-toolbar.toolbar-open {
|
|
display: block;
|
|
}
|
|
#debug-toolbar .toolbar-group {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 6px;
|
|
margin-right: 0;
|
|
padding-right: 0;
|
|
padding-bottom: 8px;
|
|
margin-bottom: 8px;
|
|
border-right: none;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
#debug-toolbar .toolbar-group:last-child {
|
|
border-bottom: none;
|
|
padding-bottom: 0;
|
|
margin-bottom: 0;
|
|
}
|
|
#debug-toolbar .toolbar-group label {
|
|
padding: 6px 10px;
|
|
font-size: 14px;
|
|
}
|
|
#debug-toolbar .toolbar-group input[type="checkbox"] {
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
#debug-toolbar button {
|
|
padding: 8px 14px;
|
|
font-size: 14px;
|
|
}
|
|
#char-count {
|
|
font-size: 14px;
|
|
}
|
|
#markdown-preview {
|
|
width: 100%;
|
|
height: 100%;
|
|
top: 0;
|
|
right: 0;
|
|
box-shadow: none;
|
|
border-left: none;
|
|
}
|
|
#markdown-preview .preview-header {
|
|
padding: 14px 16px;
|
|
}
|
|
#markdown-preview pre {
|
|
padding: 16px;
|
|
font-size: 13px;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<?php if (\think\facade\App::isDebug()) { ?>
|
|
<?php foreach ($traces as $index => $trace) { ?>
|
|
<div class="exception">
|
|
<div class="message">
|
|
<div class="info">
|
|
<div>
|
|
<h2><?php echo "#{$index} [{$trace['code']}]" . sprintf('%s in %s', parse_class($trace['name']), parse_file($trace['file'], $trace['line'])); ?></h2>
|
|
</div>
|
|
<div><h1><?php echo nl2br(htmlentities($trace['message'])); ?></h1></div>
|
|
</div>
|
|
</div>
|
|
<?php if (!empty($trace['source'])) { ?>
|
|
<div class="source-code">
|
|
<pre class="prettyprint lang-php"><ol start="<?php echo $trace['source']['first']; ?>"><?php foreach ((array) $trace['source']['source'] as $key => $value) { ?><li class="line-<?php echo "{$index}-"; echo $key + $trace['source']['first']; echo $trace['line'] === $key + $trace['source']['first'] ? ' line-error' : ''; ?>"><code><?php echo htmlentities($value); ?></code></li><?php } ?></ol></pre>
|
|
</div>
|
|
<?php }?>
|
|
<div class="trace">
|
|
<h2 data-expand="<?php echo 0 === $index ? '1' : '0'; ?>">Call Stack</h2>
|
|
<ol>
|
|
<li><?php echo sprintf('in %s', parse_file($trace['file'], $trace['line'])); ?></li>
|
|
<?php foreach ((array) $trace['trace'] as $value) { ?>
|
|
<li>
|
|
<?php
|
|
// Show Function
|
|
if ($value['function']) {
|
|
echo sprintf(
|
|
'at %s%s%s(%s)',
|
|
isset($value['class']) ? parse_class($value['class']) : '',
|
|
isset($value['type']) ? $value['type'] : '',
|
|
$value['function'],
|
|
isset($value['args'])?parse_args($value['args']):''
|
|
);
|
|
}
|
|
|
|
// Show line
|
|
if (isset($value['file']) && isset($value['line'])) {
|
|
echo sprintf(' in %s', parse_file($value['file'], $value['line']));
|
|
}
|
|
?>
|
|
</li>
|
|
<?php } ?>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
<?php } else { ?>
|
|
<div class="exception">
|
|
<div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<?php if (!empty($datas)) { ?>
|
|
<div class="exception-var">
|
|
<h2>Exception Datas</h2>
|
|
<?php foreach ((array) $datas as $label => $value) { ?>
|
|
<table>
|
|
<?php if (empty($value)) { ?>
|
|
<caption><?php echo $label; ?><small>empty</small></caption>
|
|
<?php } else { ?>
|
|
<caption><?php echo $label; ?></caption>
|
|
<tbody>
|
|
<?php foreach ((array) $value as $key => $val) { ?>
|
|
<tr>
|
|
<td><?php echo htmlentities($key); ?></td>
|
|
<td><?php echo_value($val); ?></td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
<?php } ?>
|
|
</table>
|
|
<?php } ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<?php if (!empty($tables)) { ?>
|
|
<div class="exception-var">
|
|
<h2>Environment Variables</h2>
|
|
<?php foreach ((array) $tables as $label => $value) { ?>
|
|
<table>
|
|
<?php if (empty($value)) { ?>
|
|
<caption><?php echo $label; ?><small>empty</small></caption>
|
|
<?php } else { ?>
|
|
<caption><?php echo $label; ?></caption>
|
|
<tbody>
|
|
<?php foreach ((array) $value as $key => $val) { ?>
|
|
<tr>
|
|
<td><?php echo htmlentities($key); ?></td>
|
|
<td><?php echo_value($val); ?></td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
<?php } ?>
|
|
</table>
|
|
<?php } ?>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="copyright">
|
|
<a title="官方网站" href="http://www.thinkphp.cn">ThinkPHP</a>
|
|
<span>V<?php echo \think\facade\App::version(); ?></span>
|
|
<span>{ 十年磨一剑-为API开发设计的高性能框架 }</span>
|
|
<span>- <a title="官方手册" href="https://doc.thinkphp.cn">官方手册</a></span>
|
|
</div>
|
|
|
|
<!-- AI Copy Toolbar -->
|
|
<button id="debug-toolbar-toggle" onclick="toggleToolbar()">☰</button>
|
|
<div id="debug-toolbar">
|
|
<span class="toolbar-group" id="core-group">
|
|
<label><input type="checkbox" data-key="message" checked> 错误信息</label>
|
|
<label><input type="checkbox" data-key="location" checked> 出错位置</label>
|
|
<label><input type="checkbox" data-key="callstack" checked> 调用栈</label>
|
|
<label><input type="checkbox" data-key="source"> 源码</label>
|
|
<label data-dynamic="exception-data"><input type="checkbox" data-key="exceptiondata"> 异常数据</label>
|
|
</span>
|
|
<span class="toolbar-group" id="env-group">
|
|
<label data-dynamic="env" data-env-key="GET Data"><input type="checkbox" data-key="env_get"> GET</label>
|
|
<label data-dynamic="env" data-env-key="POST Data"><input type="checkbox" data-key="env_post"> POST</label>
|
|
<label data-dynamic="env" data-env-key="Files"><input type="checkbox" data-key="env_files"> Files</label>
|
|
<label data-dynamic="env" data-env-key="Cookies"><input type="checkbox" data-key="env_cookies"> Cookies</label>
|
|
<label data-dynamic="env" data-env-key="Session"><input type="checkbox" data-key="env_session"> Session</label>
|
|
<label data-dynamic="env" data-env-key="Server/Request Data"><input type="checkbox" data-key="env_server"> Server</label>
|
|
</span>
|
|
<span class="toolbar-group">
|
|
<span id="char-count" title="当前选中内容的字符数">0字</span>
|
|
<button id="btn-copy" onclick="copyToClipboard()">复制给AI</button>
|
|
<button id="btn-preview" onclick="togglePreview()">预览</button>
|
|
<button id="btn-path" onclick="togglePathMode()">路径:简略</button>
|
|
</span>
|
|
</div>
|
|
|
|
<!-- Hidden root path -->
|
|
<div id="root-path" style="display:none;"><?php echo \think\facade\App::getRootPath(); ?></div>
|
|
|
|
<!-- Markdown Preview (right-side slide-out panel) -->
|
|
<div id="markdown-preview">
|
|
<div class="preview-header">
|
|
<span>Markdown Preview</span>
|
|
<button class="close-btn" onclick="togglePreview()">×</button>
|
|
</div>
|
|
<pre id="markdown-content"></pre>
|
|
</div>
|
|
|
|
<?php if (\think\facade\App::isDebug()) { ?>
|
|
<script>
|
|
function $(selector, node){
|
|
var elements;
|
|
|
|
node = node || document;
|
|
if(document.querySelectorAll){
|
|
elements = node.querySelectorAll(selector);
|
|
} else {
|
|
switch(selector.substr(0, 1)){
|
|
case '#':
|
|
elements = [node.getElementById(selector.substr(1))];
|
|
break;
|
|
case '.':
|
|
if(document.getElementsByClassName){
|
|
elements = node.getElementsByClassName(selector.substr(1));
|
|
} else {
|
|
elements = get_elements_by_class(selector.substr(1), node);
|
|
}
|
|
break;
|
|
default:
|
|
elements = node.getElementsByTagName();
|
|
}
|
|
}
|
|
return elements;
|
|
|
|
function get_elements_by_class(search_class, node, tag) {
|
|
var elements = [], eles,
|
|
pattern = new RegExp('(^|\\s)' + search_class + '(\\s|$)');
|
|
|
|
node = node || document;
|
|
tag = tag || '*';
|
|
|
|
eles = node.getElementsByTagName(tag);
|
|
for(var i = 0; i < eles.length; i++) {
|
|
if(pattern.test(eles[i].className)) {
|
|
elements.push(eles[i])
|
|
}
|
|
}
|
|
|
|
return elements;
|
|
}
|
|
}
|
|
|
|
$.getScript = function(src, func){
|
|
var script = document.createElement('script');
|
|
|
|
script.async = 'async';
|
|
script.src = src;
|
|
script.onload = func || function(){};
|
|
|
|
$('head')[0].appendChild(script);
|
|
}
|
|
|
|
;(function(){
|
|
var files = $('.toggle');
|
|
var ol = $('ol', $('.prettyprint')[0]);
|
|
var li = $('li', ol[0]);
|
|
|
|
// 短路径和长路径变换
|
|
for(var i = 0; i < files.length; i++){
|
|
files[i].ondblclick = function(){
|
|
var title = this.title;
|
|
|
|
this.title = this.innerHTML;
|
|
this.innerHTML = title;
|
|
}
|
|
}
|
|
|
|
(function () {
|
|
var expand = function (dom, expand) {
|
|
var ol = $('ol', dom.parentNode)[0];
|
|
expand = undefined === expand ? dom.attributes['data-expand'].value === '0' : undefined;
|
|
if (expand) {
|
|
dom.attributes['data-expand'].value = '1';
|
|
ol.style.display = 'none';
|
|
dom.innerText = 'Call Stack (展开)';
|
|
} else {
|
|
dom.attributes['data-expand'].value = '0';
|
|
ol.style.display = 'block';
|
|
dom.innerText = 'Call Stack (折叠)';
|
|
}
|
|
};
|
|
var traces = $('.trace');
|
|
for (var i = 0; i < traces.length; i ++) {
|
|
var h2 = $('h2', traces[i])[0];
|
|
expand(h2);
|
|
h2.onclick = function () {
|
|
expand(this);
|
|
};
|
|
}
|
|
})();
|
|
|
|
$.getScript('//cdn.bootcdn.net/ajax/libs/prettify/r298/prettify.min.js', function(){
|
|
prettyPrint();
|
|
});
|
|
})();
|
|
|
|
// PHP generates Markdown fragments as JS variables
|
|
var mdFragments = {};
|
|
<?php
|
|
// Message
|
|
if (isset($message)) {
|
|
$md = "# 系统发生错误\n\n## 错误信息\n> " . strip_tags((string)$message) . "\n\n";
|
|
echo 'mdFragments.message = ' . json_encode($md, JSON_UNESCAPED_UNICODE) . ";\n";
|
|
}
|
|
|
|
// Location (from first trace)
|
|
if (isset($traces) && is_array($traces) && !empty($traces)) {
|
|
$firstTrace = $traces[0];
|
|
if (isset($firstTrace['file']) && isset($firstTrace['line'])) {
|
|
$fileEscaped = str_replace('\\', '\\\\', $firstTrace['file']);
|
|
$md = "## 出错位置\n- **File:** `{$fileEscaped}`\n- **Line:** `{$firstTrace['line']}`\n\n";
|
|
echo 'mdFragments.location = ' . json_encode($md, JSON_UNESCAPED_UNICODE) . ";\n";
|
|
}
|
|
}
|
|
|
|
// Call Stack (per trace)
|
|
if (isset($traces) && is_array($traces)) {
|
|
foreach ($traces as $index => $trace) {
|
|
$md = "## 异常 #{$index}\n";
|
|
if (isset($trace['message'])) {
|
|
$md .= "**Message:** " . strip_tags($trace['message']) . "\n\n";
|
|
}
|
|
if (isset($trace['file']) && isset($trace['line'])) {
|
|
$md .= "**Location:** `{$trace['file']}` : {$trace['line']}\n\n";
|
|
}
|
|
if (!empty($trace['trace'])) {
|
|
$md .= "### 调用栈\n";
|
|
$count = 0;
|
|
$total = count($trace['trace']);
|
|
foreach ($trace['trace'] as $i => $item) {
|
|
if ($count >= 20) {
|
|
$md .= "... (共 {$total} 层,已截断)\n";
|
|
break;
|
|
}
|
|
$func = $item['function'] ?? 'unknown';
|
|
$cls = $item['class'] ?? '';
|
|
$type = $item['type'] ?? '';
|
|
$f = $item['file'] ?? '';
|
|
$l = $item['line'] ?? '';
|
|
$call = $cls . $type . $func;
|
|
$location = $f ? " in `{$f}`:{$l}" : "";
|
|
$md .= ($count + 1) . ". `{$call}`{$location}\n";
|
|
$count++;
|
|
}
|
|
$md .= "\n";
|
|
}
|
|
echo "mdFragments.callstack = " . json_encode($md, JSON_UNESCAPED_UNICODE) . ";\n";
|
|
}
|
|
}
|
|
|
|
// Source Code
|
|
if (isset($traces) && is_array($traces)) {
|
|
foreach ($traces as $index => $trace) {
|
|
if (!empty($trace['source'])) {
|
|
$md = "### 源码片段\n```php\n";
|
|
foreach ((array) $trace['source']['source'] as $key => $value) {
|
|
$lineNum = $key + $trace['source']['first'];
|
|
$marker = ($trace['line'] === $lineNum) ? ' >>>' : '';
|
|
$md .= "{$lineNum}{$marker}: " . rtrim($value) . "\n";
|
|
}
|
|
$md .= "```\n\n";
|
|
echo "mdFragments.source = " . json_encode($md, JSON_UNESCAPED_UNICODE) . ";\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Exception Data
|
|
if (isset($datas) && is_array($datas)) {
|
|
$hasData = false;
|
|
$md = "## 异常数据\n";
|
|
foreach ($datas as $label => $value) {
|
|
if (!empty($value)) {
|
|
$hasData = true;
|
|
$md .= "### {$label}\n";
|
|
foreach ($value as $k => $v) {
|
|
$val_str = is_scalar($v) ? (string)$v : json_encode($v, JSON_UNESCAPED_UNICODE);
|
|
$md .= "- **{$k}:** `{$val_str}`\n";
|
|
}
|
|
$md .= "\n";
|
|
}
|
|
}
|
|
if ($hasData) {
|
|
echo "mdFragments.exceptiondata = " . json_encode($md, JSON_UNESCAPED_UNICODE) . ";\n";
|
|
echo "window.__hasExceptionData = true;\n";
|
|
}
|
|
}
|
|
|
|
// Environment Variables (6 separate blocks)
|
|
if (isset($tables) && is_array($tables)) {
|
|
$envMap = array(
|
|
'GET Data' => 'env_get',
|
|
'POST Data' => 'env_post',
|
|
'Files' => 'env_files',
|
|
'Cookies' => 'env_cookies',
|
|
'Session' => 'env_session',
|
|
'Server/Request Data' => 'env_server',
|
|
);
|
|
foreach ($envMap as $tableKey => $jsKey) {
|
|
if (isset($tables[$tableKey]) && !empty($tables[$tableKey])) {
|
|
$md = "### {$tableKey}\n";
|
|
foreach ($tables[$tableKey] as $k => $v) {
|
|
$val_str = is_scalar($v) ? (string)$v : json_encode($v, JSON_UNESCAPED_UNICODE);
|
|
if (strlen($val_str) > 200) {
|
|
$val_str = substr($val_str, 0, 200) . '...';
|
|
}
|
|
$md .= "- **{$k}:** `{$val_str}`\n";
|
|
}
|
|
$md .= "\n";
|
|
echo "mdFragments.{$jsKey} = " . json_encode($md, JSON_UNESCAPED_UNICODE) . ";\n";
|
|
echo "window.__hasEnv_{$jsKey} = true;\n";
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
// AI Copy Toolbar JS
|
|
(function() {
|
|
var STORAGE_KEY = 'think_debug_copy_options';
|
|
var currentPathMode = 'simple';
|
|
var rootPath = '';
|
|
var rootPathEscaped = '';
|
|
|
|
// Initialize on DOM ready
|
|
function initToolbar() {
|
|
var rootDiv = document.getElementById('root-path');
|
|
if (rootDiv) {
|
|
rootPath = rootDiv.innerText.trim();
|
|
rootPathEscaped = rootPath.replace(/\\/g, '\\\\');
|
|
}
|
|
restoreCheckboxState();
|
|
updateDisabledState();
|
|
updatePreviewIfOpen();
|
|
// Auto-save on checkbox change + update preview if open
|
|
var checkboxes = document.querySelectorAll('#debug-toolbar input[type="checkbox"]');
|
|
checkboxes.forEach(function(cb) {
|
|
cb.addEventListener('change', function() {
|
|
saveCheckboxState();
|
|
updatePreviewIfOpen();
|
|
});
|
|
});
|
|
}
|
|
|
|
// Run init on DOMContentLoaded or immediately if already loaded
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', initToolbar);
|
|
} else {
|
|
initToolbar();
|
|
}
|
|
|
|
// Restore checkbox state from localStorage
|
|
function restoreCheckboxState() {
|
|
try {
|
|
var saved = localStorage.getItem(STORAGE_KEY);
|
|
if (saved) {
|
|
var state = JSON.parse(saved);
|
|
var checkboxes = document.querySelectorAll('#debug-toolbar input[type="checkbox"]');
|
|
checkboxes.forEach(function(cb) {
|
|
var key = cb.getAttribute('data-key');
|
|
if (key && state.hasOwnProperty(key)) {
|
|
cb.checked = state[key];
|
|
}
|
|
});
|
|
}
|
|
} catch(e) {}
|
|
}
|
|
|
|
// Save checkbox state to localStorage
|
|
function saveCheckboxState() {
|
|
try {
|
|
var state = {};
|
|
var checkboxes = document.querySelectorAll('#debug-toolbar input[type="checkbox"]');
|
|
checkboxes.forEach(function(cb) {
|
|
var key = cb.getAttribute('data-key');
|
|
if (key) {
|
|
state[key] = cb.checked;
|
|
}
|
|
});
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
|
|
} catch(e) {}
|
|
}
|
|
|
|
// Update preview content if preview panel is currently open
|
|
function updatePreviewIfOpen() {
|
|
var preview = document.getElementById('markdown-preview');
|
|
var content = generateMarkdown();
|
|
var countEl = document.getElementById('char-count');
|
|
if (countEl) {
|
|
countEl.textContent = content.length + '字';
|
|
}
|
|
if (preview && preview.style.display === 'block') {
|
|
document.getElementById('markdown-content').textContent = content;
|
|
}
|
|
}
|
|
|
|
// Update disabled state for env checkboxes based on data availability
|
|
function updateDisabledState() {
|
|
// Exception data
|
|
var exDataLabel = document.querySelector('label[data-dynamic="exception-data"]');
|
|
if (exDataLabel && !window.__hasExceptionData) {
|
|
exDataLabel.classList.add('disabled');
|
|
var cb = exDataLabel.querySelector('input');
|
|
if (cb) { cb.checked = false; cb.disabled = true; }
|
|
}
|
|
|
|
// Env vars
|
|
var envLabels = document.querySelectorAll('label[data-dynamic="env"]');
|
|
var envKeyMap = {
|
|
'GET Data': 'env_get',
|
|
'POST Data': 'env_post',
|
|
'Files': 'env_files',
|
|
'Cookies': 'env_cookies',
|
|
'Session': 'env_session',
|
|
'Server/Request Data': 'env_server'
|
|
};
|
|
envLabels.forEach(function(label) {
|
|
var tableKey = label.getAttribute('data-env-key');
|
|
var jsKey = envKeyMap[tableKey];
|
|
if (jsKey && !window['__hasEnv_' + jsKey]) {
|
|
label.classList.add('disabled');
|
|
var cb = label.querySelector('input');
|
|
if (cb) { cb.checked = false; cb.disabled = true; }
|
|
}
|
|
});
|
|
}
|
|
|
|
// Generate Markdown based on current checkbox state
|
|
function generateMarkdown() {
|
|
var parts = [];
|
|
var checkboxes = document.querySelectorAll('#debug-toolbar input[type="checkbox"]:not(:disabled)');
|
|
checkboxes.forEach(function(cb) {
|
|
if (cb.checked) {
|
|
var key = cb.getAttribute('data-key');
|
|
if (key && mdFragments[key]) {
|
|
parts.push(mdFragments[key]);
|
|
}
|
|
}
|
|
});
|
|
var content = parts.join('\n');
|
|
// Path replacement
|
|
if (currentPathMode === 'simple' && rootPathEscaped) {
|
|
var regex = new RegExp(rootPathEscaped, 'gi');
|
|
content = content.replace(regex, '.../');
|
|
}
|
|
return content;
|
|
}
|
|
|
|
// Copy to clipboard
|
|
window.copyToClipboard = function() {
|
|
var content = generateMarkdown();
|
|
if (!content.trim()) {
|
|
alert('请至少勾选一个内容选项');
|
|
return;
|
|
}
|
|
var btn = document.getElementById('btn-copy');
|
|
if (navigator.clipboard) {
|
|
navigator.clipboard.writeText(content).then(function() {
|
|
btn.textContent = '已复制';
|
|
btn.classList.add('copied');
|
|
setTimeout(function() {
|
|
btn.textContent = '复制给AI';
|
|
btn.classList.remove('copied');
|
|
}, 2000);
|
|
}, function(err) {
|
|
alert('复制失败: ' + err);
|
|
});
|
|
} else {
|
|
var textarea = document.createElement('textarea');
|
|
textarea.value = content;
|
|
textarea.style.position = 'fixed';
|
|
textarea.style.left = '-9999px';
|
|
document.body.appendChild(textarea);
|
|
textarea.select();
|
|
try {
|
|
document.execCommand('copy');
|
|
btn.textContent = '已复制';
|
|
btn.classList.add('copied');
|
|
setTimeout(function() {
|
|
btn.textContent = '复制给AI';
|
|
btn.classList.remove('copied');
|
|
}, 2000);
|
|
} catch (err) {
|
|
alert('复制失败');
|
|
}
|
|
document.body.removeChild(textarea);
|
|
}
|
|
saveCheckboxState();
|
|
};
|
|
|
|
// Toggle Markdown preview
|
|
window.togglePreview = function() {
|
|
var preview = document.getElementById('markdown-preview');
|
|
var btn = document.getElementById('btn-preview');
|
|
if (preview.style.display === 'none' || !preview.style.display) {
|
|
var content = generateMarkdown();
|
|
document.getElementById('markdown-content').textContent = content;
|
|
preview.style.display = 'block';
|
|
btn.textContent = '关闭预览';
|
|
btn.classList.add('active');
|
|
} else {
|
|
preview.style.display = 'none';
|
|
btn.textContent = '预览';
|
|
btn.classList.remove('active');
|
|
}
|
|
};
|
|
|
|
// Toggle path mode
|
|
window.togglePathMode = function() {
|
|
var btn = document.getElementById('btn-path');
|
|
if (currentPathMode === 'simple') {
|
|
currentPathMode = 'full';
|
|
btn.textContent = '路径:完整';
|
|
btn.classList.add('active');
|
|
} else {
|
|
currentPathMode = 'simple';
|
|
btn.textContent = '路径:简洁';
|
|
btn.classList.remove('active');
|
|
}
|
|
updatePreviewIfOpen();
|
|
};
|
|
|
|
// Toggle toolbar on mobile
|
|
window.toggleToolbar = function() {
|
|
var toolbar = document.getElementById('debug-toolbar');
|
|
var toggleBtn = document.getElementById('debug-toolbar-toggle');
|
|
if (toolbar.classList.contains('toolbar-open')) {
|
|
toolbar.classList.remove('toolbar-open');
|
|
toggleBtn.innerHTML = '☰';
|
|
} else {
|
|
toolbar.classList.add('toolbar-open');
|
|
toggleBtn.innerHTML = '×';
|
|
}
|
|
};
|
|
})();
|
|
</script>
|
|
<?php } ?>
|
|
</body>
|
|
</html>
|