From 2ecae60d86f869f51c4280166f9e54eb5f13acf1 Mon Sep 17 00:00:00 2001 From: Karson Date: Sun, 1 Apr 2018 15:12:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BC=80=E5=8F=91=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E6=9C=AA=E6=98=BE=E7=A4=BA=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84BUG=20=E4=BF=AE=E5=A4=8DAPI=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=B3=A8=E9=87=8A=E6=97=A0=E6=95=88=E7=9A=84BUG=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DAPI=E6=96=87=E6=A1=A3=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=8F=82=E6=95=B0=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/command/Api/library/Extractor.php | 6 +- .../admin/command/Api/template/index.html | 18 ++- .../common/view/tpl/think_exception.tpl | 142 +++++++++--------- extend/fast/Date.php | 1 + extend/fast/Form.php | 7 + public/api.html | 24 +-- 6 files changed, 110 insertions(+), 88 deletions(-) diff --git a/application/admin/command/Api/library/Extractor.php b/application/admin/command/Api/library/Extractor.php index bf16eb00..49bdf282 100644 --- a/application/admin/command/Api/library/Extractor.php +++ b/application/admin/command/Api/library/Extractor.php @@ -322,7 +322,6 @@ class Extractor if (preg_match_all('/@(?[A-Za-z_-]+)[\s\t]*\((?(?:(?!\)).)*)\)\r?/s', $docblock, $matches)) { $numMatches = count($matches[0]); - for ($i = 0; $i < $numMatches; ++$i) { // annotations has arguments @@ -330,7 +329,12 @@ class Extractor { $argsParts = trim($matches['args'][$i]); $name = $matches['name'][$i]; + $argsParts = preg_replace("/\{(\w+)\}/", '#$1#', $argsParts); $value = self::parseArgs($argsParts); + if(is_string($value)) + { + $value = preg_replace("/\#(\w+)\#/", '{$1}', $argsParts); + } } else { diff --git a/application/admin/command/Api/template/index.html b/application/admin/command/Api/template/index.html index ca21bbd2..aaa73b3d 100755 --- a/application/admin/command/Api/template/index.html +++ b/application/admin/command/Api/template/index.html @@ -382,27 +382,31 @@ //instead of the initial attribute var url = $(form).attr('action'); - var serializedData = new FormData(); + var formData = new FormData(); $(form).find('input').each(function (i, input) { if ($(input).attr('type') == 'file') { - serializedData.append($(input).attr('name'), $(input)[0].files[0]); + formData.append($(input).attr('name'), $(input)[0].files[0]); } else { - serializedData.append($(input).attr('name'), $(input).val()) + formData.append($(input).attr('name'), $(input).val()) } }); var index, key, value; if (matchedParamsInRoute) { + var params = {}; + formData.forEach(function(value, key){ + params[key] = value; + }); for (index = 0; index < matchedParamsInRoute.length; ++index) { try { key = matchedParamsInRoute[index]; - value = serializedData[key]; + value = params[key]; if (typeof value == "undefined") value = ""; - url = url.replace("{" + key + "}", value); - delete serializedData[key]; + url = url.replace("\{" + key + "\}", value); + formData.delete(key); } catch (err) { console.log(err); } @@ -425,7 +429,7 @@ $.ajax({ url: $('#apiUrl').val() + url, - data: $(form).attr('method') == 'get' ? $(form).serialize() : serializedData, + data: $(form).attr('method') == 'get' ? $(form).serialize() : formData, type: $(form).attr('method') + '', dataType: 'json', contentType: false, diff --git a/application/common/view/tpl/think_exception.tpl b/application/common/view/tpl/think_exception.tpl index 7ab0ccce..20fccf65 100755 --- a/application/common/view/tpl/think_exception.tpl +++ b/application/common/view/tpl/think_exception.tpl @@ -1,6 +1,7 @@ '发生错误', @@ -17,83 +18,84 @@ if (isset($_GET['lang'])) { } elseif (isset($_COOKIE['think_var'])) { $langSet = strtolower($_COOKIE['think_var']); } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { - preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches); +preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches); $langSet = strtolower($matches[1]); } $langSet = $langSet && in_array($langSet, ['zh-cn', 'en']) ? $langSet : 'zh-cn'; $langSet == 'en' && $lang = array_combine(array_keys($lang), array_keys($lang)); + ?> - - - <?=$lang['An error occurred']?> - - - - - - -
-
- -
-
- -
-
-
+ + + <?=$lang['An error occurred']?> + + + + + + +
+
+ +
+
+ +
+
+
-

- -

+

+ +

-
-
- - -
-
- +
+
+ + +
+
+ \ No newline at end of file diff --git a/extend/fast/Date.php b/extend/fast/Date.php index b468b9fa..f592a4f5 100644 --- a/extend/fast/Date.php +++ b/extend/fast/Date.php @@ -62,6 +62,7 @@ class Date * @param string $output formatting string * @return string when only a single output is requested * @return array associative list of all outputs requested + * @from https://github.com/kohana/ohanzee-helpers/blob/master/src/Date.php */ public static function span($remote, $local = NULL, $output = 'years,months,weeks,days,hours,minutes,seconds') { diff --git a/extend/fast/Form.php b/extend/fast/Form.php index e76c1864..e503f098 100644 --- a/extend/fast/Form.php +++ b/extend/fast/Form.php @@ -5,6 +5,7 @@ namespace fast; use ArrayAccess; /** + * 表单元素生成 * @class Form * @package fast * @method mixed token() static token @@ -45,6 +46,12 @@ class Form } +/** + * + * 表单元素生成 + * @from https://github.com/illuminate/html + * @package fast + */ class FormBuilder { diff --git a/public/api.html b/public/api.html index 421c59f1..d45f6f80 100755 --- a/public/api.html +++ b/public/api.html @@ -33,7 +33,7 @@ - FastAdmin + FastAdmin @@ -3476,27 +3476,31 @@ //instead of the initial attribute var url = $(form).attr('action'); - var serializedData = new FormData(); + var formData = new FormData(); $(form).find('input').each(function (i, input) { if ($(input).attr('type') == 'file') { - serializedData.append($(input).attr('name'), $(input)[0].files[0]); + formData.append($(input).attr('name'), $(input)[0].files[0]); } else { - serializedData.append($(input).attr('name'), $(input).val()) + formData.append($(input).attr('name'), $(input).val()) } }); var index, key, value; if (matchedParamsInRoute) { + var params = {}; + formData.forEach(function(value, key){ + params[key] = value; + }); for (index = 0; index < matchedParamsInRoute.length; ++index) { try { key = matchedParamsInRoute[index]; - value = serializedData[key]; + value = params[key]; if (typeof value == "undefined") value = ""; - url = url.replace("{" + key + "}", value); - delete serializedData[key]; + url = url.replace("\{" + key + "\}", value); + formData.delete(key); } catch (err) { console.log(err); } @@ -3519,7 +3523,7 @@ $.ajax({ url: $('#apiUrl').val() + url, - data: $(form).attr('method') == 'get' ? $(form).serialize() : serializedData, + data: $(form).attr('method') == 'get' ? $(form).serialize() : formData, type: $(form).attr('method') + '', dataType: 'json', contentType: false,