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 @@ - -
+
{foreach name="{%fieldList%}" item="vo"} {/foreach} -
+
\ No newline at end of file diff --git a/application/admin/command/Crud/stubs/html/select.stub b/application/admin/command/Crud/stubs/html/select.stub index b55baaaf..f3e4552c 100644 --- a/application/admin/command/Crud/stubs/html/select.stub +++ b/application/admin/command/Crud/stubs/html/select.stub @@ -1,6 +1,5 @@ - + \ No newline at end of file diff --git a/application/admin/command/Crud/stubs/index.stub b/application/admin/command/Crud/stubs/index.stub index 3c80ea8f..288affb3 100644 --- a/application/admin/command/Crud/stubs/index.stub +++ b/application/admin/command/Crud/stubs/index.stub @@ -6,10 +6,10 @@
-
diff --git a/application/admin/command/Crud/stubs/javascript.stub b/application/admin/command/Crud/stubs/javascript.stub index d633d786..0e420a20 100644 --- a/application/admin/command/Crud/stubs/javascript.stub +++ b/application/admin/command/Crud/stubs/javascript.stub @@ -32,7 +32,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin sortName: '{%order%}', exportTypes: ['csv', 'excel'], exportOptions: { - fileName: '{%controllerUrl%}_' + [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'), + fileName: '{%modelTableTypeName%}_' + [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'), ignoreColumn: [0, 'operate'], //默认不导出第一列(checkbox)与操作(operate)列 }, columns: [ diff --git a/application/admin/command/Crud/stubs/model.stub b/application/admin/command/Crud/stubs/model.stub index c08152b0..0a01586a 100755 --- a/application/admin/command/Crud/stubs/model.stub +++ b/application/admin/command/Crud/stubs/model.stub @@ -8,21 +8,21 @@ class {%modelName%} extends Model { // 表名 protected ${%modelTableType%} = '{%modelTableTypeName%}'; - + // 自动写入时间戳字段 protected $autoWriteTimestamp = {%modelAutoWriteTimestamp%}; // 定义时间戳字段名 protected $createTime = {%createTime%}; protected $updateTime = {%updateTime%}; - + // 追加属性 protected $append = [ {%appendAttrList%} ]; - + {%modelInit%} - + {%getEnumList%} {%getAttrList%}