美化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 {
@ -992,7 +1006,7 @@ EOD;
} }
$resultArr = []; $resultArr = [];
foreach ($itemArr as $k => $v) { foreach ($itemArr as $k => $v) {
$resultArr[] = " '" . mb_ucfirst($k) . "' => '{$v}'"; $resultArr[] = " '" . mb_ucfirst($k) . "' => '{$v}'";
} }
return implode(",\n", $resultArr); return implode(",\n", $resultArr);
} else { } else {

View File

@ -11,7 +11,7 @@ use app\common\controller\Backend;
*/ */
class {%controllerName%} extends Backend class {%controllerName%} extends Backend
{ {
/** /**
* {%modelName%}模型对象 * {%modelName%}模型对象
*/ */

View File

@ -1,6 +1,5 @@
<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}
</div> </div>

View File

@ -1,6 +1,5 @@
<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>
{/foreach} {/foreach}
</select> </select>

View File

@ -6,10 +6,10 @@
<div class="tab-pane fade active in" id="one"> <div class="tab-pane fade active in" id="one">
<div class="widget-body no-padding"> <div class="widget-body no-padding">
<div id="toolbar" class="toolbar"> <div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}"><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('{%controllerUrl%}/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('{%controllerUrl%}/add')?'':'hide'}" title="{:__('Add')}"><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('{%controllerUrl%}/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a> <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('{%controllerUrl%}/edit')?'':'hide'}" title="{:__('Edit')}"><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('{%controllerUrl%}/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a> <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('{%controllerUrl%}/del')?'':'hide'}" title="{:__('Delete')}"><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('{%controllerUrl%}/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>--> <!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('{%controllerUrl%}/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>-->
<div class="dropdown btn-group {:$auth->check('{%controllerUrl%}/multi')?'':'hide'}"> <div class="dropdown btn-group {:$auth->check('{%controllerUrl%}/multi')?'':'hide'}">
@ -20,9 +20,9 @@
</ul> </ul>
</div> </div>
</div> </div>
<table id="table" class="table table-striped table-bordered table-hover" <table id="table" class="table table-striped table-bordered table-hover"
data-operate-edit="{:$auth->check('{%controllerUrl%}/edit')}" data-operate-edit="{:$auth->check('{%controllerUrl%}/edit')}"
data-operate-del="{:$auth->check('{%controllerUrl%}/del')}" data-operate-del="{:$auth->check('{%controllerUrl%}/del')}"
width="100%"> width="100%">
</table> </table>
</div> </div>

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: [

View File

@ -8,21 +8,21 @@ class {%modelName%} extends Model
{ {
// 表名 // 表名
protected ${%modelTableType%} = '{%modelTableTypeName%}'; protected ${%modelTableType%} = '{%modelTableTypeName%}';
// 自动写入时间戳字段 // 自动写入时间戳字段
protected $autoWriteTimestamp = {%modelAutoWriteTimestamp%}; protected $autoWriteTimestamp = {%modelAutoWriteTimestamp%};
// 定义时间戳字段名 // 定义时间戳字段名
protected $createTime = {%createTime%}; protected $createTime = {%createTime%};
protected $updateTime = {%updateTime%}; protected $updateTime = {%updateTime%};
// 追加属性 // 追加属性
protected $append = [ protected $append = [
{%appendAttrList%} {%appendAttrList%}
]; ];
{%modelInit%} {%modelInit%}
{%getEnumList%} {%getEnumList%}
{%getAttrList%} {%getAttrList%}