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 @@ - -