From 572bdc2eb7ab540d59d251719cc4cd5021a7b283 Mon Sep 17 00:00:00 2001 From: PPPSCN <35696959@qq.com> Date: Tue, 17 Apr 2018 16:29:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8E=E5=8C=96crud=E7=94=9F=E6=88=90?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Crud.php | 18 ++++++++++++++++-- .../admin/command/Crud/stubs/controller.stub | 2 +- .../admin/command/Crud/stubs/html/radio.stub | 5 ++--- .../admin/command/Crud/stubs/html/select.stub | 3 +-- .../admin/command/Crud/stubs/index.stub | 14 +++++++------- .../admin/command/Crud/stubs/javascript.stub | 2 +- .../admin/command/Crud/stubs/model.stub | 8 ++++---- 7 files changed, 32 insertions(+), 20 deletions(-) diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index 15222d96..db41cedc 100755 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -103,6 +103,11 @@ class Crud extends Command */ protected $editorClass = 'editor'; + /** + * langList的key最长字节数 + */ + protected $fieldMaxLen = 0; + protected function configure() { $this @@ -698,7 +703,14 @@ class Crud extends Command $addList = implode("\n", array_filter($addList)); $editList = implode("\n", array_filter($editList)); $javascriptList = implode(",\n", array_filter($javascriptList)); - $langList = implode(",\n", array_filter($langList)); + //数组等号对齐 + foreach ($langList as &$line) { + if (preg_match("/^\s+'([^']+)'\s*=>\s*'([^']+)'\s*/is", $line, $matches)) { + $line = " '{$matches[1]}'" . str_pad('=>', ($this->fieldMaxLen - strlen($matches[1]) + 3), ' ', STR_PAD_LEFT) . " '{$matches[2]}'"; + } + } + unset($line); + $langList = implode(",\n", array_filter($langList)) . ','; //表注释 $tableComment = $modelTableInfo['Comment']; @@ -976,6 +988,7 @@ EOD; { if ($content || !Lang::has($field)) { $itemArr = []; + $this->fieldMaxLen = strlen($field) > $this->fieldMaxLen ? strlen($field) : $this->fieldMaxLen; $content = str_replace(',', ',', $content); if (stripos($content, ':') !== false && stripos($content, ',') && stripos($content, '=') !== false) { list($fieldLang, $item) = explode(':', $content); @@ -985,6 +998,7 @@ EOD; if (count($valArr) == 2) { list($key, $value) = $valArr; $itemArr[$field . ' ' . $key] = $value; + $this->fieldMaxLen = strlen($field . ' ' . $key) > $this->fieldMaxLen ? strlen($field . ' ' . $key) : $this->fieldMaxLen; } } } else { @@ -992,7 +1006,7 @@ EOD; } $resultArr = []; foreach ($itemArr as $k => $v) { - $resultArr[] = " '" . mb_ucfirst($k) . "' => '{$v}'"; + $resultArr[] = " '" . mb_ucfirst($k) . "' => '{$v}'"; } return implode(",\n", $resultArr); } else { diff --git a/application/admin/command/Crud/stubs/controller.stub b/application/admin/command/Crud/stubs/controller.stub index ee83f115..9b0d2d1d 100644 --- a/application/admin/command/Crud/stubs/controller.stub +++ b/application/admin/command/Crud/stubs/controller.stub @@ -11,7 +11,7 @@ use app\common\controller\Backend; */ class {%controllerName%} extends Backend { - + /** * {%modelName%}模型对象 */ diff --git a/application/admin/command/Crud/stubs/html/radio.stub b/application/admin/command/Crud/stubs/html/radio.stub index a3c7b2ec..605cc9d6 100644 --- a/application/admin/command/Crud/stubs/html/radio.stub +++ b/application/admin/command/Crud/stubs/html/radio.stub @@ -1,6 +1,5 @@ - -