Anyon 4 vuotta sitten
vanhempi
commit
60a59b1601
2 muutettua tiedostoa jossa 232 lisäystä ja 245 poistoa
  1. 224 233
      app/admin/view/error.tpl
  2. 8 12
      public/static/admin.js

+ 224 - 233
app/admin/view/error.tpl

@@ -13,80 +13,80 @@ if (!function_exists('parse_class')) {
     {
         $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>';
-}
+    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;
-}
+    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 : "'{$key}' => {$value}";
-}
+            $result[] = is_int($key) ? $value : "'{$key}' => {$value}";
+        }
 
-return implode(', ', $result);
-}
+        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';
-}
-}
+    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>
@@ -161,8 +161,8 @@ echo 'Resource';
         }
 
         .echo pre > pre {
-            padding: 0;
             margin: 0;
+            padding: 0;
         }
 
         /* Exception Info */
@@ -171,11 +171,11 @@ echo 'Resource';
         }
 
         .exception .message {
-            padding: 12px;
             border: 1px solid #ddd;
-            border-bottom: 0 none;
-            line-height: 18px;
+            padding: 12px;
             font-size: 16px;
+            line-height: 18px;
+            border-bottom: 0 none;
             border-top-left-radius: 4px;
             border-top-right-radius: 4px;
             font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif;
@@ -192,12 +192,10 @@ echo 'Resource';
         }
 
         .exception .source-code {
-            padding: 6px;
             border: 1px solid #ddd;
-
-            background: #f9f9f9;
+            padding: 6px;
             overflow-x: auto;
-
+            background: #f9f9f9;
         }
 
         .exception .source-code pre {
@@ -209,25 +207,24 @@ echo 'Resource';
             color: #4288ce;
             display: inline-block;
             min-width: 100%;
-            box-sizing: border-box;
             font-size: 14px;
+            box-sizing: border-box;
             font-family: "Century Gothic", Consolas, "Liberation Mono", Courier, Verdana, serif;
-            padding-left: < ? php echo (isset($ source) & & ! empty($ source)) ? parse_padding($ source): 40;
-            ? > px;
+            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;
+            border-left: 1px solid #ddd;
         }
 
         .exception .source-code pre code {
             color: #333;
             height: 100%;
+            font-size: 14px;
             display: inline-block;
             border-left: 1px solid #fff;
-            font-size: 14px;
             font-family: Consolas, "Liberation Mono", Courier, Verdana, "微软雅黑", serif;
         }
 
@@ -374,28 +371,37 @@ echo 'Resource';
 </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>
+    <?php if (isset($traces)) 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>
-            <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}-" . ($key + $trace['source']['first']) . ($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
+            <?php if (!empty($trace['source'])) { ?>
+                <div class="source-code">
+                    <pre class="prettyprint lang-php">
+                        <?php
+                        echo "<ol start='{$trace['source']['first']}'>";
+                        foreach ((array)$trace['source']['source'] as $key => $value) {
+                            $class = " {$index}-" . ($key + $trace['source']['first']) . ($trace['line'] === $key + $trace['source']['first'] ? ' line-error' : '');
+                            echo "<li class='{$class}'><code>" . htmlentities($value) . "</code></li>";
+                        }
+                        echo "</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(
@@ -406,169 +412,154 @@ echo 'Resource';
                                     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 } ?>
+                        </li>
+                    <?php } ?>
+                </ol>
+            </div>
+        </div>
+    <?php } ?>
 <?php } else { ?>
-<div class="exception">
-    <div class="info"><h1><?php echo htmlentities($message); ?></h1></div>
-</div>
+    <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>
+    <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 } ?>
-    </table>
-    <?php } ?>
-</div>
+    </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>
+    <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 } ?>
-        </tbody>
-        <?php } ?>
-    </table>
-    <?php } ?>
-</div>
+    </div>
 <?php } ?>
 
 <?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|$)');
