美化crud生成的代码格式

pull/71/head
PPPSCN 2018-04-17 16:29:17 +08:00
parent 8074c83bbf
commit 572bdc2eb7
7 changed files with 32 additions and 20 deletions

View File

@ -103,6 +103,11 @@ class Crud extends Command
*/ */
protected $editorClass = 'editor'; protected $editorClass = 'editor';
/**
* langList的key最长字节数
*/
protected $fieldMaxLen = 0;
protected function configure() protected function configure()
{ {
$this $this
@ -698,7 +703,14 @@ class Crud extends Command
$addList = implode("\n", array_filter($addList)); $addList = implode("\n", array_filter($addList));
$editList = implode("\n", array_filter($editList)); $editList = implode("\n", array_filter($editList));
$javascriptList = implode(",\n", array_filter($javascriptList)); $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']; $tableComment = $modelTableInfo['Comment'];
@ -976,6 +988,7 @@ EOD;
{ {
if ($content || !Lang::has($field)) { if ($content || !Lang::has($field)) {
$itemArr = []; $itemArr = [];
$this->fieldMaxLen = strlen($field) > $this->fieldMaxLen ? strlen($field) : $this->fieldMaxLen;
$content = str_replace('', ',', $content); $content = str_replace('', ',', $content);
if (stripos($content, ':') !== false && stripos($content, ',') && stripos($content, '=') !== false) { if (stripos($content, ':') !== false && stripos($content, ',') && stripos($content, '=') !== false) {
list($fieldLang, $item) = explode(':', $content); list($fieldLang, $item) = explode(':', $content);
@ -985,6 +998,7 @@ EOD;
if (count($valArr) == 2) { if (count($valArr) == 2) {
list($key, $value) = $valArr; list($key, $value) = $valArr;
$itemArr[$field . ' ' . $key] = $value; $itemArr[$field . ' ' . $key] = $value;
$this->fieldMaxLen = strlen($field . ' ' . $key) > $this->fieldMaxLen ? strlen($field . ' ' . $key) : $this->fieldMaxLen;
} }
} }
} else { } else {

View File

@ -1,5 +1,4 @@
<div class="radio" id="c-{field}">
<div class="radio">
{foreach name="{%fieldList%}" item="vo"} {foreach name="{%fieldList%}" item="vo"}
<label for="{%fieldName%}-{$key}"><input id="{%fieldName%}-{$key}" name="{%fieldName%}" type="radio" value="{$key}" {in name="key" value="{%selectedValue%}"}checked{/in} /> {$vo}</label> <label for="{%fieldName%}-{$key}"><input id="{%fieldName%}-{$key}" name="{%fieldName%}" type="radio" value="{$key}" {in name="key" value="{%selectedValue%}"}checked{/in} /> {$vo}</label>
{/foreach} {/foreach}

View File

@ -1,4 +1,3 @@
<select {%attrStr%}> <select {%attrStr%}>
{foreach name="{%fieldList%}" item="vo"} {foreach name="{%fieldList%}" item="vo"}
<option value="{$key}" {in name="key" value="{%selectedValue%}"}selected{/in}>{$vo}</option> <option value="{$key}" {in name="key" value="{%selectedValue%}"}selected{/in}>{$vo}</option>

View File

@ -32,7 +32,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
sortName: '{%order%}', sortName: '{%order%}',
exportTypes: ['csv', 'excel'], exportTypes: ['csv', 'excel'],
exportOptions: { 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)列 ignoreColumn: [0, 'operate'], //默认不导出第一列(checkbox)与操作(operate)列
}, },
columns: [ columns: [