-
+    <script>
+        function $(selector, node) {
+            var elements;
             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])
+            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;
-        }
-    }
-
-    $.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 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;
             }
         }
 
-        (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 (折叠)';
-                }
+        $.getScript = function (src, func) {
+            var script = document.createElement('script');
+            script.src = src;
+            script.async = 'async';
+            script.onload = func || function () {
             };
-            var traces = $('.trace');
-            for (var i = 0; i < traces.length; i++) {
-                var h2 = $('h2', traces[i])[0];
-                expand(h2);
-                h2.onclick = function () {
-                    expand(this);
-                };
+            $('head')[0].appendChild(script);
+        }
+
+        ;(function () {
+            var files = $('.toggle');
+            // 短路径和长路径变换
+            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.bootcss.com/prettify/r298/prettify.min.js', function () {
-            prettyPrint();
-        });
-    })();
-</script>
+            $.getScript('//cdn.bootcss.com/prettify/r298/prettify.min.js', function () {
+                prettyPrint();
+            });
+        })();
+    </script>
 <?php } ?>
 </body>
 </html>

+ 8 - 12
public/static/admin.js

@@ -36,8 +36,8 @@ require.config({
         'michat': ['plugs/michat/michat'],
         'base64': ['plugs/jquery/base64.min'],
         'upload': [tapiRoot + '/api.upload?.js'],
-        'echarts': ['plugs/echarts/echarts.min'],
         'angular': ['plugs/angular/angular.min'],
+        'echarts': ['plugs/echarts/echarts.min'],
         'ckeditor': ['plugs/ckeditor/ckeditor'],
         'websocket': ['plugs/socket/websocket'],
         'pcasunzips': ['plugs/jquery/pcasunzips'],
@@ -474,15 +474,14 @@ $(function () {
 
     /*! 表单转JSON */
     $.fn.formToJson = function () {
-        var self = this, data = {}, pushCounters = {};
+        var self = this, data = {}, push = {};
         var patterns = {"key": /[a-zA-Z0-9_]+|(?=\[\])/g, "push": /^$/, "fixed": /^\d+$/, "named": /^[a-zA-Z0-9_]+$/};
         this.build = function (base, key, value) {
-            base[key] = value;
-            return base;
+            return (base[key] = value), base;
         };
         this.pushCounter = function (name) {
-            if (pushCounters[name] === undefined) pushCounters[name] = 0;
-            return pushCounters[name]++;
+            if (push[name] === undefined) push[name] = 0;
+            return push[name]++;
         };
         $.each($(this).serializeArray(), function () {
             var key, keys = this.name.match(patterns.key), merge = this.value, name = this.name;
@@ -601,8 +600,7 @@ $(function () {
     $body.on('click', '[data-check-target]', function () {
         var checked = !!this.checked;
         $($(this).attr('data-check-target')).map(function () {
-            this.checked = checked;
-            $(this).trigger('change');
+            (this.checked = checked), $(this).trigger('change');
         });
     });
 
@@ -642,8 +640,7 @@ $(function () {
             data[attrs[i].split('#')[0]] = attrs[i].split('#')[1];
         }
         that.callback = function (ret) {
-            $this.css('border', (ret && ret.code) ? '1px solid #e6e6e6' : '1px solid red');
-            return false;
+            return $this.css('border', (ret && ret.code) ? '1px solid #e6e6e6' : '1px solid red'), false;
         };
         data['_token_'] = $this.attr('data-token') || $this.attr('data-csrf') || '--';
         if (!confirm) return $.form.load(action, data, method, that.callback, load, tips, time);
@@ -734,8 +731,7 @@ $(function () {
     $body.on('click', '[data-history-back]', function (title) {
         title = this.getAttribute('data-history-back') || '确定要返回上一页吗?';
         $.msg.confirm(title, function (index) {
-            history.back();
-            $.msg.close(index);
+            history.back(), $.msg.close(index);
         })
     });